use of com.google.devtools.j2objc.ast.ExpressionStatement in project j2objc by google.
the class CastResolver method returnValueNeedsIntCast.
// Some native objective-c methods are declared to return NSUInteger.
private boolean returnValueNeedsIntCast(Expression arg) {
ExecutableElement methodElement = TreeUtil.getExecutableElement(arg);
assert methodElement != null;
if (arg.getParent() instanceof ExpressionStatement) {
// Avoid "unused return value" warning.
return false;
}
String methodName = nameTable.getMethodSelector(methodElement);
if (methodName.equals("hash") && methodElement.getReturnType().getKind() == TypeKind.INT) {
return true;
}
return false;
}
use of com.google.devtools.j2objc.ast.ExpressionStatement 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);
}
use of com.google.devtools.j2objc.ast.ExpressionStatement in project j2objc by google.
the class EnumRewriter method addArcInitialization.
// ARC does not allow using "objc_constructInstance" so ARC code doesn't get
// the shared allocation optimization.
private void addArcInitialization(EnumDeclaration node) {
List<Statement> stmts = node.getClassInitStatements().subList(0, 0);
int i = 0;
for (EnumConstantDeclaration constant : node.getEnumConstants()) {
VariableElement varElement = constant.getVariableElement();
ClassInstanceCreation creation = new ClassInstanceCreation(constant.getExecutablePair());
TreeUtil.copyList(constant.getArguments(), creation.getArguments());
creation.addArgument(new StringLiteral(ElementUtil.getName(varElement), typeUtil));
creation.addArgument(new NumberLiteral(i++, typeUtil));
creation.setHasRetainedResult(true);
stmts.add(new ExpressionStatement(new Assignment(new SimpleName(varElement), creation)));
}
}
use of com.google.devtools.j2objc.ast.ExpressionStatement in project j2objc by google.
the class Functionizer method setFunctionCaller.
/**
* Replace method block statements with single statement that invokes function.
*/
private void setFunctionCaller(MethodDeclaration method, ExecutableElement methodElement) {
TypeMirror returnType = methodElement.getReturnType();
TypeElement declaringClass = ElementUtil.getDeclaringClass(methodElement);
Block body = new Block();
method.setBody(body);
method.removeModifiers(Modifier.NATIVE);
List<Statement> stmts = body.getStatements();
FunctionInvocation invocation = new FunctionInvocation(newFunctionElement(methodElement), returnType);
List<Expression> args = invocation.getArguments();
if (!ElementUtil.isStatic(methodElement)) {
args.add(new ThisExpression(declaringClass.asType()));
}
for (SingleVariableDeclaration param : method.getParameters()) {
args.add(new SimpleName(param.getVariableElement()));
}
if (TypeUtil.isVoid(returnType)) {
stmts.add(new ExpressionStatement(invocation));
if (ElementUtil.isConstructor(methodElement)) {
stmts.add(new ReturnStatement(new ThisExpression(declaringClass.asType())));
}
} else {
stmts.add(new ReturnStatement(invocation));
}
}
use of com.google.devtools.j2objc.ast.ExpressionStatement in project j2objc by google.
the class Functionizer method endVisit.
@Override
public void endVisit(ConstructorInvocation node) {
ExecutableElement element = node.getExecutableElement();
TypeElement declaringClass = ElementUtil.getDeclaringClass(element);
FunctionElement funcElement = newFunctionElement(element);
FunctionInvocation invocation = new FunctionInvocation(funcElement, typeUtil.getVoid());
List<Expression> args = invocation.getArguments();
args.add(new ThisExpression(declaringClass.asType()));
for (VariableElement captureParam : captureInfo.getImplicitPrefixParams(declaringClass)) {
args.add(new SimpleName(captureParam));
}
TreeUtil.moveList(node.getArguments(), args);
for (VariableElement captureParam : captureInfo.getImplicitPostfixParams(declaringClass)) {
args.add(new SimpleName(captureParam));
}
node.replaceWith(new ExpressionStatement(invocation));
assert funcElement.getParameterTypes().size() == args.size();
}
Aggregations