Added explicit IRFactory.createIncDec to create ++/-- subtree which removed need to have Token.PRE/Token.POST.

This commit is contained in:
igor%mir2.org 2003-08-15 11:19:47 +00:00
Родитель f1b5883b79
Коммит b96ac683c8
3 изменённых файлов: 48 добавлений и 59 удалений

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

@ -732,44 +732,37 @@ public class IRFactory {
return new Node(nodeType, childNode); return new Node(nodeType, childNode);
} }
public Object createUnary(int nodeType, int nodeOp, Object child) { public Object createIncDec(int nodeType, boolean post, Object child)
Node childNode = (Node) child; {
Node childNode = (Node)child;
int childType = childNode.getType();
if (nodeType == Token.INC || nodeType == Token.DEC) { if (post && !hasSideEffects(childNode)
int childType = childNode.getType(); && (childType == Token.NAME
|| childType == Token.GETPROP
if (!hasSideEffects(childNode) || childType == Token.GETELEM))
&& (nodeOp == Token.POST) {
&& (childType == Token.NAME // if it's not a LHS type, createAssignment (below) will throw
|| childType == Token.GETPROP // an exception.
|| childType == Token.GETELEM)) return new Node(nodeType, childNode);
{
// if it's not a LHS type, createAssignment (below) will throw
// an exception.
return new Node(nodeType, childNode);
}
/*
* Transform INC/DEC ops to +=1, -=1,
* expecting later optimization of all +/-=1 cases to INC, DEC.
*/
// we have to use Double for now, because
// 0.0 and 1.0 are stored as dconst_[01],
// and using a Float creates a stack mismatch.
Node rhs = (Node) createNumber(1.0);
return createAssignment(nodeType == Token.INC
? Token.ADD
: Token.SUB,
childNode,
rhs,
true,
nodeOp == Token.POST);
} }
Node result = new Node(nodeType, nodeOp); /*
result.addChildToBack(childNode); * Transform INC/DEC ops to +=1, -=1,
return result; * expecting later optimization of all +/-=1 cases to INC, DEC.
*/
// we have to use Double for now, because
// 0.0 and 1.0 are stored as dconst_[01],
// and using a Float creates a stack mismatch.
Node rhs = (Node) createNumber(1.0);
return createAssignment(nodeType == Token.INC
? Token.ADD
: Token.SUB,
childNode,
rhs,
true,
post);
} }
/** /**

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

@ -1128,7 +1128,7 @@ class Parser {
case Token.INC: case Token.INC:
case Token.DEC: case Token.DEC:
decompiler.addToken(tt); decompiler.addToken(tt);
return nf.createUnary(tt, Token.PRE, memberExpr(ts, true)); return nf.createIncDec(tt, false, memberExpr(ts, true));
case Token.DELPROP: case Token.DELPROP:
decompiler.addToken(Token.DELPROP); decompiler.addToken(Token.DELPROP);
@ -1158,7 +1158,7 @@ class Parser {
{ {
int pf = ts.getToken(); int pf = ts.getToken();
decompiler.addToken(pf); decompiler.addToken(pf);
return nf.createUnary(pf, Token.POST, pn); return nf.createIncDec(pf, true, pn);
} }
return pn; return pn;
} }

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

@ -188,39 +188,37 @@ public class Token
* more general token types, eg. 'DIV' as the op of 'ASSIGN'. * more general token types, eg. 'DIV' as the op of 'ASSIGN'.
*/ */
NOP = 103, // NOP NOP = 103, // NOP
PRE = 104, // for INC, DEC nodes.
POST = 105,
/** /**
* For JSOPs associated with keywords... * For JSOPs associated with keywords...
* eg. op = ADD; token = ASSIGN * eg. op = ADD; token = ASSIGN
*/ */
EMPTY = 106, EMPTY = 104,
/* types used for the parse tree - these never get returned /* types used for the parse tree - these never get returned
* by the scanner. * by the scanner.
*/ */
EQOP = 107, // equality ops (== !=) EQOP = 105, // equality ops (== !=)
RELOP = 108, // relational ops (< <= > >= in instanceof) RELOP = 106, // relational ops (< <= > >= in instanceof)
BLOCK = 109, // statement block BLOCK = 107, // statement block
ARRAYLIT = 110, // array literal ARRAYLIT = 108, // array literal
OBJLIT = 111, // object literal OBJLIT = 109, // object literal
LABEL = 112, // label LABEL = 110, // label
TARGET = 113, TARGET = 111,
LOOP = 114, LOOP = 112,
ENUMDONE = 115, ENUMDONE = 113,
EXPRSTMT = 116, EXPRSTMT = 114,
PARENT = 117, PARENT = 115,
JSR = 118, JSR = 116,
NEWLOCAL = 119, NEWLOCAL = 117,
USELOCAL = 120, USELOCAL = 118,
SCRIPT = 121, // top-level node for entire script SCRIPT = 119, // top-level node for entire script
TYPEOFNAME = 122, // for typeof(simple-name) TYPEOFNAME = 120, // for typeof(simple-name)
LAST_TOKEN = 122; LAST_TOKEN = 120;
public static String name(int token) public static String name(int token)
{ {
@ -332,8 +330,6 @@ public class Token
case FINALLY: return "finally"; case FINALLY: return "finally";
case RESERVED: return "reserved"; case RESERVED: return "reserved";
case NOP: return "nop"; case NOP: return "nop";
case PRE: return "pre";
case POST: return "post";
case EMPTY: return "empty"; case EMPTY: return "empty";
case BLOCK: return "block"; case BLOCK: return "block";
case ARRAYLIT: return "arraylit"; case ARRAYLIT: return "arraylit";