Index: include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h =================================================================== --- /dev/null +++ include/clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h @@ -0,0 +1,43 @@ +//== SMTContext.h -----------------------------------------------*- 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 a SMT generic Context API, which will be the base class +// for every SMT solver context specific class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONTEXT_H +#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SMTCONTEXT_H + +namespace clang { +namespace ento { + +class SMTContext { +public: + SMTContext() = default; + virtual ~SMTContext() = default; +}; + +template class SMTSolverContext : public SMTContext { +public: + SMTSolverContext() : SMTContext() {} + virtual ~SMTSolverContext() = default; + + C getContext() const { return Context; } + + virtual void reset(){}; + +protected: + C Context; +}; + +} // namespace ento +} // namespace clang + +#endif Index: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp =================================================================== --- lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp +++ lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp @@ -11,6 +11,7 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SMTContext.h" #include "clang/Config/config.h" @@ -63,19 +64,22 @@ ~Z3Config() { Z3_del_config(Config); } }; // end class Z3Config -class Z3Context { - Z3_context ZC_P; - +class Z3Context : public SMTSolverContext { public: static Z3_context ZC; - Z3Context() : ZC_P(Z3_mk_context_rc(Z3Config().Config)) { ZC = ZC_P; } + Z3Context() : SMTSolverContext() { + Context = Z3_mk_context_rc(Z3Config().Config); + ZC = Context; + } - ~Z3Context() { + void reset() override { Z3_del_context(ZC); Z3_finalize_memory(); - ZC_P = nullptr; + Context = nullptr; } + + ~Z3Context() { reset(); } }; // end class Z3Context class Z3Sort {