use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class CastResolver method rewriteFloatToIntegralCast.
private Expression rewriteFloatToIntegralCast(TypeMirror castType, Expression expr, String funcName, TypeMirror funcReturnType) {
FunctionElement element = new FunctionElement(funcName, funcReturnType, null).addParameters(typeUtil.getDouble());
FunctionInvocation invocation = new FunctionInvocation(element, funcReturnType);
invocation.addArgument(TreeUtil.remove(expr));
Expression newExpr = invocation;
if (!typeUtil.isSameType(castType, funcReturnType)) {
newExpr = new CastExpression(castType, newExpr);
}
return newExpr;
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class ArrayRewriter method visit.
// We must handle object array assignment before its children because if the
// rhs is an array creation, we can optimize with "SetAndConsume".
@Override
public boolean visit(Assignment node) {
Expression lhs = node.getLeftHandSide();
TypeMirror lhsType = lhs.getTypeMirror();
if (lhs instanceof ArrayAccess && !lhsType.getKind().isPrimitive()) {
FunctionInvocation newAssignment = newArrayAssignment(node, (ArrayAccess) lhs, lhsType);
node.replaceWith(newAssignment);
newAssignment.accept(this);
return false;
}
return true;
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class StatementGenerator method needsParenthesesForMacro.
private boolean needsParenthesesForMacro(Expression expr) {
boolean[] hasComma = { false };
expr.accept(new TreeVisitor() {
@Override
public boolean visit(ArrayInitializer node) {
hasComma[0] = true;
return false;
}
@Override
public boolean visit(CommaExpression node) {
// Adds parentheses around children.
return false;
}
@Override
public boolean visit(FunctionInvocation node) {
// Adds parentheses around children.
return false;
}
@Override
public boolean visit(StringLiteral node) {
if (!UnicodeUtils.hasValidCppCharacters(node.getLiteralValue())) {
// LiteralGenerator will emit the string using [NSString stringWithCharacters:].
hasComma[0] = true;
return false;
}
return true;
}
});
return hasComma[0];
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class Functionizer method endVisit.
@Override
public void endVisit(MethodInvocation node) {
ExecutableElement element = node.getExecutableElement();
if (!ElementUtil.isStatic(element) && !functionizableMethods.contains(element)) {
return;
}
FunctionInvocation functionInvocation = new FunctionInvocation(newFunctionElement(element), node.getTypeMirror());
List<Expression> args = functionInvocation.getArguments();
TreeUtil.moveList(node.getArguments(), args);
if (!ElementUtil.isStatic(element)) {
Expression expr = node.getExpression();
if (expr == null) {
expr = new ThisExpression(TreeUtil.getEnclosingTypeElement(node).asType());
}
args.add(0, TreeUtil.remove(expr));
}
node.replaceWith(functionInvocation);
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class OperatorRewriter method handleRetainedLocal.
private void handleRetainedLocal(VariableElement var, Expression rhs) {
if (ElementUtil.isLocalVariable(var) && ElementUtil.hasAnnotation(var, RetainedLocalRef.class) && options.useReferenceCounting()) {
FunctionElement element = new FunctionElement("JreRetainedLocalValue", TypeUtil.ID_TYPE, null);
FunctionInvocation invocation = new FunctionInvocation(element, rhs.getTypeMirror());
rhs.replaceWith(invocation);
invocation.addArgument(rhs);
}
}
Aggregations