use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method visit.
private void visit(Tree tree, @Nullable Tree terminator) {
if (!checkerDispatcher.executeCheckPreStatement(tree)) {
// Some of the check pre statement sink the execution on this node.
return;
}
switch(tree.kind()) {
case METHOD_INVOCATION:
MethodInvocationTree mit = (MethodInvocationTree) tree;
if (SYSTEM_EXIT_MATCHER.matches(mit)) {
// System exit is a sink of execution
return;
}
executeMethodInvocation(mit);
return;
case LABELED_STATEMENT:
case SWITCH_STATEMENT:
case EXPRESSION_STATEMENT:
case PARENTHESIZED_EXPRESSION:
throw new IllegalStateException("Cannot appear in CFG: " + tree.kind().name());
case VARIABLE:
executeVariable((VariableTree) tree, terminator);
break;
case TYPE_CAST:
executeTypeCast((TypeCastTree) tree);
break;
case ASSIGNMENT:
case MULTIPLY_ASSIGNMENT:
case DIVIDE_ASSIGNMENT:
case REMAINDER_ASSIGNMENT:
case PLUS_ASSIGNMENT:
case MINUS_ASSIGNMENT:
case LEFT_SHIFT_ASSIGNMENT:
case RIGHT_SHIFT_ASSIGNMENT:
case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
executeAssignment((AssignmentExpressionTree) tree);
break;
case AND_ASSIGNMENT:
case XOR_ASSIGNMENT:
case OR_ASSIGNMENT:
executeLogicalAssignment((AssignmentExpressionTree) tree);
break;
case ARRAY_ACCESS_EXPRESSION:
executeArrayAccessExpression((ArrayAccessExpressionTree) tree);
break;
case NEW_ARRAY:
executeNewArray((NewArrayTree) tree);
break;
case NEW_CLASS:
executeNewClass((NewClassTree) tree);
break;
case MULTIPLY:
case DIVIDE:
case REMAINDER:
case PLUS:
case MINUS:
case LEFT_SHIFT:
case RIGHT_SHIFT:
case UNSIGNED_RIGHT_SHIFT:
case AND:
case XOR:
case OR:
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL_TO:
case LESS_THAN:
case LESS_THAN_OR_EQUAL_TO:
case EQUAL_TO:
case NOT_EQUAL_TO:
executeBinaryExpression(tree);
break;
case POSTFIX_INCREMENT:
case POSTFIX_DECREMENT:
case PREFIX_INCREMENT:
case PREFIX_DECREMENT:
case UNARY_MINUS:
case UNARY_PLUS:
case BITWISE_COMPLEMENT:
case LOGICAL_COMPLEMENT:
case INSTANCE_OF:
executeUnaryExpression(tree);
break;
case IDENTIFIER:
executeIdentifier((IdentifierTree) tree);
break;
case MEMBER_SELECT:
executeMemberSelect((MemberSelectExpressionTree) tree);
break;
case INT_LITERAL:
case LONG_LITERAL:
case FLOAT_LITERAL:
case DOUBLE_LITERAL:
case CHAR_LITERAL:
case STRING_LITERAL:
SymbolicValue val = constraintManager.createSymbolicValue(tree);
programState = programState.stackValue(val);
programState = programState.addConstraint(val, ObjectConstraint.NOT_NULL);
break;
case BOOLEAN_LITERAL:
boolean value = Boolean.parseBoolean(((LiteralTree) tree).value());
programState = programState.stackValue(value ? SymbolicValue.TRUE_LITERAL : SymbolicValue.FALSE_LITERAL);
break;
case NULL_LITERAL:
programState = programState.stackValue(SymbolicValue.NULL_LITERAL);
break;
case LAMBDA_EXPRESSION:
case METHOD_REFERENCE:
programState = programState.stackValue(constraintManager.createSymbolicValue(tree));
break;
case ASSERT_STATEMENT:
executeAssertStatement(tree);
return;
default:
}
checkerDispatcher.executeCheckPostStatement(tree);
clearStack(tree);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeTypeCast.
private void executeTypeCast(TypeCastTree typeCast) {
Type type = typeCast.type().symbolType();
if (type.isPrimitive()) {
JavaType expType = (JavaType) typeCast.expression().symbolType();
// create SV to consume factory if any
SymbolicValue castSV = constraintManager.createSymbolicValue(typeCast);
// if exp type is a primitive and subtype of cast type, we can reuse the same symbolic value
if (!expType.isPrimitive() || !new Types().isSubtype(expType, (JavaType) type)) {
ProgramState.Pop unstack = programState.unstackValue(1);
programState = unstack.state;
programState = programState.stackValue(castSV);
}
}
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeAssignment.
private void executeAssignment(AssignmentExpressionTree tree) {
ProgramState.Pop unstack;
SymbolicValue value;
if (tree.is(Tree.Kind.ASSIGNMENT)) {
unstack = ExpressionUtils.isSimpleAssignment(tree) ? programState.unstackValue(1) : programState.unstackValue(2);
value = unstack.values.get(0);
} else {
unstack = programState.unstackValue(2);
value = constraintManager.createSymbolicValue(tree);
}
programState = unstack.state;
Symbol symbol = null;
if (tree.variable().is(Tree.Kind.IDENTIFIER) || ExpressionUtils.isSelectOnThisOrSuper(tree)) {
symbol = ExpressionUtils.extractIdentifier(tree).symbol();
programState = programState.put(symbol, value);
}
programState = programState.stackValue(value, symbol);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeLogicalAssignment.
private void executeLogicalAssignment(AssignmentExpressionTree tree) {
ExpressionTree variable = tree.variable();
// FIXME handle also assignments with this SONARJAVA-2242
if (variable.is(Tree.Kind.IDENTIFIER)) {
ProgramState.Pop unstack = programState.unstackValue(2);
ProgramState.SymbolicValueSymbol assignedTo = unstack.valuesAndSymbols.get(1);
ProgramState.SymbolicValueSymbol value = unstack.valuesAndSymbols.get(0);
programState = unstack.state;
SymbolicValue symbolicValue = constraintManager.createBinarySymbolicValue(tree, ImmutableList.of(assignedTo, value));
Symbol symbol = ((IdentifierTree) variable).symbol();
programState = programState.stackValue(symbolicValue, symbol);
programState = programState.put(symbol, symbolicValue);
}
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeUnaryExpression.
private void executeUnaryExpression(Tree tree) {
// consume one and produce one
ProgramState.Pop unstackUnary = programState.unstackValue(1);
programState = unstackUnary.state;
SymbolicValue unarySymbolicValue = constraintManager.createSymbolicValue(tree);
unarySymbolicValue.computedFrom(unstackUnary.valuesAndSymbols);
ProgramState.SymbolicValueSymbol symbolicValueSymbol = unstackUnary.valuesAndSymbols.get(0);
if (tree.is(Tree.Kind.POSTFIX_DECREMENT, Tree.Kind.POSTFIX_INCREMENT)) {
programState = programState.stackValue(symbolicValueSymbol.sv, symbolicValueSymbol.symbol);
} else {
programState = programState.stackValue(unarySymbolicValue);
}
if (tree.is(Tree.Kind.POSTFIX_DECREMENT, Tree.Kind.POSTFIX_INCREMENT, Tree.Kind.PREFIX_DECREMENT, Tree.Kind.PREFIX_INCREMENT) && symbolicValueSymbol.symbol != null) {
programState = programState.put(symbolicValueSymbol.symbol, unarySymbolicValue);
}
}
Aggregations