use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class OperatorRewriter method endVisit.
@Override
public void endVisit(InfixExpression node) {
InfixExpression.Operator op = node.getOperator();
TypeMirror nodeType = node.getTypeMirror();
String funcName = getInfixFunction(op, nodeType);
if (funcName != null) {
Iterator<Expression> operandIter = node.getOperands().iterator();
Expression leftOperand = operandIter.next();
operandIter.remove();
// translated here are all left-associative.
while (operandIter.hasNext()) {
Expression rightOperand = operandIter.next();
operandIter.remove();
FunctionElement element = new FunctionElement(funcName, nodeType, null).addParameters(leftOperand.getTypeMirror(), rightOperand.getTypeMirror());
FunctionInvocation invocation = new FunctionInvocation(element, nodeType);
List<Expression> args = invocation.getArguments();
args.add(leftOperand);
args.add(rightOperand);
leftOperand = invocation;
}
node.replaceWith(leftOperand);
} else if (op == InfixExpression.Operator.PLUS && typeUtil.isString(nodeType) && !isStringAppend(node.getParent())) {
rewriteStringConcatenation(node);
}
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class JavaCloneWriter method createReleaseStatement.
private Statement createReleaseStatement(VariableElement var) {
if (options.useARC()) {
TypeMirror voidType = typeUtil.getVoid();
FunctionElement element = new FunctionElement("JreRelease", voidType, null).addParameters(TypeUtil.ID_TYPE);
FunctionInvocation invocation = new FunctionInvocation(element, voidType);
invocation.addArgument(new SimpleName(var));
return new ExpressionStatement(invocation);
} else {
return new ExpressionStatement(new MethodInvocation(new ExecutablePair(releaseMethod), new SimpleName(var)));
}
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class Autoboxer method rewriteBoxedAssignment.
private void rewriteBoxedAssignment(Assignment node) {
Expression lhs = node.getLeftHandSide();
Expression rhs = node.getRightHandSide();
TypeMirror type = lhs.getTypeMirror();
TypeMirror primitiveType = typeUtil.unboxedType(type);
if (primitiveType == null) {
return;
}
TypeMirror pointerType = new PointerType(type);
String funcName = "JreBoxed" + getAssignFunctionName(node.getOperator()) + translationUtil.getOperatorFunctionModifier(lhs) + NameTable.capitalize(primitiveType.toString());
FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type)).addParameters(pointerType, primitiveType);
FunctionInvocation invocation = new FunctionInvocation(element, type);
invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
invocation.addArgument(TreeUtil.remove(rhs));
unbox(rhs);
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.types.FunctionElement 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 (!castType.equals(funcReturnType)) {
newExpr = new CastExpression(castType, newExpr);
}
return newExpr;
}
use of com.google.devtools.j2objc.types.FunctionElement in project j2objc by google.
the class ArrayRewriter method newArrayAccess.
private Expression newArrayAccess(ArrayAccess arrayAccessNode, TypeMirror componentType, TypeElement iosArrayElement, boolean assignable) {
String funcName = ElementUtil.getName(iosArrayElement) + "_Get";
TypeMirror returnType = componentType;
TypeMirror declaredReturnType = componentType.getKind().isPrimitive() ? componentType : TypeUtil.ID_TYPE;
if (assignable) {
funcName += "Ref";
returnType = declaredReturnType = new PointerType(componentType);
}
FunctionElement element = new FunctionElement(funcName, declaredReturnType, iosArrayElement).addParameters(iosArrayElement.asType(), typeUtil.getInt());
FunctionInvocation invocation = new FunctionInvocation(element, returnType);
invocation.addArgument(arrayAccessNode.getArray().copy());
invocation.addArgument(arrayAccessNode.getIndex().copy());
if (assignable) {
return new PrefixExpression(componentType, PrefixExpression.Operator.DEREFERENCE, invocation);
}
return invocation;
}
Aggregations