#include "expr/symbol_manager.h"
+#include "context/cdhashmap.h"
+#include "context/cdhashset.h"
+
+using namespace CVC4::context;
+
namespace CVC4 {
-SymbolManager::SymbolManager(api::Solver* s) : d_solver(s) {}
+// ---------------------------------------------- SymbolManager::Implementation
-SymbolTable* SymbolManager::getSymbolTable() { return &d_symtabAllocated; }
+class SymbolManager::Implementation
+{
+ using TermStringMap = CDHashMap<api::Term, std::string, api::TermHashFunction>;
+ using TermSet = CDHashSet<api::Term, api::TermHashFunction>;
-bool SymbolManager::setExpressionName(api::Term t,
- const std::string& name,
- bool isAssertion)
+ public:
+ Implementation()
+ : d_context(), d_names(&d_context), d_namedAsserts(&d_context)
+ {
+ }
+
+ ~Implementation() {}
+ /** set expression name */
+ bool setExpressionName(api::Term t,
+ const std::string& name,
+ bool isAssertion = false);
+ /** get expression name */
+ bool getExpressionName(api::Term t,
+ std::string& name,
+ bool isAssertion = false) const;
+ /** get expression names */
+ void getExpressionNames(const std::vector<api::Term>& ts,
+ std::vector<std::string>& names,
+ bool areAssertions = false) const;
+ /** reset */
+ void reset();
+
+ private:
+ /** The context manager for the scope maps. */
+ Context d_context;
+ /** Map terms to names */
+ TermStringMap d_names;
+ /** The set of terms with assertion names */
+ TermSet d_namedAsserts;
+};
+
+bool SymbolManager::Implementation::setExpressionName(api::Term t,
+ const std::string& name,
+ bool isAssertion)
{
if (d_names.find(t) != d_names.end())
{
return true;
}
-bool SymbolManager::getExpressionName(api::Term t,
- std::string& name,
- bool isAssertion) const
+bool SymbolManager::Implementation::getExpressionName(api::Term t,
+ std::string& name,
+ bool isAssertion) const
{
- std::map<api::Term, std::string>::const_iterator it = d_names.find(t);
+ TermStringMap::const_iterator it = d_names.find(t);
if (it == d_names.end())
{
return false;
return false;
}
}
- name = it->second;
+ name = (*it).second;
return true;
}
-void SymbolManager::getExpressionNames(const std::vector<api::Term>& ts,
- std::vector<std::string>& names,
- bool areAssertions) const
+void SymbolManager::Implementation::getExpressionNames(
+ const std::vector<api::Term>& ts,
+ std::vector<std::string>& names,
+ bool areAssertions) const
{
for (const api::Term& t : ts)
{
}
}
+void SymbolManager::Implementation::reset()
+{
+ // clear names?
+}
+
+// ---------------------------------------------- SymbolManager
+
+SymbolManager::SymbolManager(api::Solver* s)
+ : d_solver(s), d_implementation(new SymbolManager::Implementation())
+{
+}
+
+SymbolManager::~SymbolManager() {}
+
+SymbolTable* SymbolManager::getSymbolTable() { return &d_symtabAllocated; }
+
+bool SymbolManager::setExpressionName(api::Term t,
+ const std::string& name,
+ bool isAssertion)
+{
+ return d_implementation->setExpressionName(t, name, isAssertion);
+}
+
+bool SymbolManager::getExpressionName(api::Term t,
+ std::string& name,
+ bool isAssertion) const
+{
+ return d_implementation->getExpressionName(t, name, isAssertion);
+}
+
+void SymbolManager::getExpressionNames(const std::vector<api::Term>& ts,
+ std::vector<std::string>& names,
+ bool areAssertions) const
+{
+ return d_implementation->getExpressionNames(ts, names, areAssertions);
+}
+
+size_t SymbolManager::scopeLevel() const
+{
+ return d_symtabAllocated.getLevel();
+}
+
+void SymbolManager::pushScope() { d_symtabAllocated.pushScope(); }
+
+void SymbolManager::popScope() { d_symtabAllocated.popScope(); }
+
+void SymbolManager::reset()
+{
+ d_symtabAllocated.reset();
+ d_implementation->reset();
+}
+
} // namespace CVC4
#define CVC4__EXPR__SYMBOL_MANAGER_H
#include <map>
+#include <memory>
#include <set>
#include <string>
{
public:
SymbolManager(api::Solver* s);
- ~SymbolManager() {}
+ ~SymbolManager();
/** Get the underlying symbol table */
SymbolTable* getSymbolTable();
//---------------------------- named expressions
std::vector<std::string>& names,
bool areAssertions = false) const;
//---------------------------- end named expressions
+ /**
+ * Get the scope level of the symbol table.
+ */
+ size_t scopeLevel() const;
+ /**
+ * Push a scope in the symbol table.
+ */
+ void pushScope();
+ /**
+ * Pop a scope in the symbol table.
+ */
+ void popScope();
+ /**
+ * Reset this symbol manager, which resets the symbol table.
+ */
+ void reset();
private:
/** The API Solver object. */
* The declaration scope that is "owned" by this symbol manager.
*/
SymbolTable d_symtabAllocated;
- /** Map terms to names */
- std::map<api::Term, std::string> d_names;
- /** The set of terms with assertion names */
- std::set<api::Term> d_namedAsserts;
+ /** The implementation of the symbol manager */
+ class Implementation;
+ std::unique_ptr<Implementation> d_implementation;
};
} // namespace CVC4