coan 4.2.4
|
![]() |
typedef eval_result_t( evaluator_t)(struct co_precedent_ops const *ops, char const **, struct operation const **pbin_op) |
Type of evaluation functions.
ops | A pointer to an element of the precedence table which lists the operators at the current level of precedence. |
cpp | On entry, a pointer to a char* that points to the expression to be evaluated. On return, receives the address terminating the evaluated expression. |
pbin_op | Either 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. |
Definition at line 349 of file evaluator.c.
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)
cp | Pointer to the argument of the hash-error directive. |
directive_type | Type of the directive being evaluated. |
Definition at line 870 of file evaluator.c.
References canonical_string_new(), and directive_tally().
Referenced by eval_line().
static line_type_t eval_hash_define | ( | char const ** | cpp | ) | [static] |
Evaluate the text of a hash-define directive.
cpp | Pointer to the address of the directive text. This pointer is updated at exit with the address just past the text consumed. |
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().
static line_type_t eval_hash_include | ( | char const ** | cpp | ) | [static] |
Evaluate the argument of a hash-include directive.
cpp | On entry, a pointer to the address of the directive argument. On exit, the address of the first unconsumed character is stored here. |
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:-
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().
static line_type_t eval_hash_undef | ( | char const ** | cpp | ) | [static] |
Evaluate the text of a hash-define directive.
cpp | Pointer to the address of the directive text. This pointer is updated at exit with the address just past the text consumed. |
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().
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().
static eval_result_t eval_possible_symbol | ( | char const ** | cpp, |
directive_type_t | context | ||
) | [static] |
Try to evaluate a possible psymbol.
cpp | Address 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. |
context | The type of directive in which parsing takes place (either HASH_IF or HASH_INCLUDE). |
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().
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
ops | Pointer to the struct ops to be used for the evaluation. |
cpp | On entry, a pointer to the start of the text to be evaluated. Receives the address reached by evaluation. |
pbin_op | Either 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. |
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().
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.
ops | Pointer to the struct ops to be used for the evaluation. |
cpp | On entry, a pointer to the start of the text to be evaluated. Receives the address reached by evaluation. |
ignored | The parameter is present only for protopype compatibility with eval_table() and is unused. |
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.
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.
lhs | An eval_result_t containing the left-hand integer operand. |
rhs | An eval_result_t containing the right-hand integer operand. |
op | The binary operation to be applied to 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().
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().
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().
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().
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().
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().
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.
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().
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().
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().
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().
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().
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().
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.
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().
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().
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().
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().
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().
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.
cp | Line-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:
&&
, or||
operator, which has higher precedence.Definition at line 501 of file evaluator.c.
References chew_on().
Referenced by eval_table().
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.
cp | Line-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.
Definition at line 539 of file evaluator.c.
References chew_on().
Referenced by eval_table().
struct co_precedent_ops eval_ops[] |
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.