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);
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class SwitchRewriter method fixStringValue.
private void fixStringValue(SwitchStatement node) {
Expression expr = node.getExpression();
TypeMirror type = expr.getTypeMirror();
if (!typeUtil.isString(type)) {
return;
}
ArrayType arrayType = typeUtil.getArrayType(type);
ArrayInitializer arrayInit = new ArrayInitializer(arrayType);
int idx = 0;
for (Statement stmt : node.getStatements()) {
if (stmt instanceof SwitchCase) {
SwitchCase caseStmt = (SwitchCase) stmt;
if (!caseStmt.isDefault()) {
arrayInit.addExpression(TreeUtil.remove(caseStmt.getExpression()));
caseStmt.setExpression(NumberLiteral.newIntLiteral(idx++, typeUtil));
}
}
}
TypeMirror intType = typeUtil.getInt();
FunctionElement indexOfFunc = new FunctionElement("JreIndexOfStr", intType, null).addParameters(type, arrayType, intType);
FunctionInvocation invocation = new FunctionInvocation(indexOfFunc, intType);
invocation.addArgument(TreeUtil.remove(expr)).addArgument(arrayInit).addArgument(NumberLiteral.newIntLiteral(idx, typeUtil));
node.setExpression(invocation);
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class TranslationUtil method createAnnotation.
public Expression createAnnotation(AnnotationMirror annotationMirror) {
DeclaredType type = annotationMirror.getAnnotationType();
TypeElement typeElem = (TypeElement) type.asElement();
FunctionElement element = new FunctionElement("create_" + nameTable.getFullName(typeElem), type, typeElem);
FunctionInvocation invocation = new FunctionInvocation(element, type);
Map<? extends ExecutableElement, ? extends AnnotationValue> values = typeUtil.elementUtil().getElementValuesWithDefaults(annotationMirror);
for (ExecutableElement member : ElementUtil.getSortedAnnotationMembers(typeElem)) {
TypeMirror valueType = member.getReturnType();
element.addParameters(valueType);
invocation.addArgument(createAnnotationValue(valueType, values.get(member)));
}
return invocation;
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class JavaCloneWriter method createVolatileCloneStatement.
private Statement createVolatileCloneStatement(VariableElement var, VariableElement originalVar, boolean isWeak) {
TypeMirror voidType = typeUtil.getVoid();
TypeMirror pointerType = new PointerType(var.asType());
String funcName = "JreCloneVolatile" + (isWeak ? "" : "Strong");
FunctionElement element = new FunctionElement(funcName, voidType, null).addParameters(pointerType, pointerType);
FunctionInvocation invocation = new FunctionInvocation(element, voidType);
invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, new SimpleName(var)));
invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, new FieldAccess(var, new SimpleName(originalVar))));
return new ExpressionStatement(invocation);
}
Aggregations