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 (!typeUtil.isSameType(castType, funcReturnType)) {
newExpr = new CastExpression(castType, newExpr);
}
return newExpr;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TypePrivateDeclarationGenerator method printDeadClassConstant.
@Override
protected void printDeadClassConstant(VariableDeclarationFragment fragment) {
VariableElement var = fragment.getVariableElement();
Object value = var.getConstantValue();
assert value != null;
String declType = getDeclarationType(var);
declType += (declType.endsWith("*") ? "" : " ");
String name = nameTable.getVariableShortName(var);
if (ElementUtil.isPrimitiveConstant(var)) {
printf("#define %s_%s %s\n", typeName, name, LiteralGenerator.generate(value));
} else {
print("static " + UnicodeUtils.format("%s%s_%s", declType, typeName, name));
Expression initializer = fragment.getInitializer();
if (initializer != null) {
print(" = " + generateExpression(initializer));
}
println(";");
}
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class ArrayRewriter method visit.
// We must handle object array assignment before its children because if the
// rhs is an array creation, we can optimize with "SetAndConsume".
@Override
public boolean visit(Assignment node) {
Expression lhs = node.getLeftHandSide();
TypeMirror lhsType = lhs.getTypeMirror();
if (lhs instanceof ArrayAccess && !lhsType.getKind().isPrimitive()) {
FunctionInvocation newAssignment = newArrayAssignment(node, (ArrayAccess) lhs, lhsType);
node.replaceWith(newAssignment);
newAssignment.accept(this);
return false;
}
return true;
}
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);
}
}
}
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) {
TypeMirror returnType = TreeUtil.getOwningReturnType(node);
boolean returnsPrimitive = returnType.getKind().isPrimitive();
boolean exprIsPrimitive = expr.getTypeMirror().getKind().isPrimitive();
if (returnsPrimitive && !exprIsPrimitive) {
unbox(expr, (PrimitiveType) returnType);
}
if (!returnsPrimitive && exprIsPrimitive) {
box(expr);
}
}
}
Aggregations