2003/06/08 23:48:03
[org.ibex.core.git] / src / org / xwt / js / Parser.java
index ff59d3b..73b3590 100644 (file)
@@ -50,7 +50,7 @@ class Parser extends Lexer implements ByteCodes {
        precedence[LSH] = precedence[RSH] = precedence[URSH] = 12;
        precedence[ADD] = precedence[SUB] = 13;
        precedence[MUL] = precedence[DIV] = precedence[MOD] = 14;
-       precedence[BITNOT] = precedence[INSTANCEOF] = 15;
+       precedence[BITNOT] =  15;
        precedence[INC] = precedence[DEC] = 16;
        precedence[LP] = 17;
        precedence[LB] = 18;
@@ -60,6 +60,8 @@ class Parser extends Lexer implements ByteCodes {
 
     // Parsing Logic /////////////////////////////////////////////////////////
 
+    private ByteCodeBlock newbb(int line) { return new ByteCodeBlock(line, sourceName); }
+
     /** gets a token and throws an exception if it is not <tt>code</tt> */
     public void consume(int code) throws IOException {
        if (getToken() != code)
@@ -125,7 +127,7 @@ class Parser extends Lexer implements ByteCodes {
            continueExpr(b, minPrecedence);
            return;
        }
-       case BANG: case BITNOT: case INSTANCEOF: case TYPEOF: {
+       case BANG: case BITNOT: case TYPEOF: {
            startExpr(precedence[tok], b);
            b.add(tok);
            continueExpr(b, minPrecedence);
@@ -168,7 +170,7 @@ class Parser extends Lexer implements ByteCodes {
        case FUNCTION: {
            consume(LP);
            int numArgs = 0;
-           ByteCodeBlock b2 = new ByteCodeBlock(curLine, sourceName);
+           ByteCodeBlock b2 = newbb(curLine);
            b2.add(TOPSCOPE);
            b2.add(SWAP);
            b2.add(LITERAL, "arguments");
@@ -284,7 +286,7 @@ class Parser extends Lexer implements ByteCodes {
            b.add(tok == AND ? b.JF : b.JT, new Integer(0));
            int size = b.size();
            startExpr(precedence[tok], b);
-           b.arg[size - 1] = new Integer(b.size() - size + 2);
+           b.set(size - 1, new Integer(b.size() - size + 2));
            b.add(JMP, new Integer(2));
            b.add(LITERAL, tok == AND ? new Boolean(false) : new Boolean(true));
            continueExpr(b, minPrecedence);
@@ -329,12 +331,12 @@ class Parser extends Lexer implements ByteCodes {
            b.add(JF, new Integer(0));
            int size = b.size();
            startExpr(b);
-           b.arg[size - 1] = new Integer(b.size() - size + 2);
+           b.set(size - 1, new Integer(b.size() - size + 2));
            b.add(JMP, new Integer(0));
            consume(COLON);
            size = b.size();
            startExpr(b);
-           b.arg[size - 1] = new Integer(b.size() - size + 1);
+           b.set(size - 1, new Integer(b.size() - size + 1));
            continueExpr(b, minPrecedence);
            return;
        }
@@ -422,19 +424,19 @@ class Parser extends Lexer implements ByteCodes {
                
                if (peekToken() == ELSE) {
                    consume(ELSE);
-                   b.arg[size - 1] = new Integer(2 + b.size() - size);
+                   b.set(size - 1, new Integer(2 + b.size() - size));
                    b.add(JMP, new Integer(0));
                    size = b.size();
                    parseStatement(false, b);
                }
-               b.arg[size - 1] = new Integer(1 + b.size() - size);
+               b.set(size - 1, new Integer(1 + b.size() - size));
                break;
            }
 
            case WHILE: {
                consume(WHILE);
                consume(LP);
-               ByteCodeBlock loop = new ByteCodeBlock(curLine, sourceName);
+               ByteCodeBlock loop = newbb(curLine);
                b.add(LOOP, loop);
                
                loop.add(POP);
@@ -452,7 +454,7 @@ class Parser extends Lexer implements ByteCodes {
            case SWITCH: {
                consume(SWITCH);
                consume(LP);
-               ByteCodeBlock loop = new ByteCodeBlock(curLine, sourceName);
+               ByteCodeBlock loop = newbb(curLine);
                b.add(LOOP, loop);
                startExpr(loop);
                consume(RP);
@@ -471,7 +473,7 @@ class Parser extends Lexer implements ByteCodes {
                            parseStatement(false, loop);
                            if (size2 == loop.size()) break;
                        }
-                       loop.arg[size - 1] = new Integer(1 + loop.size() - size);
+                       loop.set(size - 1, new Integer(1 + loop.size() - size));
                    } else if (peekToken() == DEFAULT) {
                        consume(DEFAULT);
                        consume(COLON);
@@ -492,7 +494,7 @@ class Parser extends Lexer implements ByteCodes {
                
            case DO: {
                consume(DO);
-               ByteCodeBlock loop = new ByteCodeBlock(curLine, sourceName);
+               ByteCodeBlock loop = newbb(curLine);
                b.add(LOOP, loop);
                
                parseStatement(false, loop);
@@ -545,7 +547,7 @@ class Parser extends Lexer implements ByteCodes {
                b.add(LITERAL, "length");
                b.add(GET);
                consume(RP);
-               ByteCodeBlock b2 = new ByteCodeBlock(curLine, sourceName);
+               ByteCodeBlock b2 = newbb(curLine);
                b.add(SCOPE, b2);
                b2.add(LITERAL, new Integer(1));
                b2.add(SUB);
@@ -562,7 +564,7 @@ class Parser extends Lexer implements ByteCodes {
                break;
                
            } else {
-               ByteCodeBlock b2 = new ByteCodeBlock(curLine, sourceName);
+               ByteCodeBlock b2 = newbb(curLine);
                b.add(SCOPE, b2);
                b.add(POP);
 
@@ -572,9 +574,9 @@ class Parser extends Lexer implements ByteCodes {
                consume(SEMI);
                ByteCodeBlock e2 = startExpr();
                consume(SEMI);
-               if (e2 == null) e2 = new ByteCodeBlock(curLine, sourceName, b.LITERAL, null);
+               if (e2 == null) e2 = newbb(curLine).add(b.LITERAL, null);
 
-               ByteCodeBlock b3 = new ByteCodeBlock(curLine, sourceName);
+               ByteCodeBlock b3 = newbb(curLine);
                b2.add(LOOP, b3);
                b2.add(LITERAL, null);
 
@@ -583,7 +585,7 @@ class Parser extends Lexer implements ByteCodes {
                startExpr(b3);
                consume(RP);
                if (b3.size() - size > 0) b3.add(POP);
-               b3.arg[size - 1] = new Integer(b3.size() - size + 1);
+               b3.set(size - 1, new Integer(b3.size() - size + 1));
 
                b3.paste(e2);
                b3.add(JT, new Integer(2));