mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
Add symbol expressions (like def expressions).
They will eventually replace def expressions. Currently quite broken.
This commit is contained in:
parent
008f4e1929
commit
8f71986306
3 changed files with 42 additions and 0 deletions
|
@ -50,6 +50,7 @@ typedef enum {
|
|||
ex_expr, ///< binary expression (::ex_expr_t)
|
||||
ex_uexpr, ///< unary expression (::ex_expr_t)
|
||||
ex_def, ///< non-temporary variable (::def_t)
|
||||
ex_symbol, ///< non-temporary variable (::symbol_t)
|
||||
ex_temp, ///< temporary variable (::ex_temp_t)
|
||||
ex_name, ///< unresolved name (expr_t::e::string_val)
|
||||
|
||||
|
@ -179,6 +180,7 @@ typedef struct expr_s {
|
|||
ex_block_t block; ///< statement block expression
|
||||
ex_expr_t expr; ///< binary or unary expression
|
||||
struct def_s *def; ///< def reference expression
|
||||
struct symbol_s *symbol; ///< symbol reference expression
|
||||
ex_temp_t temp; ///< temporary variable expression
|
||||
|
||||
const char *string_val; ///< string constant
|
||||
|
@ -329,6 +331,12 @@ expr_t *new_unary_expr (int op, expr_t *e1);
|
|||
*/
|
||||
expr_t *new_def_expr (struct def_s *def);
|
||||
|
||||
/** Create a new symbol reference (non-temporary variable) expression node.
|
||||
|
||||
\return The new symbol reference expression node (::symbol_t).
|
||||
*/
|
||||
expr_t *new_symbol_expr (struct symbol_s *symbol);
|
||||
|
||||
/** Create a new temporary variable expression node.
|
||||
|
||||
Does not allocate a new temporary variable.
|
||||
|
|
|
@ -56,6 +56,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "options.h"
|
||||
#include "qfcc.h"
|
||||
#include "reloc.h"
|
||||
#include "symtab.h"
|
||||
#include "type.h"
|
||||
#include "qc-parse.h"
|
||||
|
||||
|
@ -748,6 +749,10 @@ emit_sub_expr (expr_t *e, def_t *dest)
|
|||
case ex_def:
|
||||
d = e->e.def;
|
||||
break;
|
||||
case ex_symbol:
|
||||
d = get_def (e->e.symbol->type, e->e.symbol->name, pr.scope,
|
||||
st_extern); //FIXME
|
||||
break;
|
||||
case ex_temp:
|
||||
if (!e->e.temp.def) {
|
||||
if (dest)
|
||||
|
@ -896,6 +901,7 @@ emit_expr (expr_t *e)
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case ex_symbol:
|
||||
case ex_def:
|
||||
case ex_temp:
|
||||
case ex_string:
|
||||
|
|
|
@ -60,6 +60,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "reloc.h"
|
||||
#include "strpool.h"
|
||||
#include "struct.h"
|
||||
#include "symtab.h"
|
||||
#include "type.h"
|
||||
#include "qc-parse.h"
|
||||
|
||||
|
@ -75,6 +76,7 @@ etype_t qc_types[] = {
|
|||
ev_void, // ex_expr
|
||||
ev_void, // ex_uexpr
|
||||
ev_void, // ex_def
|
||||
ev_void, // ex_symbol
|
||||
ev_void, // ex_temp
|
||||
ev_void, // ex_name
|
||||
|
||||
|
@ -199,6 +201,8 @@ get_type (expr_t *e)
|
|||
return e->e.expr.type;
|
||||
case ex_def:
|
||||
return e->e.def->type;
|
||||
case ex_symbol:
|
||||
return e->e.symbol->type;
|
||||
case ex_temp:
|
||||
return e->e.temp.type;
|
||||
case ex_pointer:
|
||||
|
@ -413,6 +417,7 @@ copy_expr (expr_t *e)
|
|||
switch (e->type) {
|
||||
case ex_error:
|
||||
case ex_def:
|
||||
case ex_symbol:
|
||||
case ex_name:
|
||||
case ex_nil:
|
||||
case ex_string:
|
||||
|
@ -613,6 +618,15 @@ new_def_expr (def_t *def)
|
|||
return e;
|
||||
}
|
||||
|
||||
expr_t *
|
||||
new_symbol_expr (symbol_t *symbol)
|
||||
{
|
||||
expr_t *e = new_expr ();
|
||||
e->type = ex_symbol;
|
||||
e->e.symbol = symbol;
|
||||
return e;
|
||||
}
|
||||
|
||||
expr_t *
|
||||
new_temp_def_expr (type_t *type)
|
||||
{
|
||||
|
@ -945,6 +959,9 @@ print_expr (expr_t *e)
|
|||
printf ("[%d]", e->e.def->ofs);
|
||||
}
|
||||
break;
|
||||
case ex_symbol:
|
||||
printf ("%s", e->e.symbol->name);
|
||||
break;
|
||||
case ex_temp:
|
||||
printf ("(");
|
||||
print_expr (e->e.temp.expr);
|
||||
|
@ -1920,6 +1937,13 @@ unary_expr (int op, expr_t *e)
|
|||
? e->e.def->type : e->e.expr.type;
|
||||
return n;
|
||||
}
|
||||
case ex_symbol:
|
||||
{
|
||||
expr_t *n = new_unary_expr (op, e);
|
||||
|
||||
n->e.expr.type = e->e.symbol->type;
|
||||
return n;
|
||||
}
|
||||
case ex_short:
|
||||
e->e.short_val *= -1;
|
||||
return e;
|
||||
|
@ -1967,6 +1991,7 @@ unary_expr (int op, expr_t *e)
|
|||
case ex_uexpr:
|
||||
case ex_expr:
|
||||
case ex_def:
|
||||
case ex_symbol:
|
||||
case ex_temp:
|
||||
{
|
||||
expr_t *n = new_unary_expr (op, e);
|
||||
|
@ -2034,6 +2059,7 @@ unary_expr (int op, expr_t *e)
|
|||
case ex_expr:
|
||||
case ex_bool:
|
||||
case ex_def:
|
||||
case ex_symbol:
|
||||
case ex_temp:
|
||||
bitnot_expr:
|
||||
if (options.code.progsversion == PROG_ID_VERSION) {
|
||||
|
@ -2078,6 +2104,8 @@ bitnot_expr:
|
|||
e = new_unary_expr ('.', e);
|
||||
e->e.expr.type = get_type (e->e.expr.e1)->t.fldptr.type;
|
||||
return e;
|
||||
case '+':
|
||||
return e; // FIXME typechecking
|
||||
}
|
||||
error (e, "internal error");
|
||||
abort ();
|
||||
|
|
Loading…
Reference in a new issue