coan
6.0.1
A C/C++ Configuration Analyzer
|
struct symbol
encapsulates a preprocessor symbol's state
More...
#include <symbol.h>
Classes | |
struct | locator |
struct symbol::locator encapsulates a symbol table entry. More... | |
Public Types | |
enum | provenance { provenance::unconfigured, provenance::global, provenance::transient } |
Symbolic constants denoting the provenance of a symbol. More... | |
using | symbol_table = std::map< std::string, symbol > |
Type of map implementing the symbol tbale. | |
using | table_entry = symbol_table::value_type |
Type of entry in the symbol table. | |
Public Member Functions | |
bool | operator== (symbol const &other) const |
Equality. | |
bool | operator!= (symbol const &other) const |
Inequality. | |
std::string const & | id () const |
Get the name of the symbol. | |
provenance | origin () const |
Get the provenance of the symbol. | |
void | originate (provenance origin) |
Set the symbol's provenance. | |
unsigned | line () const |
Get the source line-number at which this symbol was last defined or undefined. | |
std::shared_ptr< std::string const > | defn () const |
Get a pointer to the symbol's definition; null if undefined. | |
std::shared_ptr < parameter_substitution::format const > | format () const |
Get a pointer to the symbol's substitution format; null if none. More... | |
bool | defined () const |
Is the symbol defined. | |
void | set_definition (std::string const &defn) |
Set the definition of the symbol. | |
void | set_parameters (formal_parameter_list const ¶ms) |
Set a macro parameter list for the symbol. | |
void | set_parameters (size_t n) |
Impute n parameters of the symbol. | |
void | define (std::string const &defn, formal_parameter_list const ¶ms) |
Define symbol. More... | |
void | clear_parameters () |
Remove any macro parameter list. | |
void | undef () |
Undefine thesymbol. | |
void | report () const |
Report a reference to this symbol. | |
bool | configured () const |
Say whether the symbol is configured. | |
bool | deselected () const |
Say whether the symbol is deselected per the --select option. | |
bool | invoked () const |
Say whether the symbol has been invoked. More... | |
bool | self_referential () const |
Say whether the symbol's definition is infinitely regressive. | |
bool | dirty () const |
Say whether cached references of this symbol are out of date, due to configuration changes of this symbol or contributing symbols. | |
bool | clean () const |
Say whether the symbol's state has been determined. | |
bool | in_progress () const |
Say whether a determination the symbol's state is in progress. | |
std::string | signature () const |
Get the symbol's reference signature as string. More... | |
formal_parameter_list const & | parameters () const |
Get the symbol's formal parameter list. | |
size_t | which_parameter (std::string const &str) const |
Say whether a string is a parameter of the symbol. | |
bool | variadic () const |
Say whether this symbol is a variadic macro. | |
void | digest_global_define (chewer< std::string > &chew) |
Analyse and handle a -D option for this symbol. More... | |
line_type | digest_transient_define (formal_parameter_list const ¶ms, std::string const &definition) |
Analyse and handle an in-source define directive for this symbol. More... | |
void | digest_global_undef (chewer< std::string > &chew) |
Analyse and handle a -U option for this symbol. More... | |
line_type | digest_transient_undef () |
Analyse and handle an in-source undef directive for this symbol. More... | |
Static Public Member Functions | |
static size_t | count (provenance source) |
Get the number of symbols with a given provenance. | |
static size_t | count () |
Get the number of symbols in the symbol table. | |
static locator | lookup (std::string const &id) |
Lookup an identifier in the symbol table. More... | |
template<class CharSeq > | |
static locator | find_any_in (chewer< CharSeq > &chew, size_t &off) |
Search a terminal portion of a CharSeq for any known symbol name. More... | |
static void | set_selection (char const *optarg) |
static void | per_file_init () |
Delete all transient symbols from the symbol table. | |
static void | report_global_config () |
Report the global configuration, according to options. | |
Public Attributes | |
friend | reference |
Friendship to struct reference | |
Private Types | |
enum | pseudo_snapshot { pseudo_snapshot::pristine = -1, pseudo_snapshot::define_in_progress = -2, pseudo_snapshot::undef_in_progress = -3, pseudo_snapshot::infinite = -4 } |
Pseudo snapshot numbers for symbols in indeterminate states. More... | |
Private Member Functions | |
void | set_pseudo_snapshot (pseudo_snapshot n=pseudo_snapshot::pristine) |
Prime the symbol with a pseudo snapshot. | |
void | report_premiere () |
Report a symbol as resolved from the global configuration. The method invokes itself recursively on all the symbol's contributors and then reports the symbol itself. | |
void | set_invoked (bool value=true) |
Mark the symbol as invoked, or not. | |
void | subscribe_to (locator other) |
Record the symbol's definition as referring to another another symbol, and recursively as referring to those referred to by the other. | |
bool | subscribes_to (locator other) const |
Say whether the symbol's definition refers to another another symbol, directly or indirectly. | |
void | subscribe () |
Acquire all the symbol's contributors. More... | |
void | unsubscribe () |
Forget all the symbol's contributors. | |
void | make_clean () |
Assign the symbol state the current sequential snapshot number, signifying that it is up-to-date, and increment the current snapshot number. | |
void | make_dirty (pseudo_snapshot n=pseudo_snapshot::pristine) |
Assign the symbol state a pseudo snapshot number, signifying that it is out of date, and recursively to all its subscribers. | |
void | make_self_referential () |
Assign the symbol state a pseudo snapshot number, signifying that its definition involves an infinite regress, and recursively to all its subscribers. | |
void | diagnose_retrospective_redefinition () const |
Diagnose the case in which defining or undefining the symbol retrospectively changes the expansion of a previously defined symbol. | |
int | snapshot_max () const |
Get the maximum sequential snapshot number in the the recursive closure of this symbol its contributors. | |
symbol (provenance source) | |
Explicitly construct given a provenance . More... | |
Static Private Member Functions | |
static bool | selected (std::string const &id) |
Say whether a symbol name matches a selection pattern for reporting. | |
static bool | deselected (std::string const &id) |
Say whether a symbol name is excluded from reporting by the --select option. | |
static bool | add_pattern (std::string const &pattern) |
Add a symbol name pattern for reporting. More... | |
static bool | wildcard_match (std::string const &wildcard, std::string const &name) |
Say whether a symbol name matches a *-terminated wildcard prefix. | |
static symbol_table & | table () |
Get a reference to the symbol table. | |
static symbol_table::iterator | insert (std::string const &id, provenance source, symbol_table::iterator hint=table().end()) |
Insert the symbol into the symbol table with a specified provenance. More... | |
Private Attributes | |
locator | _loc |
Locator of this symbol in the symbol table. | |
std::shared_ptr< std::string > | _defn |
Pointer to the symbol's definition, if any. | |
formal_parameter_list | _params |
List of the symbol's macro arguments, if any. | |
provenance | _provenance |
The provenance of the symbol. | |
unsigned | _line |
Source line-number where symbol last defined or undefined, or 0. | |
bool | _deselected |
Is the symbol deselected? | |
bool | _invoked |
Has the symbol been invoked? | |
std::shared_ptr < parameter_substitution::format > | _format |
int | _snapshot |
std::vector< symbol::locator > | _contributors |
std::vector< symbol::locator > | _subscribers |
List of locators of the symbols to which this one contributes. | |
std::vector< bool > | _no_expand_pararms |
Static Private Attributes | |
static int | _current_snapshot_ |
The current sequential snapshot number. | |
static int | _last_global_snapshot_ |
The last snapshot number consumed by the global configuration. | |
static std::set< std::string > | _selected_symbols_set_ |
The set of symbols selected for reporting, if any. | |
static symbol_table | _sym_tab_ |
The symbol table. | |
static table_entry | _null_ |
The table entry of the null symbol. | |
|
strong |
|
strongprivate |
Pseudo snapshot numbers for symbols in indeterminate states.
|
inlineexplicitprivate |
|
inlinestaticprivate |
Add a symbol name pattern for reporting.
pattern | A symbol name pattern to select symbols for reporting |
If pattern
terminates with '*' then any symbol that initially matches the preceding portion of pattern
will be reported.
void symbol::define | ( | std::string const & | defn, |
formal_parameter_list const & | params | ||
) |
Define symbol.
defn | The definition of the symbol |
params | The parameter list of the symbol |
The symbol is assigned the new definition and parameter list, the resulting expansion and evaluation are resolved and cached and the symbol is left dirty
, i.e. other cached references of this symbol become invalid.
void symbol::digest_global_define | ( | chewer< std::string > & | chew | ) |
Analyse and handle a -D
option for this symbol.
chew | On entry, a chewer<std::string> positioned at the offset in the associated string from which to scan for a commandline definition. On return chew is positioned at the first offset not consumed. The commandline option is of the form -DSYM[(PARMS)[=VAL] or --define SYM[(PARMS)][=VAL] and chew shall finish just past SYM . |
The commandline option is analysed for well-formedness, consistency and non-redundancy in the current configuration. Errors are diagnosed. If there are none the global configuration is updated if required.
void symbol::digest_global_undef | ( | chewer< std::string > & | chew | ) |
Analyse and handle a -U
option for this symbol.
chew | On entry, a chewer<std::string> positioned at the text offset from which to scan for a commabndline un-define. On return chew is positioned at the the first offset not consumed. The commandline option is of the form -USYM and chew shall finish just past SYM . |
The option is analysed for well-formedness, consistency and non-redundancy in the current configuration. Errors are diagnosed. If there are none the global configuration is updated if required.
line_type symbol::digest_transient_define | ( | formal_parameter_list const & | params, |
std::string const & | definition | ||
) |
Analyse and handle an in-source define
directive for this symbol.
params | The macro parameter list of the symbol. |
definition | The proposed definition of the symbol. |
line_type
determined by the analysis, denoting the action to be taken on the directive.The proposed defintion is analysed for consistency and non-redundancy in the current configuration. Errors are diagnosed. If there are none the transient configuration is updated if required.
line_type symbol::digest_transient_undef | ( | ) |
Analyse and handle an in-source undef
directive for this symbol.
line_type
denoting the action to be taken with the directive.The directive is analysed for well-formedness and for consistency non-redundancy in the current configuration. Errors that are diagnosed. If there are none the transient configuration is updated if required.
|
static |
Search a terminal portion of a CharSeq
for any known symbol name.
Search a terminal portion of a parse_buffer
to find the first syntactic occurrence of the name of any symbol in the symbol table.
CharSeq | A charcter-sequence type. |
chew | On entry, a chewer<CharSeq> positioned at the offset in the associated CharSeq from which to scan. On return chew is positioned just passed the first occurrence found of he name of any known symbol, or at the end of the CharSeq if none. |
off | On return, receives the offset in the CharSeq of the first known symbol name detected, if any, else is unchanged. |
locator
of the known symbol detected, if any, else the null locator
.
|
inline |
Get a pointer to the symbol's substitution format; null if none.
The substitution format is coan's internal representation of the manner in which macro arguments are to be interpolated into the symbol's definition, if any.
|
inlinestaticprivate |
Insert the symbol into the symbol table with a specified provenance.
id | The name of the symbol to insert. |
source | The provenance of the symbol. |
hint | An iterator that is an upper bound hint to the insertion position. |
|
inline |
|
inlinestatic |
|
static |
brief Set the list of symbol masks for symbol reporting, as specified by the --select
option.
optarg | The argument of the --select option |
|
inline |
|
private |
Acquire all the symbol's contributors.
The symbol discovers all other symbols that contribute to its definition.
|
private |
|
private |
|
private |
|
mutableprivate |