use of org.checkerframework.dataflow.cfg.node.NumericalMinusNode in project checker-framework by typetools.
the class CFGTranslationPhaseOne method visitUnary.
@Override
public Node visitUnary(UnaryTree tree, Void p) {
Node result = null;
Tree.Kind kind = tree.getKind();
switch(kind) {
case BITWISE_COMPLEMENT:
case UNARY_MINUS:
case UNARY_PLUS:
{
// see JLS 15.14 and 15.15
Node expr = scan(tree.getExpression(), p);
expr = unaryNumericPromotion(expr);
switch(kind) {
case BITWISE_COMPLEMENT:
result = new BitwiseComplementNode(tree, expr);
break;
case UNARY_MINUS:
result = new NumericalMinusNode(tree, expr);
break;
case UNARY_PLUS:
result = new NumericalPlusNode(tree, expr);
break;
default:
throw new BugInCF("Unexpected kind: " + kind);
}
extendWithNode(result);
break;
}
case LOGICAL_COMPLEMENT:
{
// see JLS 15.15.6
Node expr = scan(tree.getExpression(), p);
result = new ConditionalNotNode(tree, unbox(expr));
extendWithNode(result);
break;
}
case POSTFIX_DECREMENT:
case POSTFIX_INCREMENT:
case PREFIX_DECREMENT:
case PREFIX_INCREMENT:
{
ExpressionTree exprTree = tree.getExpression();
Node expr = scan(exprTree, p);
boolean isIncrement = kind == Tree.Kind.POSTFIX_INCREMENT || kind == Tree.Kind.PREFIX_INCREMENT;
boolean isPostfix = kind == Tree.Kind.POSTFIX_INCREMENT || kind == Tree.Kind.POSTFIX_DECREMENT;
AssignmentNode unaryAssign = createIncrementOrDecrementAssign(isPostfix ? null : tree, expr, isIncrement);
addToUnaryAssignLookupMap(tree, unaryAssign);
if (isPostfix) {
TypeMirror exprType = TreeUtils.typeOf(exprTree);
VariableTree tempVarDecl = treeBuilder.buildVariableDecl(exprType, uniqueName("tempPostfix"), findOwner(), tree.getExpression());
handleArtificialTree(tempVarDecl);
VariableDeclarationNode tempVarDeclNode = new VariableDeclarationNode(tempVarDecl);
tempVarDeclNode.setInSource(false);
extendWithNode(tempVarDeclNode);
Tree tempVar = treeBuilder.buildVariableUse(tempVarDecl);
handleArtificialTree(tempVar);
Node tempVarNode = new LocalVariableNode(tempVar);
tempVarNode.setInSource(false);
extendWithNode(tempVarNode);
AssignmentNode tempAssignNode = new AssignmentNode(tree, tempVarNode, expr);
tempAssignNode.setInSource(false);
extendWithNode(tempAssignNode);
Tree resultExpr = treeBuilder.buildVariableUse(tempVarDecl);
handleArtificialTree(resultExpr);
result = new LocalVariableNode(resultExpr);
result.setInSource(false);
extendWithNode(result);
} else {
result = unaryAssign;
}
break;
}
case OTHER:
default:
// special node NLLCHK
if (tree.toString().startsWith("<*nullchk*>")) {
Node expr = scan(tree.getExpression(), p);
result = new NullChkNode(tree, expr);
extendWithNode(result);
break;
}
throw new BugInCF("Unknown kind (" + kind + ") of unary expression: " + tree);
}
return result;
}
Aggregations