use of com.google.devtools.j2objc.ast.PrefixExpression in project j2objc by google.
the class Autoboxer method rewriteBoxedPrefixOrPostfix.
private void rewriteBoxedPrefixOrPostfix(TreeNode node, Expression operand, String funcName) {
TypeMirror type = operand.getTypeMirror();
TypeMirror primitiveType = typeUtil.unboxedType(type);
if (primitiveType == null) {
return;
}
TypeMirror pointerType = new PointerType(type);
funcName = "JreBoxed" + funcName + translationUtil.getOperatorFunctionModifier(operand) + NameTable.capitalize(primitiveType.toString());
FunctionElement element = new FunctionElement(funcName, type, TypeUtil.asTypeElement(type)).addParameters(pointerType);
FunctionInvocation invocation = new FunctionInvocation(element, type);
invocation.addArgument(new PrefixExpression(pointerType, PrefixExpression.Operator.ADDRESS_OF, TreeUtil.remove(operand)));
node.replaceWith(invocation);
}
use of com.google.devtools.j2objc.ast.PrefixExpression in project j2objc by google.
the class Autoboxer method endVisit.
@Override
public void endVisit(PrefixExpression node) {
PrefixExpression.Operator op = node.getOperator();
Expression operand = node.getOperand();
if (op == PrefixExpression.Operator.INCREMENT) {
rewriteBoxedPrefixOrPostfix(node, operand, "PreIncr");
} else if (op == PrefixExpression.Operator.DECREMENT) {
rewriteBoxedPrefixOrPostfix(node, operand, "PreDecr");
} else if (!operand.getTypeMirror().getKind().isPrimitive()) {
unbox(operand);
}
}
use of com.google.devtools.j2objc.ast.PrefixExpression in project j2objc by google.
the class UnsequencedExpressionRewriter method isUnsequenced.
private boolean isUnsequenced(VariableAccess modification, Set<TreeNode> modificationAncestors, VariableAccess access) {
TreeNode commonAncestor = currentTopNode;
TreeNode node = access.expression;
while (node != currentTopNode) {
if (modificationAncestors.contains(node)) {
commonAncestor = node;
break;
}
node = node.getParent();
}
// contain the other access, then they are not unsequenced.
if (isWithinConditionalBranch(modification.expression, commonAncestor) || isWithinConditionalBranch(access.expression, commonAncestor)) {
return false;
} else if (commonAncestor instanceof CommaExpression) {
return false;
} else if (commonAncestor instanceof Assignment && modification.expression == commonAncestor) {
// "i = 1 + i++;" is unsequenced (according to clang).
return access.expression instanceof PrefixExpression || access.expression instanceof PostfixExpression;
}
return true;
}
Aggregations