use of com.google.devtools.j2objc.ast.PrefixExpression 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.PrefixExpression in project j2objc by google.
the class TreeConverter method convertPrefixExpression.
private static TreeNode convertPrefixExpression(org.eclipse.jdt.core.dom.PrefixExpression node) {
PrefixExpression newNode = new PrefixExpression();
convertExpression(node, newNode);
return newNode.setOperator(PrefixExpression.Operator.parse(node.getOperator().toString())).setOperand((Expression) TreeConverter.convert(node.getOperand())).setTypeMirror(BindingConverter.getType(node.resolveTypeBinding()));
}
use of com.google.devtools.j2objc.ast.PrefixExpression in project j2objc by google.
the class ArrayRewriter method newArrayAccess.
private Expression newArrayAccess(ArrayAccess arrayAccessNode, TypeMirror componentType, TypeElement iosArrayElement, boolean assignable) {
String funcName = ElementUtil.getName(iosArrayElement) + "_Get";
TypeMirror returnType = componentType;
TypeMirror declaredReturnType = componentType.getKind().isPrimitive() ? componentType : TypeUtil.ID_TYPE;
if (assignable) {
funcName += "Ref";
returnType = declaredReturnType = new PointerType(componentType);
}
FunctionElement element = new FunctionElement(funcName, declaredReturnType, iosArrayElement).addParameters(iosArrayElement.asType(), typeUtil.getInt());
FunctionInvocation invocation = new FunctionInvocation(element, returnType);
invocation.addArgument(arrayAccessNode.getArray().copy());
invocation.addArgument(arrayAccessNode.getIndex().copy());
if (assignable) {
return new PrefixExpression(componentType, PrefixExpression.Operator.DEREFERENCE, invocation);
}
return invocation;
}
use of com.google.devtools.j2objc.ast.PrefixExpression in project j2objc by google.
the class ComplexExpressionExtractor method endVisit.
@Override
public void endVisit(PrefixExpression node) {
TreeNode parent = node.getParent();
if (parent == null) {
return;
}
// Check for balancing dereference and address-of operators.
if (parent instanceof PrefixExpression) {
PrefixExpression.Operator thisOp = node.getOperator();
PrefixExpression.Operator parentOp = ((PrefixExpression) parent).getOperator();
if ((thisOp == PrefixExpression.Operator.DEREFERENCE && parentOp == PrefixExpression.Operator.ADDRESS_OF) || (thisOp == PrefixExpression.Operator.ADDRESS_OF && parentOp == PrefixExpression.Operator.DEREFERENCE)) {
parent.replaceWith(TreeUtil.remove(node.getOperand()));
return;
}
}
// without checking if parentheses were necessary.
switch(parent.getKind()) {
case POSTFIX_EXPRESSION:
case // Parentheses not needed, but better for readability.
PREFIX_EXPRESSION:
ParenthesizedExpression.parenthesizeAndReplace(node);
break;
default:
}
}
use of com.google.devtools.j2objc.ast.PrefixExpression 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);
}
Aggregations