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

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


      // Did we prune the parameters of the method we're calling?
      if (methodToOriginalParamsMap.containsKey(method)) {
        // This must be a static method
        assert method.isStatic();

        JMethodCall newCall = new JMethodCall(x, x.getInstance());
        List<JParameter> originalParams = methodToOriginalParamsMap.get(method);
        JMultiExpression currentMulti = null;
        for (int i = 0, c = x.getArgs().size(); i < c; ++i) {
          JExpression arg = x.getArgs().get(i);
          JParameter param = null;
          if (i < originalParams.size()) {
            param = originalParams.get(i);
          }

          if (param != null && referencedNonTypes.contains(param)) {
            // If there is an existing multi, terminate it.
            if (currentMulti != null) {
              currentMulti.exprs.add(arg);
              newCall.addArg(currentMulti);
              currentMulti = null;
            } else {
              newCall.addArg(arg);
            }
          } else if (arg.hasSideEffects()) {
            // The argument is only needed for side effects, add it to a multi.
            if (currentMulti == null) {
              currentMulti = new JMultiExpression(x.getSourceInfo());
            }
            currentMulti.exprs.add(arg);
          }
        }

        // Add any orphaned parameters on the end. Extra params are OK.
        if (currentMulti != null) {
          newCall.addArg(currentMulti);
        }

        ctx.replaceMe(newCall);
      }
    }
View Full Code Here


      /*
       * Replace the call to the original method with a call to the same method
       * on the tighter type.
       */
      JMethodCall call = new JMethodCall(x.getSourceInfo(), x.getInstance(),
          foundMethod);
      call.addArgs(x.getArgs());
      ctx.replaceMe(call);
    }
View Full Code Here

           */
          JMultiExpression multi = new JMultiExpression(info);
          JExpression instance = maybeMakeTempAssignment(multi, x.getInstance());

          // instance.method(arg, arg)
          JMethodCall localCall = new JMethodCall(info, instance, x.getTarget());
          localCall.addArgs(x.getArgs());

          // We need a second copy of the arguments for the else expression
          CloneExpressionVisitor cloner = new CloneExpressionVisitor(program);

          // instance.jsoMethod(arg, arg)
          JMethodCall jsoCall = new JMethodCall(info,
              cloner.cloneExpression(instance), jsoMethod);
          jsoCall.addArgs(cloner.cloneExpressions(x.getArgs()));

          // Cast.isJavaScriptObject() ? instance.jsoMethod() :
          // instance.method();
          JConditional newExpr = makeIsJsoConditional(info,
              cloner.cloneExpression(instance), x.getType(), jsoCall, localCall);

          multi.exprs.add(newExpr);
          // We may only have the ternary operation if there's no side-effect
          ctx.replaceMe(multi.exprs.size() == 1 ? multi.exprs.get(0) : multi);
        } else {
          /*
           * ... otherwise, if there's only a JSO implementation, we'll just
           * call that directly.
           */
          JMethodCall jsoCall = new JMethodCall(info, x.getInstance(),
              jsoMethod);
          jsoCall.addArgs(x.getArgs());
          ctx.replaceMe(jsoCall);
        }
      }
    }
View Full Code Here

    private JConditional makeIsJsoConditional(SourceInfo info,
        JExpression instance, JType conditionalType, JExpression isJsoExpr,
        JExpression notJsoExpr) {
      // Cast.isJavaScriptObjectOrString(instance)
      JMethod isJavaScriptObjectMethod = program.getIndexedMethod("Cast.isJavaScriptObjectOrString");
      JMethodCall isJavaScriptObjectExpr = new JMethodCall(info, null,
          isJavaScriptObjectMethod);
      isJavaScriptObjectExpr.addArg(instance);
      return new JConditional(info, conditionalType, isJavaScriptObjectExpr,
          isJsoExpr, notJsoExpr);
    }
View Full Code Here

    return false;
  }

  @Override
  public boolean visit(JMethodCall x, Context ctx) {
    JMethodCall newMethodCall = new JMethodCall(x,
        cloneExpression(x.getInstance()));
    newMethodCall.addArgs(cloneExpressions(x.getArgs()));
    expression = newMethodCall;
    return false;
  }
View Full Code Here

    public void endVisit(JAssertStatement x, Context ctx) {
      JExpression lhs = x.getTestExpr();
      String methodName = "Exceptions.throwAssertionError"
          + getAssertMethodSuffix(x.getArg());
      JMethod method = program.getIndexedMethod(methodName);
      JMethodCall rhs = new JMethodCall(x.getSourceInfo(), null, method);
      if (x.getArg() != null) {
        rhs.addArg(x.getArg());
      }
      JBinaryOperation binOp = new JBinaryOperation(x.getSourceInfo(), program.getTypePrimitiveBoolean(),
          JBinaryOperator.OR, lhs, rhs);
      ctx.replaceMe(binOp.makeStatement());
    }
View Full Code Here

            methodName = "Cast.isNull";
          } else {
            methodName = "Cast.isNotNull";
          }
          JMethod isNullMethod = program.getIndexedMethod(methodName);
          JMethodCall call = new JMethodCall(x.getSourceInfo(), null, isNullMethod);
          call.addArg(lhsNullLit ? rhs : lhs);
          ctx.replaceMe(call);
        } else {
          // Replace with a call to Cast.jsEquals, which does a == internally.
          String methodName;
          if (op == JBinaryOperator.EQ) {
            methodName = "Cast.jsEquals";
          } else {
            methodName = "Cast.jsNotEquals";
          }
          JMethod eqMethod = program.getIndexedMethod(methodName);
          JMethodCall call = new JMethodCall(x.getSourceInfo(), null, eqMethod);
          call.addArgs(lhs, rhs);
          ctx.replaceMe(call);
        }
      }
    }
View Full Code Here

      }
    }

    private JExpression maskUndefined(JExpression lhs) {
      JMethod maskMethod = program.getIndexedMethod("Cast.maskUndefined");
      JMethodCall lhsCall = new JMethodCall(lhs.getSourceInfo(), null, maskMethod,
          lhs.getType());
      lhsCall.addArg(lhs);
      return lhsCall;
    }
View Full Code Here

      JBlock newCatchBlock = new JBlock(catchInfo);

      {
        // $e = Exceptions.caught($e)
        JMethod caughtMethod = program.getIndexedMethod("Exceptions.caught");
        JMethodCall call = new JMethodCall(catchInfo, null, caughtMethod);
        call.addArg(new JLocalRef(catchInfo, exVar));
        newCatchBlock.addStmt(program.createAssignmentStmt(catchInfo,
            new JLocalRef(catchInfo, exVar), call));
      }

      /*
 
View Full Code Here

    return new MakeCallsStatic(program).execImpl();
  }

  static JExpression makeStaticCall(JMethodCall x, JMethod newMethod) {
    // Update the call site
    JMethodCall newCall = new JMethodCall(x.getSourceInfo().makeChild(
        MakeCallsStatic.class, "Devirtualized function call"), null, newMethod);

    /*
     * If the qualifier is a JMultiExpression, invoke on the last value. This
     * ensures that clinits maintain the same execution order relative to
     * parameters in deeply-inlined scenarios.
     */
    // (a, b).foo() --> (a, foo(b))
    if (x.getInstance() instanceof JMultiExpression) {
      JMultiExpression multi = (JMultiExpression) x.getInstance();
      int lastIndex = multi.exprs.size() - 1;
      newCall.addArg(multi.exprs.get(lastIndex));
      newCall.addArgs(x.getArgs());
      multi.exprs.set(lastIndex, newCall);
      return multi;
    } else {
      // The qualifier becomes the first arg
      // a.foo(b) --> foo(a,b)
      newCall.addArg(x.getInstance());
      newCall.addArgs(x.getArgs());
      return newCall;
    }
  }
View Full Code Here

TOP

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

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.