summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java
diff options
context:
space:
mode:
authorElliott Baron <ebaron@fedoraproject.org>2009-11-17 16:33:56 -0500
committerElliott Baron <ebaron@fedoraproject.org>2009-11-17 16:33:56 -0500
commit8e5b06bf942549bbec94becfa0936e5c2787423a (patch)
treeff757a197924b8059a26c5bb9c293017a234e4bd /org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java
parentb7e5efd36bbd548d948a2e2fa8a31648091a8dda (diff)
downloadcodan-8e5b06bf942549bbec94becfa0936e5c2787423a.tar.gz
codan-8e5b06bf942549bbec94becfa0936e5c2787423a.tar.xz
codan-8e5b06bf942549bbec94becfa0936e5c2787423a.zip
Refactored conditional parsing to an ASTVisitor.
* org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/ConditionalVisitor.java: New file. * org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java: Extracted class.
Diffstat (limited to 'org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java')
-rw-r--r--org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java74
1 files changed, 2 insertions, 72 deletions
diff --git a/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java b/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java
index 655dca2..1cd6911 100644
--- a/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java
+++ b/org.eclipse.cdt.codan.extension/src/org/eclipse/cdt/codan/extension/PropertySimulator.java
@@ -309,57 +309,8 @@ public class PropertySimulator {
SymbolicState ret = s.copy();
if (node != null) {
- // Modify execution state according to branch condition
- ExecutionStateClause clause = null;
- // *N.B.* content for condition IBlock is condition expression itself
- if (node instanceof IASTBinaryExpression) {
- // FIXME compound conditionals
- IASTBinaryExpression binExpr = (IASTBinaryExpression) node;
- int op = binExpr.getOperator();
-
- // FIXME other ops
- // Check operator is an equality operator
- if (op == IASTBinaryExpression.op_equals) { // if (x == 0)
- IASTExpression o1 = binExpr.getOperand1();
- if (o1 instanceof IASTIdExpression) {
- IASTName name = ((IASTIdExpression) o1).getName();
- clause = parseConditional(clause, name, binExpr.getOperand2(), value);
- }
- }
- else if (op == IASTBinaryExpression.op_notequals) { // if (x != 0)
- IASTExpression o1 = binExpr.getOperand1();
- if (o1 instanceof IASTIdExpression) {
- IASTName name = ((IASTIdExpression) o1).getName();
- clause = parseConditional(clause, name, binExpr.getOperand2(), !value); // Negation
- }
- }
- }
- else if (node instanceof IASTUnaryExpression) { // if (!x)
- IASTUnaryExpression uExpr = (IASTUnaryExpression) node;
- int op = uExpr.getOperator();
-
- // Check operator is a negation operator
- if (op == IASTUnaryExpression.op_not) {
- IASTExpression operand = uExpr.getOperand();
- if (operand instanceof IASTIdExpression) {
- IASTName name = ((IASTIdExpression) operand).getName();
- clause = parseConditional(clause, name, !value); // Negation
- }
- }
- }
- else if (node instanceof IASTIdExpression) { // if (x)
- IASTName name = ((IASTIdExpression) node).getName();
- clause = parseConditional(clause, name, value);
- }
-
- if (clause != null) {
- ret.getExecutionState().addClause(clause);
- // TODO Theorem Prover goes here! / Determine if branch is feasible
- ret.getExecutionState().bindTruthAssignments();
- }
- else {
- // FIXME Handle unresolvable case
- }
+ ConditionalVisitor visitor = new ConditionalVisitor(ret.getExecutionState(), value);
+ node.accept(visitor);
}
return ret;
@@ -396,25 +347,4 @@ public class PropertySimulator {
return blk.getInEdges().length > 1;
}
- // FIXME REFACTOR
- private ExecutionStateClause parseConditional(ExecutionStateClause clause, IASTName name, IASTExpression valueExpr, boolean branchTruth) {
- IBinding binding = name.resolveBinding();
- if (binding instanceof IVariable) {
- IVariable var = (IVariable) binding;
- Boolean truth = ASTParserUtil.getTruthValue(valueExpr);
- if (truth != null) {
- clause = new ExecutionStateClause(var, truth == branchTruth);
- }
- }
- return clause;
- }
-
- private ExecutionStateClause parseConditional(ExecutionStateClause clause, IASTName name, boolean branchTruth) {
- IBinding binding = name.resolveBinding();
- if (binding instanceof IVariable) {
- IVariable var = (IVariable) binding;
- clause = new ExecutionStateClause(var, branchTruth);
- }
- return clause;
- }
}