зеркало из https://github.com/mozilla/pjs.git
Using simple Token.<op> instead of (Token.EQOP, Token.<op>) to denote parser nodes for equality operations. It allowed to remove sharing of Node.intValue to mean line number and operation type so it was renamed to Node.lineno.
This commit is contained in:
Родитель
aa709dd3ba
Коммит
614d63535f
|
@ -74,11 +74,6 @@ public class IRFactory {
|
|||
return new Node(nodeType, nodeOp);
|
||||
}
|
||||
|
||||
public int getLeafType(Object leaf) {
|
||||
Node n = (Node) leaf;
|
||||
return n.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Statement leaf nodes.
|
||||
*/
|
||||
|
@ -168,13 +163,11 @@ public class IRFactory {
|
|||
* Break (possibly labeled)
|
||||
*/
|
||||
public Object createBreak(String label, int lineno) {
|
||||
Node result = new Node(Token.BREAK, lineno);
|
||||
if (label == null) {
|
||||
return result;
|
||||
return new Node(Token.BREAK, lineno);
|
||||
} else {
|
||||
Node name = Node.newString(Token.NAME, label);
|
||||
result.addChildToBack(name);
|
||||
return result;
|
||||
return new Node(Token.BREAK, name, lineno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,13 +175,11 @@ public class IRFactory {
|
|||
* Continue (possibly labeled)
|
||||
*/
|
||||
public Object createContinue(String label, int lineno) {
|
||||
Node result = new Node(Token.CONTINUE, lineno);
|
||||
if (label == null) {
|
||||
return result;
|
||||
return new Node(Token.CONTINUE, lineno);
|
||||
} else {
|
||||
Node name = Node.newString(Token.NAME, label);
|
||||
result.addChildToBack(name);
|
||||
return result;
|
||||
return new Node(Token.CONTINUE, name, lineno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,7 +335,7 @@ public class IRFactory {
|
|||
Node next = new Node(Token.ENUMNEXT);
|
||||
next.putProp(Node.ENUM_PROP, init);
|
||||
Node temp = createNewTemp(next);
|
||||
Node cond = new Node(Token.EQOP, Token.NE);
|
||||
Node cond = new Node(Token.NE);
|
||||
cond.addChildToBack(temp);
|
||||
cond.addChildToBack(new Node(Token.NULL));
|
||||
Node newBody = new Node(Token.BLOCK);
|
||||
|
@ -574,8 +565,7 @@ public class IRFactory {
|
|||
*/
|
||||
public Object createArrayLiteral(Object obj) {
|
||||
Node array;
|
||||
array = new Node(Token.NEW,
|
||||
Node.newString(Token.NAME, "Array"));
|
||||
array = new Node(Token.NEW, Node.newString(Token.NAME, "Array"));
|
||||
Node temp = createNewTemp(array);
|
||||
|
||||
Node elem = null;
|
||||
|
@ -790,12 +780,6 @@ public class IRFactory {
|
|||
// OPT: could optimize to GETPROP iff string can't be a number
|
||||
nodeType = Token.GETELEM;
|
||||
break;
|
||||
|
||||
case Token.EQ:
|
||||
case Token.NE:
|
||||
case Token.SHEQ:
|
||||
case Token.SHNE:
|
||||
return new Node(Token.EQOP, left, right, nodeType);
|
||||
}
|
||||
return new Node(nodeType, left, right);
|
||||
}
|
||||
|
|
|
@ -417,15 +417,6 @@ public class Interpreter
|
|||
markTargetLabel(node, iCodeTop);
|
||||
break;
|
||||
|
||||
case Token.EQOP :
|
||||
iCodeTop = generateICode(child, iCodeTop);
|
||||
child = child.getNext();
|
||||
iCodeTop = generateICode(child, iCodeTop);
|
||||
int op = node.getOperation();
|
||||
iCodeTop = addToken(op, iCodeTop);
|
||||
itsStackDepth--;
|
||||
break;
|
||||
|
||||
case Token.NEW :
|
||||
case Token.CALL : {
|
||||
int childCount = 0;
|
||||
|
@ -583,6 +574,10 @@ public class Interpreter
|
|||
case Token.DIV :
|
||||
case Token.MUL :
|
||||
case Token.GETELEM :
|
||||
case Token.EQ:
|
||||
case Token.NE:
|
||||
case Token.SHEQ:
|
||||
case Token.SHNE:
|
||||
case Token.IN :
|
||||
case Token.INSTANCEOF :
|
||||
case Token.LE :
|
||||
|
|
|
@ -102,24 +102,24 @@ public class Node implements Cloneable {
|
|||
right.next = null;
|
||||
}
|
||||
|
||||
public Node(int nodeType, int value) {
|
||||
public Node(int nodeType, int line) {
|
||||
type = nodeType;
|
||||
intDatum = value;
|
||||
lineno = line;
|
||||
}
|
||||
|
||||
public Node(int nodeType, Node child, int value) {
|
||||
public Node(int nodeType, Node child, int line) {
|
||||
this(nodeType, child);
|
||||
intDatum = value;
|
||||
lineno = line;
|
||||
}
|
||||
|
||||
public Node(int nodeType, Node left, Node right, int value) {
|
||||
public Node(int nodeType, Node left, Node right, int line) {
|
||||
this(nodeType, left, right);
|
||||
intDatum = value;
|
||||
lineno = line;
|
||||
}
|
||||
|
||||
public Node(int nodeType, Node left, Node mid, Node right, int value) {
|
||||
public Node(int nodeType, Node left, Node mid, Node right, int line) {
|
||||
this(nodeType, left, mid, right);
|
||||
intDatum = value;
|
||||
lineno = line;
|
||||
}
|
||||
|
||||
public static Node newNumber(double number) {
|
||||
|
@ -439,14 +439,8 @@ public class Node implements Cloneable {
|
|||
item.intValue = prop;
|
||||
}
|
||||
|
||||
public int getOperation() {
|
||||
if (type != Token.EQOP) Context.codeBug();
|
||||
return intDatum;
|
||||
}
|
||||
|
||||
public int getLineno() {
|
||||
if (type == Token.EQOP) Context.codeBug();
|
||||
return intDatum;
|
||||
return lineno;
|
||||
}
|
||||
|
||||
/** Can only be called when <tt>getType() == Token.NUMBER</tt> */
|
||||
|
@ -503,9 +497,9 @@ public class Node implements Cloneable {
|
|||
sb.append(' ');
|
||||
sb.append(getDouble());
|
||||
}
|
||||
if (intDatum != -1) {
|
||||
if (lineno != -1) {
|
||||
sb.append(' ');
|
||||
sb.append(intDatum);
|
||||
sb.append(lineno);
|
||||
}
|
||||
|
||||
for (PropListItem x = propListHead; x != null; x = x.next) {
|
||||
|
@ -575,7 +569,7 @@ public class Node implements Cloneable {
|
|||
Node next; // next sibling
|
||||
private Node first; // first element of a linked list of children
|
||||
private Node last; // last element of a linked list of children
|
||||
private int intDatum = -1; // encapsulated int data; depends on type
|
||||
private int lineno = -1; // encapsulated int data; depends on type
|
||||
|
||||
/**
|
||||
* Linked list of properties. Since vast majority of nodes would have
|
||||
|
|
|
@ -200,24 +200,22 @@ public class Token
|
|||
* by the scanner.
|
||||
*/
|
||||
|
||||
EQOP = 105, // equality ops (== !=)
|
||||
BLOCK = 105, // statement block
|
||||
ARRAYLIT = 106, // array literal
|
||||
OBJLIT = 107, // object literal
|
||||
LABEL = 108, // label
|
||||
TARGET = 109,
|
||||
LOOP = 110,
|
||||
ENUMDONE = 111,
|
||||
EXPRSTMT = 112,
|
||||
PARENT = 113,
|
||||
JSR = 114,
|
||||
NEWLOCAL = 115,
|
||||
USELOCAL = 116,
|
||||
SCRIPT = 117, // top-level node for entire script
|
||||
TYPEOFNAME = 118, // for typeof(simple-name)
|
||||
|
||||
BLOCK = 106, // statement block
|
||||
ARRAYLIT = 107, // array literal
|
||||
OBJLIT = 108, // object literal
|
||||
LABEL = 109, // label
|
||||
TARGET = 110,
|
||||
LOOP = 111,
|
||||
ENUMDONE = 112,
|
||||
EXPRSTMT = 113,
|
||||
PARENT = 114,
|
||||
JSR = 115,
|
||||
NEWLOCAL = 116,
|
||||
USELOCAL = 117,
|
||||
SCRIPT = 118, // top-level node for entire script
|
||||
TYPEOFNAME = 119, // for typeof(simple-name)
|
||||
|
||||
LAST_TOKEN = 119;
|
||||
LAST_TOKEN = 118;
|
||||
|
||||
public static String name(int token)
|
||||
{
|
||||
|
@ -305,7 +303,6 @@ public class Token
|
|||
case COLON: return "colon";
|
||||
case OR: return "or";
|
||||
case AND: return "and";
|
||||
case EQOP: return "eqop";
|
||||
case INC: return "inc";
|
||||
case DEC: return "dec";
|
||||
case DOT: return "dot";
|
||||
|
|
|
@ -1365,7 +1365,10 @@ public class Codegen extends Interpreter {
|
|||
visitRelOp(node, child);
|
||||
break;
|
||||
|
||||
case Token.EQOP:
|
||||
case Token.EQ:
|
||||
case Token.NE:
|
||||
case Token.SHEQ:
|
||||
case Token.SHNE:
|
||||
visitEqOp(node, child);
|
||||
break;
|
||||
|
||||
|
@ -1536,7 +1539,10 @@ public class Codegen extends Interpreter {
|
|||
visitIfJumpRelOp(node, child, trueLabel, falseLabel);
|
||||
break;
|
||||
|
||||
case Token.EQOP:
|
||||
case Token.EQ:
|
||||
case Token.NE:
|
||||
case Token.SHEQ:
|
||||
case Token.SHNE:
|
||||
visitIfJumpEqOp(node, child, trueLabel, falseLabel);
|
||||
break;
|
||||
|
||||
|
@ -2781,10 +2787,10 @@ public class Codegen extends Interpreter {
|
|||
|
||||
private void visitEqOp(Node node, Node child)
|
||||
{
|
||||
int op = node.getOperation();
|
||||
int type = node.getType();
|
||||
Node rightChild = child.getNext();
|
||||
boolean isStrict = op == Token.SHEQ ||
|
||||
op == Token.SHNE;
|
||||
boolean isStrict = type == Token.SHEQ ||
|
||||
type == Token.SHNE;
|
||||
if (rightChild.getType() == Token.NULL) {
|
||||
generateCodeFromNode(child, node);
|
||||
if (isStrict) {
|
||||
|
@ -2795,7 +2801,7 @@ public class Codegen extends Interpreter {
|
|||
pushUndefined();
|
||||
addByteCode(ByteCode.IF_ACMPEQ, 10);
|
||||
}
|
||||
if ((op == Token.EQ) || (op == Token.SHEQ))
|
||||
if ((type == Token.EQ) || (type == Token.SHEQ))
|
||||
classFile.add(ByteCode.GETSTATIC, "java/lang/Boolean",
|
||||
"FALSE", "Ljava/lang/Boolean;");
|
||||
else
|
||||
|
@ -2807,7 +2813,7 @@ public class Codegen extends Interpreter {
|
|||
addByteCode(ByteCode.GOTO, 7);
|
||||
addByteCode(ByteCode.POP);
|
||||
}
|
||||
if ((op == Token.EQ) || (op == Token.SHEQ))
|
||||
if ((type == Token.EQ) || (type == Token.SHEQ))
|
||||
classFile.add(ByteCode.GETSTATIC, "java/lang/Boolean",
|
||||
"TRUE", "Ljava/lang/Boolean;");
|
||||
else
|
||||
|
@ -2820,7 +2826,7 @@ public class Codegen extends Interpreter {
|
|||
generateCodeFromNode(child.getNext(), node);
|
||||
|
||||
String name;
|
||||
switch (op) {
|
||||
switch (type) {
|
||||
case Token.EQ:
|
||||
name = "eqB";
|
||||
break;
|
||||
|
@ -2850,13 +2856,13 @@ public class Codegen extends Interpreter {
|
|||
private void visitIfJumpEqOp(Node node, Node child,
|
||||
int trueGOTO, int falseGOTO)
|
||||
{
|
||||
int op = node.getOperation();
|
||||
int type = node.getType();
|
||||
Node rightChild = child.getNext();
|
||||
boolean isStrict = op == Token.SHEQ ||
|
||||
op == Token.SHNE;
|
||||
boolean isStrict = type == Token.SHEQ ||
|
||||
type == Token.SHNE;
|
||||
|
||||
if (rightChild.getType() == Token.NULL) {
|
||||
if (op != Token.EQ && op != Token.SHEQ) {
|
||||
if (type != Token.EQ && type != Token.SHEQ) {
|
||||
// invert true and false.
|
||||
int temp = trueGOTO;
|
||||
trueGOTO = falseGOTO;
|
||||
|
@ -2912,7 +2918,7 @@ public class Codegen extends Interpreter {
|
|||
dload((short)(lVar1.getJRegister() + 1));
|
||||
push(convertChild.getDouble());
|
||||
addByteCode(ByteCode.DCMPL);
|
||||
if (op == Token.EQ)
|
||||
if (type == Token.EQ)
|
||||
addByteCode(ByteCode.IFEQ, trueGOTO);
|
||||
else
|
||||
addByteCode(ByteCode.IFNE, trueGOTO);
|
||||
|
@ -2926,7 +2932,7 @@ public class Codegen extends Interpreter {
|
|||
generateCodeFromNode(rChild, node);
|
||||
|
||||
String name;
|
||||
switch (op) {
|
||||
switch (type) {
|
||||
case Token.EQ:
|
||||
name = "eq";
|
||||
addScriptRuntimeInvoke(name,
|
||||
|
|
Загрузка…
Ссылка в новой задаче