3#include <clingo/input/program.hh>
5#include <clingo/util/ordered_set.hh>
6#include <clingo/util/unordered_map.hh>
8namespace CppClingo::Input {
39 [[nodiscard]]
auto has_error()
const {
return has_error_; }
43 using Stack = std::vector<std::pair<SharedString, Arity>>;
44 using Terms = std::vector<TheoryTerm>;
47 auto priority_and_associativity_(
String op)
const -> std::pair<int, Associativity>;
50 auto priority_(
String op,
Arity arity)
const -> int;
55 auto check_(
String op)
const -> bool;
63 mutable bool has_error_ =
false;
73 template <
bool has_sign>
80 using ParserIndex =
size_t;
82 using AtomTable = Util::unordered_map<std::pair<
SharedString,
size_t>,
83 std::tuple<
TheoryAtomType, ParserIndex, std::optional<GuardTable>>>;
86 AtomTable atom_table_;
87 mutable
bool has_error_ = false;
103 if (ctx !=
nullptr) {
110 using Guard = std::unique_ptr<RewriteContext, pop_>;
114 : log_{log}, opts_{opts}, parser_{parser}, const_map_{const_map}, param_map_{param_map}, gen_{store, {},
"_A"} {
121 gen_.init(std::move(names), prefix);
137 if (
auto it = param_map_.find(name); it != param_map_.end()) {
138 return std::distance(param_map_.begin(), it);
146 if (
auto it = const_map_.find(name); it != const_map_.end()) {
147 assert(!is_param(name));
148 return *it->second.second;
153 [[nodiscard]]
auto has_params() const ->
bool {
return !const_map_.empty() || !param_map_.empty(); }
156 assert(!aux_.empty());
161 assert(!aux_.empty());
177 [[nodiscard]]
auto has_error() const ->
bool {
return has_error_; }
186 std::vector<AuxTermVec> aux_;
187 bool has_error_ =
false;
Helper to pass arguments to rewrite functions.
Definition rewrite_context.hh:97
auto store() const -> SymbolStore &
Get the symbol store.
Definition rewrite_context.hh:130
auto has_params() const -> bool
Check if there is at least one parameter (from a program or const statement).
Definition rewrite_context.hh:153
auto gen() -> NameGen &
Get the name generator.
Definition rewrite_context.hh:132
std::unique_ptr< RewriteContext, pop_ > Guard
Helper to pop auxiliary variable assignments.
Definition rewrite_context.hh:110
auto options() const -> RewriteOptions const &
Get the logger.
Definition rewrite_context.hh:126
void pop()
Pop the last variable term map pushed.
Definition rewrite_context.hh:160
void set_error()
Mark that there was an error during rewriting.
Definition rewrite_context.hh:174
auto has_error() const -> bool
Check if there has been an error during rewriting.
Definition rewrite_context.hh:177
auto parser() const -> TheoryAtomParser const &
Get the parser.
Definition rewrite_context.hh:128
auto logger() const -> Logger &
Get the logger.
Definition rewrite_context.hh:124
auto aux() -> AuxTermVec &
Get the variable term map.
Definition rewrite_context.hh:155
auto push() -> Guard
Push a fresh variable term map.
Definition rewrite_context.hh:165
auto is_const(String name) const -> std::optional< Symbol >
Check if the given identifier is a parameter defined by a constant.
Definition rewrite_context.hh:145
auto is_param(String name) const -> std::optional< size_t >
Check if the given identifier is a parameter defined by a program directive.
Definition rewrite_context.hh:136
RewriteContext(Logger &log, SymbolStore &store, RewriteOptions const &opts, TheoryAtomParser const &parser, ParamMap const ¶m_map, ConstMap const &const_map)
Construct a rewrite context.
Definition rewrite_context.hh:112
RewriteContext(RewriteContext &&) noexcept=delete
Delete move/copy constructor.
The Location of an expression in an input source.
Definition location.hh:44
Simple logger to report message to stderr or via a callback.
Definition logger.hh:63
Generator for auxiliary names.
Definition symbol.hh:585
Class managing the lifetime of a String.
Definition symbol.hh:93
Reference to a string stored in a symbol store.
Definition symbol.hh:18
A store for symbols.
Definition symbol.hh:454
Util::unordered_set< String > StringSet
A set of strings.
Definition symbol.hh:83
Util::unordered_set< SharedString > SharedStringSet
A set of strings.
Definition symbol.hh:181
tsl::hopscotch_map< Key, T, Hash, KeyEqual, Allocator, NeighborhoodSize, StoreHash, GrowthPolicy > unordered_map
Alias for unordered maps.
Definition unordered_map.hh:17
Helper to pop auxiliary variable assignments.
Definition rewrite_context.hh:100
void operator()(RewriteContext *ctx) const
Pop the last variable term map pushed.
Definition rewrite_context.hh:102