Package com.google.gwt.dev.jjs.ast

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


      if (argType != longType) {
        return;
      }

      String methodName = getEmulationMethod(x.getOp());
      JMethod method = program.getIndexedMethod("LongLib." + methodName);
      JMethodCall call = new JMethodCall(x.getSourceInfo(), null, method,
          x.getType());
      call.addArg(x.getArg());
      ctx.replaceMe(call);
    }
View Full Code Here


    }

    @Override
    public void endVisit(JMethodCall x, Context ctx) {
      JExpression instance = x.getInstance();
      JMethod method = x.getTarget();
      boolean isStatic = method.isStatic();
      boolean isStaticImpl = program.isStaticImpl(method);
      if (isStatic && !isStaticImpl && instance != null) {
        // this doesn't really belong here, but while we're here let's remove
        // non-side-effect qualifiers to statics
        if (!instance.hasSideEffects()) {
          JMethodCall newCall = new JMethodCall(x.getSourceInfo(), null,
              x.getTarget());
          newCall.addArgs(x.getArgs());
          ctx.replaceMe(newCall);
        }
      } else if (!isStatic && instance.getType() == typeNull) {
        ctx.replaceMe(Pruner.transformToNullMethodCall(x, program));
      } else if (isStaticImpl && method.getParams().size() > 0
          && method.getParams().get(0).isThis() && x.getArgs().size() > 0
          && x.getArgs().get(0).getType() == typeNull) {
        // bind null instance calls to the null method for static impls
        ctx.replaceMe(Pruner.transformToNullMethodCall(x, program));
      }
    }
View Full Code Here

    @Override
    public void endVisit(JsniMethodRef x, Context ctx) {
      // If this happens in JSNI, we can't make any type-tightening assumptions
      // Fake an assignment-to-self on all args to prevent tightening
      JMethod method = x.getTarget();
      for (JParameter param : method.getParams()) {
        addAssignment(param, new JParameterRef(
            program.createSourceInfoSynthetic(RecordVisitor.class,
                "Fake assignment"), param));
      }
    }
View Full Code Here

         * the instance method, future optimization could tighten an instance
         * call into a static call at some other call site, and fail to inline.
         * If we allowed a staticImpl param to be tighter than its instance
         * param, badness would ensue.
         */
        JMethod staticImplFor = program.staticImplFor(x);
        if (staticImplFor == null
            || !staticImplFor.getEnclosingType().getMethods().contains(staticImplFor)) {
          // The instance method has already been pruned.
          return true;
        }
        assert (x.getParams().size() == staticImplFor.getParams().size() + 1);
        for (int j = 0, c = x.getParams().size(); j < c; ++j) {
          JParameter param = x.getParams().get(j);
          Set<JParameter> set = paramUpRefs.get(param);
          if (set == null) {
            set = new HashSet<JParameter>();
            paramUpRefs.put(param, set);
          }
          if (j == 0) {
            // Fake an assignment-to-self to prevent tightening; consider this
            // an implicit assignment from a this reference of the looser type.
            assert (param.isThis());
            set.add(param);
          } else {
            JParameter baseParam = staticImplFor.getParams().get(j - 1);
            set.add(baseParam);
          }
        }
      }

View Full Code Here

     * Resolve method calls that can be computed statically.
     */
    @Override
    public void endVisit(JMethodCall x, Context ctx) {
      // Restore ignored expressions.
      JMethod target = x.getTarget();
      if (target.isStatic() && x.getInstance() != null) {
        ignoringExpressionOutput.remove(x.getInstance());
      }

      int paramCount = target.getParams().size();
      for (int i = paramCount; i < x.getArgs().size(); ++i) {
        JExpression arg = x.getArgs().get(i);
        ignoringExpressionOutput.remove(arg);
        if (!arg.hasSideEffects()) {
          x.removeArg(i--);
          didChange = true;
        }
      }

      // Normal optimizations.
      JDeclaredType targetType = target.getEnclosingType();
      if (targetType == program.getTypeJavaLangString()) {
        tryOptimizeStringCall(x, ctx, target);
      } else if (JProgram.isClinit(target)) {
        // Eliminate the call if the target is now empty.
        if (!targetType.hasClinit()) {
View Full Code Here

      return true;
    }

    @Override
    public boolean visit(JMethodCall x, Context ctx) {
      JMethod target = x.getTarget();
      if (target.isStatic() && x.getInstance() != null) {
        ignoringExpressionOutput.add(x.getInstance());
      }
      List<JExpression> args = x.getArgs();
      List<JExpression> ignoredArgs = args.subList(target.getParams().size(),
          args.size());
      ignoringExpressionOutput.addAll(ignoredArgs);
      return true;
    }
View Full Code Here

      return typeClassMap.get(type);
    }

    private JMethodCall maybeCreateClinitCall(JFieldRef x) {
      if (x.hasClinit()) {
        JMethod clinit = x.getField().getEnclosingType().getMethods().get(0);
        assert (JProgram.isClinit(clinit));
        return new JMethodCall(x.getSourceInfo(), null, clinit);
      }
      return null;
    }
View Full Code Here

      try {
        MethodBinding b = ctorDecl.binding;
        JClassType enclosingType = (JClassType) typeMap.get(scope.enclosingSourceType());
        String name = enclosingType.getShortName();
        SourceInfo info = makeSourceInfo(ctorDecl, enclosingType);
        JMethod newMethod = program.createMethod(info, name.toCharArray(),
            enclosingType, enclosingType, false, false, true, b.isPrivate(),
            false);

        // Enums have hidden arguments for name and value
        if (enclosingType.isEnumOrSubclass() != null) {
View Full Code Here

    public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
      try {
        MethodBinding b = methodDeclaration.binding;
        JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.enclosingSourceType());
        SourceInfo info = makeSourceInfo(methodDeclaration, enclosingType);
        JMethod newMethod = processMethodBinding(b, enclosingType, info);
        mapParameters(newMethod, methodDeclaration);
        info.addCorrelation(program.getCorrelator().by(newMethod));

        if (newMethod.isNative()) {
          processNativeMethod(methodDeclaration, info, enclosingType, newMethod);
        }

        return true;
      } catch (Throwable e) {
View Full Code Here

    private JMethod createSyntheticConstructor(JMethod constructor,
        boolean staticClass, JReferenceType enclosingType) {
      JClassType type = (JClassType) constructor.getEnclosingType();

      // Define the method
      JMethod synthetic = program.createMethod(type.getSourceInfo().makeChild(
          BuildDeclMapVisitor.class, "Synthetic constructor"),
          "new".toCharArray(), type, type, false, true, true, false, false);

      // new Foo() : Create the instance
      JNewInstance newInstance = new JNewInstance(
          type.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
              "new instance"), type);

      // (new Foo()).Foo() : Invoke the constructor method on the instance
      JMethodCall call = new JMethodCall(type.getSourceInfo().makeChild(
          BuildDeclMapVisitor.class, "constructor invocation"), newInstance,
          constructor);
      /*
       * If the type isn't static, make the first parameter a reference to the
       * instance of the enclosing class. It's the first instance to allow the
       * JSNI qualifier to be moved without affecting evaluation order.
       */
      JParameter enclosingInstance = null;
      if (!staticClass) {
        enclosingInstance = program.createParameter(
            synthetic.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
                "outer instance"), "this$outer".toCharArray(), enclosingType,
            false, false, synthetic);
      }

      /*
       * In one pass, add the parameters to the synthetic constructor and
       * arguments to the method call.
       */
      for (Iterator<JParameter> i = constructor.getParams().iterator(); i.hasNext();) {
        JParameter param = i.next();
        /*
         * This supports x.new Inner() by passing the enclosing instance
         * implicitly as the last argument to the constructor.
         */
        if (enclosingInstance != null && !i.hasNext()) {
          call.addArg(new JParameterRef(synthetic.getSourceInfo().makeChild(
              BuildDeclMapVisitor.class, "enclosing instance"),
              enclosingInstance));
        } else {
          JParameter syntheticParam = program.createParameter(
              synthetic.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
                  "Argument " + param.getName()),
              param.getName().toCharArray(), param.getType(), true, false,
              synthetic);
          call.addArg(new JParameterRef(
              syntheticParam.getSourceInfo().makeChild(
                  BuildDeclMapVisitor.class, "reference"), syntheticParam));
        }
      }

      // Lock the method.
      synthetic.freezeParamTypes();

      // return (new Foo()).Foo() : The only statement in the function
      JReturnStatement ret = new JReturnStatement(
          synthetic.getSourceInfo().makeChild(BuildDeclMapVisitor.class,
              "Return statement"), call);

      // Add the return statement to the method body
      JMethodBody body = (JMethodBody) synthetic.getBody();
      body.getBlock().addStmt(ret);

      // Done
      return synthetic;
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JMethod

Copyright © 2018 www.massapicom. 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.