@Override
  public void endVisit(SuperMethodInvocation node) {
    Name qualifier = node.getQualifier();
    if (qualifier == null) {
      return;
    }
    IMethodBinding method = node.getMethodBinding();
    ITypeBinding exprType = node.getTypeBinding();
    IVariableBinding var = TreeUtil.getVariableBinding(qualifier);
    assert var != null : "Expected qualifier to be a variable";
    ITypeBinding qualifierType = var.getType();

    SuperMethodBindingPair superMethod = new SuperMethodBindingPair(qualifierType, method);
    superMethods.add(superMethod);

    FunctionBinding binding =
        new FunctionBinding(getSuperFunctionName(superMethod), exprType, qualifierType);
    binding.addParameters(qualifierType, typeEnv.getIdType());
    binding.addParameters(method.getParameterTypes());
    FunctionInvocation invocation = new FunctionInvocation(binding, exprType);
    List<Expression> args = invocation.getArguments();
    args.add(TreeUtil.remove(qualifier));
    String selectorExpr = UnicodeUtils.format("@selector(%s)", nameTable.getMethodSelector(method));
    args.add(new NativeExpression(selectorExpr, typeEnv.getIdType()));
    TreeUtil.copyList(node.getArguments(), args);
    node.replaceWith(invocation);
  }
示例#2
0
 private Expression rewriteFloatToIntegralCast(
     ITypeBinding castType, Expression expr, String funcName, ITypeBinding funcReturnType) {
   FunctionBinding binding = new FunctionBinding(funcName, funcReturnType, null);
   binding.addParameter(typeEnv.resolveJavaType("double"));
   FunctionInvocation invocation = new FunctionInvocation(binding, funcReturnType);
   invocation.getArguments().add(TreeUtil.remove(expr));
   Expression newExpr = invocation;
   if (!castType.isEqualTo(funcReturnType)) {
     newExpr = new CastExpression(castType, newExpr);
   }
   return newExpr;
 }
示例#3
0
 private Statement createReleaseStatement(IVariableBinding var) {
   if (Options.useARC()) {
     ITypeBinding voidType = typeEnv.resolveJavaType("void");
     FunctionInvocation invocation =
         new FunctionInvocation("JreRelease", voidType, voidType, null);
     invocation.getArguments().add(new SimpleName(var));
     return new ExpressionStatement(invocation);
   } else {
     return new ExpressionStatement(
         new MethodInvocation(typeEnv.getReleaseMethod(), new SimpleName(var)));
   }
 }
示例#4
0
 private Statement createVolatileRetainStatement(IVariableBinding var) {
   ITypeBinding idType = typeEnv.resolveIOSType("id");
   FunctionInvocation invocation =
       new FunctionInvocation("JreRetainVolatile", idType, idType, null);
   invocation
       .getArguments()
       .add(
           new PrefixExpression(
               typeEnv.getPointerType(var.getType()),
               PrefixExpression.Operator.ADDRESS_OF,
               new SimpleName(var)));
   return new ExpressionStatement(invocation);
 }
示例#5
0
 private FunctionInvocation createCastCheck(ITypeBinding type, Expression expr) {
   type = type.getErasure();
   ITypeBinding idType = typeEnv.resolveIOSType("id");
   FunctionInvocation invocation = null;
   if ((type.isInterface() && !type.isAnnotation())
       || (type.isArray() && !type.getComponentType().isPrimitive())) {
     FunctionBinding binding = new FunctionBinding("cast_check", idType, null);
     binding.addParameters(idType, typeEnv.getIOSClass());
     invocation = new FunctionInvocation(binding, idType);
     invocation.getArguments().add(TreeUtil.remove(expr));
     invocation.getArguments().add(new TypeLiteral(type, typeEnv));
   } else if (type.isClass() || type.isArray() || type.isAnnotation() || type.isEnum()) {
     FunctionBinding binding = new FunctionBinding("cast_chk", idType, null);
     binding.addParameters(idType, idType);
     invocation = new FunctionInvocation(binding, idType);
     invocation.getArguments().add(TreeUtil.remove(expr));
     IOSMethodBinding classBinding =
         IOSMethodBinding.newMethod("class", Modifier.STATIC, idType, type);
     MethodInvocation classInvocation = new MethodInvocation(classBinding, new SimpleName(type));
     invocation.getArguments().add(classInvocation);
   }
   return invocation;
 }
示例#6
0
 @Override
 public void endVisit(FunctionInvocation node) {
   maybeCastArguments(node.getArguments(), node.getFunctionBinding().getParameterTypes());
 }