use of com.google.devtools.j2objc.ast.BooleanLiteral in project j2objc by google.
the class UnsequencedExpressionRewriter method visit.
@Override
public boolean visit(DoStatement node) {
node.getBody().accept(this);
newExpression(node.getExpression());
node.getExpression().accept(this);
List<VariableAccess> toExtract = getUnsequencedAccesses();
if (!toExtract.isEmpty()) {
// Convert "while (cond)" into "while (true) { if (!(cond)) break; ... }".
List<Statement> stmtList = TreeUtil.asStatementList(node.getBody());
extractOrderedAccesses(stmtList, currentTopNode, toExtract);
stmtList.add(createLoopTermination(node.getExpression()));
node.setExpression(new BooleanLiteral(true, typeUtil));
}
return false;
}
use of com.google.devtools.j2objc.ast.BooleanLiteral in project j2objc by google.
the class UnsequencedExpressionRewriter method visit.
@Override
public boolean visit(WhileStatement node) {
node.getBody().accept(this);
newExpression(node.getExpression());
node.getExpression().accept(this);
List<VariableAccess> toExtract = getUnsequencedAccesses();
if (!toExtract.isEmpty()) {
// Convert "while (cond)" into "while (true) { if (!(cond)) break; ... }".
List<Statement> stmtList = TreeUtil.asStatementList(node.getBody()).subList(0, 0);
extractOrderedAccesses(stmtList, currentTopNode, toExtract);
stmtList.add(createLoopTermination(node.getExpression()));
node.setExpression(new BooleanLiteral(true, typeUtil));
}
return false;
}
use of com.google.devtools.j2objc.ast.BooleanLiteral in project j2objc by google.
the class ConstantBranchPruner method endVisit.
@Override
public void endVisit(InfixExpression node) {
InfixExpression.Operator operator = node.getOperator();
if (operator != CONDITIONAL_AND && operator != CONDITIONAL_OR) {
return;
}
List<Expression> operands = node.getOperands();
int lastSideEffect = -1;
for (int i = 0; i < operands.size(); i++) {
Expression expr = operands.get(i);
if (TranslationUtil.hasSideEffect(expr)) {
lastSideEffect = i;
}
Boolean knownVal = getKnownValue(expr);
if (knownVal == null) {
continue;
}
if (knownVal == (operator == CONDITIONAL_OR)) {
// Whole expression evaluates to 'knownVal'.
operands.subList(lastSideEffect + 1, operands.size()).clear();
if (lastSideEffect < i) {
operands.add(new BooleanLiteral(knownVal, typeUtil));
}
break;
} else if (lastSideEffect < i) {
// Else remove unnecessary constant value.
operands.remove(i--);
}
}
if (operands.size() == 0) {
if (operator == CONDITIONAL_OR) {
// All constants must have been false, because a true value would have
// caused us to return in the loop above.
node.replaceWith(new BooleanLiteral(false, typeUtil));
} else {
// Likewise, all constants must have been true.
node.replaceWith(new BooleanLiteral(true, typeUtil));
}
} else if (operands.size() == 1) {
node.replaceWith(operands.remove(0));
}
}
use of com.google.devtools.j2objc.ast.BooleanLiteral in project j2objc by google.
the class GwtConverter method visit.
@Override
public boolean visit(MethodInvocation node) {
ExecutableElement method = node.getExecutableElement();
List<Expression> args = node.getArguments();
if (ElementUtil.getName(method).equals("create") && ElementUtil.getQualifiedName(ElementUtil.getDeclaringClass(method)).equals(GWT_CLASS) && args.size() == 1) {
// Convert GWT.create(Foo.class) to Foo.class.newInstance().
ExecutableElement newMethod = ElementUtil.findMethod(typeUtil.getJavaClass(), "newInstance");
Expression clazz = args.remove(0);
node.setExpression(clazz);
node.setExecutablePair(new ExecutablePair(newMethod));
} else if (isGwtTest(node)) {
node.replaceWith(new BooleanLiteral(false, typeUtil));
}
return true;
}
Aggregations