coan 4.2.4
The Evaluator component internals
Collaboration diagram for The Evaluator component internals:

Data Structures

struct  operation
struct  co_precedent_ops

Modules

 Macro-generated code

Files

file  evaluator.c

Typedefs

typedef eval_result_tevaluator_t )(struct co_precedent_ops const *ops, char const **, struct operation const **pbin_op)

Functions

static eval_result_t integer_binary_op (eval_result_t *lhs, eval_result_t *rhs, integer_bin_op_t op)
static eval_result_t op_lt (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_gt (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_le (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_ge (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_eq (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_ne (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_or (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_and (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_bit_and (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_bit_or (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_bit_xor (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_lshift (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_rshift (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_add (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_subtract (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_mult (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_divide (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t op_mod (eval_result_t *lhs, eval_result_t *rhs)
static eval_result_t eval_unary (struct co_precedent_ops const *ops, char const **cpp, struct operation const **ignored)
static eval_result_t eval_table (struct co_precedent_ops const *ops, char const **cpp, struct operation const **pbin_op)
static char const * short_circuit_and (char const *cp)
static char const * short_circuit_or (char const *cp)
static int eval_if (char const **cpp)
static line_type_t eval_hash_define (char const **cpp)
static line_type_t eval_hash_undef (char const **cpp)
static eval_result_t eval_possible_symbol (char const **cpp, directive_type_t context)
static line_type_t eval_hash_include (char const **cpp)
static char const * eval_free_form_directive (char const *cp, directive_type_t directive_type)

Variables

struct co_precedent_ops const * ops_tab = eval_ops
struct co_precedent_ops eval_ops []

Typedef Documentation

typedef eval_result_t( evaluator_t)(struct co_precedent_ops const *ops, char const **, struct operation const **pbin_op)

Type of evaluation functions.

Parameters:
opsA pointer to an element of the precedence table which lists the operators at the current level of precedence.
cppOn entry, a pointer to a char* that points to the expression to be evaluated. On return, receives the address terminating the evaluated expression.
pbin_opEither NULL or the address of a struct operation const * at which will be stored on return the adress of the binary operation, if any, that is the major operator in the parsed expression.
Returns:
An eval_result_t representing the result of evaluation.

Definition at line 349 of file evaluator.c.


Function Documentation

static char const* eval_free_form_directive ( char const *  cp,
directive_type_t  directive_type 
) [static]

Evaluate a directive that takes a free-form argumnent (hash-error, hash-pragma)

Parameters:
cpPointer to the argument of the hash-error directive.
directive_typeType of the directive being evaluated.
Returns:
The terminal address of the hash-error directive.

Definition at line 870 of file evaluator.c.

References canonical_string_new(), and directive_tally().

Referenced by eval_line().

Here is the call graph for this function:

static line_type_t eval_hash_define ( char const **  cpp) [static]

Evaluate the text of a hash-define directive.

Parameters:
cppPointer to the address of the directive text. This pointer is updated at exit with the address just past the text consumed.
Returns:
A line_type_t that denotes the action that to be taken with the line containing the hash-define directive.

Definition at line 572 of file evaluator.c.

References canonical_identifier(), canonical_string_dispose(), canonical_string_new(), canonical_string_text(), chew_on(), chew_string(), CMD_DEFS, debug(), directive_tally(), eligible_line(), HASH_DEFINE, line_len(), and symbol_evaluate_status().

Referenced by eval_line().

Here is the call graph for this function:

static line_type_t eval_hash_include ( char const **  cpp) [static]

Evaluate the argument of a hash-include directive.

Parameters:
cppOn entry, a pointer to the address of the directive argument. On exit, the address of the first unconsumed character is stored here.
Returns:
A line_type_t denoting the action to be taken with the line containing the directive.

The function is called only when the includes command is in effect.

If the argument of the hash-include directive is a malformed header name the function will report a warning diagnostic on stderr. Likewise if the argument is a macro call, since macro expension is not supported, or if the argument is preprocessor symbol that is:-

  • unknown
  • undef-ed
  • evaluates to an empty string.
  • evaluates to a string that is a malformed header name.

The function will list the hash-include directive on stdout in all circumstances if --once is not in effect. If --once is effect then the directive will be listed if it has not already been seen.

Definition at line 796 of file evaluator.c.

References canonical_string_text(), chew_header_name(), chew_on(), chew_string(), CMD_INCLUDES, dropping_line(), eligible_line(), eval_possible_symbol(), GRIPE_INVALID_INCLUDE, HASH_INCLUDE, hash_include_tally(), is_symbol_start_char(), LT_DIRECTIVE_DROP, LT_DIRECTIVE_KEEP, eval_result::most_resolved, report(), and SET_PUBLIC.

Referenced by eval_line().

Here is the call graph for this function:

static line_type_t eval_hash_undef ( char const **  cpp) [static]

Evaluate the text of a hash-define directive.

Parameters:
cppPointer to the address of the directive text. This pointer is updated at exit with the address just past the text consumed.
Returns:
A line_type_t that denotes the action that to be taken with the line containing the hash-undef directive.

Definition at line 606 of file evaluator.c.

References canonical_identifier(), canonical_string_copy(), canonical_string_dispose(), canonical_string_text(), chew_on(), CMD_DEFS, debug(), directive_tally(), eligible_line(), HASH_UNDEF, line_len(), LT_DIRECTIVE_KEEP, and symbol_evaluate_status().

Referenced by eval_line().

Here is the call graph for this function:

static int eval_if ( char const **  cpp) [static]

Evaluate the expression of a hash-if or hash-elif directive. If we can resolve the expression we return LT_TRUE or LT_FALSE accordingly, otherwise LT_IF.

Definition at line 1127 of file evaluator.c.

References bail(), chew_on(), debug(), eval_table(), GRIPE_IF_WITHOUT_COND, IS_FALSE, IS_TRUE, KEEP_CONST, LT_FALSE, LT_IF, LT_TRUE, and eval_result::value.

Referenced by eval_line().

Here is the call graph for this function:

static eval_result_t eval_possible_symbol ( char const **  cpp,
directive_type_t  context 
) [static]

Try to evaluate a possible psymbol.

Parameters:
cppAddress of a pointer to the first character of a possible symbol. The address of the first parsed character not belonging to an identifier is stored here on return.
contextThe type of directive in which parsing takes place (either HASH_IF or HASH_INCLUDE).
Returns:
If the parsed text is not a configured symbol then an eval_result_t == EVAL_RESULT_INITOR is returned Otherwise the returned eval_result_t stores the resolved value of the parsed symbol.

Definition at line 640 of file evaluator.c.

References canonical_identifier(), canonical_string_length(), canonical_string_text(), chew_macro_call(), CMD_SYMBOLS, configured_symbol_match(), eligible_line(), EVAL_RESULT_INITOR, eval_result_set_value(), GET_PUBLIC, GET_STATE, GRIPE_EMPTY_SYMBOL, GRIPE_FUNCTION_LIKE_MACRO_EXPANSION, HASH_IF, HASH_INCLUDE, int_spec_false, report(), report_symbol(), symbol_definition(), symbol_name(), symbol_resolve(), and unconfigured_symbol_tally().

Referenced by eval_hash_include(), and eval_unary().

Here is the call graph for this function:

static eval_result_t eval_table ( struct co_precedent_ops const *  ops,
char const **  cpp,
struct operation const **  pbin_op 
) [static]

Table-driven evaluation of binary operators. The evaluator does shortcircuit evaluation for && and ||. It also simplifies && and || subexpressions that can be partially solved. If we are keeping constants then constants are treated like unresolved symbols, and the rules are: CONSTANT1 && CONSTANT2 := CONSTANT1 CONSTANT && TRUE : = CONSTANT CONSTANT && FALSE := FALSE CONSTANT1 || CONSTANT2 := CONSTANT1 CONSTANT || TRUE := TRUE CONSTANT || FALSE := CONSTANT

Parameters:
opsPointer to the struct ops to be used for the evaluation.
cppOn entry, a pointer to the start of the text to be evaluated. Receives the address reached by evaluation.
pbin_opEither NULL or the address of a struct operation const * at which will be stored on return the adress of the binary operation, if any, that is the major operator in the parsed expression.
Returns:
An eval_result_t that representing the result of evaluation.

Definition at line 879 of file evaluator.c.

References chew_on(), cut_text(), debug(), DEL_PAREN, delete_paren(), EVAL_RESULT_INITOR, operation::fn, co_precedent_ops::inner, IS_FALSE, IS_TRUE, KEEP, KEEP_CONST, LEGAL, LINE_OFF, match_op(), co_precedent_ops::op, op_and(), op_or(), RESOLVED, restore_paren(), SET_DEL_PAREN, SET_ILLEGAL, SET_KEEP, SET_KEEP_PAREN, short_circuit_and(), short_circuit_or(), operation::str, and eval_result::value.

Referenced by eval_definition_text(), eval_if(), and eval_unary().

Here is the call graph for this function:

static eval_result_t eval_unary ( struct co_precedent_ops const *  ops,
char const **  cpp,
struct operation const **  ignored 
) [static]

Evaluator for innermost subexpressions, i.e.

  • !expr
  • (expr)
  • (symbol)
  • symbol
  • number
Parameters:
opsPointer to the struct ops to be used for the evaluation.
cppOn entry, a pointer to the start of the text to be evaluated. Receives the address reached by evaluation.
ignoredThe parameter is present only for protopype compatibility with eval_table() and is unused.
Returns:
An eval_result_t representing the result of evaluation.

Definition at line 982 of file evaluator.c.

References bail(), canonical_identifier(), canonical_string_dispose(), canonical_string_length(), canonical_string_text(), chew_continuation(), chew_on(), CMD_SYMBOLS, complement(), configured_symbol_match(), debug(), DEL_PAREN, delete_paren(), eligible_line(), eval_character_constant(), EVAL_FALSE, eval_numeral(), eval_possible_symbol(), EVAL_RESOLVED, EVAL_RESULT_INITOR, eval_result_set_value(), eval_table(), EVAL_TRUE, FLIP_FLAGS, GET_PUBLIC, GET_STATE, GRIPE_UNBALANCED_PAREN, HASH_IF, INT_INSOLUBLE, int_spec_false, int_spec_true, INT_TOO_BIG, is_symbol_start_char(), line_len(), LINE_OFF, match_keyword(), minus(), negate(), report_symbol(), RESOLVED, SET_CONST, SET_DEL_PAREN, SET_FLAGS, SET_ILLEGAL, SET_KEEP, SET_PUBLIC, symbol_definition(), int_spec::type, unconfigured_symbol_tally(), UNRESOLVED, int_spec::val, and eval_result::value.

Here is the call graph for this function:

static eval_result_t integer_binary_op ( eval_result_t lhs,
eval_result_t rhs,
integer_bin_op_t  op 
) [static]

Execute a binary operation on integer expressions.

Parameters:
lhsAn eval_result_t containing the left-hand integer operand.
rhsAn eval_result_t containing the right-hand integer operand.
opThe binary operation to be applied to lhs and rhs.
Returns:
An eval_result_t representing the result of evaluating op on lhs and rhs.

It is not assumed that either of the expressions lhs or rhs has been resolved to an integer value. If either of them is unresolved then the returned result represents "the unresolved expression".

Definition at line 111 of file evaluator.c.

References EVAL_RESULT_INITOR, eval_result_set_value(), INT_UNDEF, IS_CONST, co_precedent_ops::op, RESOLVED, int_spec::type, and eval_result::value.

Referenced by op_add(), op_bit_and(), op_bit_or(), op_bit_xor(), op_eq(), op_ge(), op_gt(), op_le(), op_lshift(), op_lt(), op_mult(), op_ne(), op_rshift(), and op_subtract().

Here is the call graph for this function:

static eval_result_t op_add ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Addition operator

Definition at line 266 of file evaluator.c.

References add(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_and ( eval_result_t lhs,
eval_result_t rhs 
) [static]

And operator

Definition at line 197 of file evaluator.c.

References boolean_and(), EVAL_KEEP_CONST, EVAL_RESULT_INITOR, eval_result_set_value(), int_spec_false, IS_FALSE, IS_TRUE, KEEP_CONST, SET_FLAGS_IF, UNRESOLVED, and eval_result::value.

Referenced by eval_table().

Here is the call graph for this function:

static eval_result_t op_bit_and ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Bitwise AND operator

Definition at line 231 of file evaluator.c.

References bit_and(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_bit_or ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Bitwise OR operator

Definition at line 238 of file evaluator.c.

References bit_or(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_bit_xor ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Bitwise XOR operator

Definition at line 245 of file evaluator.c.

References bit_xor(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_divide ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Division operator

Definition at line 287 of file evaluator.c.

References divide(), EVAL_RESULT_INITOR, eval_result_set_value(), GRIPE_ZERO_DIVIDE, IS_CONST, report(), RESOLVED, int_spec::val, and eval_result::value.

Here is the call graph for this function:

static eval_result_t op_eq ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Equality operator

Definition at line 156 of file evaluator.c.

References eq(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_ge ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Greater-than-or-equal operator

Definition at line 149 of file evaluator.c.

References ge(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_gt ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Greater-than operator

Definition at line 135 of file evaluator.c.

References gt(), and integer_binary_op().

Here is the call graph for this function:

static eval_result_t op_le ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Less-than-or-equal operator

Definition at line 142 of file evaluator.c.

References integer_binary_op(), and le().

Here is the call graph for this function:

static eval_result_t op_lshift ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Left-shift operator

Definition at line 252 of file evaluator.c.

References integer_binary_op(), and lshift().

Here is the call graph for this function:

static eval_result_t op_lt ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Less-than operator

Definition at line 128 of file evaluator.c.

References integer_binary_op(), and lt().

Here is the call graph for this function:

static eval_result_t op_mod ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Modulus operator

Definition at line 305 of file evaluator.c.

References EVAL_RESULT_INITOR, eval_result_set_value(), GRIPE_ZERO_DIVIDE, IS_CONST, modulus(), report(), RESOLVED, int_spec::val, and eval_result::value.

Here is the call graph for this function:

static eval_result_t op_mult ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Multiplication operator

Definition at line 280 of file evaluator.c.

References integer_binary_op(), and multiply().

Here is the call graph for this function:

static eval_result_t op_ne ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Inequality operator

Definition at line 163 of file evaluator.c.

References integer_binary_op(), and ne().

Here is the call graph for this function:

static eval_result_t op_or ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Inclusive-or operator

Definition at line 170 of file evaluator.c.

References CLEAR_FLAGS_IF, EVAL_KEEP, EVAL_KEEP_CONST, EVAL_RESOLVED, EVAL_RESULT_INITOR, eval_result_set_value(), FLAGS_IN, int_spec_false, int_spec_true, IS_FALSE, IS_TRUE, KEEP_CONST, and SET_FLAGS_IF.

Referenced by eval_table().

Here is the call graph for this function:

static eval_result_t op_rshift ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Right-shift operator

Definition at line 259 of file evaluator.c.

References integer_binary_op(), and rshift().

Here is the call graph for this function:

static eval_result_t op_subtract ( eval_result_t lhs,
eval_result_t rhs 
) [static]

Substraction operator

Definition at line 273 of file evaluator.c.

References integer_binary_op(), and subtract().

Here is the call graph for this function:

static char const* short_circuit_and ( char const *  cp) [static]

Skip right-hand operand of && in an hash-if directive when we can short-circuit the evaluation.

Parameters:
cpLine-buffer position at which the operand begins.

When an && can be short-circuited, the evaluator can skip from the start of the righthand operand until:

  • the end of the directive, or
  • an unbalanced ')', which must close the scope of the &&, or
  • a || operator, which has higher precedence.
Returns:
The address just past the skipped operand.

Definition at line 501 of file evaluator.c.

References chew_on().

Referenced by eval_table().

Here is the call graph for this function:

static char const* short_circuit_or ( char const *  cp) [static]

Skip the right-hand operand of || in an hash-if directive when we can short-circuit the evaluation.

Parameters:
cpLine-buffer position at which the operand begins.

When an || can be short-circuited, the evaluator can skip from the start of the righthand operand until the end of the directive, or an unbalanced ')', which must close the scope of the ||. None of our operators has higher precedence.

Returns:
The address just past the skipped operand.

Definition at line 539 of file evaluator.c.

References chew_on().

Referenced by eval_table().

Here is the call graph for this function:


Variable Documentation

The operator precedence table

Definition at line 422 of file evaluator.c.

struct co_precedent_ops const * ops_tab = eval_ops

The operator precedence table

Definition at line 95 of file evaluator.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines