coan 4.2.4
The Symbol component interface.
Collaboration diagram for The Symbol component interface.:

Files

file  symbol.c
file  symbol.h

Typedefs

typedef struct eval_resultsymbol_h
typedef struct eval_result const * symbol_const_h

Functions

symbol_h symbol_new (char const *name, size_t namelen)
void symbol_dispose (symbol_h sym)
symbol_h symbol_copy (symbol_const_h src)
void symbol_swap (symbol_h lhs, symbol_h rhs)
void symbol_assign (symbol_h dest, symbol_const_h src)
bool symbol_equal (symbol_const_h lhs, symbol_const_h rhs)
line_type_t symbol_define (symbol_h sym, char const *tail, char const **pend)
line_type_t symbol_undefine (symbol_h sym, char const *tail, char const **pend)
char const * symbol_name (symbol_const_h sym)
canonical_string_const_h symbol_definition (symbol_const_h sym)
int symbol_compare (symbol_const_h lhs, void const *rhs, size_t namelen)
bool symbol_is_legal (char const *tok, size_t toklen)
bool symbol_is_configured (symbol_const_h sym)
bool symbol_is_global (symbol_const_h sym)
bool is_symbol_start_char (char cp)
bool is_symbol_inner_char (char cp)
canonical_string_const_h symbol_resolve (symbol_h sym, ptr_vector_h history)
bool symbol_reported (symbol_const_h sym)
line_type_t symbol_evaluate_status (bool define, char const *symstart, const char *tail, const char **pend)

Typedef Documentation

typedef struct eval_result const* symbol_const_h

Abstract type of const symbol object

Definition at line 58 of file symbol.h.

typedef struct eval_result* symbol_h

Abstract type of symbol object

Definition at line 55 of file symbol.h.


Function Documentation

bool is_symbol_inner_char ( char  cp)

Say whether can occur within a symbol, except possibly in the first position.

Definition at line 587 of file symbol.c.

Referenced by chew_header_name(), chew_symbol(), configured_symbol_find(), delete_paren(), is_valid_symbol_char(), and symbol_is_legal().

bool is_symbol_start_char ( char  cp)

Say whether a character can be the first character of a symbol.

Definition at line 581 of file symbol.c.

Referenced by chew_symbol(), eval_hash_include(), eval_unary(), is_valid_symbol_char(), match_keyword(), and symbol_is_legal().

void symbol_assign ( symbol_h  dest,
symbol_const_h  src 
)

Assign one symbol to another.

Parameters:
destThe symbol to be assigned
srcThe symbol to be assigned to dest.

Definition at line 310 of file symbol.c.

References symbol_copy(), symbol_dispose(), and symbol_swap().

Here is the call graph for this function:

int symbol_compare ( symbol_const_h  lhs,
void const *  rhs,
size_t  namelen 
)

Compare a symbol with another symbol or a name.

Parameters:
lhsFirst symbol to be compared.
rhsSecond symbol or name to compare.
namelenIf 0 then rhs addresses a second symbol to be compared by name with lhs. Otherwise rhs addresses a name of length namelen to be compared with the name of lhs.
Returns:
A negative value if lhs is less than rhs; 0 if lhs is equal to rhs; a positive value if lhs is greater than rhs.

Definition at line 540 of file symbol.c.

References symbol_name_compare().

Referenced by symbol_equal().

Here is the call graph for this function:

symbol_h symbol_copy ( symbol_const_h  src)

Construct a copy of a symbol.

Parameters:
srcThe symbol to copy
Returns:
A copy of src.

Definition at line 288 of file symbol.c.

References symbol_copy_init(), and zallocate().

Referenced by symbol_assign().

Here is the call graph for this function:

line_type_t symbol_define ( symbol_h  sym,
char const *  tail,
char const **  pend 
)

Assign a definition to a symbol.

Parameters:
symThe symbol to be defined.
tailPointer to text immediately following the parsed symbol name.
pendNULL, or a pointer at which the address of first unconsumed character beginning from tail will be stored on return.
Returns:
a line_type_t denoting what to do with the line on which this symbol is defined. Ignored when defining globally for -D option.

Definition at line 334 of file symbol.c.

References canonical_string_dispose(), canonical_string_equal(), canonical_string_new(), flush_contradiction(), forget_contradiction(), GET_PUBLIC, GRIPE_DIFFERING_REDEF, GRIPE_DUPLICATE_ARGS, GRIPE_GARBAGE_ARG, GRIPE_GLOBAL_FUNCTION_LIKE_MACRO_DEFINITION, GRIPE_INSOURCE_FUNCTION_LIKE_MACRO_DEFINITION, GRIPE_INVALID_ARGS, GRIPE_TRANSIENT_SYMBOL_ADDED, insert_contradiction(), INSOURCE, is_unconditional_line(), eval_result::line, LT_DIRECTIVE_DROP, LT_DIRECTIVE_KEEP, eval_result::most_resolved, report_symbol_configuration(), SET_GLOBAL_SYM, SET_INSOURCE_SYM, eval_result::sym_def, symbol_definition(), symbol_is_configured(), and symbol_is_global().

