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


Java ScriptNode.getRegexpCount方法代码示例

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


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

示例1: emitRegExpInit

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void emitRegExpInit(ClassFileWriter cfw)
{
    // precompile all regexp literals

    int totalRegCount = 0;
    for (int i = 0; i != scriptOrFnNodes.length; ++i) {
        totalRegCount += scriptOrFnNodes[i].getRegexpCount();
    }
    if (totalRegCount == 0) {
        return;
    }

    cfw.startMethod(REGEXP_INIT_METHOD_NAME, REGEXP_INIT_METHOD_SIGNATURE,
            (short)(ACC_STATIC | ACC_PRIVATE));
    cfw.addField("_reInitDone", "Z",
                 (short)(ACC_STATIC | ACC_PRIVATE | ACC_VOLATILE));
    cfw.add(ByteCode.GETSTATIC, mainClassName, "_reInitDone", "Z");
    int doInit = cfw.acquireLabel();
    cfw.add(ByteCode.IFEQ, doInit);
    cfw.add(ByteCode.RETURN);
    cfw.markLabel(doInit);

    // get regexp proxy and store it in local slot 1
    cfw.addALoad(0); // context
    cfw.addInvoke(ByteCode.INVOKESTATIC,
                  "org/mozilla/javascript/ScriptRuntime",
                  "checkRegExpProxy",
                  "(Lorg/mozilla/javascript/Context;"
                  +")Lorg/mozilla/javascript/RegExpProxy;");
    cfw.addAStore(1); // proxy

    // We could apply double-checked locking here but concurrency
    // shouldn't be a problem in practice
    for (int i = 0; i != scriptOrFnNodes.length; ++i) {
        ScriptNode n = scriptOrFnNodes[i];
        int regCount = n.getRegexpCount();
        for (int j = 0; j != regCount; ++j) {
            String reFieldName = getCompiledRegexpName(n, j);
            String reFieldType = "Ljava/lang/Object;";
            String reString = n.getRegexpString(j);
            String reFlags = n.getRegexpFlags(j);
            cfw.addField(reFieldName, reFieldType,
                         (short)(ACC_STATIC | ACC_PRIVATE));
            cfw.addALoad(1); // proxy
            cfw.addALoad(0); // context
            cfw.addPush(reString);
            if (reFlags == null) {
                cfw.add(ByteCode.ACONST_NULL);
            } else {
                cfw.addPush(reFlags);
            }
            cfw.addInvoke(ByteCode.INVOKEINTERFACE,
                          "org/mozilla/javascript/RegExpProxy",
                          "compileRegExp",
                          "(Lorg/mozilla/javascript/Context;"
                          +"Ljava/lang/String;Ljava/lang/String;"
                          +")Ljava/lang/Object;");
            cfw.add(ByteCode.PUTSTATIC, mainClassName,
                    reFieldName, reFieldType);
        }
    }

    cfw.addPush(1);
    cfw.add(ByteCode.PUTSTATIC, mainClassName, "_reInitDone", "Z");
    cfw.add(ByteCode.RETURN);
    cfw.stopMethod((short)2);
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:68,代码来源:Codegen.java

示例2: emitRegExpInit

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
private void emitRegExpInit(ClassFileWriter cfw)
{
    // precompile all regexp literals

    int totalRegCount = 0;
    for (int i = 0; i != scriptOrFnNodes.length; ++i) {
        totalRegCount += scriptOrFnNodes[i].getRegexpCount();
    }
    if (totalRegCount == 0) {
        return;
    }

    cfw.startMethod(REGEXP_INIT_METHOD_NAME, REGEXP_INIT_METHOD_SIGNATURE,
        (short)(ClassFileWriter.ACC_STATIC | ClassFileWriter.ACC_PRIVATE
                | ClassFileWriter.ACC_SYNCHRONIZED));
    cfw.addField("_reInitDone", "Z",
                 (short)(ClassFileWriter.ACC_STATIC
                         | ClassFileWriter.ACC_PRIVATE));
    cfw.add(ByteCode.GETSTATIC, mainClassName, "_reInitDone", "Z");
    int doInit = cfw.acquireLabel();
    cfw.add(ByteCode.IFEQ, doInit);
    cfw.add(ByteCode.RETURN);
    cfw.markLabel(doInit);

    for (int i = 0; i != scriptOrFnNodes.length; ++i) {
        ScriptNode n = scriptOrFnNodes[i];
        int regCount = n.getRegexpCount();
        for (int j = 0; j != regCount; ++j) {
            String reFieldName = getCompiledRegexpName(n, j);
            String reFieldType = "Ljava/lang/Object;";
            String reString = n.getRegexpString(j);
            String reFlags = n.getRegexpFlags(j);
            cfw.addField(reFieldName, reFieldType,
                         (short)(ClassFileWriter.ACC_STATIC
                                 | ClassFileWriter.ACC_PRIVATE));
            cfw.addALoad(0); // proxy
            cfw.addALoad(1); // context
            cfw.addPush(reString);
            if (reFlags == null) {
                cfw.add(ByteCode.ACONST_NULL);
            } else {
                cfw.addPush(reFlags);
            }
            cfw.addInvoke(ByteCode.INVOKEINTERFACE,
                          "org/mozilla/javascript/RegExpProxy",
                          "compileRegExp",
                          "(Lorg/mozilla/javascript/Context;"
                          +"Ljava/lang/String;Ljava/lang/String;"
                          +")Ljava/lang/Object;");
            cfw.add(ByteCode.PUTSTATIC, mainClassName,
                    reFieldName, reFieldType);
        }
    }

    cfw.addPush(1);
    cfw.add(ByteCode.PUTSTATIC, mainClassName, "_reInitDone", "Z");
    cfw.add(ByteCode.RETURN);
    cfw.stopMethod((short)2);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:60,代码来源:Codegen.java

示例3: pushRegExpArray

import org.mozilla.javascript.ast.ScriptNode; //导入方法依赖的package包/类
void pushRegExpArray(ClassFileWriter cfw, ScriptNode n,
                     int contextArg, int scopeArg)
{
    int regexpCount = n.getRegexpCount();
    if (regexpCount == 0) throw badTree();

    cfw.addPush(regexpCount);
    cfw.add(ByteCode.ANEWARRAY, "java/lang/Object");

    cfw.addALoad(contextArg);
    cfw.addInvoke(ByteCode.INVOKESTATIC,
                  "org/mozilla/javascript/ScriptRuntime",
                  "checkRegExpProxy",
                  "(Lorg/mozilla/javascript/Context;"
                  +")Lorg/mozilla/javascript/RegExpProxy;");
    // Stack: proxy, array
    cfw.add(ByteCode.DUP);
    cfw.addALoad(contextArg);
    cfw.addInvoke(ByteCode.INVOKESTATIC, mainClassName,
                  REGEXP_INIT_METHOD_NAME, REGEXP_INIT_METHOD_SIGNATURE);
    for (int i = 0; i != regexpCount; ++i) {
        // Stack: proxy, array
        cfw.add(ByteCode.DUP2);
        cfw.addALoad(contextArg);
        cfw.addALoad(scopeArg);
        cfw.add(ByteCode.GETSTATIC, mainClassName,
                getCompiledRegexpName(n, i), "Ljava/lang/Object;");
        // Stack: compiledRegExp, scope, cx, proxy, array, proxy, array
        cfw.addInvoke(ByteCode.INVOKEINTERFACE,
                      "org/mozilla/javascript/RegExpProxy",
                      "wrapRegExp",
                      "(Lorg/mozilla/javascript/Context;"
                      +"Lorg/mozilla/javascript/Scriptable;"
                      +"Ljava/lang/Object;"
                      +")Lorg/mozilla/javascript/Scriptable;");
        // Stack: wrappedRegExp, array, proxy, array
        cfw.addPush(i);
        cfw.add(ByteCode.SWAP);
        cfw.add(ByteCode.AASTORE);
        // Stack: proxy, array
    }
    // remove proxy
    cfw.add(ByteCode.POP);
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:45,代码来源:Codegen.java


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