mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-15 08:22:37 +01:00
Code renames
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { Operand, ListOfNumbersExpression, SingleOperandExpression, MultipleOperandsExpression } from '../../expression';
|
||||
import { Operand, ListOfNumbersExpression, ExpressionOperand, MultipleOperandsExpression } from '../../expression';
|
||||
import formatter from '../../formatter';
|
||||
import BinaryStringView from './BinaryStringView';
|
||||
import BitwiseExpressionViewModel from './models/BitwiseExpressionViewModel';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Operand, SingleOperandExpression } from '../../../expression';
|
||||
import { Operand, ExpressionOperand } from '../../../expression';
|
||||
|
||||
export default class BitwiseExpressionViewModel {
|
||||
|
||||
@@ -74,12 +74,12 @@ export default class BitwiseExpressionViewModel {
|
||||
};
|
||||
|
||||
addExpression(expression) {
|
||||
this.maxNumberOfBits = Math.max(expression.operand1.apply().getLengthInBits(), this.maxNumberOfBits);
|
||||
this.maxNumberOfBits = Math.max(expression.operand.apply().getLengthInBits(), this.maxNumberOfBits);
|
||||
|
||||
this.items.push({
|
||||
sign: expression.sign,
|
||||
label: this.getLabel(expression.operand1),
|
||||
operand: expression.operand1,
|
||||
label: this.getLabel(expression.operand),
|
||||
operand: expression.operand,
|
||||
allowFlipBits: this.allowFlipBits
|
||||
});
|
||||
};
|
||||
@@ -87,7 +87,7 @@ export default class BitwiseExpressionViewModel {
|
||||
addShiftExpressionResult(expression, resultOperand) {
|
||||
this.maxNumberOfBits = Math.max(resultOperand.getLengthInBits(), this.maxNumberOfBits);
|
||||
this.items.push({
|
||||
sign: expression.sign + expression.operand1.toString(),
|
||||
sign: expression.sign + expression.operand.toString(),
|
||||
css: 'expression-result',
|
||||
operand: resultOperand,
|
||||
allowFlipBits: false
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Operand from './expression/Operand';
|
||||
import SingleOperandExpression from './expression/SingleOperandExpression'
|
||||
import ExpressionOperand from './expression/ExpressionOperand'
|
||||
|
||||
export { default as Operand } from './expression/Operand';
|
||||
export { default as ExpressionError } from './expression/ExpressionError';
|
||||
export { default as SingleOperandExpression } from './expression/SingleOperandExpression';
|
||||
export { default as ExpressionOperand } from './expression/ExpressionOperand';
|
||||
|
||||
var expression = {
|
||||
factories:[],
|
||||
@@ -90,7 +90,7 @@ var expression = {
|
||||
|
||||
var op = null;
|
||||
if(num.indexOf('~') == '0') {
|
||||
op = new SingleOperandExpression(input, Operand.parse(num.substring(1)), '~');
|
||||
op = new ExpressionOperand(input, Operand.parse(num.substring(1)), '~');
|
||||
}
|
||||
else {
|
||||
op = Operand.parse(num);
|
||||
@@ -99,7 +99,7 @@ var expression = {
|
||||
if(sign == null) {
|
||||
return op;
|
||||
} else {
|
||||
return new SingleOperandExpression(input, op, sign);
|
||||
return new ExpressionOperand(input, op, sign);
|
||||
}
|
||||
},
|
||||
normalizeString: function (string) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import Operand from './Operand';
|
||||
|
||||
export default class SingleOperandExpression {
|
||||
export default class ExpressionOperand {
|
||||
constructor(expressionString, operand, sign) {
|
||||
this.expressionString = expressionString;
|
||||
this.operand1 = operand;
|
||||
this.operand = operand;
|
||||
this.sign = sign;
|
||||
this.isExpression = true;
|
||||
this.isShiftExpression = this.sign.indexOf('<') >= 0 || this.sign.indexOf('>')>= 0;
|
||||
@@ -11,7 +11,7 @@ export default class SingleOperandExpression {
|
||||
}
|
||||
|
||||
apply(operand) {
|
||||
if (operand instanceof SingleOperandExpression) {
|
||||
if (operand instanceof ExpressionOperand) {
|
||||
console.error("value shouldnt be expression", value);
|
||||
throw new Error('value shouldnt be expression');
|
||||
}
|
||||
@@ -20,21 +20,21 @@ export default class SingleOperandExpression {
|
||||
|
||||
var str = '';
|
||||
if(this.sign == '~'){
|
||||
str = '~' + this.operand1.apply().value;
|
||||
str = '~' + this.operand.apply().value;
|
||||
} else {
|
||||
str = operand.value + this.sign + this.operand1.apply().value;
|
||||
str = operand.value + this.sign + this.operand.apply().value;
|
||||
}
|
||||
|
||||
console.log('eval:' + str, this);
|
||||
const resultValue = eval(str);
|
||||
|
||||
var resultOp = Operand.create(eval(str), this.operand1.kind || this.operand1.operand1.kind);
|
||||
var resultOp = Operand.create(eval(str), this.operand.kind || this.operand.operand.kind);
|
||||
console.log(resultValue, resultOp);
|
||||
|
||||
return resultOp;
|
||||
};
|
||||
|
||||
toString() {
|
||||
return this.sign + this.operand1.toString();
|
||||
return this.sign + this.operand.toString();
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,16 @@ describe("expression parser", function() {
|
||||
});
|
||||
|
||||
var expressionCases = {
|
||||
"0x2>>1": { operand1: 2, operand2:1, "sign":">>", string:"0x2>>1" },
|
||||
"123|111": { operand1: 123, operand2:111, "sign":"|", string: "123|111" },
|
||||
"23^0x1": { operand1: 23, operand2:1, "sign":"^", string: "23^0x1" },
|
||||
"0xf>>0xa": { operand1: 15, operand2:10, "sign":">>", string:"0xf>>0xa" },
|
||||
"0x10&0x11": { operand1: 0x10, operand2:0x11, "sign":"&", string:"0x10&0x11" },
|
||||
"0x1a^11": { operand1: 0x1a, operand2:11, "sign":"^", string:"0x1a^11" },
|
||||
"0x1a>>>11": { operand1: 0x1a, operand2:11, "sign":">>>", string:"0x1a>>>11" },
|
||||
'~3': { operand1: 3, operand2: null, "sign":"~", string:"~3" },
|
||||
'~0xa': { operand1: 0xa, operand2: null, "sign":"~", string:"~0xa" },
|
||||
'~-0xa': { operand1: -0xa, operand2: null, "sign":"~", string:"~-0xa" }
|
||||
"0x2>>1": { operand: 2, operand2:1, "sign":">>", string:"0x2>>1" },
|
||||
"123|111": { operand: 123, operand2:111, "sign":"|", string: "123|111" },
|
||||
"23^0x1": { operand: 23, operand2:1, "sign":"^", string: "23^0x1" },
|
||||
"0xf>>0xa": { operand: 15, operand2:10, "sign":">>", string:"0xf>>0xa" },
|
||||
"0x10&0x11": { operand: 0x10, operand2:0x11, "sign":"&", string:"0x10&0x11" },
|
||||
"0x1a^11": { operand: 0x1a, operand2:11, "sign":"^", string:"0x1a^11" },
|
||||
"0x1a>>>11": { operand: 0x1a, operand2:11, "sign":">>>", string:"0x1a>>>11" },
|
||||
'~3': { operand: 3, operand2: null, "sign":"~", string:"~3" },
|
||||
'~0xa': { operand: 0xa, operand2: null, "sign":"~", string:"~0xa" },
|
||||
'~-0xa': { operand: -0xa, operand2: null, "sign":"~", string:"~-0xa" }
|
||||
};
|
||||
|
||||
// TODO: update to support multiple expressions
|
||||
@@ -36,7 +36,7 @@ describe("expression parser", function() {
|
||||
// expect(actual).toBeDefined();
|
||||
// expect(actual).not.toBe(null);
|
||||
// expect(actual.sign).toBe(expected.sign);
|
||||
// expect(actual.operand1.value).toBe(expected.operand1);
|
||||
// expect(actual.operand.value).toBe(expected.operand);
|
||||
|
||||
// if(expected.operand2 != null) {
|
||||
// expect(actual.operand2.value).toBe(expected.operand2);
|
||||
|
||||
Reference in New Issue
Block a user