]> granicus.if.org Git - clang/commitdiff
Added class "StateVariant", a template class which serves to wrap states that
authorTed Kremenek <kremenek@apple.com>
Fri, 21 Dec 2007 00:04:19 +0000 (00:04 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 21 Dec 2007 00:04:19 +0000 (00:04 +0000)
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

include/clang/Analysis/PathSensitive/StateVariant.h [new file with mode: 0644]

diff --git a/include/clang/Analysis/PathSensitive/StateVariant.h b/include/clang/Analysis/PathSensitive/StateVariant.h
new file mode 100644 (file)
index 0000000..9c55831
--- /dev/null
@@ -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