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


Java ScriptNode.getType方法代码示例

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


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

示例1: transformCompilationUnit

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void transformCompilationUnit(ScriptNode tree, boolean inStrictMode)
{
    loops = new ObjArray();
    loopEnds = new ObjArray();

    // to save against upchecks if no finally blocks are used.
    hasFinally = false;

    // Flatten all only if we are not using scope objects for block scope
    boolean createScopeObjects = tree.getType() != Token.FUNCTION ||
                              ((FunctionNode)tree).requiresActivation();
    tree.flattenSymbolTable(!createScopeObjects);

    //uncomment to print tree before transformation
    if (Token.printTrees) System.out.println(tree.toStringTree(tree));
    transformCompilationUnit_r(tree, tree, tree, createScopeObjects,
                               inStrictMode);
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:19,代码来源:NodeTransformer.java

示例2: getBodyMethodSignature

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
String getBodyMethodSignature(ScriptNode n)
{
    StringBuilder sb = new StringBuilder();
    sb.append('(');
    sb.append(mainClassSignature);
    sb.append("Lorg/mozilla/javascript/Context;"
              +"Lorg/mozilla/javascript/Scriptable;"
              +"Lorg/mozilla/javascript/Scriptable;");
    if (n.getType() == Token.FUNCTION) {
        OptFunctionNode ofn = OptFunctionNode.get(n);
        if (ofn.isTargetOfDirectCall()) {
            int pCount = ofn.fnode.getParamCount();
            for (int i = 0; i != pCount; i++) {
                sb.append("Ljava/lang/Object;D");
            }
        }
    }
    sb.append("[Ljava/lang/Object;)Ljava/lang/Object;");
    return sb.toString();
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:21,代码来源:Codegen.java

示例3: transformCompilationUnit

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void transformCompilationUnit(ScriptNode tree)
{
    loops = new ObjArray();
    loopEnds = new ObjArray();

    // to save against upchecks if no finally blocks are used.
    hasFinally = false;

    // Flatten all only if we are not using scope objects for block scope
    boolean createScopeObjects = tree.getType() != Token.FUNCTION ||
                              ((FunctionNode)tree).requiresActivation();
    tree.flattenSymbolTable(!createScopeObjects);

    //uncomment to print tree before transformation
    if (Token.printTrees) System.out.println(tree.toStringTree(tree));
    boolean inStrictMode = tree instanceof AstRoot &&
                           ((AstRoot)tree).isInStrictMode();
    transformCompilationUnit_r(tree, tree, tree, createScopeObjects,
                               inStrictMode);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:21,代码来源:NodeTransformer.java

示例4: getBodyMethodSignature

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
String getBodyMethodSignature(ScriptNode n)
{
    StringBuffer sb = new StringBuffer();
    sb.append('(');
    sb.append(mainClassSignature);
    sb.append("Lorg/mozilla/javascript/Context;"
              +"Lorg/mozilla/javascript/Scriptable;"
              +"Lorg/mozilla/javascript/Scriptable;");
    if (n.getType() == Token.FUNCTION) {
        OptFunctionNode ofn = OptFunctionNode.get(n);
        if (ofn.isTargetOfDirectCall()) {
            int pCount = ofn.fnode.getParamCount();
            for (int i = 0; i != pCount; i++) {
                sb.append("Ljava/lang/Object;D");
            }
        }
    }
    sb.append("[Ljava/lang/Object;)Ljava/lang/Object;");
    return sb.toString();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:21,代码来源:Codegen.java

示例5: transform

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void transform(ScriptNode tree)
{
    initOptFunctions_r(tree);

    int optLevel = compilerEnv.getOptimizationLevel();

    Map<String,OptFunctionNode> possibleDirectCalls = null;
    if (optLevel > 0) {
       /*
        * Collect all of the contained functions into a hashtable
        * so that the call optimizer can access the class name & parameter
        * count for any call it encounters
        */
        if (tree.getType() == Token.SCRIPT) {
            int functionCount = tree.getFunctionCount();
            for (int i = 0; i != functionCount; ++i) {
                OptFunctionNode ofn = OptFunctionNode.get(tree, i);
                if (ofn.fnode.getFunctionType()
                    == FunctionNode.FUNCTION_STATEMENT)
                {
                    String name = ofn.fnode.getName();
                    if (name.length() != 0) {
                        if (possibleDirectCalls == null) {
                            possibleDirectCalls = new HashMap<String,OptFunctionNode>();
                        }
                        possibleDirectCalls.put(name, ofn);
                    }
                }
            }
        }
    }

    if (possibleDirectCalls != null) {
        directCallTargets = new ObjArray();
    }

    OptTransformer ot = new OptTransformer(possibleDirectCalls,
                                           directCallTargets);
    ot.transform(tree, compilerEnv);

    if (optLevel > 0) {
        (new Optimizer()).optimize(tree);
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:45,代码来源:Codegen.java

示例6: generateCode

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private byte[] generateCode(String encodedSource)
{
    boolean hasScript = (scriptOrFnNodes[0].getType() == Token.SCRIPT);
    boolean hasFunctions = (scriptOrFnNodes.length > 1 || !hasScript);
    boolean isStrictMode = scriptOrFnNodes[0].isInStrictMode();

    String sourceFile = null;
    if (compilerEnv.isGenerateDebugInfo()) {
        sourceFile = scriptOrFnNodes[0].getSourceName();
    }

    ClassFileWriter cfw = new ClassFileWriter(mainClassName,
                                              SUPER_CLASS_NAME,
                                              sourceFile);
    cfw.addField(ID_FIELD_NAME, "I", ACC_PRIVATE);

    if (hasFunctions) {
        generateFunctionConstructor(cfw);
    }

    if (hasScript) {
        cfw.addInterface("org/mozilla/javascript/Script");
        generateScriptCtor(cfw);
        generateMain(cfw);
        generateExecute(cfw);
    }

    generateCallMethod(cfw, isStrictMode);
    generateResumeGenerator(cfw);

    generateNativeFunctionOverrides(cfw, encodedSource);

    int count = scriptOrFnNodes.length;
    for (int i = 0; i != count; ++i) {
        ScriptNode n = scriptOrFnNodes[i];

        BodyCodegen bodygen = new BodyCodegen();
        bodygen.cfw = cfw;
        bodygen.codegen = this;
        bodygen.compilerEnv = compilerEnv;
        bodygen.scriptOrFn = n;
        bodygen.scriptOrFnIndex = i;

        try {
            bodygen.generateBodyCode();
        } catch (ClassFileWriter.ClassFileFormatException e) {
            throw reportClassFileFormatException(n, e.getMessage());
        }

        if (n.getType() == Token.FUNCTION) {
            OptFunctionNode ofn = OptFunctionNode.get(n);
            generateFunctionInit(cfw, ofn);
            if (ofn.isTargetOfDirectCall()) {
                emitDirectConstructor(cfw, ofn);
            }
        }
    }

    emitRegExpInit(cfw);
    emitConstantDudeInitializers(cfw);

    return cfw.toByteArray();
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:64,代码来源:Codegen.java

示例7: isGenerator

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
static boolean isGenerator(ScriptNode node)
{
    return (node.getType() == Token.FUNCTION ) &&
            ((FunctionNode)node).isGenerator();
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:6,代码来源:Codegen.java

示例8: detectDirectCall

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void detectDirectCall(Node node, ScriptNode tree)
{
    if (tree.getType() == Token.FUNCTION) {
        Node left = node.getFirstChild();

        // count the arguments
        int argCount = 0;
        Node arg = left.getNext();
        while (arg != null) {
            arg = arg.getNext();
            argCount++;
        }

        if (argCount == 0) {
            OptFunctionNode.get(tree).itsContainsCalls0 = true;
        }

        /*
         * Optimize a call site by converting call("a", b, c) into :
         *
         *  FunctionObjectFor"a" <-- instance variable init'd by constructor
         *
         *  // this is a DIRECTCALL node
         *  fn = GetProp(tmp = GetBase("a"), "a");
         *  if (fn == FunctionObjectFor"a")
         *      fn.call(tmp, b, c)
         *  else
         *      ScriptRuntime.Call(fn, tmp, b, c)
         */
        if (possibleDirectCalls != null) {
            String targetName = null;
            if (left.getType() == Token.NAME) {
                targetName = left.getString();
            } else if (left.getType() == Token.GETPROP) {
                targetName = left.getFirstChild().getNext().getString();
            } else if (left.getType() == Token.GETPROPNOWARN) {
                throw Kit.codeBug();
            }
            if (targetName != null) {
                OptFunctionNode ofn;
                ofn = possibleDirectCalls.get(targetName);
                if (ofn != null
                    && argCount == ofn.fnode.getParamCount()
                    && !ofn.fnode.requiresActivation())
                {
                    // Refuse to directCall any function with more
                    // than 32 parameters - prevent code explosion
                    // for wacky test cases
                    if (argCount <= 32) {
                        node.putProp(Node.DIRECTCALL_PROP, ofn);
                        if (!ofn.isTargetOfDirectCall()) {
                            int index = directCallTargets.size();
                            directCallTargets.add(ofn);
                            ofn.setDirectTargetIndex(index);
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:62,代码来源:OptTransformer.java

示例9: transform

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void transform(ScriptNode tree)
{
    initOptFunctions_r(tree);

    int optLevel = compilerEnv.getOptimizationLevel();

    Map<String,OptFunctionNode> possibleDirectCalls = null;
    if (optLevel > 0) {
       /*
        * Collect all of the contained functions into a hashtable
        * so that the call optimizer can access the class name & parameter
        * count for any call it encounters
        */
        if (tree.getType() == Token.SCRIPT) {
            int functionCount = tree.getFunctionCount();
            for (int i = 0; i != functionCount; ++i) {
                OptFunctionNode ofn = OptFunctionNode.get(tree, i);
                if (ofn.fnode.getFunctionType()
                    == FunctionNode.FUNCTION_STATEMENT)
                {
                    String name = ofn.fnode.getName();
                    if (name.length() != 0) {
                        if (possibleDirectCalls == null) {
                            possibleDirectCalls = new HashMap<String,OptFunctionNode>();
                        }
                        possibleDirectCalls.put(name, ofn);
                    }
                }
            }
        }
    }

    if (possibleDirectCalls != null) {
        directCallTargets = new ObjArray();
    }

    OptTransformer ot = new OptTransformer(possibleDirectCalls,
                                           directCallTargets);
    ot.transform(tree);

    if (optLevel > 0) {
        (new Optimizer()).optimize(tree);
    }
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:45,代码来源:Codegen.java

示例10: generateCode

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private byte[] generateCode(String encodedSource)
{
    boolean hasScript = (scriptOrFnNodes[0].getType() == Token.SCRIPT);
    boolean hasFunctions = (scriptOrFnNodes.length > 1 || !hasScript);

    String sourceFile = null;
    if (compilerEnv.isGenerateDebugInfo()) {
        sourceFile = scriptOrFnNodes[0].getSourceName();
    }

    ClassFileWriter cfw = new ClassFileWriter(mainClassName,
                                              SUPER_CLASS_NAME,
                                              sourceFile);
    cfw.addField(ID_FIELD_NAME, "I",
                 ClassFileWriter.ACC_PRIVATE);
    cfw.addField(DIRECT_CALL_PARENT_FIELD, mainClassSignature,
                 ClassFileWriter.ACC_PRIVATE);
    cfw.addField(REGEXP_ARRAY_FIELD_NAME, REGEXP_ARRAY_FIELD_TYPE,
                 ClassFileWriter.ACC_PRIVATE);

    if (hasFunctions) {
        generateFunctionConstructor(cfw);
    }

    if (hasScript) {
        cfw.addInterface("org/mozilla/javascript/Script");
        generateScriptCtor(cfw);
        generateMain(cfw);
        generateExecute(cfw);
    }

    generateCallMethod(cfw);
    generateResumeGenerator(cfw);

    generateNativeFunctionOverrides(cfw, encodedSource);

    int count = scriptOrFnNodes.length;
    for (int i = 0; i != count; ++i) {
        ScriptNode n = scriptOrFnNodes[i];

        BodyCodegen bodygen = new BodyCodegen();
        bodygen.cfw = cfw;
        bodygen.codegen = this;
        bodygen.compilerEnv = compilerEnv;
        bodygen.scriptOrFn = n;
        bodygen.scriptOrFnIndex = i;

        try {
            bodygen.generateBodyCode();
        } catch (ClassFileWriter.ClassFileFormatException e) {
            throw reportClassFileFormatException(n, e.getMessage());
        }

        if (n.getType() == Token.FUNCTION) {
            OptFunctionNode ofn = OptFunctionNode.get(n);
            generateFunctionInit(cfw, ofn);
            if (ofn.isTargetOfDirectCall()) {
                emitDirectConstructor(cfw, ofn);
            }
        }
    }

    if (directCallTargets != null) {
        int N = directCallTargets.size();
        for (int j = 0; j != N; ++j) {
            cfw.addField(getDirectTargetFieldName(j),
                         mainClassSignature,
                         ClassFileWriter.ACC_PRIVATE);
        }
    }

    emitRegExpInit(cfw);
    emitConstantDudeInitializers(cfw);

    return cfw.toByteArray();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:77,代码来源:Codegen.java

示例11: generateCode

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private byte[] generateCode(String encodedSource)
{
    boolean hasScript = (scriptOrFnNodes[0].getType() == Token.SCRIPT);
    boolean hasFunctions = (scriptOrFnNodes.length > 1 || !hasScript);

    String sourceFile = null;
    if (compilerEnv.isGenerateDebugInfo()) {
        sourceFile = scriptOrFnNodes[0].getSourceName();
    }

    ClassFileWriter cfw = new ClassFileWriter(mainClassName,
                                              SUPER_CLASS_NAME,
                                              sourceFile);
    cfw.addField(ID_FIELD_NAME, "I", ACC_PRIVATE);

    if (hasFunctions) {
        generateFunctionConstructor(cfw);
    }

    if (hasScript) {
        cfw.addInterface("org/mozilla/javascript/Script");
        generateScriptCtor(cfw);
        generateMain(cfw);
        generateExecute(cfw);
    }

    generateCallMethod(cfw);
    generateResumeGenerator(cfw);

    generateNativeFunctionOverrides(cfw, encodedSource);

    int count = scriptOrFnNodes.length;
    for (int i = 0; i != count; ++i) {
        ScriptNode n = scriptOrFnNodes[i];

        BodyCodegen bodygen = new BodyCodegen();
        bodygen.cfw = cfw;
        bodygen.codegen = this;
        bodygen.compilerEnv = compilerEnv;
        bodygen.scriptOrFn = n;
        bodygen.scriptOrFnIndex = i;

        try {
            bodygen.generateBodyCode();
        } catch (ClassFileWriter.ClassFileFormatException e) {
            throw reportClassFileFormatException(n, e.getMessage());
        }

        if (n.getType() == Token.FUNCTION) {
            OptFunctionNode ofn = OptFunctionNode.get(n);
            generateFunctionInit(cfw, ofn);
            if (ofn.isTargetOfDirectCall()) {
                emitDirectConstructor(cfw, ofn);
            }
        }
    }

    emitRegExpInit(cfw);
    emitConstantDudeInitializers(cfw);

    return cfw.toByteArray();
}
 
开发者ID:tiffit,项目名称:TaleCraft,代码行数:63,代码来源:Codegen.java


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