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);
}
public Object createUnary(int nodeType, int nodeOp, Object child) {
Node childNode = (Node) child;
public Object createIncDec(int nodeType, boolean post, Object child)
{
Node childNode = (Node)child;
int childType = childNode.getType();
if (nodeType == Token.INC || nodeType == Token.DEC) {
int childType = childNode.getType();
if (!hasSideEffects(childNode)
&& (nodeOp == Token.POST)
&& (childType == Token.NAME
|| childType == Token.GETPROP
|| childType == Token.GETELEM))
{
// 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);
if (post && !hasSideEffects(childNode)
&& (childType == Token.NAME
|| childType == Token.GETPROP
|| childType == Token.GETELEM))
{
// if it's not a LHS type, createAssignment (below) will throw
// an exception.
return new Node(nodeType, childNode);
}
Node result = new Node(nodeType, nodeOp);
result.addChildToBack(childNode);
return result;
/*
* 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,
post);
}
/**

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

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

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

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