Move code to classify binary and relation operation tokens to IRFactory so parser does not need to know about details of tree implementation.

This commit is contained in:
igor%mir2.org 2003-08-18 08:05:06 +00:00
Родитель 0ee771b8c2
Коммит 5be8c599eb
2 изменённых файлов: 25 добавлений и 16 удалений

Просмотреть файл

@ -768,17 +768,19 @@ public class IRFactory {
/**
* Binary
*/
public Object createBinary(int nodeType, Object left, Object right) {
Node temp;
public Object createBinary(int nodeType, Object leftObj, Object rightObj)
{
Node left = (Node)leftObj;
Node right = (Node)rightObj;
switch (nodeType) {
case Token.DOT:
nodeType = Token.GETPROP;
Node idNode = (Node) right;
idNode.setType(Token.STRING);
String id = idNode.getString();
right.setType(Token.STRING);
String id = right.getString();
if (id.equals("__proto__") || id.equals("__parent__")) {
Node result = new Node(nodeType, (Node) left);
Node result = new Node(nodeType, left);
result.putProp(Node.SPECIAL_PROP_PROP, id);
return result;
}
@ -788,14 +790,22 @@ public class IRFactory {
// OPT: could optimize to GETPROP iff string can't be a number
nodeType = Token.GETELEM;
break;
case Token.IN:
case Token.INSTANCEOF:
case Token.LE:
case Token.LT:
case Token.GE:
case Token.GT:
return new Node(Token.RELOP, left, right, nodeType);
case Token.EQ:
case Token.NE:
case Token.SHEQ:
case Token.SHNE:
return new Node(Token.EQOP, left, right, nodeType);
}
return new Node(nodeType, (Node)left, (Node)right);
}
public Object createBinary(int nodeType, int nodeOp, Object left,
Object right)
{
return new Node(nodeType, (Node) left, (Node) right, nodeOp);
return new Node(nodeType, left, right);
}
public Object createAssignment(int assignOp, Object left, Object right)

Просмотреть файл

@ -1011,8 +1011,7 @@ class Parser {
}
}
decompiler.addToken(decompilerToken);
pn = nf.createBinary(Token.EQOP, parseToken, pn,
relExpr(ts, inForInit));
pn = nf.createBinary(parseToken, pn, relExpr(ts, inForInit));
continue;
}
break;
@ -1038,7 +1037,7 @@ class Parser {
case Token.GT:
ts.getToken();
decompiler.addToken(tt);
pn = nf.createBinary(Token.RELOP, tt, pn, shiftExpr(ts));
pn = nf.createBinary(tt, pn, shiftExpr(ts));
continue;
}
break;