Examples of JProgram


Examples of com.google.gwt.dev.jjs.ast.JProgram

     * (tweaking method parameter and return types).
     */
    public void into(String... expected) throws UnableToCompleteException {
      // We can't compile expected code into non-main method.
      Preconditions.checkState(methodName.equals(MAIN_METHOD_NAME));
      JProgram program = compileSnippet(returnType, Joiner.on("\n").join(expected));
      String expectedSource =
        OptimizerTestBase.findMethod(program, methodName).getBody().toSource();
      String actualSource =
        OptimizerTestBase.findMethod(optimizedProgram, methodName)
            .getBody().toSource();
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

    return analyzeWithParams(returnType, "", codeSnippet);
  }

  protected AnalysisResult analyzeWithParams(String returnType, String params,
      String... codeSnippet) throws UnableToCompleteException {
    JProgram program = compileSnippet(returnType, params, Joiner.on("\n").join(codeSnippet), true);
    JMethodBody body = (JMethodBody) findMainMethod(program).getBody();
    Cfg cfgGraph = CfgBuilder.build(program, body.getBlock());

    assertNotNull(cfgGraph);
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

      this.logger = logger;
    }

    addSnippetImport("com.google.gwt.core.client.GWT");
    try {
      JProgram program = compileSnippet("void", "GWT.runAsync((new Object()).getClass(), null);");
      ReplaceRunAsyncs.exec(logger, program);
      fail("Expected compilation to fail");
    } catch (UnableToCompleteException e) {
      // expected
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

  public static JProgram construct(TreeLogger logger, CompilationState state,
      PrecompileTaskOptions options, ConfigProps config,
      String... entryPoints) throws UnableToCompleteException {
    options.setEnableAssertions(true);
    JProgram jprogram = AstConstructor.construct(logger, state, options, config);

    // 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;
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

        "8: END");
  }

  private CfgBuilderResult assertCfg(String returnType, String ...codeSnippet)
      throws UnableToCompleteException {
    JProgram program = compileSnippet(returnType, Joiner.on("\n").join(codeSnippet));
    JMethodBody body = (JMethodBody) findMainMethod(program).getBody();
    Cfg cfgGraph = CfgBuilder.build(program, body.getBlock());
    return new CfgBuilderResult(cfgGraph);
  }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

    ConstantsAssumption.Updater updater =
      new ConstantsAssumption.Updater(new ConstantsAssumption());

    String codeSnippet = decls;
    codeSnippet += "return " + expr + ";";
    JProgram program = compileSnippet(type, codeSnippet);
    JMethod mainMethod = findMainMethod(program);
    JBlock block = ((JMethodBody) mainMethod.getBody()).getBlock();

    List<JStatement> statements = block.getStatements();
    // TODO: not a pretty assumption detection.
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

    from("String s = null;", "null != s", true).deduce("T");
    from("String s = null;", "null != s", false).deduce("{s = null}");
  }

  private Result from(String decls, String expr, boolean b) throws UnableToCompleteException {
    JProgram program = compileSnippet("void", decls + "\n if(" + expr + ") return;");
    JMethod mainMethod = findMainMethod(program);
    JBlock block = ((JMethodBody) mainMethod.getBody()).getBlock();
    List<JStatement> statements = block.getStatements();
    JIfStatement ifStatement = (JIfStatement) statements.get(statements.size() - 1);
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

        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);
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

      /*
       * Don't use the JProgram helper because it auto-adds the new method to
       * its enclosing class.
       */
      JProgram program = x.getProgram();
      JMethod newMethod = new JMethod(program, sourceInfo, newName,
          enclosingType, returnType, false, true, true, x.isPrivate());

      // Setup parameters; map from the old params to the new params
      JParameter thisParam = program.createParameter(null,
          "this$static".toCharArray(), enclosingType, true, true, newMethod);
      Map<JParameter, JParameter> varMap = new IdentityHashMap<JParameter, JParameter>();
      for (int i = 0; i < x.params.size(); ++i) {
        JParameter oldVar = x.params.get(i);
        JParameter newVar = program.createParameter(oldVar.getSourceInfo(),
            oldVar.getName().toCharArray(), oldVar.getType(), oldVar.isFinal(),
            false, newMethod);
        varMap.put(oldVar, newVar);
      }

      // Set the new original param types based on the old original param types
      List<JType> originalParamTypes = new ArrayList<JType>();
      originalParamTypes.add(enclosingType);
      originalParamTypes.addAll(x.getOriginalParamTypes());
      newMethod.setOriginalParamTypes(originalParamTypes);

      // Move the body of the instance method to the static method
      JAbstractMethodBody movedBody = x.getBody();
      newMethod.setBody(movedBody);

      // Create a new body for the instance method that delegates to the static
      JMethodBody newBody = new JMethodBody(program, sourceInfo);
      x.setBody(newBody);
      JMethodCall newCall = new JMethodCall(program, sourceInfo, null,
          newMethod);
      newCall.getArgs().add(program.getExprThisRef(sourceInfo, enclosingType));
      for (int i = 0; i < x.params.size(); ++i) {
        JParameter param = x.params.get(i);
        newCall.getArgs().add(new JParameterRef(program, sourceInfo, param));
      }
      JStatement statement;
      if (returnType == program.getTypeVoid()) {
        statement = newCall.makeStatement();
      } else {
        statement = new JReturnStatement(program, sourceInfo, newCall);
      }
      newBody.getStatements().add(statement);

      /*
       * Rewrite the method body. Update all thisRefs to paramRefs. Update
       * paramRefs and localRefs to target the params/locals in the new method.
       */
      if (newMethod.isNative()) {
        // For natives, we also need to create the JsParameter for this$static,
        // because the jsFunc already has parameters.
        // TODO: Do we really need to do that in BuildTypeMap?
        JsFunction jsFunc = ((JsniMethodBody) movedBody).getFunc();
        JsName paramName = jsFunc.getScope().declareName("this$static");
        jsFunc.getParameters().add(0, new JsParameter(paramName));
        RewriteJsniMethodBody rewriter = new RewriteJsniMethodBody(paramName);
        // Accept the body to avoid the recursion blocker.
        rewriter.accept(jsFunc.getBody());
      } else {
        RewriteMethodBody rewriter = new RewriteMethodBody(thisParam, varMap);
        rewriter.accept(movedBody);
      }

      // Add the new method as a static impl of the old method
      program.putStaticImpl(x, newMethod);
      enclosingType.methods.add(myIndexInClass + 1, newMethod);
      return false;
    }
View Full Code Here

Examples of com.google.gwt.dev.jjs.ast.JProgram

        System.out.println("|                     (new permuation)                     |");
        System.out.println("------------------------------------------------------------");
      }

      AST ast = unifiedAst.getFreshAst();
      JProgram jprogram = ast.getJProgram();
      JsProgram jsProgram = ast.getJsProgram();
      JJSOptions options = unifiedAst.getOptions();

      ResolveRebinds.exec(jprogram, rebindAnswers);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.