Referenced by configured_symbol_add().

Here is the call graph for this function:

canonical_string_const_h symbol_definition ( symbol_const_h  sym)

Get the definition of a symbol.

Parameters:
symThe symbol whose definition is to be queried.
Returns:
A canonical string containing the definition of sym, if the symbol is defined, otherwise NULL.

Definition at line 533 of file symbol.c.

Referenced by configured_symbol_match_const(), eval_line(), eval_possible_symbol(), eval_unary(), symbol_define(), symbol_definition_resolve(), symbol_equal(), symbol_resolve(), and symbol_undefine().

void symbol_dispose ( symbol_h  sym)

Dispose of a symbol object, releasing its resources. If sym is NULL the call is a no-op.

Definition at line 279 of file symbol.c.

References eval_result_clear().

Referenced by symbol_assign(), and symbol_evaluate_status().

Here is the call graph for this function:

bool symbol_equal ( symbol_const_h  lhs,
symbol_const_h  rhs 
)

Say whether two symbols are equal.

Parameters:
lhsThe first symbol to compare.
rhsThe second symbol to compare.
Returns:
True if both symbols are NULL or if they have the same name and are identically defined or undefined.

Definition at line 320 of file symbol.c.

References canonical_string_equal(), eq(), symbol_compare(), and symbol_definition().

Here is the call graph for this function:

line_type_t symbol_evaluate_status ( bool  define,
char const *  symstart,
const char *  tail,
const char **  pend 
)

Evaluate the defined/undefined status of a symbol by parsing a commandline option or in-source directive.

This function processes all contexts in which a symbol may be defined or undefined, whether commandline -D or -U options or in-source #define or #undef directives. In the latter case the function makes no presumption that the directive is an active one. If the directive is active, the symbol will be configured appropriately as defined or defined. If it is not, no change of symbol status will be made.

The functions performs all reporting with respect to the parsed symbol that is required by the operative options.

Parameters:
defineIs this symbol configured as defined, or undefined?
symstartPointer to the start of a symbol name.
tailEither NULL a pointer to the text following the parsed occurrence of the symbol name. If not NULL then symstart is assumed to address just the symbol name null-terminated. Otherwise the symbol name is parsed from symstart.
pendIgnored if tail is NULL. Otherwise, if pend is not NULL, it is a pointer at which the address of the first unconsumed character beginning from tail will be stored on return.

If tail is NULL then symstart is assumed to be the start of a commandline argument to a -D or -U option. Otherwise tail is assumed to address the text following the parsed symbol name is a #define or #undef directive.

Returns:
A line_type_t that is insignificant when parsing a -D option. When parsing a #define directive, it denotes the action that to be taken with the line on which the symbol definition appears.

Definition at line 667 of file symbol.c.

References chew_symbol(), CMD_SYMBOLS, configured_symbol_add(), configured_symbol_match(), dropping_line(), eligible_line(), HASH_DEFINE, HASH_UNDEF, INSOURCE, LT_DIRECTIVE_KEEP, report_symbol(), symbol_dispose(), symbol_is_configured(), and symbol_new().

Referenced by eval_hash_define(), eval_hash_undef(), and parse_command_args().

Here is the call graph for this function:

bool symbol_is_configured ( symbol_const_h  sym)

Say whether a symbol is configured, either globally or in-source /param sym The name of the symbol to query. /return True if a symbol named symname is configured, else false.

Definition at line 567 of file symbol.c.

References GLOBAL_SYM, and INSOURCE_SYM.

Referenced by configured_symbol_add(), configured_symbol_match_const(), symbol_define(), symbol_evaluate_status(), symbol_resolve(), and symbol_undefine().

bool symbol_is_global ( symbol_const_h  sym)

Say whether a symbol is configured globally, i.e. by a -D or -U commandline option, rather than in-source by a #define or #undef directive. /param sym The name of the symbol to query. /return True if a symbol named symname is configured globally, else false.

Definition at line 574 of file symbol.c.

References GLOBAL_SYM.

Referenced by symbol_define(), and symbol_undefine().

bool symbol_is_legal ( char const *  tok,
size_t  toklen 
)

Say whether a token is legal preprocesor symbol name.

Parameters:
tokStart of the token.
toklenLength of the token
Returns:
True if the token comprises a legal preprocessor symbol name.

