Examples of JProgram


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

  public String compile(TreeLogger logger, RebindOracle rebindOracle)
      throws UnableToCompleteException {

    try {

      JProgram jprogram = new JProgram(logger, rebindOracle);
      JsProgram jsProgram = new JsProgram();

      if (JProgram.isTracingEnabled()) {
        System.out.println("------------------------------------------------------------");
        System.out.println("|                     (new permuation)                     |");
        System.out.println("------------------------------------------------------------");
      }

      {
        /*
         * (1) Build a flattened map of TypeDeclarations => JType. The resulting
         * map contains entries for all reference types. BuildTypeMap also
         * parses all JSNI.
         */
        TypeMap typeMap = new TypeMap(jprogram);
        TypeDeclaration[] allTypeDeclarations = BuildTypeMap.exec(typeMap,
            goldenCuds, jsProgram);

        // BuildTypeMap can uncover syntactic JSNI errors; report & abort
        checkForErrors(logger, true);

        // Compute all super type/sub type info
        jprogram.typeOracle.computeBeforeAST();

        // (2) Create our own Java AST from the JDT AST.
        GenerateJavaAST.exec(allTypeDeclarations, typeMap, jprogram, jsProgram,
            options.isEnableAssertions());

        // GenerateJavaAST can uncover semantic JSNI errors; report & abort
        checkForErrors(logger, true);

        // Enable GC.
        typeMap = null;
        allTypeDeclarations = null;
      }

      // (3) Perform Java AST normalizations.

      FixAssignmentToUnbox.exec(jprogram);

      /*
       * TODO: If we defer this until later, we could maybe use the results of
       * the assertions to enable more optimizations.
       */
      if (options.isEnableAssertions()) {
        // Turn into assertion checking calls.
        AssertionNormalizer.exec(jprogram);
      } else {
        // Remove all assert statements.
        AssertionRemover.exec(jprogram);
      }

      // Resolve all rebinds through GWT.create().
      ReplaceRebinds.exec(jprogram);

      if (options.isValidateOnly()) {
        // That's it, we're done.
        return null;
      }

      // Also rebind all non-static entry points.
      findEntryPoints(logger, rebindOracle, declEntryPoints, jprogram);

      // Replace references to JSO subtypes with JSO itself.
      JavaScriptObjectNormalizer.exec(jprogram);

      /*
       * Record the beginning of optimations; this turns on certain checks that
       * guard against problematic late construction of things like class
       * literals.
       */
      jprogram.beginOptimizations();

      // (4) Optimize the normalized Java AST
      boolean didChange;
      do {
        // Recompute clinits each time, they can become empty.
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

        "int[][]", "Object[]", "Object");
  }

  private Result analyzeSnippet(String codeSnippet)
      throws UnableToCompleteException {
    JProgram program = compileSnippet("void", codeSnippet);
    ControlFlowAnalyzer cfa = new ControlFlowAnalyzer(program);
    cfa.traverseFrom(findMainMethod(program));
    return new Result(program, cfa);
  }
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program, ImmutableList.<String>of(),
        ImmutableList
            .of("EntryPoint$A.i1", "EntryPoint$A.i2", "EntryPoint$A.fi1", "EntryPoint$A.fi2"));
  }
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program,
        ImmutableList.of("EntryPoint$B.i1", "EntryPoint$B.i2", "EntryPoint$B.fi2"),
        ImmutableList.of("EntryPoint$B.fi1"));
  }
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program, ImmutableList.<String>of(),
        ImmutableList
            .of("EntryPoint$B.fi1", "EntryPoint$B.i1", "EntryPoint$B.i2", "EntryPoint$B.fi2"));
    MakeCallsStatic.exec(program, false);
    assertAnalysisCorrect(program, ImmutableList.<String>of(),
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program, ImmutableList.<String>of(),
        ImmutableList
            .of("EntryPoint$B.fi1", "EntryPoint$B.i1", "EntryPoint$B.i2", "EntryPoint$B.fi2"));
  }
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program, ImmutableList.<String>of(),
        ImmutableList
            .of("EntryPoint$B.fi1", "EntryPoint$B.i1", "EntryPoint$B.i2", "EntryPoint$B.fi2"));
  }
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program,
        ImmutableList.of("EntryPoint$B.i1", "EntryPoint$B.i2", "EntryPoint$B.fi2"),
        ImmutableList.of("EntryPoint$B.fi1"));
  }
View Full Code Here

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

        "  int i1 = 1;",
        "  Integer i2 = new Integer(1);",
        "  final int fi1 = 1;",
        "  final Integer fi2 = new Integer(1);",
        "}");
    JProgram program = compileSnippet("void", "return;");
    assertAnalysisCorrect(program,
        ImmutableList.of("EntryPoint$B.i1", "EntryPoint$B.i2", "EntryPoint$B.fi2"),
        ImmutableList.of("EntryPoint$B.fi1"));
  }
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.