use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class Autoboxer method endVisit.
@Override
public void endVisit(ReturnStatement node) {
Expression expr = node.getExpression();
if (expr != null) {
boolean returnsPrimitive = TreeUtil.getOwningReturnType(node).getKind().isPrimitive();
boolean exprIsPrimitive = expr.getTypeMirror().getKind().isPrimitive();
if (returnsPrimitive && !exprIsPrimitive) {
unbox(expr);
}
if (!returnsPrimitive && exprIsPrimitive) {
box(expr);
}
}
}
use of com.google.devtools.j2objc.ast.Expression 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.ast.Expression 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.ast.Expression in project j2objc by google.
the class TreeConverter method convertPrefixExpression.
private static TreeNode convertPrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression node) {
PrefixExpression newNode = new PrefixExpression();
convertExpression(node, newNode);
return newNode.setOperator(PrefixExpression.Operator.parse(node.getOperator().toString())).setOperand((Expression) TreeConverter.convert(node.getOperand())).setTypeMirror(BindingConverter.getType(node.resolveTypeBinding()));
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class ArrayRewriter method createInvocation.
private MethodInvocation createInvocation(ArrayCreation node) {
ArrayType arrayType = node.getTypeMirror();
boolean retainedResult = node.hasRetainedResult() || options.useARC();
ArrayInitializer initializer = node.getInitializer();
if (initializer != null) {
return newInitializedArrayInvocation(arrayType, initializer.getExpressions(), retainedResult);
} else {
List<Expression> dimensions = node.getDimensions();
if (dimensions.size() == 1) {
return newSingleDimensionArrayInvocation(arrayType, dimensions.get(0), retainedResult);
} else {
return newMultiDimensionArrayInvocation(arrayType, dimensions, retainedResult);
}
}
}
Aggregations