15 if (sc.
indices !=
nullptr) os <<
"(_ ";
24 for (std::size_t i : *sc.
indices)
33 os <<
"(declare-sort " << decl.first <<
" " << decl.second <<
")" << std::endl;
43 auto pIter = parameters.find(sc.
name);
44 if (pIter != parameters.end())
return pIter->second;
50 v.push_back(
replace(sd, parameters));
82 mIndexable[sort] = std::make_pair(indices, type);
86 if (indices.empty())
return sort;
88 auto newsc = std::make_unique<SortContent>(sc);
89 if (newsc->indices ==
nullptr)
90 newsc->indices = std::make_unique<std::vector<std::size_t>>(indices);
92 newsc->indices->insert(newsc->indices->end(), indices.begin(), indices.end());
97 auto sc = std::make_unique<SortContent>(name);
101 CARL_LOG_ERROR(
"carl.formula",
"The sort " << name <<
" has not been declared or defined.");
104 return Sort(it->second);
108 assert(!params.empty());
111 std::size_t arity = decl->second;
112 if (arity != params.size()) {
113 CARL_LOG_ERROR(
"carl.formula",
"The sort " << name <<
" was declared to have " << arity <<
" parameters, but " << params.size() <<
" were given.");
116 auto sc = std::make_unique<SortContent>(name, params);
122 if (st.first.size() != params.size()) {
123 CARL_LOG_ERROR(
"carl.formula",
"The sort " << name <<
" was defined to have " << st.first.size() <<
" parameters, but " << params.size() <<
" were given.");
126 std::map<std::string, Sort> repl;
127 for (std::size_t i = 0; i < params.size(); i++)
128 repl[st.first[i]] = params[i];
129 return replace(st.second, repl);
131 CARL_LOG_ERROR(
"carl.formula",
"The sort " << name <<
" was neither declared nor defined and thus cannot be instantiated.");
#define CARL_LOG_ERROR(channel, msg)
carl is the main namespace for the library.
VariableType
Several types of variables are supported.
Implements a sort (for defining types of variables and functions).
The actual content of a sort.
std::unique_ptr< std::vector< std::size_t > > indices
The sort's indices. A sort can be indexed with the "_" operator. It is nullptr, if no indices are pre...
SortContent getUnindexed() const
Return a copy of this SortContent without any indices.
std::string name
The sort's name.
std::unique_ptr< std::vector< Sort > > parameters
The sort's argument types. It is nullptr, if the sort's arity is zero.
bool declare(const std::string &name, std::size_t arity)
Adds a sort declaration.
Sort replace(const Sort &sort, const std::map< std::string, Sort > ¶meters)
Recursively replaces sorts within the given sort according to the mapping of sort names to sorts as d...
void makeSortIndexable(const Sort &sort, std::size_t indices, VariableType type)
Sort index(const Sort &sort, const std::vector< std::size_t > &indices)
bool isSymbolFree(const std::string &name) const
std::pair< std::vector< std::string >, Sort > SortTemplate
The type of a sort template, define by define-sort.
std::map< Sort, std::pair< std::size_t, VariableType > > mIndexable
Stores all sorts that may become interpreted when indexed.
std::map< const SortContent *, std::size_t, carl::less< const SortContent * > > mSortMap
Maps the sort contents to unique ids.
const SortContent & getContent(const Sort &sort) const
void exportDefinitions(std::ostream &os) const
Sort addSort(const std::string &name, VariableType type=VariableType::VT_UNINTERPRETED)
Sort getSort(std::unique_ptr< SortContent > &&content, VariableType type)
std::size_t getArity(const Sort &sort) const
VariableType checkIndices(const SortContent &content, std::size_t count) const
std::map< std::string, SortTemplate > mDefinitions
Stores all sort definitions invoked by a define-sort.
bool define(const std::string &name, const std::vector< std::string > ¶ms, const Sort &sort)
Adds a sort template definitions.
std::ostream & print(std::ostream &os, const Sort &sort) const
Prints the given sort on the given output stream.
std::size_t addSortContent(std::unique_ptr< SortContent > &&content, VariableType type)
std::map< std::string, std::size_t > mDeclarations
Stores all sort declarations invoked by a declare-sort.