aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-12-21 00:04:19 +0000
committerTed Kremenek <kremenek@apple.com>2007-12-21 00:04:19 +0000
commiteaac0b0d727a7fd5df08bd548ffdcfd354b91480 (patch)
tree97d35df95cea83f11fc851cea926de7ea522e842
parent2a11a5f13aec18eb8c076bc2c3249afc932c921a (diff)
Added class "StateVariant", a template class which serves to wrap states that
are generated by transfer functions used by the path-sensitive dataflow solver. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45273 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathSensitive/StateVariant.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/include/clang/Analysis/PathSensitive/StateVariant.h b/include/clang/Analysis/PathSensitive/StateVariant.h
new file mode 100644
index 0000000000..9c558314b7
--- /dev/null
+++ b/include/clang/Analysis/PathSensitive/StateVariant.h
@@ -0,0 +1,53 @@
+//==- StateVariant.h - Variant to wrap generated analysis states --*- C++ -*-=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois
+// Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the template class StateVariant, which serves to wrap
+// states that are generated by transfer functions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_ANALYSIS_PS_STATEVARIANT
+#define LLVM_CLANG_ANALYSIS_PS_STATEVARIANT
+
+namespace clang {
+
+template<typename StateTy>
+class StateVariant {
+ enum VariantFlag { Infeasible, ImpotentStmt, HasState };
+ StateTy* State;
+ VariantFlag Flag;
+
+ explicit StateVariant(StateTy* state, VariantFlag f) : State(state), Flag(f){}
+
+public:
+ StateVariant(StateTy* state) : State(state), Flag(HasState) {}
+
+ bool isInfeasible() const { return Flag == Infeasible; }
+ bool isStmtImpotent() const { return Flag == ImpotentStmt; }
+
+ StateTy* getState() const {
+ assert (!isInfeasible());
+ return State;
+ }
+
+ // Factory methods to create states indicating infeasible paths or that
+ // a statement can never modify the program state (from the perspective of
+ // the analysis).
+ static inline StateVariant DenoteInfeasiblePath(StateTy* state = NULL) {
+ return StateVariant(state,Infeasible);
+ }
+
+ static inline StateVariant DenoteImpotentStmt(StateTy* state) {
+ return StateVariant(state,ImpotentStmt);
+ }
+};
+
+} // end clang namespace
+
+#endif