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

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


      // Create a new body for the instance method that delegates to the static
      SourceInfo delegateCallSourceInfo = sourceInfo.makeChild(
          CreateStaticImplsVisitor.class, "Degelgating to devirtualized method");
      JMethodBody newBody = new JMethodBody(delegateCallSourceInfo);
      x.setBody(newBody);
      JMethodCall newCall = new JMethodCall(delegateCallSourceInfo, null,
          newMethod);
      newCall.addArg(new JThisRef(delegateCallSourceInfo, enclosingType));
      for (int i = 0; i < x.getParams().size(); ++i) {
        JParameter param = x.getParams().get(i);
        newCall.addArg(new JParameterRef(delegateCallSourceInfo, param));
      }
      JStatement statement;
      if (returnType == program.getTypeVoid()) {
        statement = newCall.makeStatement();
      } else {
        statement = new JReturnStatement(delegateCallSourceInfo, newCall);
      }
      newBody.getBlock().addStmt(statement);
View Full Code Here


      if (!x.getTarget().isStatic()) {
        // for polymorphic calls, force wrapping
        JExpression newInst = checkAndReplaceJso(x.getInstance(),
            program.getTypeJavaLangObject());
        if (newInst != x.getInstance()) {
          JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
              newInst, x.getTarget(), x.isStaticDispatchOnly());
          newCall.getArgs().addAll(x.getArgs());
          ctx.replaceMe(newCall);
        }
      }
    }
View Full Code Here

      RewriteMethodBody rewriter = new RewriteMethodBody(thisParam, varMap);
      rewriter.accept(newMethod);

      SourceInfo bodyInfo = x.body.getSourceInfo();
      // delegate from the instance method to the static method
      JMethodCall newCall = new JMethodCall(program, bodyInfo, null, newMethod);
      newCall.getArgs().add(program.getExprThisRef(bodyInfo, enclosingType));
      for (int i = 0; i < x.params.size(); ++i) {
        JParameter param = (JParameter) x.params.get(i);
        newCall.getArgs().add(new JParameterRef(program, bodyInfo, param));
      }
      JStatement statement;
      if (oldReturnType == program.getTypeVoid()) {
        statement = newCall.makeStatement();
      } else {
        statement = new JReturnStatement(program, bodyInfo, newCall);
      }
      x.body.statements.add(statement);
View Full Code Here

      if (newMethod == null || x.canBePolymorphic()) {
        return;
      }

      // Update the call site
      JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(), null,
          newMethod);

      // The qualifier becomes the first arg
      newCall.getArgs().add(x.getInstance());
      // Copy the rest of the args
      for (int i = 0; i < x.getArgs().size(); ++i) {
        newCall.getArgs().add(x.getArgs().get(i));
      }
      ctx.replaceMe(newCall);
    }
View Full Code Here

        if (elementType instanceof JReferenceType
            && (!((JReferenceType) elementType).isFinal())
            || elementType != x.getRhs().getType()) {
          // replace this assignment with a call to setCheck()

          JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
              setCheckMethod);
          call.getArgs().add(arrayRef.getInstance());
          call.getArgs().add(arrayRef.getIndexExpr());
          call.getArgs().add(x.getRhs());
          ctx.replaceMe(call);
        }
      }
    }
View Full Code Here

    }

    private void processDims(JNewArray x, Context ctx, JArrayType arrayType,
        JLiteral litTypeName) {
      // override the type of the called method with the array's type
      JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
          initDims, arrayType);
      JsonArray typeIdList = new JsonArray(program);
      JsonArray queryIdList = new JsonArray(program);
      JsonArray dimList = new JsonArray(program);
      JType leafType = arrayType.getLeafType();
      int outstandingDims = arrayType.getDims();
      for (int i = 0; i < x.dims.size(); ++i) {
        JExpression dim = (JExpression) x.dims.get(i);
        if (dim instanceof JAbsentArrayDimension) {
          break;
        }

        /*
         * For each non-empty dimension, reduce the number of dims on the end
         * type.
         *
         * new int[2][ ][ ]->int[][]
         *
         * new int[2][3][ ]->int[]
         *
         * new int[2][3][4]->int
         *
         */
        JArrayType cur = program.getTypeArray(leafType, outstandingDims--);
        JLiteral typeIdLit = program.getLiteralInt(program.getTypeId(cur));
        typeIdList.exprs.add(typeIdLit);
        JLiteral queryIdLit = program.getLiteralInt(tryGetQueryId(cur));
        queryIdList.exprs.add(queryIdLit);
        dimList.exprs.add(dim);
      }
      JType targetType = leafType;
      if (outstandingDims > 0) {
        targetType = program.getTypeArray(targetType, outstandingDims);
      }

      call.getArgs().add(litTypeName);
      call.getArgs().add(typeIdList);
      call.getArgs().add(queryIdList);
      call.getArgs().add(dimList);
      call.getArgs().add(targetType.getDefaultValue());
      ctx.replaceMe(call);
    }
View Full Code Here

    }

    private void processInitializers(JNewArray x, Context ctx,
        JArrayType arrayType, JLiteral litTypeName) {
      // override the type of the called method with the array's type
      JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
          initValues, arrayType);
      JLiteral typeIdLit = program.getLiteralInt(program.getTypeId(arrayType));
      JLiteral queryIdLit = program.getLiteralInt(tryGetQueryId(arrayType));
      JsonArray initList = new JsonArray(program);
      for (int i = 0; i < x.initializers.size(); ++i) {
        initList.exprs.add(x.initializers.get(i));
      }
      call.getArgs().add(litTypeName);
      call.getArgs().add(typeIdLit);
      call.getArgs().add(queryIdLit);
      call.getArgs().add(initList);
      ctx.replaceMe(call);
    }
View Full Code Here

      JLocal exObj = popTempLocal();
      JLocalRef exRef = new JLocalRef(program, catchInfo, exObj);
      JBlock newCatchBlock = new JBlock(program, catchInfo);
      // $e = Exceptions.caught($e)
      JMethod caughtMethod = program.getSpecialMethod("Exceptions.caught");
      JMethodCall call = new JMethodCall(program, catchInfo, null, caughtMethod);
      call.getArgs().add(exRef);
      JExpressionStatement asg = program.createAssignmentStmt(catchInfo, exRef,
          call);
      newCatchBlock.statements.add(asg);

      /*
 
View Full Code Here

        SourceInfo info = ctor.body.getSourceInfo();

        currentMethod = ctor;
        currentMethodScope = x.scope;

        JMethodCall superOrThisCall = null;
        ExplicitConstructorCall ctorCall = x.constructorCall;
        if (ctorCall != null) {
          superOrThisCall = (JMethodCall) dispatch("processExpression",
              ctorCall);
        }

        /*
         * Determine if we have an explicit this call. The presence of an
         * explicit this call indicates we can skip certain initialization steps
         * (as the callee will perform those steps for us). These skippable
         * steps are 1) assigning synthetic args to fields and 2) running
         * initializers.
         */
        boolean hasExplicitThis = (ctorCall != null)
            && !ctorCall.isSuperAccess();

        JClassType enclosingType = (JClassType) ctor.getEnclosingType();

        // Call clinit; $clinit is always in position 0.
        JMethod clinitMethod = (JMethod) enclosingType.methods.get(0);
        JMethodCall clinitCall = new JMethodCall(program, info, null,
            clinitMethod);
        ctor.body.statements.add(clinitCall.makeStatement());

        /*
         * All synthetic fields must be assigned, unless we have an explicit
         * this constructor call, in which case the callee will assign them for
         * us.
         */
        if (!hasExplicitThis) {
          ReferenceBinding declaringClass = x.binding.declaringClass;
          if (declaringClass instanceof NestedTypeBinding) {
            Iterator/* <JParameter> */paramIt = getSyntheticsIterator(ctor);
            NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
            if (nestedBinding.enclosingInstances != null) {
              for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
                SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
                JParameter param = (JParameter) paramIt.next();
                if (arg.matchingField != null) {
                  JField field = (JField) typeMap.get(arg);
                  ctor.body.statements.add(program.createAssignmentStmt(info,
                      createVariableRef(info, field), createVariableRef(info,
                          param)));
                }
              }
            }

            if (nestedBinding.outerLocalVariables != null) {
              for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
                SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
                JParameter param = (JParameter) paramIt.next();
                JField field = (JField) typeMap.get(arg);
                ctor.body.statements.add(program.createAssignmentStmt(info,
                    createVariableRef(info, field), createVariableRef(info,
                        param)));
              }
            }
          }
        }

        // optional this or super constructor call
        if (superOrThisCall != null) {
          ctor.body.statements.add(superOrThisCall.makeStatement());
        }

        JExpression thisRef = createThisRef(info, enclosingType);

        /*
         * Call the synthetic instance initializer method, unless we have an
         * explicit this constructor call, in which case the callee will.
         */
        if (!hasExplicitThis) {
          // $init is always in position 1 (clinit is in 0)
          JMethod initMethod = (JMethod) enclosingType.methods.get(1);
          JMethodCall initCall = new JMethodCall(program, info, thisRef,
              initMethod);
          ctor.body.statements.add(initCall.makeStatement());
        }

        // user code (finally!)
        if (x.statements != null) {
          for (int i = 0, n = x.statements.length; i < n; ++i) {
View Full Code Here

        return program.getLiteralNull();
      }
      JClassType newType = (JClassType) typeMap.get(typeBinding);
      MethodBinding b = x.binding;
      JMethod ctor = (JMethod) typeMap.get(b);
      JMethodCall call;
      JClassType javaLangString = program.getTypeJavaLangString();
      if (newType == javaLangString) {
        /*
         * MAGIC: java.lang.String is implemented as a JavaScript String
         * primitive with a modified prototype. This requires funky handling of
         * constructor calls. We find a method named _String() whose signature
         * matches the requested constructor
         */
        int ctorArgc = ctor.params.size();
        JMethod targetMethod = null;
        outer : for (int j = 0; j < javaLangString.methods.size(); ++j) {
          JMethod method = (JMethod) javaLangString.methods.get(j);
          if (method.getName().equals("_String")
              && method.params.size() == ctorArgc) {
            for (int i = 0; i < ctorArgc; ++i) {
              JParameter mparam = (JParameter) method.params.get(i);
              JParameter cparam = (JParameter) ctor.params.get(i);
              if (mparam.getType() != cparam.getType()) {
                continue outer;
              }
            }
            targetMethod = method;
            break;
          }
        }
        if (targetMethod == null) {
          throw new InternalCompilerException(
              "String constructor error; no matching implementation.");
        }
        call = new JMethodCall(program, makeSourceInfo(x), null, targetMethod);
      } else {
        JNewInstance newInstance = new JNewInstance(program, info, newType);
        call = new JMethodCall(program, info, newInstance, ctor);
      }

      // Plain old regular user arguments
      if (x.arguments != null) {
        for (int i = 0, n = x.arguments.length; i < n; ++i) {
          call.getArgs().add(dispProcessExpression(x.arguments[i]));
        }
      }

      // Synthetic args for inner classes
      ReferenceBinding targetBinding = b.declaringClass;
      if (targetBinding.isNestedType() && !targetBinding.isStatic()) {
        NestedTypeBinding nestedBinding = (NestedTypeBinding) targetBinding;
        // Synthetic this args for inner classes
        if (nestedBinding.enclosingInstances != null) {
          for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
            SyntheticArgumentBinding arg = nestedBinding.enclosingInstances[i];
            JClassType syntheticThisType = (JClassType) typeMap.get(arg.type);
            call.getArgs().add(createThisRef(info, syntheticThisType));
          }
        }
        // Synthetic locals for local classes
        if (nestedBinding.outerLocalVariables != null) {
          for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
            SyntheticArgumentBinding arg = nestedBinding.outerLocalVariables[i];
            JVariable variable = (JVariable) typeMap.get(arg.actualOuterLocalVariable);
            call.getArgs().add(
                createVariableRef(info, variable, arg.actualOuterLocalVariable));
          }
        }
      }

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.