Definition at line 553 of file symbol.c.

References is_symbol_inner_char(), and is_symbol_start_char().

Here is the call graph for this function:

char const* symbol_name ( symbol_const_h  sym)

Get the name of a symbol.

Parameters:
symThe symbol whose name is to be queried.
Returns:
Pointer to the 0-terminated name of the symbol.

Definition at line 526 of file symbol.c.

Referenced by configured_symbol_find(), configured_symbol_match_const(), eval_possible_symbol(), report_symbol(), report_symbol_configuration(), symbol_definition_resolve(), symbol_name_compare(), and symbol_resolve().

symbol_h symbol_new ( char const *  name,
size_t  namelen 
)

Construct a new symbol object

Parameters:
namePointer to the name of the symbol.
namelenThe length of the symbol name.
Returns:
A symbol object having the specified name, no definition and 0 tally.

Definition at line 268 of file symbol.c.

References symbol_init(), and zallocate().

Referenced by hash_include_new(), symbol_evaluate_status(), and unconfigured_symbol_tally().

Here is the call graph for this function:

bool symbol_reported ( symbol_const_h  sym)

Say whether a symbol has been reported.

Definition at line 593 of file symbol.c.

References REPORTED.

Referenced by report_symbol().

canonical_string_const_h symbol_resolve ( symbol_h  sym,
ptr_vector_h  history 
)

Get the most resolved value of a symbol reference.

Parameters:
symThe symbol whose most resolved value is wanted.
historyEither NULL or else ptr_vector_h containing the the configured symbols that have been passed as the first parameter to recursively ancestral calls to the function. If sym is already in this list then one or more circular definitions exist.
Returns:
A canonical string containing the most resolved value of the symbol reference.

If the symbol is neither defined nor undefined, its most resolved form is NULL.

If the symbol is undefined, its most resolved form is the string "0".

If the symbol is defined then its definition is recursively resolved by substitution of the definitions of defined symbol references. In the string that results from this exhaustive resolution, each maximally long portion that is soluble CPP expression is evaluated and replaced with its integer value. The result of this final replacement is the most resolved form of the symbol reference.

In case a symbol is found to have a circular definition, its most resolved form is taken to be the symbol name.

The function stores the most resolved form of the symbol reference internally in the symbol and returns that copy as const.

Definition at line 600 of file symbol.c.

References canonical_numeral(), canonical_string_dispose(), canonical_string_new(), canonical_string_text(), clone(), eval_definition_text(), eval_result_clear(), eval_result_set_value(), GRIPE_CIRCULAR_SYM_DEF, eval_result::most_resolved, ptr_vector_append(), ptr_vector_begin_const(), ptr_vector_drop(), ptr_vector_end_const(), ptr_vector_new(), report(), RESOLVED, SET_KEEP, symbol_definition(), symbol_definition_resolve(), symbol_is_configured(), symbol_name(), and eval_result::value.

Referenced by eval_possible_symbol(), report_symbol(), and symbol_definition_resolve().

Here is the call graph for this function:

void symbol_swap ( symbol_h  lhs,
symbol_h  rhs 
)

Exchange two symbols

Definition at line 298 of file symbol.c.

References canonical_string_swap(), eval_result::flags, eval_result::most_resolved, PODSWAP, eval_result::sym_def, eval_result::sym_name, and eval_result::value.

Referenced by symbol_assign().

Here is the call graph for this function:

line_type_t symbol_undefine ( symbol_h  sym,
char const *  tail,
char const **  pend 
)

Remove any definition from a symbol.

Parameters:
symThe symbol to be undefined.
tailPointer to text immediately following the parsed symbol name.
pendNULL, or a pointer at which the address of first unconsumed character beginning from tail will be stored on return.
Returns:
a line_type_t denoting what to do with the line on which this symbol is udefined. Ignored when udefining globally for -U option.

Definition at line 449 of file symbol.c.

References canonical_string_dispose(), eval_result_set_value(), flush_contradiction(), GET_PUBLIC, GRIPE_DUPLICATE_ARGS, GRIPE_GARBAGE_ARG, GRIPE_INVALID_ARGS, GRIPE_TRANSIENT_SYMBOL_ADDED, GRIPE_UNDEFING_DEFINED, INSOURCE, int_spec_false, is_unconditional_line(), eval_result::line, LT_DIRECTIVE_DROP, LT_DIRECTIVE_KEEP, eval_result::most_resolved, report_symbol_configuration(), save_contradiction(), SET_GLOBAL_SYM, SET_INSOURCE_SYM, SET_PUBLIC, eval_result::sym_def, symbol_definition(), symbol_is_configured(), and symbol_is_global().

Referenced by configured_symbol_add().

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines