use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class Functionizer method endVisit.
@Override
public void endVisit(ConstructorInvocation node) {
ExecutableElement element = node.getExecutableElement();
TypeElement declaringClass = ElementUtil.getDeclaringClass(element);
FunctionElement funcElement = newFunctionElement(element);
FunctionInvocation invocation = new FunctionInvocation(funcElement, typeUtil.getVoid());
List<Expression> args = invocation.getArguments();
args.add(new ThisExpression(declaringClass.asType()));
for (VariableElement captureParam : captureInfo.getImplicitPrefixParams(declaringClass)) {
args.add(new SimpleName(captureParam));
}
TreeUtil.moveList(node.getArguments(), args);
for (VariableElement captureParam : captureInfo.getImplicitPostfixParams(declaringClass)) {
args.add(new SimpleName(captureParam));
}
node.replaceWith(new ExpressionStatement(invocation));
assert funcElement.getParameterTypes().size() == args.size();
}
use of com.google.devtools.j2objc.types.FunctionElement 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);
}
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class DestructorGenerator method createRelease.
private Statement createRelease(VariableElement var) {
TypeMirror varType = var.asType();
if (ElementUtil.isStatic(var) || varType.getKind().isPrimitive() || ElementUtil.isWeakReference(var)) {
return null;
}
boolean isVolatile = ElementUtil.isVolatile(var);
boolean isRetainedWith = ElementUtil.isRetainedWithField(var);
String funcName = null;
if (isRetainedWith) {
funcName = isVolatile ? "JreVolatileRetainedWithRelease" : "JreRetainedWithRelease";
} else if (isVolatile) {
funcName = "JreReleaseVolatile";
} else if (options.useReferenceCounting()) {
funcName = "RELEASE_";
}
if (funcName == null) {
return null;
}
TypeMirror voidType = typeUtil.getVoid();
TypeMirror idType = TypeUtil.ID_TYPE;
FunctionElement element = new FunctionElement(funcName, voidType, null);
FunctionInvocation releaseInvocation = new FunctionInvocation(element, voidType);
if (isRetainedWith) {
element.addParameters(idType);
releaseInvocation.addArgument(new ThisExpression(ElementUtil.getDeclaringClass(var).asType()));
}
element.addParameters(isVolatile ? TypeUtil.ID_PTR_TYPE : idType);
Expression arg = new SimpleName(var);
if (isVolatile) {
arg = new PrefixExpression(new PointerType(varType), PrefixExpression.Operator.ADDRESS_OF, arg);
}
releaseInvocation.addArgument(arg);
return new ExpressionStatement(releaseInvocation);
}
use of com.google.devtools.j2objc.types.FunctionElement 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.types.FunctionElement 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);
}
Aggregations