use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MethodTranslator method visitForEachStatement.
@Override
public TreeNode visitForEachStatement(ForEachStatement node, Void data) {
EnhancedForStatement forStatement = new EnhancedForStatement();
AstType astType = node.getVariableType();
Type type = (Type) astType.acceptVisitor(this, null);
String varName = node.getVariableName();
GeneratedVariableElement elem = GeneratedVariableElement.newLocalVar(varName, type.getTypeMirror(), executableElement);
elem.addModifiers(node.getVariableModifiers());
localVariableTable.put(varName, elem);
return forStatement.setParameter(new SingleVariableDeclaration(elem)).setExpression((Expression) node.getInExpression().acceptVisitor(this, null)).setBody((Statement) node.getEmbeddedStatement().acceptVisitor(this, null));
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MethodTranslator method visitConditionalExpression.
@Override
public TreeNode visitConditionalExpression(com.strobel.decompiler.languages.java.ast.ConditionalExpression node, Void data) {
Expression conditionExpr = (Expression) node.getCondition().acceptVisitor(this, null);
Expression trueExpr = (Expression) node.getTrueExpression().acceptVisitor(this, null);
Expression falseExpr = (Expression) node.getFalseExpression().acceptVisitor(this, null);
TypeMirror trueType = trueExpr.getTypeMirror();
TypeMirror falseType = falseExpr.getTypeMirror();
return new ConditionalExpression().setTypeMirror(typeUtil.inferConditionalExpressionType(trueType, falseType)).setExpression(conditionExpr).setThenExpression(trueExpr).setElseExpression(falseExpr);
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MethodTranslator method visitBinaryOperatorExpression.
@Override
public TreeNode visitBinaryOperatorExpression(BinaryOperatorExpression node, Void data) {
Expression leftExpr = (Expression) node.getLeft().acceptVisitor(this, null);
Expression rightExpr = (Expression) node.getRight().acceptVisitor(this, null);
InfixExpression binaryExpr = new InfixExpression().addOperand(leftExpr).addOperand(rightExpr);
switch(node.getOperator()) {
case BITWISE_AND:
binaryExpr.setOperator(InfixExpression.Operator.AND).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case BITWISE_OR:
binaryExpr.setOperator(InfixExpression.Operator.OR).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case EXCLUSIVE_OR:
binaryExpr.setOperator(InfixExpression.Operator.XOR).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case LOGICAL_AND:
binaryExpr.setOperator(InfixExpression.Operator.CONDITIONAL_AND).setTypeMirror(typeUtil.getBoolean());
break;
case LOGICAL_OR:
binaryExpr.setOperator(InfixExpression.Operator.CONDITIONAL_OR).setTypeMirror(typeUtil.getBoolean());
break;
case GREATER_THAN:
binaryExpr.setOperator(InfixExpression.Operator.GREATER).setTypeMirror(typeUtil.getBoolean());
break;
case GREATER_THAN_OR_EQUAL:
binaryExpr.setOperator(InfixExpression.Operator.GREATER_EQUALS).setTypeMirror(typeUtil.getBoolean());
break;
case LESS_THAN:
binaryExpr.setOperator(InfixExpression.Operator.LESS).setTypeMirror(typeUtil.getBoolean());
break;
case LESS_THAN_OR_EQUAL:
binaryExpr.setOperator(InfixExpression.Operator.LESS_EQUALS).setTypeMirror(typeUtil.getBoolean());
break;
case EQUALITY:
binaryExpr.setOperator(InfixExpression.Operator.EQUALS).setTypeMirror(typeUtil.getBoolean());
break;
case INEQUALITY:
binaryExpr.setOperator(InfixExpression.Operator.NOT_EQUALS).setTypeMirror(typeUtil.getBoolean());
break;
case ADD:
binaryExpr.setOperator(InfixExpression.Operator.PLUS).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case SUBTRACT:
binaryExpr.setOperator(InfixExpression.Operator.MINUS).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case MULTIPLY:
binaryExpr.setOperator(InfixExpression.Operator.TIMES).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case DIVIDE:
binaryExpr.setOperator(InfixExpression.Operator.DIVIDE).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case MODULUS:
binaryExpr.setOperator(InfixExpression.Operator.REMAINDER).setTypeMirror(typeUtil.binaryNumericPromotion(leftExpr.getTypeMirror(), rightExpr.getTypeMirror()));
break;
case SHIFT_LEFT:
binaryExpr.setOperator(InfixExpression.Operator.LEFT_SHIFT).setTypeMirror(typeUtil.unaryNumericPromotion(leftExpr.getTypeMirror()));
break;
case SHIFT_RIGHT:
binaryExpr.setOperator(InfixExpression.Operator.RIGHT_SHIFT_SIGNED).setTypeMirror(typeUtil.unaryNumericPromotion(leftExpr.getTypeMirror()));
break;
case UNSIGNED_SHIFT_RIGHT:
binaryExpr.setOperator(InfixExpression.Operator.RIGHT_SHIFT_UNSIGNED).setTypeMirror(typeUtil.unaryNumericPromotion(leftExpr.getTypeMirror()));
break;
default:
throw new AssertionError("Unsupported infix operator: " + node.getOperator());
}
return binaryExpr;
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MethodTranslator method visitArrayCreationExpression.
@Override
public TreeNode visitArrayCreationExpression(ArrayCreationExpression node, Void data) {
Type baseType = (Type) node.getType().acceptVisitor(this, null);
AstNodeCollection<com.strobel.decompiler.languages.java.ast.Expression> dimexprs = node.getDimensions();
ArrayInitializerExpression init = node.getInitializer();
ArrayType arrayType = new ArrayType(typeUtil.getArrayType(baseType.getTypeMirror(), dimexprs.size() + node.getAdditionalArraySpecifiers().size()));
if (init.isNull()) {
List<Expression> dimensions = dimexprs.stream().map(e -> (Expression) e.acceptVisitor(this, null)).collect(Collectors.toList());
return new ArrayCreation().setType(arrayType).setDimensions(dimensions);
} else {
ArrayInitializer arrayInit = (ArrayInitializer) init.acceptVisitor(this, null);
return new ArrayCreation().setType(arrayType).setInitializer(arrayInit.setTypeMirror(arrayType.getTypeMirror()));
}
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class MethodTranslator method visitMemberReferenceExpression.
@Override
public TreeNode visitMemberReferenceExpression(MemberReferenceExpression node, Void data) {
Expression qualifier = (Expression) node.getFirstChild().acceptVisitor(this, null);
TypeElement owner = (TypeElement) ((DeclaredType) qualifier.getTypeMirror()).asElement();
VariableElement field = ElementUtil.findField(owner, node.getMemberName());
if (field != null) {
return new FieldAccess(field, qualifier);
}
throw new AssertionError("not implemented");
}
Aggregations