⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optimizer.java

📁 java中比较著名的js引擎当属mozilla开源的rhino
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    }                    else {                        if (lType == NumberType) {                            if (rType == NumberType) {                                n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH);                            }                            else {                                n.putIntProp(Node.ISNUMBER_PROP, Node.LEFT);                            }                        }                        else {                            if (rType == NumberType) {                                n.putIntProp(Node.ISNUMBER_PROP, Node.RIGHT);                            }                        }                    }                    // we actually build a boolean value                    return NoType;                }            case Token.ADD : {                    Node lChild = n.getFirstChild();                    Node rChild = lChild.getNext();                    int lType = rewriteForNumberVariables(lChild);                    int rType = rewriteForNumberVariables(rChild);                    if (convertParameter(lChild)) {                        if (convertParameter(rChild)) {                            return NoType;                        }                        else {                            if (rType == NumberType) {                                n.putIntProp(Node.ISNUMBER_PROP, Node.RIGHT);                            }                        }                    }                    else {                        if (convertParameter(rChild)) {                            if (lType == NumberType) {                                n.putIntProp(Node.ISNUMBER_PROP, Node.LEFT);                            }                        }                        else {                            if (lType == NumberType) {                                if (rType == NumberType) {                                    n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH);                                    return NumberType;                                }                                else {                                    n.putIntProp(Node.ISNUMBER_PROP, Node.LEFT);                                }                            }                            else {                                if (rType == NumberType) {                                    n.putIntProp(Node.ISNUMBER_PROP,                                                 Node.RIGHT);                                }                            }                        }                    }                    return NoType;                }            case Token.BITXOR :            case Token.BITOR :            case Token.BITAND :            case Token.RSH :            case Token.LSH :            case Token.SUB :            case Token.MUL :            case Token.DIV :            case Token.MOD : {                    Node lChild = n.getFirstChild();                    Node rChild = lChild.getNext();                    int lType = rewriteForNumberVariables(lChild);                    int rType = rewriteForNumberVariables(rChild);                    markDCPNumberContext(lChild);                    markDCPNumberContext(rChild);                    if (lType == NumberType) {                        if (rType == NumberType) {                            n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH);                            return NumberType;                        }                        else {                            if (!convertParameter(rChild)) {                                n.removeChild(rChild);                                n.addChildToBack(                                    new Node(Token.TO_DOUBLE, rChild));                                n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH);                            }                            return NumberType;                        }                    }                    else {                        if (rType == NumberType) {                            if (!convertParameter(lChild)) {                                n.removeChild(lChild);                                n.addChildToFront(                                    new Node(Token.TO_DOUBLE, lChild));                                n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH);                            }                            return NumberType;                        }                        else {                            if (!convertParameter(lChild)) {                                n.removeChild(lChild);                                n.addChildToFront(                                    new Node(Token.TO_DOUBLE, lChild));                            }                            if (!convertParameter(rChild)) {                                n.removeChild(rChild);                                n.addChildToBack(                                    new Node(Token.TO_DOUBLE, rChild));                            }                            n.putIntProp(Node.ISNUMBER_PROP, Node.BOTH);                            return NumberType;                        }                    }                }            case Token.SETELEM :            case Token.SETELEM_OP : {                    Node arrayBase = n.getFirstChild();                    Node arrayIndex = arrayBase.getNext();                    Node rValue = arrayIndex.getNext();                    int baseType = rewriteForNumberVariables(arrayBase);                    if (baseType == NumberType) {// can never happen ???                        if (!convertParameter(arrayBase)) {                            n.removeChild(arrayBase);                            n.addChildToFront(                                new Node(Token.TO_OBJECT, arrayBase));                        }                    }                    int indexType = rewriteForNumberVariables(arrayIndex);                    if (indexType == NumberType) {                        // setting the ISNUMBER_PROP signals the codegen                        // to use the OptRuntime.setObjectIndex that takes                        // a double index                        n.putIntProp(Node.ISNUMBER_PROP, Node.LEFT);                        markDCPNumberContext(arrayIndex);                    }                    int rValueType = rewriteForNumberVariables(rValue);                    if (rValueType == NumberType) {                        if (!convertParameter(rValue)) {                            n.removeChild(rValue);                            n.addChildToBack(                                new Node(Token.TO_OBJECT, rValue));                        }                    }                    return NoType;                }            case Token.GETELEM : {                    Node arrayBase = n.getFirstChild();                    Node arrayIndex = arrayBase.getNext();                    int baseType = rewriteForNumberVariables(arrayBase);                    if (baseType == NumberType) {// can never happen ???                        if (!convertParameter(arrayBase)) {                            n.removeChild(arrayBase);                            n.addChildToFront(                                new Node(Token.TO_OBJECT, arrayBase));                        }                    }                    int indexType = rewriteForNumberVariables(arrayIndex);                    if (indexType == NumberType) {                        if (!convertParameter(arrayIndex)) {                            // setting the ISNUMBER_PROP signals the codegen                            // to use the OptRuntime.getObjectIndex that takes                            // a double index                            n.putIntProp(Node.ISNUMBER_PROP, Node.RIGHT);                        }                    }                    return NoType;                }            case Token.CALL :                {                    Node child = n.getFirstChild(); // the function node                    if (child.getType() == Token.GETELEM) {                        // Optimization of x[0]() is not supported                        // so bypass GETELEM optimization that                        // rewriteForNumberVariables would trigger                        rewriteAsObjectChildren(child, child.getFirstChild());                    } else {                        rewriteForNumberVariables(child);                    }                    child = child.getNext(); // the first arg                    OptFunctionNode target                            = (OptFunctionNode)n.getProp(Node.DIRECTCALL_PROP);                    if (target != null) {/*    we leave each child as a Number if it can be. The codegen will    handle moving the pairs of parameters.*/                        while (child != null) {                            int type = rewriteForNumberVariables(child);                            if (type == NumberType) {                                markDCPNumberContext(child);                            }                            child = child.getNext();                        }                    } else {                        rewriteAsObjectChildren(n, child);                    }                    return NoType;                }            default : {                    rewriteAsObjectChildren(n, n.getFirstChild());                    return NoType;                }        }    }    private void rewriteAsObjectChildren(Node n, Node child)    {        // Force optimized children to be objects        while (child != null) {            Node nextChild = child.getNext();            int type = rewriteForNumberVariables(child);            if (type == NumberType) {                if (!convertParameter(child)) {                    n.removeChild(child);                    Node nuChild = new Node(Token.TO_OBJECT, child);                    if (nextChild == null)                        n.addChildToBack(nuChild);                    else                        n.addChildBefore(nuChild, nextChild);                }            }            child = nextChild;        }    }    private static void buildStatementList_r(Node node, ObjArray statements)    {        int type = node.getType();        if (type == Token.BLOCK            || type == Token.LOCAL_BLOCK            || type == Token.LOOP            || type == Token.FUNCTION)        {            Node child = node.getFirstChild();            while (child != null) {                buildStatementList_r(child, statements);                child = child.getNext();            }        } else {            statements.add(node);        }    }    private int itsOptLevel;    private boolean inDirectCallFunction;    OptFunctionNode theFunction;    private boolean parameterUsedInNumberContext;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -