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

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


        }
      } else {
        qualifier = dispProcessExpression(x.receiver);
      }

      JMethodCall call = new JMethodCall(program, info, qualifier, method);

      // On a super ref, don't allow polymorphic dispatch. Oddly enough,
      // QualifiedSuperReference not derived from SuperReference!
      boolean isSuperRef = x.receiver instanceof SuperReference
          || x.receiver instanceof QualifiedSuperReference;
      if (isSuperRef) {
        call.setStaticDispatchOnly();
      }

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

      return call;
    }
View Full Code Here


      SourceInfo info = makeSourceInfo(x);
      MethodBinding b = x.binding;
      JMethod ctor = (JMethod) typeMap.get(b);
      JClassType enclosingType = (JClassType) ctor.getEnclosingType();
      JNewInstance newInstance = new JNewInstance(program, info, enclosingType);
      JMethodCall call = new JMethodCall(program, info, newInstance, ctor);
      JExpression qualifier = dispProcessExpression(x.enclosingInstance);
      List qualList = new ArrayList();
      qualList.add(qualifier);

      /*
       * Really weird: Sometimes an allocation expression needs both its
       * explicit qualifier AND its implicit enclosing class! We add this second
       * because the explicit qualifier takes precedence.
       */
      if (!currentMethod.isStatic()) {
        JExpression implicitOuter = program.getExprThisRef(info,
            (JClassType) currentClass);
        qualList.add(implicitOuter);
      }

      // Plain old regular 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(syntheticThisType, qualList));
          }
        }
        // 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

    JMethodCall processSuperConstructorCall(ExplicitConstructorCall x) {
      SourceInfo info = makeSourceInfo(x);
      JMethod ctor = (JMethod) typeMap.get(x.binding);
      JExpression trueQualifier = createThisRef(info, currentClass);
      JMethodCall call = new JMethodCall(program, info, trueQualifier, ctor);

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

      // We have to find and pass through any synthetics our supertype needs
      ReferenceBinding superClass = x.binding.declaringClass;
      if (superClass instanceof NestedTypeBinding && !superClass.isStatic()) {
        NestedTypeBinding myBinding = (NestedTypeBinding) currentClassScope.referenceType().binding;
        NestedTypeBinding superBinding = (NestedTypeBinding) superClass;

        // enclosing types
        if (superBinding.enclosingInstances != null) {
          JExpression qualifier = dispProcessExpression(x.qualification);
          for (int j = 0; j < superBinding.enclosingInstances.length; ++j) {
            SyntheticArgumentBinding arg = superBinding.enclosingInstances[j];
            JClassType classType = (JClassType) typeMap.get(arg.type);
            if (qualifier == null) {
              /*
               * Got to be one of my params; it would be illegal to use a this
               * ref at this moment-- we would most likely be passing in a
               * supertype field that HASN'T BEEN INITIALIZED YET.
               *
               * Unfortunately, my params might not work as-is, so we have to
               * check each one to see if any will make a suitable this ref.
               */
              List/* <JExpression> */workList = new ArrayList/* <JExpression> */();
              Iterator/* <JParameter> */paramIt = getSyntheticsIterator(currentMethod);
              for (int i = 0; i < myBinding.enclosingInstances.length; ++i) {
                workList.add(createVariableRef(info,
                    (JParameter) paramIt.next()));
              }
              call.getArgs().add(createThisRef(classType, workList));
            } else {
              call.getArgs().add(createThisRef(classType, qualifier));
            }
          }
        }

        // outer locals
        if (superBinding.outerLocalVariables != null) {
          for (int j = 0; j < superBinding.outerLocalVariables.length; ++j) {
            SyntheticArgumentBinding arg = superBinding.outerLocalVariables[j];
            // Got to be one of my params
            JType varType = (JType) typeMap.get(arg.type);
            String varName = String.valueOf(arg.name);
            JParameter param = null;
            for (int i = 0; i < currentMethod.params.size(); ++i) {
              JParameter paramIt = (JParameter) currentMethod.params.get(i);
              if (varType == paramIt.getType()
                  && varName.equals(paramIt.getName())) {
                param = paramIt;
              }
            }
            if (param == null) {
              throw new InternalCompilerException(
                  "Could not find matching local arg for explicit super ctor call.");
            }
            call.getArgs().add(createVariableRef(info, param));
          }
        }
      }

      return call;
View Full Code Here

    JMethodCall processThisConstructorCall(ExplicitConstructorCall x) {
      SourceInfo info = makeSourceInfo(x);
      JMethod ctor = (JMethod) typeMap.get(x.binding);
      JExpression trueQualifier = createThisRef(info, currentClass);
      JMethodCall call = new JMethodCall(program, info, trueQualifier, ctor);

      assert (x.qualification == null);

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

      // All synthetics must be passed through to the target ctor
      ReferenceBinding declaringClass = x.binding.declaringClass;
      if (declaringClass instanceof NestedTypeBinding) {
        Iterator/* <JParameter> */paramIt = getSyntheticsIterator(currentMethod);
        NestedTypeBinding nestedBinding = (NestedTypeBinding) declaringClass;
        if (nestedBinding.enclosingInstances != null) {
          for (int i = 0; i < nestedBinding.enclosingInstances.length; ++i) {
            call.getArgs().add(
                createVariableRef(info, (JParameter) paramIt.next()));
          }
        }
        if (nestedBinding.outerLocalVariables != null) {
          for (int i = 0; i < nestedBinding.outerLocalVariables.length; ++i) {
            call.getArgs().add(
                createVariableRef(info, (JParameter) paramIt.next()));
          }
        }
      }

View Full Code Here

          }

          // Construct a new instance of the class to qualify the non-static
          // call
          JNewInstance newInstance = new JNewInstance(program, null, mainClass);
          qualifier = new JMethodCall(program, null, newInstance, noArgCtor);
        }
      }

      // qualifier will be null if onModuleLoad is static
      JMethodCall onModuleLoadCall = new JMethodCall(program, null, qualifier,
          mainMethod);
      bootStrapMethod.body.statements.add(onModuleLoadCall.makeStatement());
    }
    program.addEntryMethod(bootStrapMethod);
  }
View Full Code Here

      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(program, x.getSourceInfo(),
              null, x.getTarget());
          newCall.getArgs().addAll(x.getArgs());
          ctx.replaceMe(newCall);
        }
      } else if (!isStatic && instance.getType() == typeNull) {
        // bind null instance calls to the null method
        if (!instance.hasSideEffects()) {
          instance = program.getLiteralNull();
        }
        JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
            instance, program.getNullMethod());
        ctx.replaceMe(newCall);
      } else if (isStaticImpl && x.getArgs().size() > 0
          && ((JExpression) x.getArgs().get(0)).getType() == typeNull) {
        // bind null instance calls to the null method for static impls
        instance = (JExpression) x.getArgs().get(0);
        if (!instance.hasSideEffects()) {
          instance = program.getLiteralNull();
        }
        JMethodCall newCall = new JMethodCall(program, x.getSourceInfo(),
            instance, program.getNullMethod());
        ctx.replaceMe(newCall);
      }
    }
View Full Code Here

        // Replace the character with a call to Cast.charToString()
        if (stringValueOfChar == null) {
          stringValueOfChar = program.getSpecialMethod("Cast.charToString");
          assert (stringValueOfChar != null);
        }
        JMethodCall call = new JMethodCall(program, expr.getSourceInfo(), null,
            stringValueOfChar);
        call.getArgs().add(expr);
        return call;
      }
      return expr;
    }
View Full Code Here

         */
        JMethod method = program.getSpecialMethod("Cast.throwClassCastExceptionUnlessNull");
        /*
         * Override the type of the magic method with the null type.
         */
        JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
            method, program.getTypeNull());
        call.getArgs().add(x.getExpr());
        replaceExpr = call;
      } else if (toType instanceof JReferenceType) {
        JExpression curExpr = x.getExpr();
        JReferenceType refType = (JReferenceType) toType;
        JType argType = x.getExpr().getType();
        if (program.isJavaScriptObject(argType)) {
          /*
           * A JSO-derived class that is about to be cast must be "wrapped"
           * first. Since a JSO was never constructed, it may not have an
           * accessible prototype. Instead we copy fields from the seed
           * function's prototype directly onto the target object as expandos.
           * See com.google.gwt.lang.Cast.wrapJSO().
           */
          JMethod wrap = program.getSpecialMethod("Cast.wrapJSO");
          // override the type of the called method with the JSO's type
          JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
              wrap, argType);
          JClassSeed seed = program.getLiteralClassSeed((JClassType) argType);
          call.getArgs().add(curExpr);
          call.getArgs().add(seed);
          curExpr = call;
        }
        if (argType instanceof JClassType
            && program.typeOracle.canTriviallyCast((JClassType) argType,
                refType)) {
          // TODO(???): why is this only for JClassType?
          // just remove the cast
          replaceExpr = curExpr;
        } else {
          JMethod method = program.getSpecialMethod("Cast.dynamicCast");
          // override the type of the called method with the target cast type
          JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
              method, toType);
          Integer boxedInt = (Integer) queryIds.get(refType);
          JIntLiteral qId = program.getLiteralInt(boxedInt.intValue());
          call.getArgs().add(curExpr);
          call.getArgs().add(qId);
          replaceExpr = call;
        }
      } else {
        /*
         * See JLS 5.1.3: if a cast narrows from one type to another, we must
         * call a narrowing conversion function. EXCEPTION: we currently have no
         * way to narrow double to float, so don't bother.
         */
        boolean narrow = false, round = false;
        JPrimitiveType tByte = program.getTypePrimitiveByte();
        JPrimitiveType tChar = program.getTypePrimitiveChar();
        JPrimitiveType tShort = program.getTypePrimitiveShort();
        JPrimitiveType tInt = program.getTypePrimitiveInt();
        JPrimitiveType tLong = program.getTypePrimitiveLong();
        JPrimitiveType tFloat = program.getTypePrimitiveFloat();
        JPrimitiveType tDouble = program.getTypePrimitiveDouble();
        JType fromType = x.getExpr().getType();
        if (tByte == fromType) {
          if (tChar == toType) {
            narrow = true;
          }
        } else if (tShort == fromType) {
          if (tByte == toType || tChar == toType) {
            narrow = true;
          }
        } else if (tChar == fromType) {
          if (tByte == toType || tShort == toType) {
            narrow = true;
          }
        } else if (tInt == fromType) {
          if (tByte == toType || tShort == toType || tChar == toType) {
            narrow = true;
          }
        } else if (tLong == fromType) {
          if (tByte == toType || tShort == toType || tChar == toType
              || tInt == toType) {
            narrow = true;
          }
        } else if (tFloat == fromType || tDouble == fromType) {
          if (tByte == toType || tShort == toType || tChar == toType
              || tInt == toType || tLong == toType) {
            round = true;
          }
        }

        if (narrow || round) {
          // Replace the expression with a call to the narrow or round method
          String methodName = "Cast." + (narrow ? "narrow_" : "round_")
              + toType.getName();
          JMethod castMethod = program.getSpecialMethod(methodName);
          JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
              castMethod);
          call.getArgs().add(x.getExpr());
          replaceExpr = call;
        } else {
          // Just remove the cast
          replaceExpr = x.getExpr();
        }
View Full Code Here

            program.getTypePrimitiveBoolean(), JBinaryOperator.NEQ,
            x.getExpr(), nullLit);
        ctx.replaceMe(eq);
      } else {
        JMethod method = program.getSpecialMethod("Cast.instanceOf");
        JMethodCall call = new JMethodCall(program, x.getSourceInfo(), null,
            method);
        Integer boxedInt = (Integer) queryIds.get(x.getTestType());
        JIntLiteral qId = program.getLiteralInt(boxedInt.intValue());
        call.getArgs().add(x.getExpr());
        call.getArgs().add(qId);
        ctx.replaceMe(call);
      }
    }
View Full Code Here

                + originalMainClassName
                + "' to qualify a call to non-static entry method 'onModuleLoad'", null);
        throw new UnableToCompleteException();
      }
    }
    return new JMethodCall(info, qualifier, entryMethod);
  }
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.