示例#1
0
  public static JProgram construct(
      TreeLogger logger, CompilationState state, Properties properties, String... entryPoints)
      throws UnableToCompleteException {
    PrecompileTaskOptions options = new PrecompileTaskOptionsImpl();
    options.setEnableAssertions(true);
    JProgram jprogram = AstConstructor.construct(logger, state, options, properties);

    // Add entry methods for entry points.
    for (String entryPoint : entryPoints) {
      JDeclaredType entryType = jprogram.getFromTypeMap(entryPoint);
      for (JMethod method : entryType.getMethods()) {
        if (method.isStatic() && JProgram.isClinit(method)) {
          jprogram.addEntryMethod(method);
        }
      }
    }
    // Tree is now ready to optimize.
    return jprogram;
  }
示例#2
0
  /**
   * Given the source code to a Java class named <code>test.EntryPoint</code>, compiles it with
   * emulated stack traces turned on and returns the JavaScript.
   */
  private JsProgram compileClass(String... lines) throws UnableToCompleteException {

    // Gather the Java source code to compile.

    final String code = Joiner.on("\n").join(lines);

    MockResourceOracle sourceOracle = new MockResourceOracle();
    sourceOracle.addOrReplace(
        new MockJavaResource("test.EntryPoint") {
          @Override
          public CharSequence getContent() {
            return code;
          }
        });
    sourceOracle.add(JavaAstConstructor.getCompilerTypes());

    PrecompileTaskOptions options = new PrecompileTaskOptionsImpl();
    options.setOutput(JsOutputOption.PRETTY);
    options.setRunAsyncEnabled(false);
    CompilerContext context =
        new CompilerContext.Builder()
            .options(options)
            .minimalRebuildCache(new MinimalRebuildCache())
            .build();

    ConfigurationProperties config =
        new ConfigurationProperties(Arrays.asList(recordFileNamesProp, recordLineNumbersProp));

    CompilationState state =
        CompilationStateBuilder.buildFrom(logger, context, sourceOracle.getResources(), null);
    JProgram jProgram = AstConstructor.construct(logger, state, options, config);
    jProgram.addEntryMethod(findMethod(jProgram, "onModuleLoad"));

    if (inline) {
      MethodInliner.exec(jProgram);
    }

    CatchBlockNormalizer.exec(jProgram);
    // Construct the JavaScript AST.

    // These passes are needed by GenerateJavaScriptAST.
    ComputeCastabilityInformation.exec(jProgram, false);
    ImplementCastsAndTypeChecks.exec(jProgram, false);
    ArrayNormalizer.exec(jProgram);

    StringTypeMapper typeMapper = new StringTypeMapper(jProgram);
    ResolveRuntimeTypeReferences.exec(jProgram, typeMapper, TypeOrder.FREQUENCY);
    Map<StandardSymbolData, JsName> symbolTable =
        new TreeMap<StandardSymbolData, JsName>(new SymbolData.ClassIdentComparator());

    BindingProperty stackMode = new BindingProperty("compiler.stackMode");
    stackMode.addDefinedValue(new ConditionNone(), "EMULATED");

    PermutationProperties properties =
        new PermutationProperties(
            Arrays.asList(
                new BindingProperties(
                    new BindingProperty[] {stackMode}, new String[] {"EMULATED"}, config)));

    JsProgram jsProgram = new JsProgram();
    JavaToJavaScriptMap jjsmap =
        GenerateJavaScriptAST.exec(
                logger, jProgram, jsProgram, context, typeMapper, symbolTable, properties)
            .getLeft();

    // Finally, run the pass we care about.
    JsStackEmulator.exec(jProgram, jsProgram, properties, jjsmap);

    return jsProgram;
  }
示例#3
0
文件: JjsUtils.java 项目: uddata/gwt
 public static boolean closureStyleLiteralsNeeded(PrecompileTaskOptions options) {
   return closureStyleLiteralsNeeded(
       options.isIncrementalCompileEnabled(), options.isClosureCompilerFormatEnabled());
 }