use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class TreeConverter method convertQualifiedName.
private static TreeNode convertQualifiedName(org.eclipse.jdt.core.dom.QualifiedName node) {
QualifiedName newNode = new QualifiedName();
convertName(node, newNode);
return newNode.setQualifier((Name) TreeConverter.convert(node.getQualifier())).setName((SimpleName) TreeConverter.convert(node.getName()));
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class UnsequencedExpressionRewriter method visit.
@Override
public boolean visit(AssertStatement node) {
Expression expr = node.getExpression();
visitAndExtract(expr, node);
Expression msg = node.getMessage();
if (msg != null) {
newExpression(msg);
msg.accept(this);
List<VariableAccess> toExtract = getUnsequencedAccesses();
if (!toExtract.isEmpty()) {
// If the message expression needs any extraction, then we first extract
// the entire boolean expression to preserve ordering between the two.
VariableElement exprVar = GeneratedVariableElement.newLocalVar("unseq$" + count++, expr.getTypeMirror(), currentMethod);
TreeUtil.insertBefore(node, new VariableDeclarationStatement(exprVar, node.getExpression().copy()));
node.setExpression(new SimpleName(exprVar));
extractOrderedAccesses(TreeUtil.asStatementList(node).subList(0, 0), currentTopNode, toExtract);
}
}
return false;
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class UnsequencedExpressionRewriter method extractConditionalExpression.
private void extractConditionalExpression(List<Statement> stmtList, ConditionalExpression conditional, List<VariableAccess> toExtract) {
Expression condition = conditional.getExpression();
Expression thenExpr = conditional.getThenExpression();
Expression elseExpr = conditional.getElseExpression();
List<VariableAccess> conditionAccesses = Lists.newArrayList();
List<VariableAccess> thenAccesses = Lists.newArrayList();
List<VariableAccess> elseAccesses = Lists.newArrayList();
boolean needsExtraction = false;
for (VariableAccess access : toExtract) {
TreeNode node = access.expression;
while (node.getParent() != conditional) {
node = node.getParent();
}
if (node == condition) {
conditionAccesses.add(access);
} else if (node == thenExpr) {
thenAccesses.add(access);
} else if (node == elseExpr) {
elseAccesses.add(access);
} else {
throw new AssertionError();
}
if (node != condition) {
// We need to extract an if-statement if there is an access that
// executes conditionally.
needsExtraction = true;
}
}
extractOrderedAccesses(stmtList, condition, conditionAccesses);
// The recursive call might replace the condition child.
condition = conditional.getExpression();
if (needsExtraction) {
VariableElement resultVar = GeneratedVariableElement.newLocalVar("unseq$" + count++, conditional.getTypeMirror(), currentMethod);
conditional.replaceWith(new SimpleName(resultVar));
stmtList.add(new VariableDeclarationStatement(resultVar, null));
IfStatement newIf = new IfStatement();
newIf.setExpression(condition.copy());
stmtList.add(newIf);
Block thenBlock = new Block();
newIf.setThenStatement(thenBlock);
List<Statement> thenStmts = thenBlock.getStatements();
extractOrderedAccesses(thenStmts, thenExpr, thenAccesses);
// The recursive call might replace the then expression child.
thenExpr = conditional.getThenExpression();
thenStmts.add(new ExpressionStatement(new Assignment(new SimpleName(resultVar), thenExpr.copy())));
Block elseBlock = new Block();
newIf.setElseStatement(elseBlock);
List<Statement> elseStmts = elseBlock.getStatements();
extractOrderedAccesses(elseStmts, elseExpr, elseAccesses);
// The recursive call might replace the else expression child.
elseExpr = conditional.getElseExpression();
elseStmts.add(new ExpressionStatement(new Assignment(new SimpleName(resultVar), elseExpr.copy())));
} else {
extractOrderedAccesses(stmtList, thenExpr, thenAccesses);
extractOrderedAccesses(stmtList, elseExpr, elseAccesses);
}
}
Aggregations