coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
expansion_base Struct Referenceabstract

struct expansion_base is an abstract base for classes that encapsulate a mode of macro-expansion of a reference. More...

#include <expansion_base.h>

Inheritance diagram for expansion_base:
reference explained_expansion unexplained_expansion

Public Member Functions

 expansion_base (reference const &ref)
 Construct from a reference.
 
std::string const & value () const
 Get the current expanded value of the reference.
 
virtual unsigned expand ()=0
 Perform the expansion of the reference returning the total number of edits applied.
 
virtual void throw_self () const =0
 Throw the runtime object.
 
std::string const & invocation () const override
 Get a string representing the invocation of the reference with the current expansions of its arguments.
 
- Public Member Functions inherited from reference
 reference (symbol::locator loc, reference const *invoker=nullptr)
 Construct given a symbol locator. More...
 
 reference (symbol::locator loc, argument_list const &args, reference const *invoker=nullptr)
 Construct given a symbol locator argument_list and optional parent reference.
 
template<class CharSeq >
 reference (symbol::locator loc, chewer< CharSeq > &chew, reference const *invoker=nullptr)
 Construct given a symbol locator, a chewer<CharSeq>, and optional parent reference. More...
 
bool operator== (reference const &other) const
 Equality. More...
 
bool operator!= (reference const &other) const
 Inequality.
 
std::string const & id () const
 Get the name of the symbol referenced.
 
std::string const & expansion ()
 Get the expansion of the reference.
 
evaluation const & eval ()
 Get the evaluation of the expansion.
 
bool reported ()
 Say whether this reference has been reported.
 
bool complete ()
 Say whether this reference has been fully expanded.
 
void report ()
 Report this reference appropriately.
 
symbol::locator const & callee () const
 Get a [const] the state of the referenced symbol.
 
symbol::locator callee ()
 
argument_list const & args () const
 Get a [const] reference to the argument_list of the reference.
 
argument_listargs ()
 

Static Public Member Functions

static std::unique_ptr
< expansion_base
factory (bool explain, reference const &ref)
 Global factory of subclasses of expansion_base More...
 
static constexpr unsigned max_expansion_size ()
 Cut-off size for macro-expansions.
 

Protected Member Functions

void set_expansion_flags ()
 Assign the expand-flags of the reference's arguments, if any, in accordance with the definition, if any, of the referenced symbol. More...
 
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()
 
void edit (std::string &str, size_t at, size_t len, std::string const &replacement)
 
unsigned edit_buf (std::string &str, expansion_base const &e, size_t off=0)
 Replace all remaining occurrences of a reference throughout a string. More...
 
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. More...
 
bool args_expansion_done () const
 Say whether all arguments are fully expanded.
 
virtual unsigned expand (std::string &str)=0
 Expand a string, returning the number of edits applied.
 
bool substitute ()
 Substitute the fully expanded arguments into the definition of the reference, returning true if the current value of the expansion is changed.
 
- Protected Member Functions inherited from reference
bool explain () const
 Say whether we are to explain this reference.
 
bool explaining () const
 Say whether this reference is to be explained or is descended from one being explained.
 
bool reportable () const
 Say whether this reference is eligible for reporting.
 
void do_report ()
 Do reporting of the reference if reportable.
 
reference_cache::iterator lower_bound () const
 Get a lower bound to this reference in the reference cache.
 
reference_cache::insert_result lookup ()
 Lookup the reference in the cache. More...
 
reference_cache::value_type digest ()
 Return a cache entry for this reference.
 
reference_cache::entry expand (bool explain)
 Expand the reference. More...
 
evaluation validate () const
 Diagnose a syntactically invalid reference. More...
 

Protected Attributes

std::string _value
 The current expanded value.
 
size_t _cur_arg = 0
 Index of the first argument not yet fully expanded.
 
- Protected Attributes inherited from reference
symbol::locator _referee
 The symbol_state of the referenced symbol.
 
argument_list _args
 The argument_list of the reference.
 
reference const * _invoker
 Pointer to the reference that invokes this one, if any, else null.
 
std::string _key
 Key to this reference in the reference cache.
 

Additional Inherited Members

- Public Types inherited from reference
using insert_result = reference_cache::insert_result
 Type of result from cache insertion.
 

Detailed Description

struct expansion_base is an abstract base for classes that encapsulate a mode of macro-expansion of a reference.

Definition at line 50 of file expansion_base.h.

Member Function Documentation

void expansion_base::edit ( std::string &  str,
size_t  at,
size_t  len,
std::string const &  replacement 
)
inlineprotected

Edit a string

Parameters
strThe string to edit
atOffset in str where replacement starts
lenLength to be replaced.
replacementString to replace the len characters at at

Definition at line 122 of file expansion_base.h.

unsigned expansion_base::edit_buf ( std::string &  str,
expansion_base const &  e,
size_t  off = 0 
)
protected

Replace all remaining occurrences of a reference throughout a string.

Parameters
strThe string to edit.
eAn expansion, s.t. that each ocurrence of that expansion's reference in str is to be replaced with its expanded value.
offOffset into str at which to start replacement.
Returns
The number of replacements made.

Definition at line 116 of file expansion_base.cpp.

unsigned expansion_base::edit_trailing_args ( expansion_base const &  e,
size_t  start = 0 
)
protected

Replace all occurrences of a reference throughout a terminal segment of this expansions's arguments.

Parameters
eAn expansion.
startIndex into the arguments of this expansion.
Returns
The number of replacements made.

In each expandable argument of the reference of this expansion, starting at index start, all occurrences of the reference of e are replaced with the value of e

Definition at line 137 of file expansion_base.cpp.

unique_ptr< expansion_base > expansion_base::factory ( bool  explain,
reference const &  ref 
)
static

Global factory of subclasses of expansion_base

Parameters
explainIs an explained_expansion or an unexplained_expansion to be constructed?
refA reference to be expanded.
Returns
Pointer to a dynamically allocated explained_expansion or unexplained_expansion depending on whether the --explain option is operative.

Definition at line 188 of file expansion_base.cpp.

void expansion_base::set_expansion_flags ( )
protected

Assign the expand-flags of the reference's arguments, if any, in accordance with the definition, if any, of the referenced symbol.

The definition of the referenced symbol determines whether an argument of the reference is to be expanded, quoted, or retained literally.

Definition at line 85 of file expansion_base.cpp.


The documentation for this struct was generated from the following files: