Examples of JMethodBody


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

  private Result analyzeExpression(String type, String expression)
      throws UnableToCompleteException {
    JProgram program = compileSnippet(type, "return " + expression + ";");
    ExpressionAnalyzer ea = new ExpressionAnalyzer();
    JMethod mainMethod = findMainMethod(program);
    JMethodBody body = (JMethodBody) mainMethod.getBody();
    JReturnStatement returnStmt = (JReturnStatement) body.getStatements().get(0);
    ea.accept(returnStmt.getExpr());
    return new Result(ea);
  }
View Full Code Here

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

  private JExpression getExpression(String type, String expression)
      throws UnableToCompleteException {
    JProgram program = compileSnippet(type, "return " + expression + ";");
    JMethod mainMethod = findMainMethod(program);
    JMethodBody body = (JMethodBody) mainMethod.getBody();
    JReturnStatement returnStmt = (JReturnStatement) body.getStatements().get(0);
    return returnStmt.getExpr();
  }
View Full Code Here

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

  private JBlock getStatement(String statement)
      throws UnableToCompleteException {
    JProgram program = compileSnippet("void", statement);
    JMethod mainMethod = findMainMethod(program);
    JMethodBody body = (JMethodBody) mainMethod.getBody();
    return body.getBlock();
  }
View Full Code Here

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

  private void insertImplicitClinitCalls(final JMethod method) {
    // Mimic the method inliner which inserts clinits calls prior to method or field dereference.
    // The actual clinit() calls might be inserted as a result of optimizations: e,g,
    // DeadCodeElimination inserts clinit calls when it removes (some) field accesses or method
    // calls.
    final JMethodBody body = (JMethodBody) method.getBody();

    new JModVisitor() {

      private JMethodCall createClinitCall(SourceInfo sourceInfo, JDeclaredType targetType) {
        JMethod clinit = targetType.getClinitTarget().getClinitMethod();
View Full Code Here

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

          "return " + expressionSnippets[expressionSnippets.length - 1];
    }
    String snippet = Joiner.on(";\n").join(expressionSnippets) + ";\n";
    final JProgram program = compileSnippet(returnType, snippet);
    JMethod method = findMethod(program, MAIN_METHOD_NAME);
    JMethodBody body = (JMethodBody) method.getBody();
    JMultiExpression multi = new JMultiExpression(body.getSourceInfo());

    // Transform statement sequence into a JMultiExpression
    for (JStatement stmt : body.getStatements()) {

      if (stmt instanceof JExpressionStatement) {
        JExpressionStatement exprStmt = (JExpressionStatement) stmt;
        JExpression expr = exprStmt.getExpr();
        multi.addExpressions(expr);
      } else if (stmt instanceof JReturnStatement) {
        JReturnStatement returnStatement = (JReturnStatement) stmt;
        JExpression expr = returnStatement.getExpr();
        if (expr != null) {
            multi.addExpressions(expr);
        }
      } else {
        assert false : "Not a valid multiexpression";
      }
    }

    // Take care of the return type
    JStatement multiStm;
    if (!returnType.equals("void")) {
      multiStm = new JReturnStatement(multi.getSourceInfo(), multi);
    } else {
      multiStm = multi.makeStatement();
    }

    // Replace the method body
    JMethodBody newBody = new JMethodBody(method.getBody().getSourceInfo());
    newBody.getBlock().addStmt(multiStm);
    method.setBody(newBody);
    newBody.setMethod(method);
    if (addClinitCalls) {
      insertImplicitClinitCalls(method);
    }

View Full Code Here

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

  }

  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);

    Map<CfgEdge, A> map = AnalysisSolver.solve(cfgGraph, createAnalysis(), forward);
    return new AnalysisResult(cfgGraph, map);
View Full Code Here

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

    extends OptimizerTestBase {
  protected boolean forward = true;

  @Override
  protected boolean optimizeMethod(JProgram program, JMethod method) {
    JMethodBody body = (JMethodBody) method.getBody();
    Cfg cfgGraph = CfgBuilder.build(program, body.getBlock());

    assertNotNull(cfgGraph);

    return AnalysisSolver.solveIntegrated(cfgGraph, createIntegratedAnalysis(), forward);
  }
View Full Code Here

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

  }

  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.JMethodBody

    return new JIntLiteral(SourceOrigin.UNKNOWN, value);
  }

  private JLocal newLocal(String name, JPrimitiveType type) {
    return JProgram.createLocal(SourceOrigin.UNKNOWN, name, type, false,
        new JMethodBody(SourceOrigin.UNKNOWN));
  }
View Full Code Here

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

      // 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.
       */
 
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.