mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
Resurrect constant_expr().
This commit is contained in:
parent
bc882ddc3c
commit
d162838299
2 changed files with 28 additions and 0 deletions
|
@ -438,6 +438,16 @@ short expr_short (expr_t *e);
|
|||
*/
|
||||
int is_constant (expr_t *e);
|
||||
|
||||
/** Return a value expression representing the constant stored in \a e.
|
||||
|
||||
If \a e does not represent a constant, or \a e is already a value or
|
||||
nil expression, then \a e is returned rather than a new expression.
|
||||
|
||||
\param e The expression from which to extract the value.
|
||||
\return A new expression holding the value of \a e or \e itself.
|
||||
*/
|
||||
expr_t *constant_expr (expr_t *e);
|
||||
|
||||
/** Check if the op-code is a comparison.
|
||||
|
||||
\param op The op-code to check.
|
||||
|
|
|
@ -602,6 +602,24 @@ is_constant (expr_t *e)
|
|||
return 0;
|
||||
}
|
||||
|
||||
expr_t *
|
||||
constant_expr (expr_t *e)
|
||||
{
|
||||
expr_t *new;
|
||||
if (!is_constant (e))
|
||||
return e;
|
||||
if (e->type == ex_nil || e->type == ex_value)
|
||||
return e;
|
||||
if (e->type != ex_symbol || e->e.symbol->sy_type != sy_const)
|
||||
return e;
|
||||
new = new_expr ();
|
||||
new->type = ex_value;
|
||||
new->line = e->line;
|
||||
new->file = e->file;
|
||||
new->e.value = e->e.symbol->s.value;
|
||||
return new;
|
||||
}
|
||||
|
||||
int
|
||||
is_string_val (expr_t *e)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue