[cfe-commits] r45273 - /cfe/trunk/include/clang/Analysis/PathSensitive/StateVariant.h

Ted Kremenek kremenek at apple.com
Thu Dec 20 16:04:20 PST 2007


Author: kremenek
Date: Thu Dec 20 18:04:19 2007
New Revision: 45273

URL: http://llvm.org/viewvc/llvm-project?rev=45273&view=rev
Log:
Added class "StateVariant", a template class which serves to wrap states that
are generated by transfer functions used by the path-sensitive dataflow solver.

Added:
    cfe/trunk/include/clang/Analysis/PathSensitive/StateVariant.h

Added: cfe/trunk/include/clang/Analysis/PathSensitive/StateVariant.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/StateVariant.h?rev=45273&view=auto

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/StateVariant.h (added)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/StateVariant.h Thu Dec 20 18:04:19 2007
@@ -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





More information about the cfe-commits mailing list