use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class ArrayRewriter method newArrayAssignment.
private FunctionInvocation newArrayAssignment(Assignment assignmentNode, ArrayAccess arrayAccessNode, TypeMirror componentType) {
Assignment.Operator op = assignmentNode.getOperator();
assert !componentType.getKind().isPrimitive();
assert op == Assignment.Operator.ASSIGN;
Expression value = TreeUtil.remove(assignmentNode.getRightHandSide());
Expression retainedValue = TranslationUtil.retainResult(value);
String funcName = "IOSObjectArray_Set";
if (retainedValue != null) {
funcName = "IOSObjectArray_SetAndConsume";
value = retainedValue;
}
TypeElement objArrayType = TypeUtil.IOS_OBJECT_ARRAY;
TypeMirror idType = TypeUtil.ID_TYPE;
FunctionElement element = new FunctionElement(funcName, idType, objArrayType).addParameters(objArrayType.asType(), typeUtil.getInt(), idType);
FunctionInvocation invocation = new FunctionInvocation(element, componentType);
List<Expression> args = invocation.getArguments();
args.add(TreeUtil.remove(arrayAccessNode.getArray()));
args.add(TreeUtil.remove(arrayAccessNode.getIndex()));
args.add(value);
return invocation;
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(ExpressionStatement node) {
Expression expression = node.getExpression();
TypeMirror type = expression.getTypeMirror();
if (!type.getKind().isPrimitive() && !type.getKind().equals(TypeKind.VOID) && options.useARC() && (expression instanceof MethodInvocation || expression instanceof SuperMethodInvocation || expression instanceof FunctionInvocation)) {
// Avoid clang warning that the return value is unused.
buffer.append("(void) ");
}
expression.accept(this);
buffer.append(";\n");
return false;
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class Autoboxer method rewriteBoxedPrefixOrPostfix.
private void rewriteBoxedPrefixOrPostfix(TreeNode node, Expression operand, String funcName) {
TypeMirror type = operand.getTypeMirror();
TypeMirror primitiveType = typeUtil.unboxedType(type);
if (primitiveType == null) {
return;
}
TypeMirror pointerType = new PointerType(type);
funcName = "JreBoxed" + funcName + translationUtil.getOperatorFunctionModifier(operand) + NameTable.capitalize(primitiveType.toString());
FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type)).addParameters(pointerType);
FunctionInvocation invocation = new FunctionInvocation(element, type);
invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(operand)));
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class OperatorRewriter method rewriteVolatileLoad.
private void rewriteVolatileLoad(Expression node) {
VariableElement var = TreeUtil.getVariableElement(node);
if (var != null && ElementUtil.isVolatile(var) && !TranslationUtil.isAssigned(node)) {
TypeMirror type = node.getTypeMirror();
TypeMirror declaredType = type.getKind().isPrimitive() ? type : TypeUtil.ID_TYPE;
String funcName = "JreLoadVolatile" + NameTable.capitalize(declaredType.toString());
FunctionElement element = new FunctionElement(funcName, declaredType, null).addParameters(TypeUtil.ID_PTR_TYPE);
FunctionInvocation invocation = new FunctionInvocation(element, type);
node.replaceWith(invocation);
invocation.addArgument(new PrefixExpression(new PointerType(type), PrefixExpression.Operator.ADDRESS_OF, node));
}
}
use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class OperatorRewriter method rewriteRetainedLocal.
private void rewriteRetainedLocal(Expression expr) {
if (expr.getKind() == TreeNode.Kind.STRING_LITERAL || expr.getKind() == TreeNode.Kind.FUNCTION_INVOCATION) {
return;
}
FunctionElement element = new FunctionElement("JreRetainedLocalValue", TypeUtil.ID_TYPE, null);
FunctionInvocation invocation = new FunctionInvocation(element, expr.getTypeMirror());
expr.replaceWith(invocation);
invocation.addArgument(expr);
}
Aggregations