use of com.google.devtools.j2objc.ast.FunctionInvocation in project j2objc by google.
the class OperatorRewriter method rewriteCompoundAssign.
private void rewriteCompoundAssign(Assignment node) {
if (!shouldRewriteCompoundAssign(node)) {
return;
}
Expression lhs = node.getLeftHandSide();
Expression rhs = node.getRightHandSide();
TypeMirror lhsType = lhs.getTypeMirror();
TypeMirror lhsPointerType = new PointerType(lhsType);
String funcName = "Jre" + node.getOperator().getName() + (isVolatile(lhs) ? "Volatile" : "") + NameTable.capitalize(lhsType.toString()) + getPromotionSuffix(node);
FunctionElement element = new FunctionElement(funcName, lhsType, null).addParameters(lhsPointerType, rhs.getTypeMirror());
FunctionInvocation invocation = new FunctionInvocation(element, lhsType);
List<Expression> args = invocation.getArguments();
args.add(new PrefixExpression(lhsPointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(lhs)));
args.add(TreeUtil.remove(rhs));
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.ast.FunctionInvocation 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.FunctionInvocation 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();
}
use of com.google.devtools.j2objc.ast.FunctionInvocation 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.FunctionInvocation in project j2objc by google.
the class DestructorGenerator method createRelease.
private Statement createRelease(VariableElement var) {
TypeMirror varType = var.asType();
if (ElementUtil.isStatic(var) || varType.getKind().isPrimitive() || ElementUtil.isWeakReference(var)) {
return null;
}
boolean isVolatile = ElementUtil.isVolatile(var);
boolean isRetainedWith = ElementUtil.isRetainedWithField(var);
String funcName = null;
if (isRetainedWith) {
funcName = isVolatile ? "JreVolatileRetainedWithRelease" : "JreRetainedWithRelease";
} else if (isVolatile) {
funcName = "JreReleaseVolatile";
} else if (options.useReferenceCounting()) {
funcName = "RELEASE_";
}
if (funcName == null) {
return null;
}
TypeMirror voidType = typeUtil.getVoid();
TypeMirror idType = TypeUtil.ID_TYPE;
FunctionElement element = new FunctionElement(funcName, voidType, null);
FunctionInvocation releaseInvocation = new FunctionInvocation(element, voidType);
if (isRetainedWith) {
element.addParameters(idType);
releaseInvocation.addArgument(new ThisExpression(ElementUtil.getDeclaringClass(var).asType()));
}
element.addParameters(isVolatile ? TypeUtil.ID_PTR_TYPE : idType);
Expression arg = new SimpleName(var);
if (isVolatile) {
arg = new PrefixExpression(new PointerType(varType), PrefixExpression.Operator.ADDRESS_OF, arg);
}
releaseInvocation.addArgument(arg);
return new ExpressionStatement(releaseInvocation);
}
Aggregations