use of com.google.devtools.j2objc.types.PointerType in project j2objc by google.
the class StaticVarRewriter method rewriteStaticAccess.
private void rewriteStaticAccess(Expression node) {
VariableElement var = TreeUtil.getVariableElement(node);
if (var == null || !needsStaticLoad(node, var)) {
return;
}
TypeElement declaringClass = ElementUtil.getDeclaringClass(var);
boolean assignable = TranslationUtil.isAssigned(node);
StringBuilder code = new StringBuilder(ElementUtil.isEnumConstant(var) ? "JreLoadEnum" : "JreLoadStatic");
TypeMirror exprType = var.asType();
if (assignable) {
code.append("Ref");
exprType = new PointerType(exprType);
}
code.append("(");
code.append(nameTable.getFullName(declaringClass));
code.append(", ");
code.append(nameTable.getVariableShortName(var));
code.append(")");
NativeExpression nativeExpr = new NativeExpression(code.toString(), exprType);
nativeExpr.addImportType(declaringClass.asType());
Expression newNode = nativeExpr;
if (assignable) {
newNode = new PrefixExpression(var.asType(), PrefixExpression.Operator.DEREFERENCE, newNode);
}
node.replaceWith(newNode);
}
use of com.google.devtools.j2objc.types.PointerType 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.types.PointerType in project j2objc by google.
the class OperatorRewriter method rewriteVolatileLoad.
private void rewriteVolatileLoad(Expression node) {
VariableElement var = TreeUtil.getVariableElement(node);
if (var != null && ElementUtil.isVolatile(var) && !TranslationUtil.isAssigned(node)) {
TypeMirror type = node.getTypeMirror();
TypeMirror declaredType = type.getKind().isPrimitive() ? type : TypeUtil.ID_TYPE;
String funcName = "JreLoadVolatile" + NameTable.capitalize(declaredType.toString());
FunctionElement element = new FunctionElement(funcName, declaredType, null).addParameters(TypeUtil.ID_PTR_TYPE);
FunctionInvocation invocation = new FunctionInvocation(element, type);
node.replaceWith(invocation);
invocation.addArgument(new PrefixExpression(new PointerType(type), PrefixExpression.Operator.ADDRESS_OF, node));
}
}
use of com.google.devtools.j2objc.types.PointerType 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