зеркало из https://github.com/mozilla/gecko-dev.git
Changing Token.POS, Token.NEG to represent their parser tree nodes by the token themselves, not via pair Token.UNARYOP, POS/NEG. It simplifies code especially in optimizer/Optimizer.java
This commit is contained in:
Родитель
9a1fbf3def
Коммит
09c327adc3
|
@ -601,8 +601,9 @@ public class Interpreter
|
|||
break;
|
||||
|
||||
case Token.POS:
|
||||
case Token.NEG :
|
||||
iCodeTop = generateICode(child, iCodeTop);
|
||||
iCodeTop = addToken(Token.POS, iCodeTop);
|
||||
iCodeTop = addToken(type, iCodeTop);
|
||||
break;
|
||||
|
||||
case Token.UNARYOP :
|
||||
|
@ -621,12 +622,6 @@ public class Interpreter
|
|||
case Token.TYPEOF :
|
||||
iCodeTop = addToken(Token.TYPEOF, iCodeTop);
|
||||
break;
|
||||
case Token.NEG :
|
||||
iCodeTop = addToken(Token.NEG, iCodeTop);
|
||||
break;
|
||||
case Token.POS :
|
||||
iCodeTop = addToken(Token.POS, iCodeTop);
|
||||
break;
|
||||
default:
|
||||
badTree(node);
|
||||
break;
|
||||
|
|
|
@ -1118,12 +1118,12 @@ class Parser {
|
|||
case Token.ADD:
|
||||
// Convert to special POS token in decompiler and parse tree
|
||||
decompiler.addToken(Token.POS);
|
||||
return nf.createUnary(Token.UNARYOP, Token.POS, unaryExpr(ts));
|
||||
return nf.createUnary(Token.POS, unaryExpr(ts));
|
||||
|
||||
case Token.SUB:
|
||||
// Convert to special NEG token in decompiler and parse tree
|
||||
decompiler.addToken(Token.NEG);
|
||||
return nf.createUnary(Token.UNARYOP, Token.NEG, unaryExpr(ts));
|
||||
return nf.createUnary(Token.NEG, unaryExpr(ts));
|
||||
|
||||
case Token.INC:
|
||||
case Token.DEC:
|
||||
|
|
|
@ -1281,10 +1281,14 @@ public class Codegen extends Interpreter {
|
|||
break;
|
||||
|
||||
case Token.POS:
|
||||
case Token.NEG:
|
||||
addByteCode(ByteCode.NEW, "java/lang/Double");
|
||||
addByteCode(ByteCode.DUP);
|
||||
generateCodeFromNode(child, node);
|
||||
addScriptRuntimeInvoke("toNumber", "(Ljava/lang/Object;)D");
|
||||
if (type == Token.NEG) {
|
||||
addByteCode(ByteCode.DNEG);
|
||||
}
|
||||
addDoubleConstructor();
|
||||
break;
|
||||
|
||||
|
@ -2324,18 +2328,6 @@ public class Codegen extends Interpreter {
|
|||
addDoubleConstructor();
|
||||
break;
|
||||
|
||||
case Token.POS:
|
||||
case Token.NEG:
|
||||
addByteCode(ByteCode.NEW, "java/lang/Double");
|
||||
addByteCode(ByteCode.DUP);
|
||||
generateCodeFromNode(child, node);
|
||||
addScriptRuntimeInvoke("toNumber", "(Ljava/lang/Object;)D");
|
||||
if (op == Token.NEG) {
|
||||
addByteCode(ByteCode.DNEG);
|
||||
}
|
||||
addDoubleConstructor();
|
||||
break;
|
||||
|
||||
default:
|
||||
badTree();
|
||||
}
|
||||
|
|
|
@ -795,12 +795,12 @@ class Optimizer
|
|||
}
|
||||
else if (lt == Token.NUMBER && lChild.getDouble() == 0) {
|
||||
// first 0: 0-x -> -x
|
||||
replace = new Node(Token.UNARYOP, rChild, Token.NEG);
|
||||
replace = new Node(Token.NEG, rChild);
|
||||
}
|
||||
else if (rt == Token.NUMBER && rChild.getDouble() == 0) {
|
||||
//second 0: x - 0 -> +x
|
||||
// can not make simply x because x - 0 must be number
|
||||
replace = new Node(Token.UNARYOP, lChild, Token.POS);
|
||||
replace = new Node(Token.POS, lChild);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -814,12 +814,12 @@ class Optimizer
|
|||
else if (lt == Token.NUMBER && lChild.getDouble() == 1) {
|
||||
// first 1: 1*x -> +x
|
||||
// not simply x to force number convertion
|
||||
replace = new Node(Token.UNARYOP, rChild, Token.POS);
|
||||
replace = new Node(Token.POS, rChild);
|
||||
}
|
||||
else if (rt == Token.NUMBER && rChild.getDouble() == 1) {
|
||||
// second 1: x*1 -> +x
|
||||
// not simply x to force number convertion
|
||||
replace = new Node(Token.UNARYOP, lChild, Token.POS);
|
||||
replace = new Node(Token.POS, lChild);
|
||||
}
|
||||
// can't do x*0: Infinity * 0 gives NaN, not 0
|
||||
break;
|
||||
|
@ -834,7 +834,7 @@ class Optimizer
|
|||
else if (rt == Token.NUMBER && rChild.getDouble() == 1) {
|
||||
// second 1: x/1 -> +x
|
||||
// not simply x to force number convertion
|
||||
replace = new Node(Token.UNARYOP, lChild, Token.POS);
|
||||
replace = new Node(Token.POS, lChild);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче