use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MethodTranslator method visitAssignmentExpression.
@Override
public TreeNode visitAssignmentExpression(AssignmentExpression node, Void data) {
Expression leftExpr = (Expression) node.getLeft().acceptVisitor(this, null);
Expression rightExpr = (Expression) node.getRight().acceptVisitor(this, null);
Assignment assignment = new Assignment(leftExpr, rightExpr);
switch(node.getOperator()) {
case ASSIGN:
assignment.setOperator(Assignment.Operator.ASSIGN);
break;
case ADD:
assignment.setOperator(Assignment.Operator.PLUS_ASSIGN);
break;
case SUBTRACT:
assignment.setOperator(Assignment.Operator.MINUS_ASSIGN);
break;
case MULTIPLY:
assignment.setOperator(Assignment.Operator.TIMES_ASSIGN);
break;
case DIVIDE:
assignment.setOperator(Assignment.Operator.DIVIDE_ASSIGN);
break;
case MODULUS:
assignment.setOperator(Assignment.Operator.REMAINDER_ASSIGN);
break;
case SHIFT_LEFT:
assignment.setOperator(Assignment.Operator.LEFT_SHIFT_ASSIGN);
break;
case SHIFT_RIGHT:
assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN);
break;
case UNSIGNED_SHIFT_RIGHT:
assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN);
break;
case BITWISE_AND:
assignment.setOperator(Assignment.Operator.BIT_AND_ASSIGN);
break;
case BITWISE_OR:
assignment.setOperator(Assignment.Operator.BIT_OR_ASSIGN);
break;
case EXCLUSIVE_OR:
assignment.setOperator(Assignment.Operator.BIT_XOR_ASSIGN);
break;
default:
throw new AssertionError("Unsupported assignment operator: " + node.getOperator());
}
return assignment;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(CommaExpression node) {
buffer.append('(');
for (Iterator<Expression> it = node.getExpressions().iterator(); it.hasNext(); ) {
Expression e = it.next();
e.accept(this);
if (it.hasNext()) {
buffer.append(", ");
}
}
buffer.append(')');
return false;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(VariableDeclarationFragment node) {
buffer.append(nameTable.getVariableQualifiedName(node.getVariableElement()));
Expression initializer = node.getInitializer();
if (initializer != null) {
buffer.append(" = ");
initializer.accept(this);
}
return false;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(InfixExpression node) {
InfixExpression.Operator op = node.getOperator();
List<Expression> operands = node.getOperands();
assert operands.size() >= 2;
String opStr = ' ' + op.toString() + ' ';
boolean isFirst = true;
for (Expression operand : operands) {
if (!isFirst) {
buffer.append(opStr);
}
isFirst = false;
operand.accept(this);
}
return false;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(ArrayInitializer node) {
javax.lang.model.type.ArrayType type = (javax.lang.model.type.ArrayType) node.getTypeMirror();
TypeMirror componentType = type.getComponentType();
buffer.append(UnicodeUtils.format("(%s[]){ ", NameTable.getPrimitiveObjCType(componentType)));
for (Iterator<Expression> it = node.getExpressions().iterator(); it.hasNext(); ) {
it.next().accept(this);
if (it.hasNext()) {
buffer.append(", ");
}
}
buffer.append(" }");
return false;
}
Aggregations