1 #ifndef EXPANSION_BASE_H
2 #define EXPANSION_BASE_H
56 std::string
const &
value()
const {
63 virtual unsigned expand() = 0;
88 static std::unique_ptr<expansion_base>
123 size_t at,
size_t len,
124 std::string
const & replacement) {
125 size_t next_size = str.size() - len + replacement.size();
129 str.replace(at,len,replacement);
166 virtual unsigned expand(std::string & str) = 0;
unsigned edit_buf(std::string &str, expansion_base const &e, size_t off=0)
Replace all remaining occurrences of a reference throughout a string.
std::string str() const
Cast the parameter list to its canonical string representation.
void set_expansion_flags()
Assign the expand-flags of the reference's arguments, if any, in accordance with the definition...
argument_list const & args() const
Get a [const] reference to the argument_list of the reference.
expansion_base(reference const &ref)
Construct from a reference.
size_t size() const
Get the number of parameters in the parameter_list_base
unsigned edit_trailing_args(expansion_base const &e, size_t start=0)
Replace all occurrences of a reference throughout a terminal segment of this expansions's arguments...
size_t _cur_arg
Index of the first argument not yet fully expanded.
virtual void throw_self() const =0
Throw the runtime object.
size_t seek_expandable_arg()
Seek to the next argument of the reference, if any, that is eligible for expansion, returning its index if found, else args.size()
bool is_expandable(size_t n) const
Say whether the nth argument, if any, is eligible for macro expansion.
std::string const & id() const
Get the name of the symbol referenced.
bool substitute()
Substitute the fully expanded arguments into the definition of the reference, returning true if the c...
static std::unique_ptr< expansion_base > factory(bool explain, reference const &ref)
Global factory of subclasses of expansion_base
void edit(std::string &str, size_t at, size_t len, std::string const &replacement)
static constexpr unsigned max_expansion_size()
Cut-off size for macro-expansions.
std::string _value
The current expanded value.
std::string const & value() const
Get the current expanded value of the reference.
struct expansion_base is an abstract base for classes that encapsulate a mode of macro-expansion of a...
std::string const & invocation() const override
Get a string representing the invocation of the reference with the current expansions of its argument...
bool args_expansion_done() const
Say whether all arguments are fully expanded.
bool explain() const
Say whether we are to explain this reference.
virtual unsigned expand()=0
Perform the expansion of the reference returning the total number of edits applied.