当前位置: 首页>>代码示例>>Java>>正文


Java FunctionNode.FUNCTION_EXPRESSION属性代码示例

本文整理汇总了Java中org.mozilla.javascript.ast.FunctionNode.FUNCTION_EXPRESSION属性的典型用法代码示例。如果您正苦于以下问题:Java FunctionNode.FUNCTION_EXPRESSION属性的具体用法?Java FunctionNode.FUNCTION_EXPRESSION怎么用?Java FunctionNode.FUNCTION_EXPRESSION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.mozilla.javascript.ast.FunctionNode的用法示例。


在下文中一共展示了FunctionNode.FUNCTION_EXPRESSION属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitFunction

private void visitFunction(OptFunctionNode ofn, int functionType)
{
    int fnIndex = codegen.getIndex(ofn.fnode);
    cfw.add(ByteCode.NEW, codegen.mainClassName);
    // Call function constructor
    cfw.add(ByteCode.DUP);
    cfw.addALoad(variableObjectLocal);
    cfw.addALoad(contextLocal);           // load 'cx'
    cfw.addPush(fnIndex);
    cfw.addInvoke(ByteCode.INVOKESPECIAL, codegen.mainClassName,
                  "<init>", Codegen.FUNCTION_CONSTRUCTOR_SIGNATURE);

    if (functionType == FunctionNode.ARROW_FUNCTION) {
        cfw.addALoad(contextLocal);           // load 'cx'
        cfw.addALoad(variableObjectLocal);
        cfw.addALoad(thisObjLocal);
        addOptRuntimeInvoke("bindThis",
                            "(Lorg/mozilla/javascript/NativeFunction;"
                            +"Lorg/mozilla/javascript/Context;"
                            +"Lorg/mozilla/javascript/Scriptable;"
                            +"Lorg/mozilla/javascript/Scriptable;"
                            +")Lorg/mozilla/javascript/Function;");
    }

    if (functionType == FunctionNode.FUNCTION_EXPRESSION ||
        functionType == FunctionNode.ARROW_FUNCTION) {
        // Leave closure object on stack and do not pass it to
        // initFunction which suppose to connect statements to scope
        return;
    }
    cfw.addPush(functionType);
    cfw.addALoad(variableObjectLocal);
    cfw.addALoad(contextLocal);           // load 'cx'
    addOptRuntimeInvoke("initFunction",
                        "(Lorg/mozilla/javascript/NativeFunction;"
                        +"I"
                        +"Lorg/mozilla/javascript/Scriptable;"
                        +"Lorg/mozilla/javascript/Context;"
                        +")V");
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:40,代码来源:Codegen.java

示例2: visitFunction

private void visitFunction(OptFunctionNode ofn, int functionType)
{
    int fnIndex = codegen.getIndex(ofn.fnode);
    cfw.add(ByteCode.NEW, codegen.mainClassName);
    // Call function constructor
    cfw.add(ByteCode.DUP);
    cfw.addALoad(variableObjectLocal);
    cfw.addALoad(contextLocal);           // load 'cx'
    cfw.addPush(fnIndex);
    cfw.addInvoke(ByteCode.INVOKESPECIAL, codegen.mainClassName,
                  "<init>", Codegen.FUNCTION_CONSTRUCTOR_SIGNATURE);

    if (functionType == FunctionNode.FUNCTION_EXPRESSION) {
        // Leave closure object on stack and do not pass it to
        // initFunction which suppose to connect statements to scope
        return;
    }
    cfw.addPush(functionType);
    cfw.addALoad(variableObjectLocal);
    cfw.addALoad(contextLocal);           // load 'cx'
    addOptRuntimeInvoke("initFunction",
                        "(Lorg/mozilla/javascript/NativeFunction;"
                        +"I"
                        +"Lorg/mozilla/javascript/Scriptable;"
                        +"Lorg/mozilla/javascript/Context;"
                        +")V");
}
 
开发者ID:tiffit,项目名称:TaleCraft,代码行数:27,代码来源:Codegen.java

示例3: transformFunction

private Node transformFunction(FunctionNode fn) {
    int functionType = fn.getFunctionType();
    int start = decompiler.markFunctionStart(functionType);
    Node mexpr = decompileFunctionHeader(fn);
    int index = currentScriptOrFn.addFunction(fn);

    PerFunctionVariables savedVars = new PerFunctionVariables(fn);
    try {
        // If we start needing to record much more codegen metadata during
        // function parsing, we should lump it all into a helper class.
        Node destructuring = (Node)fn.getProp(Node.DESTRUCTURING_PARAMS);
        fn.removeProp(Node.DESTRUCTURING_PARAMS);

        int lineno = fn.getBody().getLineno();
        ++nestingOfFunction;  // only for body, not params
        Node body = transform(fn.getBody());

        if (!fn.isExpressionClosure()) {
            decompiler.addToken(Token.RC);
        }
        fn.setEncodedSourceBounds(start, decompiler.markFunctionEnd(start));

        if (functionType != FunctionNode.FUNCTION_EXPRESSION && !fn.isExpressionClosure()) {
            // Add EOL only if function is not part of expression
            // since it gets SEMI + EOL from Statement in that case
            decompiler.addToken(Token.EOL);
        }

        if (destructuring != null) {
            body.addChildToFront(new Node(Token.EXPR_VOID,
                                          destructuring, lineno));
        }

        int syntheticType = fn.getFunctionType();
        Node pn = initFunction(fn, index, body, syntheticType);
        if (mexpr != null) {
            pn = createAssignment(Token.ASSIGN, mexpr, pn);
            if (syntheticType != FunctionNode.FUNCTION_EXPRESSION) {
                pn = createExprStatementNoReturn(pn, fn.getLineno());
            }
        }
        return pn;

    } finally {
        --nestingOfFunction;
        savedVars.restore();
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:48,代码来源:IRFactory.java

示例4: transformGenExpr

private Node transformGenExpr(GeneratorExpression node) {
    Node pn;
    
    FunctionNode fn = new FunctionNode();
    fn.setSourceName(currentScriptOrFn.getNextTempName());
    fn.setIsGenerator();
    fn.setFunctionType(FunctionNode.FUNCTION_EXPRESSION);
    fn.setRequiresActivation();
  
    int functionType = fn.getFunctionType();
    int start = decompiler.markFunctionStart(functionType);
    Node mexpr = decompileFunctionHeader(fn);
    int index = currentScriptOrFn.addFunction(fn);

    PerFunctionVariables savedVars = new PerFunctionVariables(fn);
    try {
        // If we start needing to record much more codegen metadata during
        // function parsing, we should lump it all into a helper class.
        Node destructuring = (Node)fn.getProp(Node.DESTRUCTURING_PARAMS);
        fn.removeProp(Node.DESTRUCTURING_PARAMS);

        int lineno = node.lineno;
        ++nestingOfFunction;  // only for body, not params
        Node body = genExprTransformHelper(node);

        if (!fn.isExpressionClosure()) {
            decompiler.addToken(Token.RC);
        }
        fn.setEncodedSourceBounds(start, decompiler.markFunctionEnd(start));

        if (functionType != FunctionNode.FUNCTION_EXPRESSION && !fn.isExpressionClosure()) {
            // Add EOL only if function is not part of expression
            // since it gets SEMI + EOL from Statement in that case
            decompiler.addToken(Token.EOL);
        }

        if (destructuring != null) {
            body.addChildToFront(new Node(Token.EXPR_VOID,
                                          destructuring, lineno));
        }

        int syntheticType = fn.getFunctionType();
        pn = initFunction(fn, index, body, syntheticType);
        if (mexpr != null) {
            pn = createAssignment(Token.ASSIGN, mexpr, pn);
            if (syntheticType != FunctionNode.FUNCTION_EXPRESSION) {
                pn = createExprStatementNoReturn(pn, fn.getLineno());
            }
        }
    } finally {
        --nestingOfFunction;
        savedVars.restore();
    }
   
    Node call = createCallOrNew(Token.CALL, pn);
    call.setLineno(node.getLineno());
    decompiler.addToken(Token.LP);
    decompiler.addToken(Token.RP);
    return call;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:60,代码来源:IRFactory.java

示例5: initFunction

private Node initFunction(FunctionNode fnNode, int functionIndex,
                          Node statements, int functionType) {
    fnNode.setFunctionType(functionType);
    fnNode.addChildToBack(statements);

    int functionCount = fnNode.getFunctionCount();
    if (functionCount != 0) {
        // Functions containing other functions require activation objects
        fnNode.setRequiresActivation();
    }

    if (functionType == FunctionNode.FUNCTION_EXPRESSION) {
        Name name = fnNode.getFunctionName();
        if (name != null && name.length() != 0
                && fnNode.getSymbol(name.getIdentifier()) == null) {
            // A function expression needs to have its name as a
            // variable (if it isn't already allocated as a variable).
            // See ECMA Ch. 13.  We add code to the beginning of the
            // function to initialize a local variable of the
            // function's name to the function value, but only if the
            // function doesn't already define a formal parameter, var,
            // or nested function with the same name.
            fnNode.putSymbol(new Symbol(Token.FUNCTION, name.getIdentifier()));
            Node setFn = new Node(Token.EXPR_VOID,
                             new Node(Token.SETNAME,
                                      Node.newString(Token.BINDNAME,
                                                     name.getIdentifier()),
                                 new Node(Token.THISFN)));
            statements.addChildrenToFront(setFn);
        }
    }

    // Add return to end if needed.
    Node lastStmt = statements.getLastChild();
    if (lastStmt == null || lastStmt.getType() != Token.RETURN) {
        statements.addChildToBack(new Node(Token.RETURN));
    }

    Node result = Node.newString(Token.FUNCTION, fnNode.getName());
    result.putIntProp(Node.FUNCTION_PROP, functionIndex);
    return result;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:42,代码来源:IRFactory.java

示例6: visitFunction

private void visitFunction(OptFunctionNode ofn, int functionType)
{
    int fnIndex = codegen.getIndex(ofn.fnode);
    cfw.add(ByteCode.NEW, codegen.mainClassName);
    // Call function constructor
    cfw.add(ByteCode.DUP);
    cfw.addALoad(variableObjectLocal);
    cfw.addALoad(contextLocal);           // load 'cx'
    cfw.addPush(fnIndex);
    cfw.addInvoke(ByteCode.INVOKESPECIAL, codegen.mainClassName,
                  "<init>", Codegen.FUNCTION_CONSTRUCTOR_SIGNATURE);

    // Init mainScript field;
    cfw.add(ByteCode.DUP);
    if (isTopLevel) {
        cfw.add(ByteCode.ALOAD_0);
    } else {
        cfw.add(ByteCode.ALOAD_0);
        cfw.add(ByteCode.GETFIELD,
                codegen.mainClassName,
                Codegen.DIRECT_CALL_PARENT_FIELD,
                codegen.mainClassSignature);
    }
    cfw.add(ByteCode.PUTFIELD,
            codegen.mainClassName,
            Codegen.DIRECT_CALL_PARENT_FIELD,
            codegen.mainClassSignature);

    int directTargetIndex = ofn.getDirectTargetIndex();
    if (directTargetIndex >= 0) {
        cfw.add(ByteCode.DUP);
        if (isTopLevel) {
            cfw.add(ByteCode.ALOAD_0);
        } else {
            cfw.add(ByteCode.ALOAD_0);
            cfw.add(ByteCode.GETFIELD,
                    codegen.mainClassName,
                    Codegen.DIRECT_CALL_PARENT_FIELD,
                    codegen.mainClassSignature);
        }
        cfw.add(ByteCode.SWAP);
        cfw.add(ByteCode.PUTFIELD,
                codegen.mainClassName,
                Codegen.getDirectTargetFieldName(directTargetIndex),
                codegen.mainClassSignature);
    }

    if (functionType == FunctionNode.FUNCTION_EXPRESSION) {
        // Leave closure object on stack and do not pass it to
        // initFunction which suppose to connect statements to scope
        return;
    }
    cfw.addPush(functionType);
    cfw.addALoad(variableObjectLocal);
    cfw.addALoad(contextLocal);           // load 'cx'
    addOptRuntimeInvoke("initFunction",
                        "(Lorg/mozilla/javascript/NativeFunction;"
                        +"I"
                        +"Lorg/mozilla/javascript/Scriptable;"
                        +"Lorg/mozilla/javascript/Context;"
                        +")V");
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:62,代码来源:Codegen.java


注:本文中的org.mozilla.javascript.ast.FunctionNode.FUNCTION_EXPRESSION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。