use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class Autoboxer method endVisit.
@Override
public void endVisit(ConditionalExpression node) {
Expression expr = node.getExpression();
if (!expr.getTypeMirror().getKind().isPrimitive()) {
unbox(expr);
}
boolean nodeIsPrimitive = node.getTypeMirror().getKind().isPrimitive();
Expression thenExpr = node.getThenExpression();
boolean thenIsPrimitive = thenExpr.getTypeMirror().getKind().isPrimitive();
Expression elseExpr = node.getElseExpression();
boolean elseIsPrimitive = elseExpr.getTypeMirror().getKind().isPrimitive();
if (thenIsPrimitive && !nodeIsPrimitive) {
box(thenExpr);
} else if (!thenIsPrimitive && nodeIsPrimitive) {
unbox(thenExpr);
}
if (elseIsPrimitive && !nodeIsPrimitive) {
box(elseExpr);
} else if (!elseIsPrimitive && nodeIsPrimitive) {
unbox(elseExpr);
}
}
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 Functionizer method endVisit.
@Override
public void endVisit(SuperConstructorInvocation node) {
ExecutableElement element = node.getExecutableElement();
AbstractTypeDeclaration typeDecl = TreeUtil.getEnclosingType(node);
TypeElement type = typeDecl.getTypeElement();
FunctionElement funcElement = newFunctionElement(element);
FunctionInvocation invocation = new FunctionInvocation(funcElement, typeUtil.getVoid());
List<Expression> args = invocation.getArguments();
args.add(new ThisExpression(ElementUtil.getDeclaringClass(element).asType()));
if (typeDecl instanceof TypeDeclaration) {
TypeDeclaration typeDeclaration = (TypeDeclaration) typeDecl;
if (captureInfo.needsOuterParam(ElementUtil.getSuperclass(type))) {
Expression outerArg = TreeUtil.remove(node.getExpression());
args.add(outerArg != null ? outerArg : typeDeclaration.getSuperOuter().copy());
}
TreeUtil.moveList(typeDeclaration.getSuperCaptureArgs(), args);
}
TreeUtil.moveList(node.getArguments(), args);
if (ElementUtil.isEnum(type)) {
for (VariableElement param : captureInfo.getImplicitEnumParams()) {
args.add(new SimpleName(param));
}
}
node.replaceWith(new ExpressionStatement(invocation));
assert funcElement.getParameterTypes().size() == args.size();
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class Functionizer method endVisit.
@Override
public void endVisit(ClassInstanceCreation node) {
ExecutableElement element = node.getExecutableElement();
TypeElement type = ElementUtil.getDeclaringClass(element);
FunctionElement funcElement = newAllocatingConstructorElement(element);
FunctionInvocation invocation = new FunctionInvocation(funcElement, node.getTypeMirror());
invocation.setHasRetainedResult(node.hasRetainedResult() || options.useARC());
List<Expression> args = invocation.getArguments();
Expression outerExpr = node.getExpression();
if (outerExpr != null) {
args.add(TreeUtil.remove(outerExpr));
} else if (captureInfo.needsOuterParam(type)) {
args.add(new ThisExpression(ElementUtil.getDeclaringClass(type).asType()));
}
TreeUtil.moveList(node.getCaptureArgs(), args);
TreeUtil.moveList(node.getArguments(), args);
node.replaceWith(invocation);
assert funcElement.getParameterTypes().size() == args.size();
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(ReturnStatement node) {
buffer.append("return");
Expression expr = node.getExpression();
if (expr != null) {
buffer.append(' ');
expr.accept(this);
}
buffer.append(";\n");
return false;
}
Aggregations