call", indent, "", e);
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
dasprintf (dstr, "|p%d", i, i);
dasprintf (dstr, "\",shape=record];\n");
- for (i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
_print_expr (dstr, args[i], level + 1, id, next);
dasprintf (dstr, "%*se_%p:p%d -> e_%p;\n", indent + 2, "", e, i,
args[i]);
@@ -446,7 +442,7 @@ print_call (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_branch (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_branch (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
switch (e->branch.type) {
case pr_branch_eq:
@@ -467,7 +463,7 @@ print_branch (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_return (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_return (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -481,7 +477,7 @@ print_return (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_uexpr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_uexpr (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -492,7 +488,7 @@ print_uexpr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_def (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_def (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -501,7 +497,7 @@ print_def (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_symbol (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_symbol (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -510,7 +506,7 @@ print_symbol (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_temp (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_temp (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -519,11 +515,11 @@ print_temp (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_vector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_vector (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
- for (expr_t *ele = e->vector.list; ele; ele = ele->next) {
+ for (const expr_t *ele = e->vector.list; ele; ele = ele->next) {
_print_expr (dstr, ele, level, id, next);
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, ele);
}
@@ -532,7 +528,7 @@ print_vector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_selector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_selector (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -541,7 +537,7 @@ print_selector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_nil (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_nil (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -550,7 +546,7 @@ print_nil (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_value (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_value (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
const char *label = "?!?";
@@ -564,19 +560,19 @@ print_value (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_compound (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_compound (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
dasprintf (dstr, "%*se_%p [label=\"compound init\"];\n", indent, "", e);
}
static void
-print_memset (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_memset (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
- expr_t *dst = e->memset.dst;
- expr_t *val = e->memset.val;
- expr_t *count = e->memset.count;
+ const expr_t *dst = e->memset.dst;
+ const expr_t *val = e->memset.val;
+ const expr_t *count = e->memset.count;
_print_expr (dstr, dst, level, id, next);
_print_expr (dstr, val, level, id, next);
_print_expr (dstr, count, level, id, next);
@@ -587,7 +583,7 @@ print_memset (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_adjstk (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_adjstk (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -596,10 +592,10 @@ print_adjstk (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_with (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_with (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
- expr_t *with = e->with.with;
+ const expr_t *with = e->with.with;
_print_expr (dstr, with, level, id, next);
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, with);
@@ -608,7 +604,7 @@ print_with (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_args (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_args (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -617,7 +613,7 @@ print_args (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_horizontal (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_horizontal (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
@@ -628,7 +624,7 @@ print_horizontal (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_swizzle (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_swizzle (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
static char swizzle_components[] = "xyzw";
int indent = level * 2 + 2;
@@ -652,7 +648,7 @@ print_swizzle (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_extend (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_extend (dstring_t *dstr, const expr_t *e, int level, int id, const expr_t *next)
{
int indent = level * 2 + 2;
ex_extend_t extend = e->extend;
@@ -672,7 +668,8 @@ print_extend (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-print_multivec (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+print_multivec (dstring_t *dstr, const expr_t *e, int level, int id,
+ const expr_t *next)
{
int indent = level * 2 + 2;
ex_multivec_t multivec = e->multivec;
@@ -690,9 +687,10 @@ print_multivec (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
static void
-_print_expr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
+_print_expr (dstring_t *dstr, const expr_t *e, int level, int id,
+ const expr_t *next)
{
- static print_f print_funcs[ex_count] = {
+ static print_f *print_funcs[ex_count] = {
[ex_error] = print_error,
[ex_state] = print_state,
[ex_bool] = print_bool,
@@ -732,7 +730,7 @@ _print_expr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
if (e->printid == id) // already printed this expression
return;
- e->printid = id;
+ ((expr_t *) e)->printid = id;
if ((int) e->type < 0 || e->type >= ex_count || !print_funcs[e->type]) {
const char *type = va (0, "%d", e->type);
@@ -748,11 +746,11 @@ _print_expr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
}
void
-dump_dot_expr (void *_e, const char *filename)
+dump_dot_expr (const void *_e, const char *filename)
{
static int id = 0;
dstring_t *dstr = dstring_newstr ();
- expr_t *e = (expr_t *) _e;
+ const expr_t *e = _e;
dasprintf (dstr, "digraph expr_%p {\n", e);
dasprintf (dstr, " graph [label=\"%s\"];\n", quote_string (filename));
@@ -773,7 +771,7 @@ dump_dot_expr (void *_e, const char *filename)
}
void
-print_expr (expr_t *e)
+print_expr (const expr_t *e)
{
dump_dot_expr (e, 0);
}
diff --git a/tools/qfcc/source/dot_flow.c b/tools/qfcc/source/dot_flow.c
index 4a37156b4..1e2b8f961 100644
--- a/tools/qfcc/source/dot_flow.c
+++ b/tools/qfcc/source/dot_flow.c
@@ -409,31 +409,31 @@ print_flowgraph (flow_dot_t *method, flowgraph_t *graph, const char *filename)
}
void
-dump_dot_flow (void *g, const char *filename)
+dump_dot_flow (const void *g, const char *filename)
{
print_flowgraph (&flow_dot_methods[0], (flowgraph_t *) g, filename);
}
void
-dump_dot_flow_dags (void *g, const char *filename)
+dump_dot_flow_dags (const void *g, const char *filename)
{
print_flowgraph (&flow_dot_methods[1], (flowgraph_t *) g, filename);
}
void
-dump_dot_flow_live (void *g, const char *filename)
+dump_dot_flow_live (const void *g, const char *filename)
{
print_flowgraph (&flow_dot_methods[2], (flowgraph_t *) g, filename);
}
void
-dump_dot_flow_reaching (void *g, const char *filename)
+dump_dot_flow_reaching (const void *g, const char *filename)
{
print_flowgraph (&flow_dot_methods[3], (flowgraph_t *) g, filename);
}
void
-dump_dot_flow_statements (void *g, const char *filename)
+dump_dot_flow_statements (const void *g, const char *filename)
{
print_flowgraph (&flow_dot_methods[4], (flowgraph_t *) g, filename);
}
diff --git a/tools/qfcc/source/emit.c b/tools/qfcc/source/emit.c
index 4770d4f80..27051f963 100644
--- a/tools/qfcc/source/emit.c
+++ b/tools/qfcc/source/emit.c
@@ -60,10 +60,10 @@
static def_t zero_def;
-static def_t *get_operand_def (expr_t *expr, operand_t *op);
+static def_t *get_operand_def (const expr_t *expr, operand_t *op);
static def_t *
-get_tempop_def (expr_t *expr, operand_t *tmpop, type_t *type)
+get_tempop_def (const expr_t *expr, operand_t *tmpop, type_t *type)
{
tempop_t *tempop = &tmpop->tempop;
if (tempop->def) {
@@ -81,7 +81,7 @@ get_tempop_def (expr_t *expr, operand_t *tmpop, type_t *type)
}
static def_t *
-get_value_def (expr_t *expr, ex_value_t *value, type_t *type)
+get_value_def (const expr_t *expr, ex_value_t *value, type_t *type)
{
def_t *def;
@@ -101,7 +101,7 @@ get_value_def (expr_t *expr, ex_value_t *value, type_t *type)
}
static def_t *
-get_operand_def (expr_t *expr, operand_t *op)
+get_operand_def (const expr_t *expr, operand_t *op)
{
if (!op)
return 0;
@@ -167,7 +167,7 @@ add_statement_op_ref (operand_t *op, dstatement_t *st, int field)
}
static void
-use_tempop (operand_t *op, expr_t *expr)
+use_tempop (operand_t *op, const expr_t *expr)
{
if (!op || op->op_type != op_temp)
return;
@@ -227,7 +227,7 @@ emit_statement (statement_t *statement)
internal_error (statement->expr, "ice ice baby");
}
if (options.code.debug) {
- expr_t *e = statement->expr;
+ const expr_t *e = statement->expr;
pr_uint_t line = (e ? e->line : pr.source_line) - lineno_base;
if (line != pr.linenos[pr.num_linenos - 1].line) {
diff --git a/tools/qfcc/source/evaluate.c b/tools/qfcc/source/evaluate.c
index 469a8611d..584367d9a 100644
--- a/tools/qfcc/source/evaluate.c
+++ b/tools/qfcc/source/evaluate.c
@@ -223,8 +223,8 @@ get_def (operand_t *op)
internal_error (0, "unexpected operand");
}
-expr_t *
-evaluate_constexpr (expr_t *e)
+const expr_t *
+evaluate_constexpr (const expr_t *e)
{
debug (e, "fold_constants");
if (e->type == ex_uexpr) {
diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c
index 24d234a93..094acc1de 100644
--- a/tools/qfcc/source/expr.c
+++ b/tools/qfcc/source/expr.c
@@ -69,11 +69,10 @@
ALLOC_STATE (expr_t, exprs);
ALLOC_STATE (ex_listitem_t, listitems);
-expr_t *
-convert_name (expr_t *e)
+const expr_t *
+convert_name (const expr_t *e)
{
symbol_t *sym;
- expr_t *new;
if (!e || e->type != ex_symbol)
return e;
@@ -82,28 +81,23 @@ convert_name (expr_t *e)
if (!strcmp (sym->name, "__PRETTY_FUNCTION__")
&& current_func) {
- new = new_string_expr (current_func->name);
- goto convert;
+ return new_string_expr (current_func->name);
}
if (!strcmp (sym->name, "__FUNCTION__")
&& current_func) {
- new = new_string_expr (current_func->def->name);
- goto convert;
+ return new_string_expr (current_func->def->name);
}
if (!strcmp (sym->name, "__LINE__")
&& current_func) {
- new = new_int_expr (e->line);
- goto convert;
+ return new_int_expr (e->line);
}
if (!strcmp (sym->name, "__INFINITY__")
&& current_func) {
- new = new_float_expr (INFINITY);
- goto convert;
+ return new_float_expr (INFINITY);
}
if (!strcmp (sym->name, "__FILE__")
&& current_func) {
- new = new_string_expr (GETSTR (e->file));
- goto convert;
+ return new_string_expr (GETSTR (e->file));
}
if (!sym->table) {
error (e, "%s undefined", sym->name);
@@ -112,23 +106,19 @@ convert_name (expr_t *e)
return e;
}
if (sym->sy_type == sy_convert) {
- new = sym->s.convert.conv (sym, sym->s.convert.data);
- goto convert;
+ return sym->s.convert.conv (sym, sym->s.convert.data);
}
if (sym->sy_type == sy_expr) {
- new = copy_expr (sym->s.expr);
- goto convert;
+ return sym->s.expr;
}
if (sym->sy_type == sy_type)
internal_error (e, "unexpected typedef");
// var, const and func shouldn't need extra handling
return e;
-convert:
- return expr_file_line (new, e);
}
type_t *
-get_type (expr_t *e)
+get_type (const expr_t *e)
{
const type_t *type = 0;
e = convert_name (e);
@@ -215,7 +205,7 @@ get_type (expr_t *e)
}
etype_t
-extract_type (expr_t *e)
+extract_type (const expr_t *e)
{
type_t *type = get_type (e);
@@ -225,32 +215,31 @@ extract_type (expr_t *e)
}
expr_t *
-type_mismatch (expr_t *e1, expr_t *e2, int op)
+type_mismatch (const expr_t *e1, const expr_t *e2, int op)
{
- e1 = error (e1, "type mismatch: %s %s %s",
- get_type_string (get_type (e1)), get_op_string (op),
- get_type_string (get_type (e2)));
- return e1;
+ return error (e1, "type mismatch: %s %s %s",
+ get_type_string (get_type (e1)), get_op_string (op),
+ get_type_string (get_type (e2)));
}
expr_t *
-param_mismatch (expr_t *e, int param, const char *fn, type_t *t1, type_t *t2)
+param_mismatch (const expr_t *e, int param, const char *fn, type_t *t1, type_t *t2)
{
- e = error (e, "type mismatch for parameter %d of %s: expected %s, got %s",
- param, fn, get_type_string (t1), get_type_string (t2));
- return e;
+ return error (e, "type mismatch for parameter %d of %s: "
+ "expected %s, got %s", param, fn, get_type_string (t1),
+ get_type_string (t2));
}
expr_t *
-test_error (expr_t *e, type_t *t)
+test_error (const expr_t *e, type_t *t)
{
dstring_t *s = dstring_newstr ();
print_type_str (s, t);
- e = error (e, "%s cannot be tested", s->str);
+ auto err = error (e, "%s cannot be tested", s->str);
dstring_delete (s);
- return e;
+ return err;
}
expr_t *
@@ -266,7 +255,7 @@ new_expr (void)
}
ex_listitem_t *
-new_listitem (expr_t *e)
+new_listitem (const expr_t *e)
{
ex_listitem_t *li;
ALLOC (16384, ex_listitem_t, listitems, li);
@@ -275,7 +264,7 @@ new_listitem (expr_t *e)
}
expr_t *
-list_append_expr (expr_t *list, expr_t *expr)
+list_append_expr (expr_t *list, const expr_t *expr)
{
auto li = new_listitem (expr);
*list->list.tail = li;
@@ -284,7 +273,7 @@ list_append_expr (expr_t *list, expr_t *expr)
}
expr_t *
-list_prepend_expr (expr_t *list, expr_t *expr)
+list_prepend_expr (expr_t *list, const expr_t *expr)
{
auto li = new_listitem (expr);
li->next = list->list.head;
@@ -317,7 +306,7 @@ list_prepend_list (expr_t *list, ex_list_t *prepend)
}
expr_t *
-new_list_expr (expr_t *first)
+new_list_expr (const expr_t *first)
{
auto list = new_expr ();
list->type = ex_list;
@@ -330,7 +319,7 @@ new_list_expr (expr_t *first)
}
int
-list_count (ex_list_t *list)
+list_count (const ex_list_t *list)
{
int count = 0;
for (auto li = list->head; li; li = li->next) {
@@ -340,7 +329,7 @@ list_count (ex_list_t *list)
}
void
-list_scatter (ex_list_t *list, expr_t **exprs)
+list_scatter (const ex_list_t *list, const expr_t **exprs)
{
for (auto li = list->head; li; li = li->next) {
*exprs++ = li->expr;
@@ -348,7 +337,7 @@ list_scatter (ex_list_t *list, expr_t **exprs)
}
void
-list_scatter_rev (ex_list_t *list, expr_t **exprs)
+list_scatter_rev (const ex_list_t *list, const expr_t **exprs)
{
int count = list_count (list);
for (auto li = list->head; li; li = li->next) {
@@ -357,7 +346,7 @@ list_scatter_rev (ex_list_t *list, expr_t **exprs)
}
void
-list_gather (ex_list_t *list, expr_t **exprs, int count)
+list_gather (ex_list_t *list, const expr_t **exprs, int count)
{
if (!list->tail) {
list->tail = &list->head;
@@ -369,209 +358,6 @@ list_gather (ex_list_t *list, expr_t **exprs, int count)
}
}
-expr_t *
-copy_expr (expr_t *e)
-{
- expr_t *n;
- expr_t *t;
-
- if (!e)
- return 0;
- switch (e->type) {
- case ex_error:
- case ex_def:
- case ex_symbol:
- case ex_nil:
- case ex_value:
- // nothing to do here
- n = new_expr ();
- *n = *e;
- n->line = pr.source_line;
- n->file = pr.source_file;
- return n;
- case ex_state:
- return new_state_expr (copy_expr (e->state.frame),
- copy_expr (e->state.think),
- copy_expr (e->state.step));
- case ex_bool:
- n = new_expr ();
- *n = *e;
- n->line = pr.source_line;
- n->file = pr.source_file;
- if (e->boolean.true_list) {
- int count = e->boolean.true_list->size;
- size_t size = field_offset (ex_boollist_t, e[count]);
- n->boolean.true_list = malloc (size);
- while (count--)
- n->boolean.true_list->e[count] =
- copy_expr (e->boolean.true_list->e[count]);
- }
- if (e->boolean.false_list) {
- int count = e->boolean.false_list->size;
- size_t size = field_offset (ex_boollist_t, e[count]);
- n->boolean.false_list = malloc (size);
- while (count--)
- n->boolean.false_list->e[count] =
- copy_expr (e->boolean.false_list->e[count]);
- }
- n->boolean.e = copy_expr (e->boolean.e);
- return n;
- case ex_label:
- /// Create a fresh label
- return new_label_expr ();
- case ex_labelref:
- return new_label_ref (e->labelref.label);
- case ex_block:
- n = new_expr ();
- *n = *e;
- n->line = pr.source_line;
- n->file = pr.source_file;
- n->block.head = 0;
- n->block.tail = &n->block.head;
- n->block.result = 0;
- for (auto t = e->block.head; t; t = t->next) {
- if (t->expr == e->block.result) {
- n->block.result = copy_expr (t->expr);
- append_expr (n, n->block.result);
- } else {
- append_expr (n, copy_expr (t->expr));
- }
- }
- if (e->block.result && !n->block.result)
- internal_error (e, "bogus block result?");
- return n;
- case ex_expr:
- n = new_expr ();
- *n = *e;
- n->line = pr.source_line;
- n->file = pr.source_file;
- n->expr.e1 = copy_expr (e->expr.e1);
- n->expr.e2 = copy_expr (e->expr.e2);
- return n;
- case ex_uexpr:
- n = new_expr ();
- *n = *e;
- n->line = pr.source_line;
- n->file = pr.source_file;
- n->expr.e1 = copy_expr (e->expr.e1);
- return n;
- case ex_temp:
- n = new_expr ();
- *n = *e;
- n->line = pr.source_line;
- n->file = pr.source_file;
- return n;
- case ex_vector:
- n = new_expr ();
- *n = *e;
- n->vector.type = e->vector.type;
- n->vector.list = copy_expr (e->vector.list);
- t = e->vector.list;
- e = n->vector.list;
- while (t->next) {
- e->next = copy_expr (t->next);
- e = e->next;
- t = t->next;
- }
- return n;
- case ex_selector:
- n = new_expr ();
- *n = *e;
- n->selector.sel_ref = copy_expr (e->selector.sel_ref);
- return n;
- case ex_compound:
- n = new_expr ();
- *n = *e;
- for (element_t *i = e->compound.head; i; i = i->next) {
- append_element (n, new_element (i->expr, i->designator));
- }
- return n;
- case ex_memset:
- n = new_expr ();
- *n = *e;
- n->memset.dst = copy_expr (e->memset.dst);
- n->memset.val = copy_expr (e->memset.val);
- n->memset.count = copy_expr (e->memset.count);
- return n;
- case ex_alias:
- n = new_expr ();
- *n = *e;
- n->alias.expr = copy_expr (e->alias.expr);
- n->alias.offset = copy_expr (e->alias.offset);
- return n;
- case ex_address:
- n = new_expr ();
- *n = *e;
- n->address.lvalue = copy_expr (e->address.lvalue);
- n->address.offset = copy_expr (e->address.offset);
- return n;
- case ex_assign:
- n = new_expr ();
- *n = *e;
- n->assign.dst = copy_expr (e->assign.dst);
- n->assign.src = copy_expr (e->assign.src);
- return n;
- case ex_branch:
- n = new_expr ();
- *n = *e;
- n->branch.target = copy_expr (e->branch.target);
- n->branch.index = copy_expr (e->branch.index);
- n->branch.test = copy_expr (e->branch.test);
- n->branch.args = copy_expr (e->branch.args);
- return n;
- case ex_return:
- n = new_expr ();
- *n = *e;
- n->retrn.ret_val = copy_expr (e->retrn.ret_val);
- return n;
- case ex_adjstk:
- n = new_expr ();
- *n = *e;
- return n;
- case ex_with:
- n = new_expr ();
- *n = *e;
- n->with.with = copy_expr (e->with.with);
- return n;
- case ex_args:
- n = new_expr ();
- *n = *e;
- return n;
- case ex_horizontal:
- n = new_expr ();
- *n = *e;
- e->hop.vec = copy_expr (e->hop.vec);
- return n;
- case ex_swizzle:
- n = new_expr ();
- *n = *e;
- e->swizzle.src = copy_expr (e->swizzle.src);
- return n;
- case ex_extend:
- n = new_expr ();
- *n = *e;
- e->extend.src = copy_expr (e->extend.src);
- return n;
- case ex_multivec:
- n = new_expr ();
- *n = *e;
- n->multivec.components = copy_expr (e->multivec.components);
- t = e->multivec.components;
- e = n->multivec.components;
- while (t->next) {
- e->next = copy_expr (t->next);
- e = e->next;
- t = t->next;
- }
- return n;
- case ex_list:
- break;//FIXME
- case ex_count:
- break;
- }
- internal_error (e, "invalid expression");
-}
-
expr_t *
expr_file_line (expr_t *dst, const expr_t *src)
{
@@ -601,7 +387,7 @@ new_error_expr (void)
}
expr_t *
-new_state_expr (expr_t *frame, expr_t *think, expr_t *step)
+new_state_expr (const expr_t *frame, const expr_t *think, const expr_t *step)
{
expr_t *s = new_expr ();
@@ -613,7 +399,7 @@ new_state_expr (expr_t *frame, expr_t *think, expr_t *step)
}
expr_t *
-new_bool_expr (ex_boollist_t *true_list, ex_boollist_t *false_list, expr_t *e)
+new_bool_expr (ex_boollist_t *true_list, ex_boollist_t *false_list, const expr_t *e)
{
expr_t *b = new_expr ();
@@ -635,7 +421,7 @@ new_label_expr (void)
return l;
}
-expr_t *
+const expr_t *
named_label_expr (symbol_t *label)
{
symbol_t *sym;
@@ -662,38 +448,51 @@ named_label_expr (symbol_t *label)
}
expr_t *
-new_label_ref (ex_label_t *label)
+new_label_ref (const ex_label_t *label)
{
expr_t *l = new_expr ();
l->type = ex_labelref;
l->labelref.label = label;
- label->used++;
+ ((ex_label_t *) label)->used++;
return l;
}
expr_t *
-new_block_expr (void)
+new_block_expr (const expr_t *old)
{
expr_t *b = new_expr ();
b->type = ex_block;
b->block.head = 0;
b->block.tail = &b->block.head;
+ if (old) {
+ if (old->type != ex_block) {
+ internal_error (old, "not a block expression");
+ }
+ if ((b->block.head = old->block.head)) {
+ b->block.tail = old->block.tail;
+ }
+ b->block.result = old->block.result;
+ b->block.is_call = old->block.is_call;
+ expr_file_line (b, old);
+ }
b->block.return_addr = __builtin_return_address (0);
return b;
}
expr_t *
-new_binary_expr (int op, expr_t *e1, expr_t *e2)
+new_binary_expr (int op, const expr_t *e1, const expr_t *e2)
{
expr_t *e = new_expr ();
- if (e1->type == ex_error)
- return e1;
- if (e2 && e2->type == ex_error)
- return e2;
+ if (e1->type == ex_error) {
+ internal_error (e1, "error expr in new_binary_expr");
+ }
+ if (e2 && e2->type == ex_error) {
+ internal_error (e2, "error expr in new_binary_expr");
+ }
e->type = ex_expr;
e->expr.op = op;
@@ -708,7 +507,7 @@ build_block_expr (expr_t *list, bool set_result)
if (list->type != ex_list) {
return list;
}
- expr_t *b = new_block_expr ();
+ expr_t *b = new_block_expr (0);
b->block.head = list->list.head;
b->block.tail = list->list.tail;
@@ -720,12 +519,13 @@ build_block_expr (expr_t *list, bool set_result)
}
expr_t *
-new_unary_expr (int op, expr_t *e1)
+new_unary_expr (int op, const expr_t *e1)
{
expr_t *e = new_expr ();
- if (e1 && e1->type == ex_error)
- return e1;
+ if (e1 && e1->type == ex_error) {
+ internal_error (e1, "error expr in new_binary_expr");
+ }
e->type = ex_uexpr;
e->expr.op = op;
@@ -734,12 +534,13 @@ new_unary_expr (int op, expr_t *e1)
}
expr_t *
-new_horizontal_expr (int op, expr_t *vec, type_t *type)
+new_horizontal_expr (int op, const expr_t *vec, type_t *type)
{
- type_t *vec_type = get_type (vec);
- if (!vec_type) {
- return vec;
+ vec = convert_name (vec);
+ if (vec->type == ex_error) {
+ return (expr_t *) vec;
}
+ type_t *vec_type = get_type (vec);
if (!is_math (vec_type) || is_scalar (vec_type)) {
internal_error (vec, "horizontal operand not a vector type");
}
@@ -756,12 +557,13 @@ new_horizontal_expr (int op, expr_t *vec, type_t *type)
}
expr_t *
-new_swizzle_expr (expr_t *src, const char *swizzle)
+new_swizzle_expr (const expr_t *src, const char *swizzle)
{
- type_t *src_type = get_type (src);
- if (!src_type) {
- return src;
+ src = convert_name (src);
+ if (src->type == ex_error) {
+ return (expr_t *) src;
}
+ type_t *src_type = get_type (src);
int src_width = type_width (src_type);
ex_swizzle_t swiz = {};
@@ -823,7 +625,7 @@ new_swizzle_expr (expr_t *src, const char *swizzle)
}
expr_t *
-new_extend_expr (expr_t *src, type_t *type, int ext, bool rev)
+new_extend_expr (const expr_t *src, type_t *type, int ext, bool rev)
{
expr_t *expr = new_expr ();
expr->type = ex_extend;
@@ -878,7 +680,7 @@ new_args_expr (void)
return e;
}
-expr_t *
+const expr_t *
new_value_expr (ex_value_t *value)
{
expr_t *e = new_expr ();
@@ -887,14 +689,14 @@ new_value_expr (ex_value_t *value)
return e;
}
-expr_t *
+const expr_t *
new_zero_expr (type_t *type)
{
pr_type_t zero[type_size (type)] = {};
return new_value_expr (new_type_value (type, zero));
}
-expr_t *
+const expr_t *
new_name_expr (const char *name)
{
expr_t *e = new_expr ();
@@ -908,92 +710,94 @@ new_name_expr (const char *name)
return e;
}
-expr_t *
+const expr_t *
new_string_expr (const char *string_val)
{
return new_value_expr (new_string_val (string_val));
}
-expr_t *
-new_double_expr (double double_val)
+const expr_t *
+new_double_expr (double double_val, bool implicit)
{
- return new_value_expr (new_double_val (double_val));
+ auto d = (expr_t *) new_value_expr (new_double_val (double_val));
+ d->implicit = implicit;
+ return d;
}
-expr_t *
+const expr_t *
new_float_expr (float float_val)
{
return new_value_expr (new_float_val (float_val));
}
-expr_t *
+const expr_t *
new_vector_expr (const float *vector_val)
{
return new_value_expr (new_vector_val (vector_val));
}
-expr_t *
+const expr_t *
new_entity_expr (int entity_val)
{
return new_value_expr (new_entity_val (entity_val));
}
-expr_t *
+const expr_t *
new_field_expr (int field_val, type_t *type, def_t *def)
{
return new_value_expr (new_field_val (field_val, type, def));
}
-expr_t *
+const expr_t *
new_func_expr (int func_val, type_t *type)
{
return new_value_expr (new_func_val (func_val, type));
}
-expr_t *
+const expr_t *
new_pointer_expr (int val, type_t *type, def_t *def)
{
return new_value_expr (new_pointer_val (val, type, def, 0));
}
-expr_t *
+const expr_t *
new_quaternion_expr (const float *quaternion_val)
{
return new_value_expr (new_quaternion_val (quaternion_val));
}
-expr_t *
+const expr_t *
new_int_expr (int int_val)
{
return new_value_expr (new_int_val (int_val));
}
-expr_t *
+const expr_t *
new_uint_expr (unsigned uint_val)
{
return new_value_expr (new_uint_val (uint_val));
}
-expr_t *
+const expr_t *
new_long_expr (pr_long_t long_val)
{
return new_value_expr (new_long_val (long_val));
}
-expr_t *
+const expr_t *
new_ulong_expr (pr_ulong_t ulong_val)
{
return new_value_expr (new_ulong_val (ulong_val));
}
-expr_t *
+const expr_t *
new_short_expr (short short_val)
{
return new_value_expr (new_short_val (short_val));
}
int
-is_constant (expr_t *e)
+is_constant (const expr_t *e)
{
while (e->type == ex_alias) {
e = e->alias.expr;
@@ -1007,7 +811,7 @@ is_constant (expr_t *e)
}
int
-is_variable (expr_t *e)
+is_variable (const expr_t *e)
{
while (e->type == ex_alias) {
e = e->alias.expr;
@@ -1021,15 +825,14 @@ is_variable (expr_t *e)
}
int
-is_selector (expr_t *e)
+is_selector (const expr_t *e)
{
return e->type == ex_selector;
}
-expr_t *
-constant_expr (expr_t *e)
+const expr_t *
+constant_expr (const expr_t *e)
{
- expr_t *new;
symbol_t *sym;
ex_value_t *value;
@@ -1051,20 +854,18 @@ constant_expr (expr_t *e)
} else {
return e;
}
- new = new_value_expr (value);
- new->line = e->line;
- new->file = e->file;
- return new;
+ auto new = new_value_expr (value);
+ return expr_file_line ((expr_t *) new, e);//FIXME cast
}
int
-is_nil (expr_t *e)
+is_nil (const expr_t *e)
{
return e->type == ex_nil;
}
int
-is_string_val (expr_t *e)
+is_string_val (const expr_t *e)
{
if (e->type == ex_nil)
return 1;
@@ -1077,7 +878,7 @@ is_string_val (expr_t *e)
}
const char *
-expr_string (expr_t *e)
+expr_string (const expr_t *e)
{
if (e->type == ex_nil)
return 0;
@@ -1087,7 +888,7 @@ expr_string (expr_t *e)
}
int
-is_float_val (expr_t *e)
+is_float_val (const expr_t *e)
{
if (e->type == ex_nil)
return 1;
@@ -1100,7 +901,7 @@ is_float_val (expr_t *e)
}
double
-expr_double (expr_t *e)
+expr_double (const expr_t *e)
{
if (e->type == ex_nil)
return 0;
@@ -1117,7 +918,7 @@ expr_double (expr_t *e)
}
float
-expr_float (expr_t *e)
+expr_float (const expr_t *e)
{
if (e->type == ex_nil)
return 0;
@@ -1134,7 +935,7 @@ expr_float (expr_t *e)
}
int
-is_vector_val (expr_t *e)
+is_vector_val (const expr_t *e)
{
if (e->type == ex_nil)
return 1;
@@ -1147,7 +948,7 @@ is_vector_val (expr_t *e)
}
const float *
-expr_vector (expr_t *e)
+expr_vector (const expr_t *e)
{
if (e->type == ex_nil)
return vec3_origin;
@@ -1164,7 +965,7 @@ expr_vector (expr_t *e)
}
int
-is_quaternion_val (expr_t *e)
+is_quaternion_val (const expr_t *e)
{
if (e->type == ex_nil)
return 1;
@@ -1177,7 +978,7 @@ is_quaternion_val (expr_t *e)
}
const float *
-expr_quaternion (expr_t *e)
+expr_quaternion (const expr_t *e)
{
if (e->type == ex_nil)
return quat_origin;
@@ -1194,7 +995,7 @@ expr_quaternion (expr_t *e)
}
int
-is_int_val (expr_t *e)
+is_int_val (const expr_t *e)
{
if (e->type == ex_nil) {
return 1;
@@ -1214,7 +1015,7 @@ is_int_val (expr_t *e)
}
int
-expr_int (expr_t *e)
+expr_int (const expr_t *e)
{
if (e->type == ex_nil) {
return 0;
@@ -1243,7 +1044,7 @@ expr_int (expr_t *e)
}
int
-is_uint_val (expr_t *e)
+is_uint_val (const expr_t *e)
{
if (e->type == ex_nil) {
return 1;
@@ -1263,7 +1064,7 @@ is_uint_val (expr_t *e)
}
unsigned
-expr_uint (expr_t *e)
+expr_uint (const expr_t *e)
{
if (e->type == ex_nil) {
return 0;
@@ -1288,7 +1089,7 @@ expr_uint (expr_t *e)
}
int
-is_short_val (expr_t *e)
+is_short_val (const expr_t *e)
{
if (e->type == ex_nil) {
return 1;
@@ -1304,7 +1105,7 @@ is_short_val (expr_t *e)
}
short
-expr_short (expr_t *e)
+expr_short (const expr_t *e)
{
if (e->type == ex_nil) {
return 0;
@@ -1320,7 +1121,7 @@ expr_short (expr_t *e)
}
unsigned short
-expr_ushort (expr_t *e)
+expr_ushort (const expr_t *e)
{
if (e->type == ex_nil) {
return 0;
@@ -1336,7 +1137,7 @@ expr_ushort (expr_t *e)
}
int
-is_integral_val (expr_t *e)
+is_integral_val (const expr_t *e)
{
if (is_constant (e)) {
if (is_int_val (e)) {
@@ -1353,7 +1154,7 @@ is_integral_val (expr_t *e)
}
int
-expr_integral (expr_t *e)
+expr_integral (const expr_t *e)
{
if (is_constant (e)) {
if (is_int_val (e)) {
@@ -1370,7 +1171,7 @@ expr_integral (expr_t *e)
}
int
-is_pointer_val (expr_t *e)
+is_pointer_val (const expr_t *e)
{
if (e->type == ex_value && e->value->lltype == ev_ptr) {
return 1;
@@ -1379,7 +1180,7 @@ is_pointer_val (expr_t *e)
}
int
-is_math_val (expr_t *e)
+is_math_val (const expr_t *e)
{
while (e->type == ex_alias) {
e = e->alias.expr;
@@ -1394,8 +1195,8 @@ is_math_val (expr_t *e)
return 0;
}
-expr_t *
-new_alias_expr (type_t *type, expr_t *expr)
+const expr_t *
+new_alias_expr (type_t *type, const expr_t *expr)
{
if (is_ptr (type) && expr->type == ex_address) {
auto new = new_address_expr (type, expr->address.lvalue,
@@ -1413,7 +1214,7 @@ new_alias_expr (type_t *type, expr_t *expr)
// a noop due to the offset being 0 and thus casting back to the original
// type
if (type == get_type (expr)) {
- return expr;
+ return (expr_t *) expr;
}
expr_t *alias = new_expr ();
@@ -1425,11 +1226,11 @@ new_alias_expr (type_t *type, expr_t *expr)
return edag_add_expr (alias);
}
-expr_t *
-new_offset_alias_expr (type_t *type, expr_t *expr, int offset)
+const expr_t *
+new_offset_alias_expr (type_t *type, const expr_t *expr, int offset)
{
if (expr->type == ex_alias && expr->alias.offset) {
- expr_t *ofs_expr = expr->alias.offset;
+ const expr_t *ofs_expr = expr->alias.offset;
if (!is_constant (ofs_expr)) {
internal_error (ofs_expr, "non-constant offset for alias expr");
}
@@ -1452,7 +1253,8 @@ new_offset_alias_expr (type_t *type, expr_t *expr, int offset)
}
expr_t *
-new_address_expr (type_t *lvtype, expr_t *lvalue, expr_t *offset)
+new_address_expr (const type_t *lvtype, const expr_t *lvalue,
+ const expr_t *offset)
{
expr_t *addr = new_expr ();
addr->type = ex_address;
@@ -1463,7 +1265,7 @@ new_address_expr (type_t *lvtype, expr_t *lvalue, expr_t *offset)
}
expr_t *
-new_assign_expr (expr_t *dst, expr_t *src)
+new_assign_expr (const expr_t *dst, const expr_t *src)
{
expr_t *addr = new_expr ();
addr->type = ex_assign;
@@ -1473,7 +1275,7 @@ new_assign_expr (expr_t *dst, expr_t *src)
}
expr_t *
-new_return_expr (expr_t *ret_val)
+new_return_expr (const expr_t *ret_val)
{
expr_t *retrn = new_expr ();
retrn->type = ex_return;
@@ -1492,7 +1294,7 @@ new_adjstk_expr (int mode, int offset)
}
expr_t *
-new_with_expr (int mode, int reg, expr_t *val)
+new_with_expr (int mode, int reg, const expr_t *val)
{
expr_t *with = new_expr ();
with->type = ex_with;
@@ -1502,7 +1304,7 @@ new_with_expr (int mode, int reg, expr_t *val)
return with;
}
-static expr_t *
+static const expr_t *
param_expr (const char *name, type_t *type)
{
symbol_t *sym;
@@ -1515,20 +1317,20 @@ param_expr (const char *name, type_t *type)
return new_alias_expr (type, sym_expr);
}
-expr_t *
+const expr_t *
new_ret_expr (type_t *type)
{
return param_expr (".return", type);
}
-expr_t *
+const expr_t *
new_param_expr (type_t *type, int num)
{
return param_expr (va (0, ".param_%d", num), type);
}
expr_t *
-new_memset_expr (expr_t *dst, expr_t *val, expr_t *count)
+new_memset_expr (const expr_t *dst, const expr_t *val, const expr_t *count)
{
expr_t *e = new_expr ();
e->type = ex_memset;
@@ -1539,7 +1341,7 @@ new_memset_expr (expr_t *dst, expr_t *val, expr_t *count)
}
expr_t *
-append_expr (expr_t *block, expr_t *e)
+append_expr (expr_t *block, const expr_t *e)
{
if (block->type != ex_block)
internal_error (block, "not a block expression");
@@ -1558,7 +1360,7 @@ append_expr (expr_t *block, expr_t *e)
}
expr_t *
-prepend_expr (expr_t *block, expr_t *e)
+prepend_expr (expr_t *block, const expr_t *e)
{
if (block->type != ex_block)
internal_error (block, "not a block expression");
@@ -1581,7 +1383,7 @@ prepend_expr (expr_t *block, expr_t *e)
}
symbol_t *
-get_name (expr_t *e)
+get_name (const expr_t *e)
{
if (e->type == ex_symbol) {
return e->symbol;
@@ -1590,7 +1392,7 @@ get_name (expr_t *e)
}
symbol_t *
-get_struct_field (const type_t *t1, expr_t *e1, expr_t *e2)
+get_struct_field (const type_t *t1, const expr_t *e1, const expr_t *e2)
{
symtab_t *strct = t1->t.symtab;
symbol_t *sym = get_name (e2);
@@ -1611,13 +1413,12 @@ get_struct_field (const type_t *t1, expr_t *e1, expr_t *e2)
name += 4;
}
error (e2, "'%s' has no member named '%s'", name, sym->name);
- e1->type = ex_error;
}
return field;
}
-expr_t *
-field_expr (expr_t *e1, expr_t *e2)
+const expr_t *
+field_expr (const expr_t *e1, const expr_t *e2)
{
const type_t *t1, *t2;
expr_t *e;
@@ -1655,7 +1456,7 @@ field_expr (expr_t *e1, expr_t *e2)
if (!field)
return e1;
- expr_t *offset = new_short_expr (field->s.offset);
+ const expr_t *offset = new_short_expr (field->s.offset);
e1 = offset_pointer_expr (e1, offset);
e1 = cast_expr (pointer_type (field->type), e1);
return unary_expr ('.', e1);
@@ -1668,7 +1469,7 @@ field_expr (expr_t *e1, expr_t *e2)
ivar = class_find_ivar (class, protected, sym->name);
if (!ivar)
return new_error_expr ();
- expr_t *offset = new_short_expr (ivar->s.offset);
+ const expr_t *offset = new_short_expr (ivar->s.offset);
e1 = offset_pointer_expr (e1, offset);
e1 = cast_expr (pointer_type (ivar->type), e1);
return unary_expr ('.', e1);
@@ -1702,12 +1503,13 @@ field_expr (expr_t *e1, expr_t *e2)
|| e2->value->lltype != ev_field) {
internal_error (e2, "unexpected field exression");
}
- e2->value = new_field_val (e2->value->v.pointer.val + field->s.offset, field->type, e2->value->v.pointer.def);
+ auto fv = new_field_val (e2->value->v.pointer.val + field->s.offset, field->type, e2->value->v.pointer.def);
+ e2 = expr_file_line ((expr_t *) new_value_expr (fv), e2);
// create a new . expression
return field_expr (e1, e2);
} else {
if (e1->type == ex_uexpr && e1->expr.op == '.') {
- expr_t *offset = new_short_expr (field->s.offset);
+ const expr_t *offset = new_short_expr (field->s.offset);
e1 = offset_pointer_expr (e1->expr.e1, offset);
e1 = cast_expr (pointer_type (field->type), e1);
return unary_expr ('.', e1);
@@ -1723,12 +1525,13 @@ field_expr (expr_t *e1, expr_t *e2)
return type_mismatch (e1, e2, '.');
}
-expr_t *
-convert_from_bool (expr_t *e, type_t *type)
+const expr_t *
+convert_from_bool (const expr_t *e, type_t *type)
{
- expr_t *zero;
- expr_t *one;
- expr_t *cond;
+ const expr_t *zero;
+ const expr_t *one;
+
+ expr_t *enum_zero, *enum_one;
if (is_float (type)) {
one = new_float_expr (1);
@@ -1736,27 +1539,29 @@ convert_from_bool (expr_t *e, type_t *type)
} else if (is_int (type)) {
one = new_int_expr (1);
zero = new_int_expr (0);
- } else if (is_enum (type) && enum_as_bool (type, &zero, &one)) {
- // don't need to do anything
+ } else if (is_enum (type) && enum_as_bool (type, &enum_zero, &enum_one)) {
+ zero = enum_zero;
+ one = enum_one;
} else if (is_uint (type)) {
one = new_uint_expr (1);
zero = new_uint_expr (0);
} else {
return error (e, "can't convert from boolean value");
}
- cond = new_expr ();
+ auto cond = new_expr ();
*cond = *e;
cond->next = 0;
- cond = conditional_expr (cond, one, zero);
- return expr_file_line (cond, e);
+ return conditional_expr (cond, one, zero);
}
-expr_t *
-convert_nil (expr_t *e, type_t *t)
+const expr_t *
+convert_nil (const expr_t *e, const type_t *t)
{
- e->nil = t;
- return e;
+ auto nil = expr_file_line (new_expr (), e);
+ nil->type = ex_nil;
+ nil->nil = (type_t *) t;//FIXME cast
+ return nil;
}
int
@@ -1785,7 +1590,7 @@ is_logic (int op)
}
int
-has_function_call (expr_t *e)
+has_function_call (const expr_t *e)
{
switch (e->type) {
case ex_bool:
@@ -1857,7 +1662,7 @@ has_function_call (expr_t *e)
}
int
-is_function_call (expr_t *e)
+is_function_call (const expr_t *e)
{
if (e->type != ex_block || !e->block.is_call) {
return 0;
@@ -1866,8 +1671,8 @@ is_function_call (expr_t *e)
return e->type == ex_branch && e->branch.type == pr_branch_call;
}
-expr_t *
-asx_expr (int op, expr_t *e1, expr_t *e2)
+const expr_t *
+asx_expr (int op, const expr_t *e1, const expr_t *e2)
{
if (e1->type == ex_error)
return e1;
@@ -1875,20 +1680,21 @@ asx_expr (int op, expr_t *e1, expr_t *e2)
return e2;
else {
expr_t *e = new_expr ();
+ auto paren = new_expr ();
*e = *e1;
- e2->paren = 1;
- return assign_expr (e, binary_expr (op, e1, e2));
+ *paren = *e2;
+ paren->paren = 1;
+ return assign_expr (e, binary_expr (op, e1, paren));
}
}
-expr_t *
-unary_expr (int op, expr_t *e)
+const expr_t *
+unary_expr (int op, const expr_t *e)
{
vec3_t v;
quat_t q;
const char *s;
- expr_t *new;
type_t *t;
e = convert_name (e);
@@ -1910,9 +1716,7 @@ unary_expr (int op, expr_t *e)
case ev_ptr:
internal_error (e, "type check failed!");
case ev_double:
- new = new_double_expr (-expr_double (e));
- new->implicit = e->implicit;
- return new;
+ return new_double_expr (-expr_double (e), e->implicit);
case ev_float:
return new_float_expr (-expr_float (e));
case ev_vector:
@@ -1961,7 +1765,7 @@ unary_expr (int op, expr_t *e)
expr_t *n = new_unary_expr (op, e);
n->expr.type = get_type (e);
- return n;
+ return edag_add_expr (n);
}
case ex_block:
if (!e->block.result) {
@@ -1971,7 +1775,7 @@ unary_expr (int op, expr_t *e)
expr_t *n = new_unary_expr (op, e);
n->expr.type = get_type (e);
- return n;
+ return edag_add_expr (n);
}
case ex_branch:
return error (e, "invalid type for unary -");
@@ -1988,21 +1792,21 @@ unary_expr (int op, expr_t *e)
expr_t *n = new_unary_expr (op, e);
n->expr.type = get_type (e);
- return n;
+ return edag_add_expr (n);
}
case ex_def:
{
expr_t *n = new_unary_expr (op, e);
n->expr.type = e->def->type;
- return n;
+ return edag_add_expr (n);
}
case ex_symbol:
{
expr_t *n = new_unary_expr (op, e);
n->expr.type = e->symbol->type;
- return n;
+ return edag_add_expr (n);
}
case ex_multivec:
return algebra_negate (e);
@@ -2184,7 +1988,7 @@ unary_expr (int op, expr_t *e)
case ex_extend:
bitnot_expr:
if (options.code.progsversion == PROG_ID_VERSION) {
- expr_t *n1 = new_int_expr (-1);
+ const expr_t *n1 = new_int_expr (-1);
return binary_expr ('-', n1, e);
} else {
expr_t *n = new_unary_expr (op, e);
@@ -2208,9 +2012,9 @@ bitnot_expr:
case '.':
if (extract_type (e) != ev_ptr)
return error (e, "invalid type for unary .");
- e = new_unary_expr ('.', e);
- e->expr.type = get_type (e->expr.e1)->t.fldptr.type;
- return e;
+ auto new = new_unary_expr ('.', e);
+ new->expr.type = get_type (e)->t.fldptr.type;
+ return expr_file_line (new, e);
case '+':
if (!is_math (get_type (e)))
return error (e, "invalid type for unary +");
@@ -2224,7 +2028,7 @@ bitnot_expr:
}
void
-vararg_integer (expr_t *e)
+vararg_integer (const expr_t *e)
{
if (is_int_val (e) && options.code.progsversion < PROG_VERSION
&& options.warnings.vararg_integer) {
@@ -2232,16 +2036,15 @@ vararg_integer (expr_t *e)
}
}
-expr_t *
-build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
+const expr_t *
+build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *params)
{
int param_count = 0;
- expr_t *assign;
expr_t *call;
expr_t *err = 0;
int arg_count = params ? list_count (¶ms->list) :0;
- expr_t *arguments[arg_count];
+ const expr_t *arguments[arg_count];
if (params) {
list_scatter_rev (¶ms->list, arguments);
}
@@ -2308,9 +2111,9 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
}
if (i < param_count) {
if (e->type == ex_nil)
- convert_nil (e, t = ftype->t.func.param_types[i]);
+ e = convert_nil (e, t = ftype->t.func.param_types[i]);
if (e->type == ex_bool)
- convert_from_bool (e, ftype->t.func.param_types[i]);
+ e = convert_from_bool (e, ftype->t.func.param_types[i]);
if (e->type == ex_error)
return e;
if (!type_assignable (ftype->t.func.param_types[i], t)) {
@@ -2320,9 +2123,9 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
t = ftype->t.func.param_types[i];
} else {
if (e->type == ex_nil)
- convert_nil (e, t = type_nil);
+ e = convert_nil (e, t = type_nil);
if (e->type == ex_bool)
- convert_from_bool (e, get_type (e));
+ e = convert_from_bool (e, get_type (e));
if (is_int_val (e)
&& options.code.progsversion == PROG_ID_VERSION)
e = cast_expr (&type_float, e);
@@ -2353,10 +2156,10 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
if (ftype->t.func.num_params < 0) {
emit_args = !ftype->t.func.no_va_list;
}
- call = expr_file_line (new_block_expr (), fexpr);
+ call = expr_file_line (new_block_expr (0), fexpr);
call->block.is_call = 1;
int arg_expr_count = 0;
- expr_t *arg_exprs[arg_count][2];
+ const expr_t *arg_exprs[arg_count][2];
expr_t *args = new_list_expr (0);
// args is built in reverse order so it matches params
for (int i = 0; i < arg_count; i++) {
@@ -2373,16 +2176,16 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
// expression tree
// That, or always use a temp, since it should get optimized out
if (has_function_call (e)) {
- expr_t *cast = cast_expr (arg_types[i], e);
- expr_t *tmp = new_temp_def_expr (arg_types[i]);
+ auto cast = cast_expr (arg_types[i], e);
+ auto tmp = new_temp_def_expr (arg_types[i]);
tmp = expr_file_line (tmp, e);
list_prepend_expr (args, tmp);
- arg_exprs[arg_expr_count][0] = expr_file_line (cast, e);
+ arg_exprs[arg_expr_count][0] = cast;
arg_exprs[arg_expr_count][1] = tmp;
arg_expr_count++;
} else {
- e = expr_file_line (cast_expr (arg_types[i], e), e);
+ e = cast_expr (arg_types[i], e);
list_prepend_expr (args, e);
}
}
@@ -2391,34 +2194,33 @@ build_function_call (expr_t *fexpr, const type_t *ftype, expr_t *params)
list_prepend_expr (args, new_args_expr ());
}
for (int i = 0; i < arg_expr_count - 1; i++) {
- assign = assign_expr (arg_exprs[i][1], arg_exprs[i][0]);
- append_expr (call, expr_file_line (assign, arg_exprs[i][0]));
+ auto assign = assign_expr (arg_exprs[i][1], arg_exprs[i][0]);
+ //append_expr (call, expr_file_line (assign, arg_exprs[i][0]));
+ append_expr (call, assign);
}
if (arg_expr_count) {
auto e = assign_expr (arg_exprs[arg_expr_count - 1][1],
arg_exprs[arg_expr_count - 1][0]);
- e = expr_file_line (e, arg_exprs[arg_expr_count - 1][0]);
+ //e = expr_file_line (e, arg_exprs[arg_expr_count - 1][0]);
append_expr (call, e);
}
type_t *ret_type = ftype->t.func.type;
- call->block.result = expr_file_line (call_expr (fexpr, args, ret_type),
- fexpr);
+ call->block.result = call_expr (fexpr, args, ret_type);
return call;
}
-expr_t *
-function_expr (expr_t *fexpr, expr_t *params)
+const expr_t *
+function_expr (const expr_t *fexpr, const expr_t *params)
{
type_t *ftype;
- expr_t *tmp_params = 0, **tp = &tmp_params;
- for (auto p = params; p; p = p->next) {
- *tp = convert_name (p);
- tp = &(*tp)->next;
+ if (params) {
+ for (auto p = params->list.head; p; p = p->next) {
+ p->expr = convert_name (p->expr);
+ }
}
- params = tmp_params;
- find_function (fexpr, params);
+ fexpr = find_function (fexpr, params);
fexpr = convert_name (fexpr);
ftype = get_type (fexpr);
@@ -2446,8 +2248,8 @@ function_expr (expr_t *fexpr, expr_t *params)
return build_function_call (fexpr, ftype, params);
}
-expr_t *
-branch_expr (int op, expr_t *test, expr_t *label)
+const expr_t *
+branch_expr (int op, const expr_t *test, const expr_t *label)
{
// need to translate op due to precedence rules dictating the layout
// of the token ids
@@ -2466,7 +2268,7 @@ branch_expr (int op, expr_t *test, expr_t *label)
internal_error (label, "not a label");
}
if (label) {
- label->label.used++;
+ ((expr_t *) label)->label.used++;
}
expr_t *branch = new_expr ();
branch->type = ex_branch;
@@ -2476,14 +2278,14 @@ branch_expr (int op, expr_t *test, expr_t *label)
return branch;
}
-expr_t *
-goto_expr (expr_t *label)
+const expr_t *
+goto_expr (const expr_t *label)
{
if (label && label->type != ex_label) {
internal_error (label, "not a label");
}
if (label) {
- label->label.used++;
+ ((expr_t *) label)->label.used++;//FIXME cast
}
expr_t *branch = new_expr ();
branch->type = ex_branch;
@@ -2492,8 +2294,8 @@ goto_expr (expr_t *label)
return branch;
}
-expr_t *
-jump_table_expr (expr_t *table, expr_t *index)
+const expr_t *
+jump_table_expr (const expr_t *table, const expr_t *index)
{
expr_t *branch = new_expr ();
branch->type = ex_branch;
@@ -2503,8 +2305,8 @@ jump_table_expr (expr_t *table, expr_t *index)
return branch;
}
-expr_t *
-call_expr (expr_t *func, expr_t *args, type_t *ret_type)
+const expr_t *
+call_expr (const expr_t *func, const expr_t *args, type_t *ret_type)
{
expr_t *branch = new_expr ();
branch->type = ex_branch;
@@ -2515,8 +2317,8 @@ call_expr (expr_t *func, expr_t *args, type_t *ret_type)
return branch;
}
-expr_t *
-return_expr (function_t *f, expr_t *e)
+const expr_t *
+return_expr (function_t *f, const expr_t *e)
{
const type_t *t;
const type_t *ret_type = unalias_type (f->type->t.func.type);
@@ -2566,7 +2368,7 @@ return_expr (function_t *f, expr_t *e)
if (is_void(t)) {
if (e->type == ex_nil) {
t = ret_type;
- convert_nil (e, (type_t *) t);//FIXME cast
+ e = convert_nil (e, t);
} else {
if (!options.traditional)
return error (e, "void value not ignored as it ought to be");
@@ -2593,13 +2395,13 @@ return_expr (function_t *f, expr_t *e)
e = assign_expr (new_temp_def_expr (t), e);
}
if (e->type == ex_block) {
- e->block.result->rvalue = 1;
+ ((expr_t *) e->block.result)->rvalue = 1;//FIXME
}
return new_return_expr (e);
}
-expr_t *
-at_return_expr (function_t *f, expr_t *e)
+const expr_t *
+at_return_expr (function_t *f, const expr_t *e)
{
const type_t *ret_type = unalias_type (f->type->t.func.type);
@@ -2612,7 +2414,7 @@ at_return_expr (function_t *f, expr_t *e)
} else if (!is_function_call (e)) {
return error (e, "@return value not a function");
}
- expr_t *call_expr = e->block.result->branch.target;
+ const expr_t *call_expr = e->block.result->branch.target;
const type_t *call_type = get_type (call_expr);
if (!is_func (call_type) && !call_type->t.func.void_return) {
return error (e, "@return function not void_return");
@@ -2622,16 +2424,9 @@ at_return_expr (function_t *f, expr_t *e)
return ret_expr;
}
-expr_t *
-conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2)
+const expr_t *
+conditional_expr (const expr_t *cond, const expr_t *e1, const expr_t *e2)
{
- expr_t *block = new_block_expr ();
- type_t *type1 = get_type (e1);
- type_t *type2 = get_type (e2);
- expr_t *tlabel = new_label_expr ();
- expr_t *flabel = new_label_expr ();
- expr_t *elabel = new_label_expr ();
-
if (cond->type == ex_error)
return cond;
if (e1->type == ex_error)
@@ -2639,16 +2434,23 @@ conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2)
if (e2->type == ex_error)
return e2;
- cond = convert_bool (cond, 1);
- if (cond->type == ex_error)
- return cond;
+ expr_t *c = (expr_t *) convert_bool (cond, 1);
+ if (c->type == ex_error)
+ return c;
- backpatch (cond->boolean.true_list, tlabel);
- backpatch (cond->boolean.false_list, flabel);
+ expr_t *block = expr_file_line (new_block_expr (0), cond);
+ type_t *type1 = get_type (e1);
+ type_t *type2 = get_type (e2);
+ expr_t *tlabel = expr_file_line (new_label_expr (), cond);
+ expr_t *flabel = expr_file_line (new_label_expr (), cond);
+ expr_t *elabel = expr_file_line (new_label_expr (), cond);
+
+ backpatch (c->boolean.true_list, tlabel);
+ backpatch (c->boolean.false_list, flabel);
block->block.result = (type1 == type2) ? new_temp_def_expr (type1) : 0;
- append_expr (block, cond);
- append_expr (cond->boolean.e, flabel);
+ append_expr (block, c);
+ append_expr ((expr_t *) c->boolean.e, flabel);//FIXME cast
if (block->block.result)
append_expr (block, assign_expr (block->block.result, e2));
else
@@ -2663,20 +2465,17 @@ conditional_expr (expr_t *cond, expr_t *e1, expr_t *e2)
return block;
}
-expr_t *
-incop_expr (int op, expr_t *e, int postop)
+const expr_t *
+incop_expr (int op, const expr_t *e, int postop)
{
- expr_t *one;
-
if (e->type == ex_error)
return e;
- one = new_int_expr (1); // int constants get auto-cast to float
+ auto one = new_int_expr (1); // int constants get auto-cast to float
if (postop) {
expr_t *t1, *t2;
type_t *type = get_type (e);
- expr_t *block = new_block_expr ();
- expr_t *res = new_expr ();
+ expr_t *block = new_block_expr (0);
if (e->type == ex_error) // get_type failed
return e;
@@ -2684,10 +2483,9 @@ incop_expr (int op, expr_t *e, int postop)
t2 = new_temp_def_expr (type);
append_expr (block, assign_expr (t1, e));
append_expr (block, assign_expr (t2, binary_expr (op, t1, one)));
- res = copy_expr (e);
- if (res->type == ex_uexpr && res->expr.op == '.')
- res = deref_pointer_expr (address_expr (res, 0));
- append_expr (block, assign_expr (res, t2));
+ if (e->type == ex_uexpr && e->expr.op == '.')
+ e = deref_pointer_expr (address_expr (e, 0));
+ append_expr (block, assign_expr (e, t2));
block->block.result = t1;
return block;
} else {
@@ -2695,8 +2493,8 @@ incop_expr (int op, expr_t *e, int postop)
}
}
-expr_t *
-array_expr (expr_t *array, expr_t *index)
+const expr_t *
+array_expr (const expr_t *array, const expr_t *index)
{
array = convert_name (array);
index = convert_name (index);
@@ -2704,11 +2502,8 @@ array_expr (expr_t *array, expr_t *index)
type_t *array_type = get_type (array);
type_t *index_type = get_type (index);
type_t *ele_type;
- expr_t *scale;
- expr_t *offset;
- expr_t *base;
- expr_t *ptr;
- expr_t *e;
+ const expr_t *base;
+ const expr_t *ptr;
int ind = 0;
if (array->type == ex_error)
@@ -2746,15 +2541,15 @@ array_expr (expr_t *array, expr_t *index)
} else {
ele_type = ev_types[array_type->type];
if (array->type == ex_uexpr && array->expr.op == '.') {
- expr_t *vec = offset_pointer_expr (array->expr.e1, index);
+ auto vec = offset_pointer_expr (array->expr.e1, index);
vec = cast_expr (pointer_type (ele_type), vec);
return unary_expr ('.', vec);
}
base = new_int_expr (0);
}
- scale = new_int_expr (type_size (ele_type));
+ auto scale = new_int_expr (type_size (ele_type));
+ auto offset = binary_expr ('*', base, scale);
index = binary_expr ('*', index, scale);
- offset = binary_expr ('*', base, scale);
index = binary_expr ('-', index, offset);
if (is_short_val (index))
ind = expr_short (index);
@@ -2764,11 +2559,11 @@ array_expr (expr_t *array, expr_t *index)
if (array->type == ex_uexpr && array->expr.op == '.') {
ptr = array->expr.e1;
} else {
- expr_t *alias = new_offset_alias_expr (ele_type, array, 0);
+ auto alias = new_offset_alias_expr (ele_type, array, 0);
ptr = new_address_expr (ele_type, alias, 0);
}
} else if (is_nonscalar (array_type)) {
- expr_t *alias = new_offset_alias_expr (ele_type, array, 0);
+ auto alias = new_offset_alias_expr (ele_type, array, 0);
ptr = new_address_expr (ele_type, alias, 0);
} else {
ptr = array;
@@ -2776,12 +2571,12 @@ array_expr (expr_t *array, expr_t *index)
ptr = offset_pointer_expr (ptr, index);
ptr = cast_expr (pointer_type (ele_type), ptr);
- e = unary_expr ('.', ptr);
+ auto e = unary_expr ('.', ptr);
return e;
}
-expr_t *
-deref_pointer_expr (expr_t *pointer)
+const expr_t *
+deref_pointer_expr (const expr_t *pointer)
{
type_t *pointer_type = get_type (pointer);
@@ -2792,8 +2587,8 @@ deref_pointer_expr (expr_t *pointer)
return unary_expr ('.', pointer);
}
-expr_t *
-offset_pointer_expr (expr_t *pointer, expr_t *offset)
+const expr_t *
+offset_pointer_expr (const expr_t *pointer, const expr_t *offset)
{
type_t *ptr_type = get_type (pointer);
if (!is_ptr (ptr_type)) {
@@ -2802,7 +2597,7 @@ offset_pointer_expr (expr_t *pointer, expr_t *offset)
if (!is_integral (get_type (offset))) {
internal_error (offset, "pointer offset is not an integer type");
}
- expr_t *ptr;
+ const expr_t *ptr;
if (pointer->type == ex_alias && !pointer->alias.offset
&& is_integral (get_type (pointer->alias.expr))) {
ptr = pointer->alias.expr;
@@ -2810,8 +2605,9 @@ offset_pointer_expr (expr_t *pointer, expr_t *offset)
if (pointer->address.offset) {
offset = binary_expr ('+', pointer->address.offset, offset);
}
- pointer->address.offset = offset;
- return pointer;
+ ptr = new_address_expr (ptr_type->t.fldptr.type,
+ pointer->address.lvalue, offset);
+ return ptr;
} else {
ptr = cast_expr (&type_int, pointer);
}
@@ -2819,8 +2615,8 @@ offset_pointer_expr (expr_t *pointer, expr_t *offset)
return cast_expr (ptr_type, ptr);
}
-expr_t *
-address_expr (expr_t *e1, type_t *t)
+const expr_t *
+address_expr (const expr_t *e1, type_t *t)
{
expr_t *e;
@@ -2844,13 +2640,10 @@ address_expr (expr_t *e1, type_t *t)
return e;
}
if (is_array (type)) {
- e = e1;
- e->type = ex_value;
- e->value = new_pointer_val (0, t, def, 0);
+ auto ptrval = new_pointer_val (0, t, def, 0);
+ return new_value_expr (ptrval);
} else {
- e = new_pointer_expr (0, t, def);
- e->line = e1->line;
- e->file = e1->file;
+ return new_pointer_expr (0, t, def);
}
}
break;
@@ -2862,18 +2655,14 @@ address_expr (expr_t *e1, type_t *t)
//FIXME this test should be in statements.c
if (options.code.progsversion == PROG_VERSION
&& (def->local || def->param)) {
- e = new_address_expr (t, e1, 0);
- return e;
+ return new_address_expr (t, e1, 0);
}
if (is_array (type)) {
- e = e1;
- e->type = ex_value;
- e->value = new_pointer_val (0, t, def, 0);
+ auto ptrval = new_pointer_val (0, t, def, 0);
+ return new_value_expr (ptrval);
} else {
- e = new_pointer_expr (0, t, def);
- e->line = e1->line;
- e->file = e1->file;
+ return new_pointer_expr (0, t, def);
}
break;
}
@@ -2887,11 +2676,11 @@ address_expr (expr_t *e1, type_t *t)
return error (e1, "invalid type for unary &");
case ex_uexpr:
if (e1->expr.op == '.') {
- e = e1->expr.e1;
- if (e->type == ex_expr && e->expr.op == '.') {
- e = new_address_expr (e->expr.type, e->expr.e1, e->expr.e2);
+ auto p = e1->expr.e1;
+ if (p->type == ex_expr && p->expr.op == '.') {
+ p = new_address_expr (p->expr.type, p->expr.e1, p->expr.e2);
}
- break;
+ return p;
}
return error (e1, "invalid type for unary &");
case ex_label:
@@ -2910,8 +2699,8 @@ address_expr (expr_t *e1, type_t *t)
return e;
}
-expr_t *
-build_if_statement (int not, expr_t *test, expr_t *s1, expr_t *els, expr_t *s2)
+const expr_t *
+build_if_statement (int not, const expr_t *test, const expr_t *s1, const expr_t *els, const expr_t *s2)
{
int line = pr.source_line;
pr_string_t file = pr.source_file;
@@ -2930,7 +2719,7 @@ build_if_statement (int not, expr_t *test, expr_t *s1, expr_t *els, expr_t *s2)
pr.source_line = test->line;
pr.source_file = test->file;
- if_expr = new_block_expr ();
+ if_expr = new_block_expr (0);
test = convert_bool (test, 1);
if (test->type != ex_error) {
@@ -2941,7 +2730,7 @@ build_if_statement (int not, expr_t *test, expr_t *s1, expr_t *els, expr_t *s2)
backpatch (test->boolean.true_list, tl);
backpatch (test->boolean.false_list, fl);
}
- append_expr (test->boolean.e, tl);
+ append_expr ((expr_t *) test->boolean.e, tl);//FIXME cast
append_expr (if_expr, test);
}
append_expr (if_expr, s1);
@@ -2968,20 +2757,20 @@ build_if_statement (int not, expr_t *test, expr_t *s1, expr_t *els, expr_t *s2)
return if_expr;
}
-expr_t *
-build_while_statement (int not, expr_t *test, expr_t *statement,
- expr_t *break_label, expr_t *continue_label)
+const expr_t *
+build_while_statement (int not, const expr_t *test, const expr_t *statement,
+ const expr_t *break_label, const expr_t *continue_label)
{
int line = pr.source_line;
pr_string_t file = pr.source_file;
- expr_t *l1 = new_label_expr ();
- expr_t *l2 = break_label;
+ const expr_t *l1 = new_label_expr ();
+ const expr_t *l2 = break_label;
expr_t *while_expr;
pr.source_line = test->line;
pr.source_file = test->file;
- while_expr = new_block_expr ();
+ while_expr = new_block_expr (0);
append_expr (while_expr, goto_expr (continue_label));
append_expr (while_expr, l1);
@@ -2997,7 +2786,7 @@ build_while_statement (int not, expr_t *test, expr_t *statement,
backpatch (test->boolean.true_list, l1);
backpatch (test->boolean.false_list, l2);
}
- append_expr (test->boolean.e, l2);
+ append_expr ((expr_t *) test->boolean.e, l2);//FIXME cast
append_expr (while_expr, test);
}
@@ -3007,9 +2796,10 @@ build_while_statement (int not, expr_t *test, expr_t *statement,
return while_expr;
}
-expr_t *
-build_do_while_statement (expr_t *statement, int not, expr_t *test,
- expr_t *break_label, expr_t *continue_label)
+const expr_t *
+build_do_while_statement (const expr_t *statement, int not, const expr_t *test,
+ const expr_t *break_label,
+ const expr_t *continue_label)
{
expr_t *l1 = new_label_expr ();
int line = pr.source_line;
@@ -3024,7 +2814,7 @@ build_do_while_statement (expr_t *statement, int not, expr_t *test,
pr.source_line = test->line;
pr.source_file = test->file;
- do_while_expr = new_block_expr ();
+ do_while_expr = new_block_expr (0);
append_expr (do_while_expr, l1);
append_expr (do_while_expr, statement);
@@ -3039,7 +2829,7 @@ build_do_while_statement (expr_t *statement, int not, expr_t *test,
backpatch (test->boolean.true_list, l1);
backpatch (test->boolean.false_list, break_label);
}
- append_expr (test->boolean.e, break_label);
+ append_expr ((expr_t *) test->boolean.e, break_label);//FIXME
append_expr (do_while_expr, test);
}
@@ -3049,15 +2839,15 @@ build_do_while_statement (expr_t *statement, int not, expr_t *test,
return do_while_expr;
}
-expr_t *
-build_for_statement (expr_t *init, expr_t *test, expr_t *next,
- expr_t *statement,
- expr_t *break_label, expr_t *continue_label)
+const expr_t *
+build_for_statement (const expr_t *init, const expr_t *test, const expr_t *next,
+ const expr_t *statement, const expr_t *break_label,
+ const expr_t *continue_label)
{
expr_t *tl = new_label_expr ();
- expr_t *fl = break_label;
+ const expr_t *fl = break_label;
expr_t *l1 = 0;
- expr_t *t;
+ const expr_t *t;
int line = pr.source_line;
pr_string_t file = pr.source_file;
expr_t *for_expr;
@@ -3073,7 +2863,7 @@ build_for_statement (expr_t *init, expr_t *test, expr_t *next,
pr.source_line = t->line;
pr.source_file = t->file;
- for_expr = new_block_expr ();
+ for_expr = new_block_expr (0);
append_expr (for_expr, init);
if (test) {
@@ -3090,7 +2880,7 @@ build_for_statement (expr_t *init, expr_t *test, expr_t *next,
if (test->type != ex_error) {
backpatch (test->boolean.true_list, tl);
backpatch (test->boolean.false_list, fl);
- append_expr (test->boolean.e, fl);
+ append_expr ((expr_t *) test->boolean.e, fl);//FIXME cast
append_expr (for_expr, test);
}
} else {
@@ -3104,8 +2894,8 @@ build_for_statement (expr_t *init, expr_t *test, expr_t *next,
return for_expr;
}
-expr_t *
-build_state_expr (expr_t *e)
+const expr_t *
+build_state_expr (const expr_t *e)
{
int count = e ? list_count (&e->list) : 0;
if (count < 2) {
@@ -3114,11 +2904,11 @@ build_state_expr (expr_t *e)
if (count > 3) {
return error (e, "too many state arguments");
}
- expr_t *state_args[3] = {};
+ const expr_t *state_args[3] = {};
list_scatter (&e->list, state_args);
- expr_t *frame = state_args[0];
- expr_t *think = state_args[1];
- expr_t *step = state_args[2];
+ const expr_t *frame = state_args[0];
+ const expr_t *think = state_args[1];
+ const expr_t *step = state_args[2];
if (think->type == ex_symbol)
think = think_expr (think->symbol);
@@ -3137,7 +2927,7 @@ build_state_expr (expr_t *e)
return new_state_expr (frame, think, step);
}
-expr_t *
+const expr_t *
think_expr (symbol_t *think_sym)
{
symbol_t *sym;
@@ -3158,20 +2948,19 @@ think_expr (symbol_t *think_sym)
return new_symbol_expr (think_sym);
}
-expr_t *
+const expr_t *
encode_expr (type_t *type)
{
dstring_t *encoding = dstring_newstr ();
- expr_t *e;
encode_type (encoding, type);
- e = new_string_expr (encoding->str);
+ auto e = new_string_expr (encoding->str);
free (encoding);
return e;
}
-expr_t *
-sizeof_expr (expr_t *expr, struct type_s *type)
+const expr_t *
+sizeof_expr (const expr_t *expr, struct type_s *type)
{
if (!((!expr) ^ (!type)))
internal_error (0, 0);
diff --git a/tools/qfcc/source/expr_algebra.c b/tools/qfcc/source/expr_algebra.c
index 4ee35a349..b8fdb8b38 100644
--- a/tools/qfcc/source/expr_algebra.c
+++ b/tools/qfcc/source/expr_algebra.c
@@ -86,8 +86,22 @@ anti_com (const expr_t *e)
return e && e->type == ex_expr && e->expr.anticommute;
}
-static expr_t *
-neg_expr (expr_t *e)
+static const expr_t *
+typed_binary_expr (type_t *type, int op, const expr_t *e1, const expr_t *e2)
+{
+ auto e = new_binary_expr (op, e1, e2);
+ e->expr.type = type;
+ if (op == '+' || op == '*' || op == HADAMARD || op == DOT) {
+ e->expr.commutative = true;
+ }
+ if (op == '-' || op == CROSS || op == WEDGE) {
+ e->expr.anticommute = true;
+ }
+ return e;
+}
+
+static const expr_t *
+neg_expr (const expr_t *e)
{
if (!e) {
// propagated zero
@@ -97,17 +111,18 @@ neg_expr (expr_t *e)
return e->expr.e1;
}
auto type = get_type (e);
+ expr_t *neg;
if (anti_com (e)) {
- e = new_binary_expr (e->expr.op, e->expr.e2, e->expr.e1);
+ neg = new_binary_expr (e->expr.op, e->expr.e2, e->expr.e1);
} else {
- e = new_unary_expr ('-', e);
+ neg = new_unary_expr ('-', e);
}
- e->expr.type = type;
- return edag_add_expr (fold_constants (e));
+ neg->expr.type = type;
+ return edag_add_expr (fold_constants (neg));
}
-static expr_t *
-ext_expr (expr_t *src, type_t *type, int extend, bool reverse)
+static const expr_t *
+ext_expr (const expr_t *src, type_t *type, int extend, bool reverse)
{
if (!src) {
return 0;
@@ -119,13 +134,13 @@ ext_expr (expr_t *src, type_t *type, int extend, bool reverse)
}
auto ext = edag_add_expr (new_extend_expr (src, type, extend, reverse));
if (neg) {
- ext = neg_expr (ext);
+ return neg_expr (ext);
}
return ext;
}
-static expr_t *
-alias_expr (type_t *type, expr_t *e, int offset)
+static const expr_t *
+alias_expr (type_t *type, const expr_t *e, int offset)
{
if (type == get_type (e)) {
if (offset) {
@@ -146,8 +161,8 @@ alias_expr (type_t *type, expr_t *e, int offset)
return edag_add_expr (e);
}
-static expr_t *
-offset_cast (type_t *type, expr_t *expr, int offset)
+static const expr_t *
+offset_cast (type_t *type, const expr_t *expr, int offset)
{
if (type->meta != ty_basic) {
internal_error (expr, "offset cast to non-basic type");
@@ -166,8 +181,7 @@ offset_cast (type_t *type, expr_t *expr, int offset)
if (!e2) {
return e1;
}
- auto cast = new_binary_expr (op, e1, e2);
- cast->expr.type = type;
+ auto cast = typed_binary_expr (type, op, e1, e2);
return edag_add_expr (cast);
}
if (expr->type == ex_extend) {
@@ -215,7 +229,7 @@ get_mvec_sym (type_t *type)
}
static bool
-check_types (expr_t **e, algebra_t *algebra)
+check_types (const expr_t **e, algebra_t *algebra)
{
auto layout = &algebra->layout;
for (int i = 0; i < layout->count; i++) {
@@ -230,8 +244,8 @@ check_types (expr_t **e, algebra_t *algebra)
return true;
}
-static expr_t *
-promote_scalar (type_t *dst_type, expr_t *scalar)
+static const expr_t *
+promote_scalar (type_t *dst_type, const expr_t *scalar)
{
auto scalar_type = get_type (scalar);
if (scalar_type != dst_type) {
@@ -245,8 +259,8 @@ promote_scalar (type_t *dst_type, expr_t *scalar)
return edag_add_expr (scalar);
}
-static expr_t *
-mvec_expr (expr_t *expr, algebra_t *algebra)
+static const expr_t *
+mvec_expr (const expr_t *expr, algebra_t *algebra)
{
auto mvtype = get_type (expr);
expr = edag_add_expr (expr);
@@ -274,18 +288,20 @@ mvec_expr (expr_t *expr, algebra_t *algebra)
.type = algebra_mvec_type (algebra, group_mask),
.algebra = algebra,
};
- expr_t **c = &mvec->multivec.components;
+ expr_t *components = 0;
+ expr_t **c = &components;
for (auto sym = get_mvec_sym (mvtype); sym; sym = sym->next) {
- *c = new_offset_alias_expr (sym->type, expr, sym->s.offset);
+ *c = (expr_t *) new_offset_alias_expr (sym->type, expr, sym->s.offset);
c = &(*c)->next;
mvec->multivec.count++;
}
+ mvec->multivec.components = components;
return mvec;
}
static void
-mvec_scatter (expr_t **components, expr_t *mvec, algebra_t *algebra)
+mvec_scatter (const expr_t **components, const expr_t *mvec, algebra_t *algebra)
{
auto layout = &algebra->layout;
int group;
@@ -325,29 +341,29 @@ mvec_scatter (expr_t **components, expr_t *mvec, algebra_t *algebra)
}
}
-static expr_t *
-mvec_gather (expr_t **components, algebra_t *algebra)
+static const expr_t *
+mvec_gather (const expr_t **components, algebra_t *algebra)
{
auto layout = &algebra->layout;
pr_uint_t group_mask = 0;
int count = 0;
- expr_t *mvec = 0;
+ const expr_t *vec = 0;
for (int i = 0; i < layout->count; i++) {
if (components[i]) {
count++;
- mvec = components[i];
+ vec = components[i];
group_mask |= 1 << i;
}
}
if (count == 1) {
- return mvec;
+ return vec;
}
if (!count) {
return new_zero_expr (algebra->type);
}
- mvec = new_expr ();
+ auto mvec = new_expr ();
mvec->type = ex_multivec;
mvec->multivec = (ex_multivec_t) {
.type = algebra_mvec_type (algebra, group_mask),
@@ -355,7 +371,7 @@ mvec_gather (expr_t **components, algebra_t *algebra)
};
for (int i = layout->count; i-- > 0; ) {
if (components[i]) {
- components[i]->next = mvec->multivec.components;
+ ((expr_t *) components[i])->next = (expr_t *) mvec->multivec.components;//FIXME
mvec->multivec.components = components[i];
mvec->multivec.count++;
}
@@ -371,15 +387,15 @@ ext_compat (const expr_t *a, const expr_t *b)
&& a->extend.type == b->extend.type);
}
-static expr_t *
+static const expr_t *
extract_extended_neg (const expr_t *expr)
{
auto e = expr->extend;
return neg_expr (ext_expr (neg_expr (e.src), e.type, e.extend, e.reverse));
}
#endif
-static __attribute__((pure)) expr_t *
-traverse_scale (expr_t *expr)
+static const expr_t * __attribute__((pure))
+traverse_scale (const expr_t *expr)
{
while (expr && expr->type == ex_expr && expr->expr.op == SCALE) {
expr = expr->expr.e1;
@@ -419,9 +435,9 @@ is_cross (const expr_t *expr)
}
static void
-distribute_terms_core (expr_t *sum,
- expr_t **adds, int *addind,
- expr_t **subs, int *subind, bool negative)
+distribute_terms_core (const expr_t *sum,
+ const expr_t **adds, int *addind,
+ const expr_t **subs, int *subind, bool negative)
{
bool subtract = (sum->expr.op == '-') ^ negative;
auto e1 = sum->expr.e1;
@@ -452,8 +468,8 @@ distribute_terms_core (expr_t *sum,
}
}
-static expr_t *
-sum_expr_low (type_t *type, int op, expr_t *a, expr_t *b)
+static const expr_t *
+sum_expr_low (type_t *type, int op, const expr_t *a, const expr_t *b)
{
if (!a) {
return op == '-' ? neg_expr (b) : b;
@@ -465,16 +481,13 @@ sum_expr_low (type_t *type, int op, expr_t *a, expr_t *b)
return 0;
}
- auto sum = new_binary_expr (op, a, b);
- sum->expr.type = type;
- sum->expr.commutative = op == '+';
- sum->expr.anticommute = op == '-';
+ auto sum = typed_binary_expr (type, op, a, b);
sum = edag_add_expr (sum);
return sum;
}
static void
-distribute_terms (expr_t *sum, expr_t **adds, expr_t **subs)
+distribute_terms (const expr_t *sum, const expr_t **adds, const expr_t **subs)
{
int addind = 0;
int subind = 0;
@@ -485,11 +498,11 @@ distribute_terms (expr_t *sum, expr_t **adds, expr_t **subs)
distribute_terms_core (sum, adds, &addind, subs, &subind, false);
}
-static expr_t *
-collect_terms (type_t *type, expr_t **adds, expr_t **subs)
+static const expr_t *
+collect_terms (type_t *type, const expr_t **adds, const expr_t **subs)
{
- expr_t *a = 0;
- expr_t *b = 0;
+ const expr_t *a = 0;
+ const expr_t *b = 0;
for (auto s = adds; *s; s++) {
a = sum_expr_low (type, '+', a, *s);
}
@@ -500,8 +513,8 @@ collect_terms (type_t *type, expr_t **adds, expr_t **subs)
return sum;
}
-static expr_t *
-sum_expr (type_t *type, expr_t *a, expr_t *b)
+static const expr_t *
+sum_expr (type_t *type, const expr_t *a, const expr_t *b)
{
if (!a) {
return b;
@@ -510,13 +523,13 @@ sum_expr (type_t *type, expr_t *a, expr_t *b)
return a;
}
- auto sum = new_binary_expr ('+', a, b);
+ auto sum = typed_binary_expr (type, '+', a, b);
int num_terms = count_terms (sum);
- expr_t *adds[num_terms + 1] = {};
- expr_t *subs[num_terms + 1] = {};
+ const expr_t *adds[num_terms + 1] = {};
+ const expr_t *subs[num_terms + 1] = {};
distribute_terms (sum, adds, subs);
- expr_t **dstadd, **srcadd;
- expr_t **dstsub, **srcsub;
+ const expr_t **dstadd, **srcadd;
+ const expr_t **dstsub, **srcsub;
for (dstadd = adds, srcadd = adds; *srcadd; srcadd++) {
for (dstsub = subs, srcsub = subs; *srcsub; srcsub++) {
@@ -541,7 +554,7 @@ sum_expr (type_t *type, expr_t *a, expr_t *b)
}
static void
-component_sum (int op, expr_t **c, expr_t **a, expr_t **b,
+component_sum (int op, const expr_t **c, const expr_t **a, const expr_t **b,
algebra_t *algebra)
{
auto layout = &algebra->layout;
@@ -574,8 +587,8 @@ component_sum (int op, expr_t **c, expr_t **a, expr_t **b,
}
}
-static expr_t *
-scale_expr (type_t *type, expr_t *a, expr_t *b)
+static const expr_t *
+scale_expr (type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@@ -599,8 +612,7 @@ scale_expr (type_t *type, expr_t *a, expr_t *b)
b = neg_expr (b);
}
- auto scale = new_binary_expr (op, a, b);
- scale->expr.type = type;
+ auto scale = typed_binary_expr (type, op, a, b);
scale = fold_constants (scale);
scale = edag_add_expr (scale);
if (neg) {
@@ -613,16 +625,16 @@ scale_expr (type_t *type, expr_t *a, expr_t *b)
return scale;
}
-static expr_t *
-check_dot (expr_t *a, expr_t *b, int b_count)
+static const expr_t *
+check_dot (const expr_t *a, const expr_t *b, int b_count)
{
- expr_t *b_adds[b_count + 1] = {};
- expr_t *b_subs[b_count + 1] = {};
+ const expr_t *b_adds[b_count + 1] = {};
+ const expr_t *b_subs[b_count + 1] = {};
a = traverse_scale (a);
distribute_terms (b, b_adds, b_subs);
- expr_t **s, **d;
+ const expr_t **s, **d;
for (s = b_adds, d = s; *s; s++) {
auto c = traverse_scale (*s);
if (is_cross (c)) {
@@ -648,8 +660,8 @@ check_dot (expr_t *a, expr_t *b, int b_count)
return collect_terms (get_type (b), b_adds, b_subs);
}
-static expr_t *
-dot_expr (type_t *type, expr_t *a, expr_t *b)
+static const expr_t *
+dot_expr (type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@@ -674,27 +686,25 @@ dot_expr (type_t *type, expr_t *a, expr_t *b)
b = check_dot (a, b, b_terms);
}
- auto dot = new_binary_expr (DOT, a, b);
- dot->expr.type = type;
+ auto dot = typed_binary_expr (type, DOT, a, b);
dot = edag_add_expr (dot);
if (neg) {
dot = neg_expr (dot);
- dot->expr.type = type;
dot = edag_add_expr (dot);
}
return dot;
}
-static expr_t *
-check_cross (expr_t *a, expr_t *b, int b_count)
+static const expr_t *
+check_cross (const expr_t *a, const expr_t *b, int b_count)
{
- expr_t *b_adds[b_count + 1] = {};
- expr_t *b_subs[b_count + 1] = {};
+ const expr_t *b_adds[b_count + 1] = {};
+ const expr_t *b_subs[b_count + 1] = {};
a = traverse_scale (a);
distribute_terms (b, b_adds, b_subs);
- expr_t **s, **d;
+ const expr_t **s, **d;
for (s = b_adds, d = s; *s; s++) {
if (a != traverse_scale (*s)) {
*d++ = *s;
@@ -710,8 +720,8 @@ check_cross (expr_t *a, expr_t *b, int b_count)
return collect_terms (get_type (b), b_adds, b_subs);
}
-static expr_t *
-cross_expr (type_t *type, expr_t *a, expr_t *b)
+static const expr_t *
+cross_expr (type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@@ -745,15 +755,13 @@ cross_expr (type_t *type, expr_t *a, expr_t *b)
b = check_cross (a, b, b_terms);
}
- auto cross = new_binary_expr (CROSS, a, b);
- cross->expr.type = type;
- cross->expr.anticommute = true;
+ auto cross = typed_binary_expr (type, CROSS, a, b);
cross = edag_add_expr (cross);
return cross;
}
-static expr_t *
-wedge_expr (type_t *type, expr_t *a, expr_t *b)
+static const expr_t *
+wedge_expr (type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@@ -773,16 +781,14 @@ wedge_expr (type_t *type, expr_t *a, expr_t *b)
a = b;
b = t;
}
- auto wedge = new_binary_expr (WEDGE, a, b);
- wedge->expr.type = type;
- wedge->expr.anticommute = true;
+ auto wedge = typed_binary_expr (type, WEDGE, a, b);
wedge = edag_add_expr (wedge);
return wedge;
}
-typedef void (*pga_func) (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg);
+typedef void (*pga_func) (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg);
static void
-scale_component (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+scale_component (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
if (is_algebra (get_type (b))) {
auto t = a;
@@ -800,7 +806,7 @@ scale_component (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_dot_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -811,7 +817,7 @@ pga3_x_y_z_w_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -821,7 +827,7 @@ pga3_x_y_z_w_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_dot_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_dot_wx_wy_wz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -831,7 +837,7 @@ pga3_x_y_z_w_dot_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_dot_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_dot_wxyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -842,7 +848,7 @@ pga3_x_y_z_w_dot_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_x_y_z_w_dot_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -857,7 +863,7 @@ pga3_x_y_z_w_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_yz_zx_xy_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_dot_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -867,14 +873,14 @@ pga3_yz_zx_xy_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_yz_zx_xy_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto dot_type = algebra_mvec_type (alg, 0x04);
c[2] = neg_expr (dot_expr (dot_type, a, b));
}
static void
-pga3_yz_zx_xy_dot_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_dot_wxyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -885,7 +891,7 @@ pga3_yz_zx_xy_dot_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_yz_zx_xy_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_yz_zx_xy_dot_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -904,7 +910,7 @@ pga3_yz_zx_xy_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wx_wy_wz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wx_wy_wz_dot_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -914,7 +920,7 @@ pga3_wx_wy_wz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wxyz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wxyz_dot_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto dot_type = algebra_mvec_type (alg, 0x20);
@@ -924,7 +930,7 @@ pga3_wxyz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wxyz_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wxyz_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -935,7 +941,7 @@ pga3_wxyz_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wxyz_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wxyz_dot_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 0);
@@ -945,7 +951,7 @@ pga3_wxyz_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wzy_wxz_wyx_xyz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_dot_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -960,7 +966,7 @@ pga3_wzy_wxz_wyx_xyz_dot_x_y_z_w (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -979,7 +985,7 @@ pga3_wzy_wxz_wyx_xyz_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_dot_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wzy_wxz_wyx_xyz_dot_wxyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 3);
@@ -989,7 +995,7 @@ pga3_wzy_wxz_wyx_xyz_dot_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wzy_wxz_wyx_xyz_dot_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_dot_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1042,7 +1048,7 @@ static pga_func pga3_dot_funcs[6][6] = {
};
static void
-pga2_yw_wx_xy_dot_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_dot_yw_wx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 2);
@@ -1052,7 +1058,7 @@ pga2_yw_wx_xy_dot_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_yw_wx_xy_dot_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_dot_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto wtype = vector_type (stype, 2);
@@ -1069,7 +1075,7 @@ pga2_yw_wx_xy_dot_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_yw_wx_xy_dot_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_dot_wxy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 2);
@@ -1079,7 +1085,7 @@ pga2_yw_wx_xy_dot_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_x_y_w_dot_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_dot_yw_wx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto wtype = vector_type (stype, 2);
@@ -1096,7 +1102,7 @@ pga2_x_y_w_dot_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_x_y_w_dot_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_dot_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 2);
@@ -1107,7 +1113,7 @@ pga2_x_y_w_dot_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_x_y_w_dot_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_dot_wxy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 2);
@@ -1119,7 +1125,7 @@ pga2_x_y_w_dot_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_wxy_dot_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_wxy_dot_yw_wx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 0);
@@ -1129,7 +1135,7 @@ pga2_wxy_dot_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_wxy_dot_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_wxy_dot_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 2);
@@ -1167,55 +1173,55 @@ static pga_func pga2_dot_funcs[4][4] = {
};
static void
-vga3_x_y_z_dot_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_dot_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = dot_expr (algebra_mvec_type (alg, 0x08), a, b);
}
static void
-vga3_x_y_z_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = cross_expr (algebra_mvec_type (alg, 0x01), b, a);
}
static void
-vga3_x_y_z_dot_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_dot_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[2] = scale_expr (algebra_mvec_type (alg, 0x04), a, b);
}
static void
-vga3_yz_zx_xy_dot_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_dot_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = cross_expr (algebra_mvec_type (alg, 0x01), b, a);
}
static void
-vga3_yz_zx_xy_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = neg_expr (dot_expr (algebra_mvec_type (alg, 0x08), a, b));
}
static void
-vga3_yz_zx_xy_dot_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_dot_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = neg_expr (scale_expr (algebra_mvec_type (alg, 0x01), a, b));
}
static void
-vga3_xyz_dot_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_xyz_dot_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[2] = scale_expr (algebra_mvec_type (alg, 0x04), b, a);
}
static void
-vga3_xyz_dot_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_xyz_dot_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = neg_expr (scale_expr (algebra_mvec_type (alg, 0x01), b, a));
}
static void
-vga3_xyz_dot_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_xyz_dot_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = neg_expr (scale_expr (algebra_mvec_type (alg, 0x08), b, a));
}
@@ -1249,7 +1255,7 @@ static pga_func vga3_dot_funcs[4][4] = {
};
static void
-component_dot (expr_t **c, expr_t *a, expr_t *b, algebra_t *algebra)
+component_dot (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *algebra)
{
int p = algebra->plus;
int m = algebra->minus;
@@ -1278,16 +1284,16 @@ component_dot (expr_t **c, expr_t *a, expr_t *b, algebra_t *algebra)
}
}
-static expr_t *
-inner_product (expr_t *e1, expr_t *e2)
+static const expr_t *
+inner_product (const expr_t *e1, const expr_t *e2)
{
auto t1 = get_type (e1);
auto t2 = get_type (e2);
auto algebra = is_algebra (t1) ? algebra_get (t1) : algebra_get (t2);
auto layout = &algebra->layout;
- expr_t *a[layout->count] = {};
- expr_t *b[layout->count] = {};
- expr_t *c[layout->count] = {};
+ const expr_t *a[layout->count] = {};
+ const expr_t *b[layout->count] = {};
+ const expr_t *c[layout->count] = {};
e1 = mvec_expr (e1, algebra);
e2 = mvec_expr (e2, algebra);
mvec_scatter (a, e1, algebra);
@@ -1296,7 +1302,7 @@ inner_product (expr_t *e1, expr_t *e2)
for (int i = 0; i < layout->count; i++) {
for (int j = 0; j < layout->count; j++) {
if (a[i] && b[j]) {
- expr_t *w[layout->count] = {};
+ const expr_t *w[layout->count] = {};
component_dot (w, a[i], b[j], algebra);
if (!check_types (w, algebra)) {
internal_error (a[i], "wrong types in dot product");
@@ -1309,7 +1315,7 @@ inner_product (expr_t *e1, expr_t *e2)
}
static void
-pga3_x_y_z_w_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_wedge_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1325,7 +1331,7 @@ pga3_x_y_z_w_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_wedge_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_wedge_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1341,7 +1347,7 @@ pga3_x_y_z_w_wedge_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_wedge_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_wedge_wx_wy_wz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1352,14 +1358,14 @@ pga3_x_y_z_w_wedge_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_wedge_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_x_y_z_w_wedge_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
c[4] = dot_expr (algebra_mvec_type (alg, 0x10), a, b);
}
static void
-pga3_yz_zx_xy_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_wedge_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1377,13 +1383,13 @@ pga3_yz_zx_xy_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
// bivector-bivector wedge is commutative
#define pga3_wx_wy_wz_wedge_yz_zx_xy pga3_yz_zx_xy_wedge_wx_wy_wz
static void
-pga3_yz_zx_xy_wedge_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_wedge_wx_wy_wz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[4] = dot_expr (algebra_mvec_type (alg, 0x10), a, b);
}
static void
-pga3_wx_wy_wz_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wx_wy_wz_wedge_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1394,7 +1400,7 @@ pga3_wx_wy_wz_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wzy_wxz_wyx_xyz_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_wedge_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
c[4] = neg_expr (dot_expr (algebra_mvec_type (alg, 0x10), a, b));
@@ -1438,13 +1444,13 @@ static pga_func pga3_wedge_funcs[6][6] = {
// vector-bivector wedge is commutative
#define pga2_x_y_w_wedge_yw_wx_xy pga2_yw_wx_xy_wedge_x_y_w
static void
-pga2_yw_wx_xy_wedge_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_wedge_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[1] = dot_expr (algebra_mvec_type (alg, 0x02), a, b);
}
static void
-pga2_x_y_w_wedge_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_wedge_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto wedge_type = algebra_mvec_type (alg, 0x04);
c[2] = cross_expr (wedge_type, a, b);
@@ -1472,19 +1478,19 @@ static pga_func pga2_wedge_funcs[4][4] = {
};
static void
-vga3_x_y_z_wedge_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_wedge_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[2] = cross_expr (algebra_mvec_type (alg, 0x04), a, b);
}
static void
-vga3_x_y_z_wedge_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_wedge_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[1] = dot_expr (algebra_mvec_type (alg, 0x02), a, b);
}
static void
-vga3_yz_zx_xy_wedge_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_wedge_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[1] = dot_expr (algebra_mvec_type (alg, 0x02), a, b);
}
@@ -1511,7 +1517,7 @@ static pga_func vga3_wedge_funcs[4][4] = {
};
static void
-component_wedge (expr_t **c, expr_t *a, expr_t *b, algebra_t *algebra)
+component_wedge (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *algebra)
{
int p = algebra->plus;
int m = algebra->minus;
@@ -1540,16 +1546,16 @@ component_wedge (expr_t **c, expr_t *a, expr_t *b, algebra_t *algebra)
}
}
-static expr_t *
-outer_product (expr_t *e1, expr_t *e2)
+static const expr_t *
+outer_product (const expr_t *e1, const expr_t *e2)
{
auto t1 = get_type (e1);
auto t2 = get_type (e2);
auto algebra = is_algebra (t1) ? algebra_get (t1) : algebra_get (t2);
auto layout = &algebra->layout;
- expr_t *a[layout->count] = {};
- expr_t *b[layout->count] = {};
- expr_t *c[layout->count] = {};
+ const expr_t *a[layout->count] = {};
+ const expr_t *b[layout->count] = {};
+ const expr_t *c[layout->count] = {};
e1 = mvec_expr (e1, algebra);
e2 = mvec_expr (e2, algebra);
mvec_scatter (a, e1, algebra);
@@ -1558,7 +1564,7 @@ outer_product (expr_t *e1, expr_t *e2)
for (int i = 0; i < layout->count; i++) {
for (int j = 0; j < layout->count; j++) {
if (a[i] && b[j]) {
- expr_t *w[layout->count] = {};
+ const expr_t *w[layout->count] = {};
component_wedge (w, a[i], b[j], algebra);
if (!check_types (w, algebra)) {
internal_error (a[i], "wrong types in wedge product");
@@ -1571,7 +1577,7 @@ outer_product (expr_t *e1, expr_t *e2)
}
static void
-pga3_x_y_z_w_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_geom_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1588,7 +1594,7 @@ pga3_x_y_z_w_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1605,7 +1611,7 @@ pga3_x_y_z_w_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_geom_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_geom_wx_wy_wz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1617,7 +1623,7 @@ pga3_x_y_z_w_geom_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_geom_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_x_y_z_w_geom_wxyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1629,7 +1635,7 @@ pga3_x_y_z_w_geom_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_x_y_z_w_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_x_y_z_w_geom_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1644,7 +1650,7 @@ pga3_x_y_z_w_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_yz_zx_xy_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_geom_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1661,21 +1667,21 @@ pga3_yz_zx_xy_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_yz_zx_xy_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[1] = cross_expr (algebra_mvec_type (alg, 0x02), b, a);
c[2] = neg_expr (dot_expr (algebra_mvec_type (alg, 0x04), b, a));
}
static void
-pga3_yz_zx_xy_geom_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_geom_wx_wy_wz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = cross_expr (algebra_mvec_type (alg, 0x08), b, a);
c[4] = dot_expr (algebra_mvec_type (alg, 0x10), b, a);
}
static void
-pga3_yz_zx_xy_geom_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_yz_zx_xy_geom_wxyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sb = offset_cast (stype, b, 0);
@@ -1683,7 +1689,7 @@ pga3_yz_zx_xy_geom_wxyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_yz_zx_xy_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_yz_zx_xy_geom_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1701,7 +1707,7 @@ pga3_yz_zx_xy_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wx_wy_wz_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wx_wy_wz_geom_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1713,14 +1719,14 @@ pga3_wx_wy_wz_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wx_wy_wz_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wx_wy_wz_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = cross_expr (algebra_mvec_type (alg, 0x08), b, a);
c[4] = dot_expr (algebra_mvec_type (alg, 0x10), a, b);
}
static void
-pga3_wx_wy_wz_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_wx_wy_wz_geom_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1732,7 +1738,7 @@ pga3_wx_wy_wz_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wxyz_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wxyz_geom_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1744,7 +1750,7 @@ pga3_wxyz_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wxyz_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga3_wxyz_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 0);
@@ -1752,7 +1758,7 @@ pga3_wxyz_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga3_wxyz_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_wxyz_geom_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1764,7 +1770,7 @@ pga3_wxyz_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_geom_x_y_z_w (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1779,7 +1785,7 @@ pga3_wzy_wxz_wyx_xyz_geom_x_y_z_w (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1797,7 +1803,7 @@ pga3_wzy_wxz_wyx_xyz_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_geom_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_geom_wx_wy_wz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1809,7 +1815,7 @@ pga3_wzy_wxz_wyx_xyz_geom_wx_wy_wz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_geom_wxyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_geom_wxyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1821,7 +1827,7 @@ pga3_wzy_wxz_wyx_xyz_geom_wxyz (expr_t **c, expr_t *a, expr_t *b,
}
static void
-pga3_wzy_wxz_wyx_xyz_geom_wzy_wxz_wyx_xyz (expr_t **c, expr_t *a, expr_t *b,
+pga3_wzy_wxz_wyx_xyz_geom_wzy_wxz_wyx_xyz (const expr_t **c, const expr_t *a, const expr_t *b,
algebra_t *alg)
{
auto stype = alg->type;
@@ -1885,7 +1891,7 @@ static pga_func pga3_geometric_funcs[6][6] = {
};
static void
-pga2_yw_wx_xy_geom_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_geom_yw_wx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 3);
@@ -1900,7 +1906,7 @@ pga2_yw_wx_xy_geom_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_yw_wx_xy_geom_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_geom_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto wtype = vector_type (stype, 2);
@@ -1918,7 +1924,7 @@ pga2_yw_wx_xy_geom_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_yw_wx_xy_geom_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_yw_wx_xy_geom_wxy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 2);
@@ -1928,7 +1934,7 @@ pga2_yw_wx_xy_geom_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_x_y_w_geom_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_geom_yw_wx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto wtype = vector_type (stype, 2);
@@ -1946,7 +1952,7 @@ pga2_x_y_w_geom_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_x_y_w_geom_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_geom_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 2);
@@ -1958,7 +1964,7 @@ pga2_x_y_w_geom_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_x_y_w_geom_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_x_y_w_geom_wxy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 2);
@@ -1970,7 +1976,7 @@ pga2_x_y_w_geom_wxy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_wxy_geom_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_wxy_geom_yw_wx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto sa = offset_cast (stype, a, 0);
@@ -1980,7 +1986,7 @@ pga2_wxy_geom_yw_wx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
}
static void
-pga2_wxy_geom_x_y_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+pga2_wxy_geom_x_y_w (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
auto stype = alg->type;
auto vtype = vector_type (stype, 2);
@@ -2018,58 +2024,58 @@ static pga_func pga2_geometric_funcs[6][6] = {
};
static void
-vga3_x_y_z_geom_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_geom_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = dot_expr (algebra_mvec_type (alg, 0x08), a, b);
c[2] = cross_expr (algebra_mvec_type (alg, 0x04), a, b);
}
static void
-vga3_x_y_z_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = cross_expr (algebra_mvec_type (alg, 0x01), b, a);
c[1] = dot_expr (algebra_mvec_type (alg, 0x02), a, b);
}
static void
-vga3_x_y_z_geom_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_x_y_z_geom_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[2] = scale_expr (algebra_mvec_type (alg, 0x04), a, b);
}
static void
-vga3_yz_zx_xy_geom_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_geom_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = cross_expr (algebra_mvec_type (alg, 0x01), b, a);
c[1] = dot_expr (algebra_mvec_type (alg, 0x02), a, b);
}
static void
-vga3_yz_zx_xy_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = neg_expr (dot_expr (algebra_mvec_type (alg, 0x08), a, b));
}
static void
-vga3_yz_zx_xy_geom_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_yz_zx_xy_geom_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = neg_expr (scale_expr (algebra_mvec_type (alg, 0x01), a, b));
}
static void
-vga3_xyz_geom_x_y_z (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_xyz_geom_x_y_z (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[2] = scale_expr (algebra_mvec_type (alg, 0x04), b, a);
}
static void
-vga3_xyz_geom_yz_zx_xy (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_xyz_geom_yz_zx_xy (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[0] = neg_expr (scale_expr (algebra_mvec_type (alg, 0x01), b, a));
}
static void
-vga3_xyz_geom_xyz (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
+vga3_xyz_geom_xyz (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *alg)
{
c[3] = neg_expr (scale_expr (algebra_mvec_type (alg, 0x08), b, a));
}
@@ -2102,7 +2108,7 @@ static pga_func vga3_geometric_funcs[6][6] = {
};
static void
-component_geometric (expr_t **c, expr_t *a, expr_t *b, algebra_t *algebra)
+component_geometric (const expr_t **c, const expr_t *a, const expr_t *b, algebra_t *algebra)
{
int p = algebra->plus;
int m = algebra->minus;
@@ -2131,16 +2137,16 @@ component_geometric (expr_t **c, expr_t *a, expr_t *b, algebra_t *algebra)
}
}
-static expr_t *
-geometric_product (expr_t *e1, expr_t *e2)
+static const expr_t *
+geometric_product (const expr_t *e1, const expr_t *e2)
{
auto t1 = get_type (e1);
auto t2 = get_type (e2);
auto algebra = is_algebra (t1) ? algebra_get (t1) : algebra_get (t2);
auto layout = &algebra->layout;
- expr_t *a[layout->count] = {};
- expr_t *b[layout->count] = {};
- expr_t *c[layout->count] = {};
+ const expr_t *a[layout->count] = {};
+ const expr_t *b[layout->count] = {};
+ const expr_t *c[layout->count] = {};
e1 = mvec_expr (e1, algebra);
e2 = mvec_expr (e2, algebra);
mvec_scatter (a, e1, algebra);
@@ -2149,7 +2155,7 @@ geometric_product (expr_t *e1, expr_t *e2)
for (int i = 0; i < layout->count; i++) {
for (int j = 0; j < layout->count; j++) {
if (a[i] && b[j]) {
- expr_t *w[layout->count] = {};
+ const expr_t *w[layout->count] = {};
component_geometric (w, a[i], b[j], algebra);
if (!check_types (w, algebra)) {
internal_error (a[i], "wrong types in geometric product");
@@ -2161,8 +2167,8 @@ geometric_product (expr_t *e1, expr_t *e2)
return mvec_gather (c, algebra);
}
-static expr_t *
-regressive_product (expr_t *e1, expr_t *e2)
+static const expr_t *
+regressive_product (const expr_t *e1, const expr_t *e2)
{
auto a = algebra_dual (e1);
auto b = algebra_dual (e2);
@@ -2170,16 +2176,16 @@ regressive_product (expr_t *e1, expr_t *e2)
return algebra_dual (c);
}
-static expr_t *
-multivector_sum (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+multivector_sum (int op, const expr_t *e1, const expr_t *e2)
{
auto t1 = get_type (e1);
auto t2 = get_type (e2);
auto algebra = is_algebra (t1) ? algebra_get (t1) : algebra_get (t2);
auto layout = &algebra->layout;
- expr_t *a[layout->count] = {};
- expr_t *b[layout->count] = {};
- expr_t *c[layout->count];
+ const expr_t *a[layout->count] = {};
+ const expr_t *b[layout->count] = {};
+ const expr_t *c[layout->count];
e1 = mvec_expr (e1, algebra);
e2 = mvec_expr (e2, algebra);
mvec_scatter (a, e1, algebra);
@@ -2188,16 +2194,16 @@ multivector_sum (int op, expr_t *e1, expr_t *e2)
return mvec_gather (c, algebra);
}
-static expr_t *
-commutator_product (expr_t *e1, expr_t *e2)
+static const expr_t *
+commutator_product (const expr_t *e1, const expr_t *e2)
{
auto ab = geometric_product (e1, e2);
auto ba = geometric_product (e2, e1);
return multivector_sum ('-', ab, ba);
}
-static expr_t *
-multivector_divide (expr_t *e1, expr_t *e2)
+static const expr_t *
+multivector_divide (const expr_t *e1, const expr_t *e2)
{
if (is_algebra (get_type (e2))) {
return error (e2, "Division is left-right ambiguous (and works only"
@@ -2211,7 +2217,7 @@ multivector_divide (expr_t *e1, expr_t *e2)
auto algebra = algebra_get (t1);
auto layout = &algebra->layout;
auto stype = algebra->type;
- expr_t *a[layout->count] = {};
+ const expr_t *a[layout->count] = {};
e1 = mvec_expr (e1, algebra);
e2 = promote_scalar (algebra->type, e2);
mvec_scatter (a, e1, algebra);
@@ -2226,15 +2232,14 @@ multivector_divide (expr_t *e1, expr_t *e2)
if (width > 1) {
den = ext_expr (den, vector_type (stype, width), 2, false);
}
- a[i] = new_binary_expr ('/', a[i], den);
- a[i]->expr.type = ct;
+ a[i] = typed_binary_expr (ct, '/', a[i], den);
a[i] = edag_add_expr (a[i]);
}
return mvec_gather (a, algebra);
}
-expr_t *
-algebra_binary_expr (int op, expr_t *e1, expr_t *e2)
+const expr_t *
+algebra_binary_expr (int op, const expr_t *e1, const expr_t *e2)
{
switch (op) {
case DOT:
@@ -2257,13 +2262,13 @@ algebra_binary_expr (int op, expr_t *e1, expr_t *e2)
return error (e1, "invalid operator");
}
-expr_t *
-algebra_negate (expr_t *e)
+const expr_t *
+algebra_negate (const expr_t *e)
{
auto t = get_type (e);
auto algebra = algebra_get (t);
auto layout = &algebra->layout;
- expr_t *n[layout->count] = {};
+ const expr_t *n[layout->count] = {};
e = mvec_expr (e, algebra);
mvec_scatter (n, e, algebra);
@@ -2271,18 +2276,13 @@ algebra_negate (expr_t *e)
if (!n[i]) {
continue;
}
- auto ct = get_type (n[i]);
- if (is_algebra (ct)) {
- n[i] = cast_expr (float_type (ct), n[i]);
- }
n[i] = neg_expr (n[i]);
- n[i]->expr.type = ct;
}
return mvec_gather (n, algebra);
}
-expr_t *
-algebra_dual (expr_t *e)
+const expr_t *
+algebra_dual (const expr_t *e)
{
if (!is_algebra (get_type (e))) {
//FIXME check for being in an @algebra { } block
@@ -2291,8 +2291,8 @@ algebra_dual (expr_t *e)
auto algebra = algebra_get (get_type (e));
auto layout = &algebra->layout;
- expr_t *a[layout->count] = {};
- expr_t *b[layout->count] = {};
+ const expr_t *a[layout->count] = {};
+ const expr_t *b[layout->count] = {};
e = mvec_expr (e, algebra);
mvec_scatter (a, e, algebra);
@@ -2329,13 +2329,13 @@ set_sign (pr_type_t *val, int sign, const type_t *type)
}
}
-expr_t *
-algebra_reverse (expr_t *e)
+const expr_t *
+algebra_reverse (const expr_t *e)
{
auto t = get_type (e);
auto algebra = algebra_get (t);
auto layout = &algebra->layout;
- expr_t *r[layout->count] = {};
+ const expr_t *r[layout->count] = {};
e = mvec_expr (e, algebra);
mvec_scatter (r, e, algebra);
@@ -2364,8 +2364,7 @@ algebra_reverse (expr_t *e)
if (neg) {
auto rev = new_value_expr (new_type_value (ct, ones));
rev = edag_add_expr (rev);
- r[i] = new_binary_expr (HADAMARD, r[i], rev);
- r[i]->expr.type = ct;
+ r[i] = typed_binary_expr (ct, HADAMARD, r[i], rev);
r[i] = edag_add_expr (rev);
}
}
@@ -2373,8 +2372,8 @@ algebra_reverse (expr_t *e)
return mvec_gather (r, algebra);
}
-expr_t *
-algebra_cast_expr (type_t *dstType, expr_t *e)
+const expr_t *
+algebra_cast_expr (type_t *dstType, const expr_t *e)
{
type_t *srcType = get_type (e);
if (dstType->type == ev_invalid
@@ -2397,7 +2396,7 @@ algebra_cast_expr (type_t *dstType, expr_t *e)
}
static void
-zero_components (expr_t *block, expr_t *dst, int memset_base, int memset_size)
+zero_components (expr_t *block, const expr_t *dst, int memset_base, int memset_size)
{
auto base = alias_expr (&type_int, dst, memset_base);
auto zero = new_int_expr (0);
@@ -2433,7 +2432,7 @@ summed_extend (const expr_t *e)
}
static void
-assign_extend (expr_t *block, expr_t *dst, expr_t *src)
+assign_extend (expr_t *block, const expr_t *dst, const expr_t *src)
{
auto ext1 = src->expr.e1->extend;
auto ext2 = src->expr.e2->extend;
@@ -2447,8 +2446,8 @@ assign_extend (expr_t *block, expr_t *dst, expr_t *src)
append_expr (block, edag_add_expr (new_assign_expr (dst2, ext2.src)));
}
-expr_t *
-algebra_assign_expr (expr_t *dst, expr_t *src)
+const expr_t *
+algebra_assign_expr (const expr_t *dst, const expr_t *src)
{
type_t *srcType = get_type (src);
type_t *dstType = get_type (dst);
@@ -2456,7 +2455,7 @@ algebra_assign_expr (expr_t *dst, expr_t *src)
if (src->type != ex_multivec) {
if (srcType == dstType) {
if (summed_extend (src)) {
- auto block = edag_add_expr (new_block_expr ());
+ auto block = new_block_expr (0);
assign_extend (block, dst, src);
return block;
}
@@ -2469,12 +2468,12 @@ algebra_assign_expr (expr_t *dst, expr_t *src)
}
auto algebra = algebra_get (dstType);
auto layout = &algebra->layout;
- expr_t *c[layout->count] = {};
+ const expr_t *c[layout->count] = {};
src = mvec_expr (src, algebra);
mvec_scatter (c, src, algebra);
auto sym = get_mvec_sym (dstType);
- auto block = new_block_expr ();
+ auto block = new_block_expr (0);
int memset_base = 0;
for (int i = 0; i < layout->count; i++) {
if (!c[i]) {
@@ -2503,8 +2502,8 @@ algebra_assign_expr (expr_t *dst, expr_t *src)
return block;
}
-expr_t *
-algebra_field_expr (expr_t *mvec, expr_t *field_name)
+const expr_t *
+algebra_field_expr (const expr_t *mvec, const expr_t *field_name)
{
auto mvec_type = get_type (mvec);
auto algebra = algebra_get (mvec_type);
@@ -2529,7 +2528,7 @@ algebra_field_expr (expr_t *mvec, expr_t *field_name)
mvec_type->name, field_sym->name);
}
auto layout = &algebra->layout;
- expr_t *a[layout->count] = {};
+ const expr_t *a[layout->count] = {};
mvec_scatter (a, mvec_expr (mvec, algebra), algebra);
pr_uint_t group_mask = get_group_mask (field->type, algebra);
for (int i = 0; i < layout->count; i++) {
diff --git a/tools/qfcc/source/expr_assign.c b/tools/qfcc/source/expr_assign.c
index c9c373a8a..43e9029e9 100644
--- a/tools/qfcc/source/expr_assign.c
+++ b/tools/qfcc/source/expr_assign.c
@@ -65,17 +65,17 @@
#include "tools/qfcc/include/type.h"
#include "tools/qfcc/include/value.h"
-static expr_t *
-check_assign_logic_precedence (expr_t *dst, expr_t *src)
+static const expr_t *
+check_assign_logic_precedence (const expr_t *dst, const expr_t *src)
{
if (src->type == ex_expr && !src->paren && is_logic (src->expr.op)) {
// traditional QuakeC gives = higher precedence than && and ||
- expr_t *assignment;
notice (src, "precedence of `=' and `%s' inverted for "
"traditional code", get_op_string (src->expr.op));
// change {a = (b logic c)} to {(a = b) logic c}
- assignment = assign_expr (dst, src->expr.e1);
- assignment->paren = 1; // protect assignment from binary_expr
+ auto assignment = assign_expr (dst, src->expr.e1);
+ // protect assignment from binary_expr
+ ((expr_t *) assignment)->paren = 1;
return binary_expr (src->expr.op, assignment, src->expr.e2);
}
return 0;
@@ -154,8 +154,8 @@ is_lvalue (const expr_t *expr)
return 0;
}
-static expr_t *
-check_valid_lvalue (expr_t *expr)
+static const expr_t *
+check_valid_lvalue (const expr_t *expr)
{
if (!is_lvalue (expr)) {
if (options.traditional) {
@@ -167,8 +167,8 @@ check_valid_lvalue (expr_t *expr)
return 0;
}
-static expr_t *
-check_types_compatible (expr_t *dst, expr_t *src)
+static const expr_t *
+check_types_compatible (const expr_t *dst, const expr_t *src)
{
type_t *dst_type = get_type (dst);
type_t *src_type = get_type (src);
@@ -192,7 +192,7 @@ check_types_compatible (expr_t *dst, expr_t *src)
}
}
// the types are different but cast-compatible
- expr_t *new = cast_expr (dst_type, src);
+ auto new = cast_expr (dst_type, src);
// the cast was a no-op, so the types are compatible at the
// low level (very true for default type <-> enum)
if (new != src) {
@@ -222,14 +222,14 @@ check_types_compatible (expr_t *dst, expr_t *src)
}
static void
-copy_qv_elements (expr_t *block, expr_t *dst, expr_t *src)
+copy_qv_elements (expr_t *block, const expr_t *dst, const expr_t *src)
{
- expr_t *dx, *sx;
- expr_t *dy, *sy;
- expr_t *dz, *sz;
- expr_t *dw, *sw;
- expr_t *ds, *ss;
- expr_t *dv, *sv;
+ const expr_t *dx, *sx;
+ const expr_t *dy, *sy;
+ const expr_t *dz, *sz;
+ const expr_t *dw, *sw;
+ const expr_t *ds, *ss;
+ const expr_t *dv, *sv;
if (is_vector (src->vector.type)) {
// guaranteed to have three elements
@@ -271,10 +271,10 @@ copy_qv_elements (expr_t *block, expr_t *dst, expr_t *src)
}
static int
-copy_elements (expr_t *block, expr_t *dst, expr_t *src, int base)
+copy_elements (expr_t *block, const expr_t *dst, const expr_t *src, int base)
{
int index = 0;
- for (expr_t *e = src->vector.list; e; e = e->next) {
+ for (const expr_t *e = src->vector.list; e; e = e->next) {
if (e->type == ex_vector) {
index += copy_elements (block, dst, e, index + base);
} else {
@@ -287,11 +287,11 @@ copy_elements (expr_t *block, expr_t *dst, expr_t *src, int base)
return index;
}
-static expr_t *
-assign_vector_expr (expr_t *dst, expr_t *src)
+static const expr_t *
+assign_vector_expr (const expr_t *dst, const expr_t *src)
{
if (src->type == ex_vector && dst->type != ex_vector) {
- expr_t *block = new_block_expr ();
+ expr_t *block = new_block_expr (0);
if (options.code.progsversion < PROG_VERSION) {
copy_qv_elements (block, dst, src);
@@ -304,16 +304,16 @@ assign_vector_expr (expr_t *dst, expr_t *src)
return 0;
}
-static __attribute__((pure)) int
-is_memset (expr_t *e)
+static int __attribute__((pure))
+is_memset (const expr_t *e)
{
return e->type == ex_memset;
}
-expr_t *
-assign_expr (expr_t *dst, expr_t *src)
+const expr_t *
+assign_expr (const expr_t *dst, const expr_t *src)
{
- expr_t *expr;
+ const expr_t *expr;
type_t *dst_type, *src_type;
dst = convert_name (dst);
@@ -381,7 +381,7 @@ assign_expr (expr_t *dst, expr_t *src)
return expr;
}
} else {
- convert_nil (src, dst_type);
+ src = convert_nil (src, dst_type);
}
expr = new_assign_expr (dst, src);
diff --git a/tools/qfcc/source/expr_binary.c b/tools/qfcc/source/expr_binary.c
index 269fa7308..7ea62e312 100644
--- a/tools/qfcc/source/expr_binary.c
+++ b/tools/qfcc/source/expr_binary.c
@@ -44,21 +44,26 @@ typedef struct {
type_t *result_type;
type_t *a_cast;
type_t *b_cast;
- expr_t *(*process)(int op, expr_t *e1, expr_t *e2);
+ const expr_t *(*process)(int op, const expr_t *e1, const expr_t *e2);
bool (*commutative) (void);
bool (*anticommute) (void);
} expr_type_t;
-static expr_t *pointer_arithmetic (int op, expr_t *e1, expr_t *e2);
-static expr_t *pointer_compare (int op, expr_t *e1, expr_t *e2);
-static expr_t *func_compare (int op, expr_t *e1, expr_t *e2);
-static expr_t *inverse_multiply (int op, expr_t *e1, expr_t *e2);
-static expr_t *double_compare (int op, expr_t *e1, expr_t *e2);
-static expr_t *vector_compare (int op, expr_t *e1, expr_t *e2);
-static expr_t *vector_dot (int op, expr_t *e1, expr_t *e2);
-static expr_t *vector_multiply (int op, expr_t *e1, expr_t *e2);
-static expr_t *vector_scale (int op, expr_t *e1, expr_t *e2);
-static expr_t *entity_compare (int op, expr_t *e1, expr_t *e2);
+static const expr_t *pointer_arithmetic (int op, const expr_t *e1,
+ const expr_t *e2);
+static const expr_t *pointer_compare (int op, const expr_t *e1,
+ const expr_t *e2);
+static const expr_t *func_compare (int op, const expr_t *e1,
+ const expr_t *e2);
+static const expr_t *inverse_multiply (int op, const expr_t *e1,
+ const expr_t *e2);
+static const expr_t *double_compare (int op, const expr_t *e1,
+ const expr_t *e2);
+static const expr_t *vector_compare (int op, const expr_t *e1, const expr_t *e2);
+static const expr_t *vector_dot (int op, const expr_t *e1, const expr_t *e2);
+static const expr_t *vector_multiply (int op, const expr_t *e1, const expr_t *e2);
+static const expr_t *vector_scale (int op, const expr_t *e1, const expr_t *e2);
+static const expr_t *entity_compare (int op, const expr_t *e1, const expr_t *e2);
static bool always (void)
{
@@ -721,8 +726,8 @@ static expr_type_t **binary_expr_types[ev_type_count] = {
// supported operators for scalar-vector expressions
static int scalar_vec_ops[] = { '*', '/', '%', MOD, 0 };
-static expr_t *
-convert_scalar (expr_t *scalar, int op, expr_t *vec)
+static const expr_t *
+convert_scalar (const expr_t *scalar, int op, const expr_t *vec)
{
int *s_op = scalar_vec_ops;
while (*s_op && *s_op != op) {
@@ -737,7 +742,7 @@ convert_scalar (expr_t *scalar, int op, expr_t *vec)
if (is_constant (scalar)) {
int width = type_width (get_type (vec));
- expr_t *elements[width];
+ const expr_t *elements[width];
for (int i = 0; i < width; i++) {
elements[i] = scalar;
}
@@ -749,14 +754,14 @@ convert_scalar (expr_t *scalar, int op, expr_t *vec)
return new_extend_expr (scalar, vec_type, 2, false);//2 = copy
}
-static expr_t *
-pointer_arithmetic (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+pointer_arithmetic (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
- expr_t *ptr = 0;
- expr_t *offset = 0;
- expr_t *psize;
+ const expr_t *ptr = 0;
+ const expr_t *offset = 0;
+ const expr_t *psize;
type_t *ptype = 0;
if (!is_ptr (t1) && !is_ptr (t2)) {
@@ -789,8 +794,8 @@ pointer_arithmetic (int op, expr_t *e1, expr_t *e2)
return offset_pointer_expr (ptr, offset);
}
-static expr_t *
-pointer_compare (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+pointer_compare (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
@@ -810,8 +815,8 @@ pointer_compare (int op, expr_t *e1, expr_t *e2)
return e;
}
-static expr_t *
-func_compare (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+func_compare (int op, const expr_t *e1, const expr_t *e2)
{
expr_t *e;
@@ -828,17 +833,17 @@ func_compare (int op, expr_t *e1, expr_t *e2)
return e;
}
-static expr_t *
-inverse_multiply (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+inverse_multiply (int op, const expr_t *e1, const expr_t *e2)
{
// There is no vector/float or quaternion/float instruction and adding
// one would mean the engine would have to do 1/f every time
- expr_t *one = new_float_expr (1);
+ auto one = new_float_expr (1);
return binary_expr ('*', e1, binary_expr ('/', one, e2));
}
-static expr_t *
-vector_compare (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+vector_compare (int op, const expr_t *e1, const expr_t *e2)
{
if (options.code.progsversion < PROG_VERSION) {
expr_t *e = new_binary_expr (op, e1, e2);
@@ -856,16 +861,16 @@ vector_compare (int op, expr_t *e1, expr_t *e2)
return new_horizontal_expr (hop, e, &type_int);
}
-static expr_t *
-vector_dot (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+vector_dot (int op, const expr_t *e1, const expr_t *e2)
{
expr_t *e = new_binary_expr (DOT, e1, e2);
e->expr.type = &type_float;
return e;
}
-static expr_t *
-vector_multiply (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+vector_multiply (int op, const expr_t *e1, const expr_t *e2)
{
if (options.math.vector_mult == DOT) {
// vector * vector is dot product in v6 progs (ick)
@@ -877,14 +882,14 @@ vector_multiply (int op, expr_t *e1, expr_t *e2)
return e;
}
-static expr_t *
-vector_scale (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+vector_scale (int op, const expr_t *e1, const expr_t *e2)
{
// Ensure the expression is always vector * scalar. The operation is
// always commutative, and the Ruamoko ISA supports only vector * scalar
// (though v6 does support scalar * vector, one less if).
if (is_scalar (get_type (e1))) {
- expr_t *t = e1;
+ auto t = e1;
e1 = e2;
e2 = t;
}
@@ -893,8 +898,8 @@ vector_scale (int op, expr_t *e1, expr_t *e2)
return e;
}
-static expr_t *
-double_compare (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+double_compare (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
@@ -928,8 +933,8 @@ double_compare (int op, expr_t *e1, expr_t *e2)
return e;
}
-static expr_t *
-entity_compare (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+entity_compare (int op, const expr_t *e1, const expr_t *e2)
{
if (options.code.progsversion == PROG_VERSION) {
e1 = new_alias_expr (&type_int, e1);
@@ -945,8 +950,8 @@ entity_compare (int op, expr_t *e1, expr_t *e2)
#define invalid_binary_expr(_op, _e1, _e2) \
_invalid_binary_expr(_op, _e1, _e2, __FILE__, __LINE__, __FUNCTION__)
-static expr_t *
-_invalid_binary_expr (int op, expr_t *e1, expr_t *e2,
+static const expr_t *
+_invalid_binary_expr (int op, const expr_t *e1, const expr_t *e2,
const char *file, int line, const char *func)
{
type_t *t1, *t2;
@@ -957,8 +962,8 @@ _invalid_binary_expr (int op, expr_t *e1, expr_t *e2,
get_type_string (t2));
}
-static expr_t *
-reimplement_binary_expr (int op, expr_t *e1, expr_t *e2)
+static const expr_t *
+reimplement_binary_expr (int op, const expr_t *e1, const expr_t *e2)
{
expr_t *e;
@@ -967,7 +972,7 @@ reimplement_binary_expr (int op, expr_t *e1, expr_t *e2)
case '%':
{
expr_t *tmp1, *tmp2;
- e = new_block_expr ();
+ e = new_block_expr (0);
tmp1 = new_temp_def_expr (&type_float);
tmp2 = new_temp_def_expr (&type_float);
@@ -982,15 +987,21 @@ reimplement_binary_expr (int op, expr_t *e1, expr_t *e2)
return 0;
}
-static expr_t *
-check_precedence (int op, expr_t *e1, expr_t *e2)
+static void
+set_paren (const expr_t *e)
+{
+ ((expr_t *) e)->paren = 1;
+}
+
+static const expr_t *
+check_precedence (int op, const expr_t *e1, const expr_t *e2)
{
if (e1->type == ex_uexpr && e1->expr.op == '!' && !e1->paren) {
if (options.traditional) {
if (op != AND && op != OR && op != '=') {
notice (e1, "precedence of `!' and `%s' inverted for "
"traditional code", get_op_string (op));
- e1->expr.e1->paren = 1;
+ set_paren (e1->expr.e1);
return unary_expr ('!', binary_expr (op, e1->expr.e1, e2));
}
} else if (op == '&' || op == '|') {
@@ -1010,7 +1021,7 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
"traditional code", get_op_string (op),
get_op_string (e2->expr.op));
e1 = binary_expr (op, e1, e2->expr.e1);
- e1->paren = 1;
+ set_paren (e1);
return binary_expr (e2->expr.op, e1, e2->expr.e2);
}
if (((op == EQ || op == NE) && is_compare (e2->expr.op))
@@ -1020,7 +1031,7 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
"traditional code", get_op_string (op),
get_op_string (e2->expr.op));
e1 = binary_expr (op, e1, e2->expr.e1);
- e1->paren = 1;
+ set_paren (e1);
return binary_expr (e2->expr.op, e1, e2->expr.e2);
}
} else if (e1->type == ex_expr && !e1->paren) {
@@ -1032,7 +1043,7 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
"traditional code", get_op_string (op),
get_op_string (e1->expr.op));
e2 = binary_expr (op, e1->expr.e2, e2);
- e2->paren = 1;
+ set_paren (e1);
return binary_expr (e1->expr.op, e1->expr.e1, e2);
}
}
@@ -1067,7 +1078,8 @@ check_precedence (int op, expr_t *e1, expr_t *e2)
return 0;
}
-static int is_call (expr_t *e)
+static int
+is_call (const expr_t *e)
{
return e->type == ex_block && e->block.is_call;
}
@@ -1081,12 +1093,12 @@ promote_type (type_t *dst, type_t *src)
return vector_type (base_type (dst), type_width (src));
}
-expr_t *
-binary_expr (int op, expr_t *e1, expr_t *e2)
+const expr_t *
+binary_expr (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1, *t2;
etype_t et1, et2;
- expr_t *e;
+ const expr_t *e;
expr_type_t *expr_type;
e1 = convert_name (e1);
@@ -1095,19 +1107,23 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if (e1->type == ex_alias && is_call (e1->alias.expr)) {
// move the alias expression inside the block so the following check
// can detect the call and move the temp assignment into the block
- expr_t *block = e1->alias.expr;
- e1->alias.expr = block->block.result;
- block->block.result = e1;
+ auto block = (expr_t *) e1->alias.expr;
+ auto ne = new_expr ();
+ *ne = *e1;
+ ne->alias.expr = block->block.result;
+ block->block.result = ne;
e1 = block;
}
if (e1->type == ex_block && e1->block.is_call
&& has_function_call (e2) && e1->block.result) {
- // the temp assignment needs to be insided the block so assignment
+ // the temp assignment needs to be inside the block so assignment
// code generation doesn't see it when applying right-associativity
expr_t *tmp = new_temp_def_expr (get_type (e1->block.result));
- e = assign_expr (tmp, e1->block.result);
- append_expr (e1, e);
- e1->block.result = tmp;
+ auto ne = assign_expr (tmp, e1->block.result);
+ auto nb = new_block_expr (e1);
+ append_expr (nb, ne);
+ nb->block.result = tmp;
+ e1 = nb;
}
if (e1->type == ex_error)
return e1;
@@ -1136,10 +1152,10 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if (op == EQ || op == NE) {
if (e1->type == ex_nil) {
t1 = t2;
- convert_nil (e1, t1);
+ e1 = convert_nil (e1, t1);
} else if (e2->type == ex_nil) {
t2 = t1;
- convert_nil (e2, t2);
+ e2 = convert_nil (e2, t2);
}
}
@@ -1236,7 +1252,7 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
et2 = low_level_type (t2);
// both widths are the same at this point
if (t1->width > 1) {
- e = new_binary_expr (op, e1, e2);
+ auto ne = new_binary_expr (op, e1, e2);
if (is_compare (op)) {
t1 = int_type (t1);
}
@@ -1246,8 +1262,8 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
}
t1 = base_type (t1);
}
- e->expr.type = t1;
- return edag_add_expr (e);
+ ne->expr.type = t1;
+ return edag_add_expr (ne);
}
}
@@ -1269,18 +1285,18 @@ binary_expr (int op, expr_t *e1, expr_t *e2)
if ((e = reimplement_binary_expr (op, e1, e2)))
return edag_add_expr (fold_constants (e));
- e = new_binary_expr (op, e1, e2);
- e->expr.type = expr_type->result_type;
+ auto ne = new_binary_expr (op, e1, e2);
+ ne->expr.type = expr_type->result_type;
if (expr_type->commutative) {
- e->expr.commutative = expr_type->commutative ();
+ ne->expr.commutative = expr_type->commutative ();
}
if (expr_type->anticommute) {
- e->expr.anticommute = expr_type->anticommute ();
+ ne->expr.anticommute = expr_type->anticommute ();
}
if (is_compare (op) || is_logic (op)) {
if (options.code.progsversion == PROG_ID_VERSION) {
- e->expr.type = &type_float;
+ ne->expr.type = &type_float;
}
}
- return edag_add_expr (fold_constants (e));
+ return edag_add_expr (fold_constants (ne));
}
diff --git a/tools/qfcc/source/expr_bool.c b/tools/qfcc/source/expr_bool.c
index 989634f3b..7d1b961f6 100644
--- a/tools/qfcc/source/expr_bool.c
+++ b/tools/qfcc/source/expr_bool.c
@@ -66,10 +66,10 @@
#include "tools/qfcc/source/qc-parse.h"
-expr_t *
-test_expr (expr_t *e)
+const expr_t *
+test_expr (const expr_t *e)
{
- expr_t *new = 0;
+ const expr_t *new = 0;
type_t *type;
e = convert_name (e);
@@ -128,12 +128,12 @@ test_expr (expr_t *e)
}
return e;
}
- new = expr_file_line (new_zero_expr (type), e);
- new = expr_file_line (binary_expr (NE, e, new), e);
+ new = expr_file_line ((expr_t *) new_zero_expr (type), e);
+ new = expr_file_line ((expr_t *) binary_expr (NE, e, new), e);
return test_expr (new);
case ev_double:
- new = expr_file_line (new_zero_expr (type), e);
- new = expr_file_line (binary_expr (NE, e, new), e);
+ new = expr_file_line ((expr_t *) new_zero_expr (type), e);
+ new = expr_file_line ((expr_t *) binary_expr (NE, e, new), e);
return test_expr (new);
case ev_vector:
new = new_zero_expr (&type_vector);
@@ -156,16 +156,14 @@ test_expr (expr_t *e)
}
return test_error (e, get_type (e));
}
- new->line = e->line;
- new->file = e->file;
+ new = expr_file_line ((expr_t *) new, e);
new = binary_expr (NE, e, new);
- new->line = e->line;
- new->file = e->file;
+ new = expr_file_line ((expr_t *) new, e);
return new;
}
void
-backpatch (ex_boollist_t *list, expr_t *label)
+backpatch (ex_boollist_t *list, const expr_t *label)
{
int i;
expr_t *e;
@@ -182,7 +180,7 @@ backpatch (ex_boollist_t *list, expr_t *label)
} else {
internal_error (e, 0);
}
- label->label.used++;
+ ((expr_t *)label)->label.used++;
}
}
@@ -205,18 +203,18 @@ merge (ex_boollist_t *l1, ex_boollist_t *l2)
}
static ex_boollist_t *
-make_list (expr_t *e)
+make_list (const expr_t *e)
{
ex_boollist_t *m;
m = malloc (field_offset (ex_boollist_t, e[1]));
m->size = 1;
- m->e[0] = e;
+ m->e[0] = (expr_t *) e;
return m;
}
-expr_t *
-bool_expr (int op, expr_t *label, expr_t *e1, expr_t *e2)
+const expr_t *
+bool_expr (int op, const expr_t *label, const expr_t *e1, const expr_t *e2)
{
expr_t *block;
@@ -231,7 +229,7 @@ bool_expr (int op, expr_t *label, expr_t *e1, expr_t *e2)
if (e2->type == ex_error)
return e2;
- block = new_block_expr ();
+ block = new_block_expr (0);
append_expr (block, e1);
append_expr (block, label);
append_expr (block, e2);
@@ -254,7 +252,7 @@ bool_expr (int op, expr_t *label, expr_t *e1, expr_t *e2)
}
static int __attribute__((pure))
-has_block_expr (expr_t *e)
+has_block_expr (const expr_t *e)
{
while (e->type == ex_alias) {
e = e->alias.expr;
@@ -262,17 +260,14 @@ has_block_expr (expr_t *e)
return e->type == ex_block;
}
-expr_t *
-convert_bool (expr_t *e, int block)
+const expr_t *
+convert_bool (const expr_t *e, int block)
{
- expr_t *b;
-
if (e->type == ex_assign) {
- expr_t *tst;
if (!e->paren && options.warnings.precedence)
warning (e, "suggest parentheses around assignment "
"used as truth value");
- tst = e->assign.src;
+ auto tst = e->assign.src;
if (has_block_expr (tst) && has_block_expr (e->assign.dst)) {
tst = new_temp_def_expr (get_type (tst));
e = new_assign_expr (e->assign.dst,
@@ -280,11 +275,11 @@ convert_bool (expr_t *e, int block)
} else if (has_block_expr (tst)) {
tst = e->assign.dst;
}
- b = convert_bool (tst, 1);
+ auto b = convert_bool (tst, 1);
if (b->type == ex_error)
return b;
// insert the assignment into the boolean's block
- prepend_expr (b->boolean.e, e);
+ prepend_expr ((expr_t *) b->boolean.e, e); //FIXME cast
return b;
}
@@ -292,17 +287,17 @@ convert_bool (expr_t *e, int block)
&& !is_string(get_type (e->expr.e1))) {
e = convert_bool (e->expr.e1, 0);
if (e->type == ex_error)
- return e;
+ return (expr_t *) e;
e = unary_expr ('!', e);
}
if (e->type != ex_bool) {
e = test_expr (e);
if (e->type == ex_error)
- return e;
+ return (expr_t *) e;
if (is_constant (e)) {
int val;
- b = goto_expr (0);
+ auto b = goto_expr (0);
if (is_int_val (e)) {
val = expr_int (e);
} else {
@@ -313,7 +308,7 @@ convert_bool (expr_t *e, int block)
else
e = new_bool_expr (0, make_list (b), b);
} else {
- b = new_block_expr ();
+ auto b = new_block_expr (0);
append_expr (b, branch_expr (NE, e, 0));
append_expr (b, goto_expr (0));
e = new_bool_expr (make_list (b->block.head->expr),
@@ -321,9 +316,9 @@ convert_bool (expr_t *e, int block)
}
}
if (block && e->boolean.e->type != ex_block) {
- expr_t *block = new_block_expr ();
+ expr_t *block = new_block_expr (0);
append_expr (block, e->boolean.e);
- e->boolean.e = block;
+ ((expr_t *) e)->boolean.e = block;
}
return edag_add_expr (e);
}
diff --git a/tools/qfcc/source/expr_cast.c b/tools/qfcc/source/expr_cast.c
index 341de4066..924274fd9 100644
--- a/tools/qfcc/source/expr_cast.c
+++ b/tools/qfcc/source/expr_cast.c
@@ -44,8 +44,8 @@
#include "tools/qfcc/include/type.h"
#include "tools/qfcc/include/value.h"
-expr_t *
-cast_error (expr_t *e, type_t *t1, type_t *t2)
+const expr_t *
+cast_error (const expr_t *e, type_t *t1, type_t *t2)
{
e = error (e, "cannot cast from %s to %s", get_type_string (t1),
get_type_string (t2));
@@ -54,7 +54,7 @@ cast_error (expr_t *e, type_t *t1, type_t *t2)
static void
do_conversion (pr_type_t *dst_value, type_t *dstType,
- pr_type_t *src_value, type_t *srcType, expr_t *expr)
+ pr_type_t *src_value, type_t *srcType, const expr_t *expr)
{
int from = type_cast_map[base_type (srcType)->type];
int to = type_cast_map[base_type (dstType)->type];
@@ -69,8 +69,8 @@ do_conversion (pr_type_t *dst_value, type_t *dstType,
}
}
-static expr_t *
-cast_math (type_t *dstType, type_t *srcType, expr_t *expr)
+static const expr_t *
+cast_math (type_t *dstType, type_t *srcType, const expr_t *expr)
{
pr_type_t src_value[type_size (srcType)];
pr_type_t dst_value[type_size (dstType)];
@@ -82,10 +82,9 @@ cast_math (type_t *dstType, type_t *srcType, expr_t *expr)
return new_value_expr (new_type_value (dstType, dst_value));
}
-expr_t *
-cast_expr (type_t *dstType, expr_t *e)
+const expr_t *
+cast_expr (type_t *dstType, const expr_t *e)
{
- expr_t *c;
type_t *srcType;
e = convert_name (e);
@@ -93,6 +92,10 @@ cast_expr (type_t *dstType, expr_t *e)
if (e->type == ex_error)
return e;
+ if (is_nil (e)) {
+ return convert_nil (e, dstType);
+ }
+
dstType = (type_t *) unalias_type (dstType); //FIXME cast
srcType = get_type (e);
@@ -104,10 +107,10 @@ cast_expr (type_t *dstType, expr_t *e)
return e;
if ((is_ptr (dstType) && is_string (srcType))
|| (is_string (dstType) && is_ptr (srcType))) {
- c = new_alias_expr (dstType, e);
- return c;
+ return new_alias_expr (dstType, e);
}
if (is_algebra (dstType) || is_algebra (srcType)) {
+ const expr_t *c;
if ((c = algebra_cast_expr (dstType, e))) {
return c;
}
@@ -136,19 +139,21 @@ cast_expr (type_t *dstType, expr_t *e)
e = new_int_expr (expr_ushort (e));
srcType = &type_int;
}
+ expr_t *c = 0;
if (is_constant (e) && is_math (dstType) && is_math (srcType)) {
return cast_math (dstType, srcType, e);
} else if (is_integral (dstType) && is_integral (srcType)
&& type_size (dstType) == type_size (srcType)) {
- c = new_alias_expr (dstType, e);
+ c = (expr_t *) new_alias_expr (dstType, e);
} else if (is_scalar (dstType) && is_scalar (srcType)) {
c = new_unary_expr ('C', e);
c->expr.type = dstType;
} else if (e->type == ex_uexpr && e->expr.op == '.') {
- e->expr.type = dstType;
- c = e;
+ c = new_expr ();
+ *c = *e;
+ c->expr.type = dstType;
} else {
- c = new_alias_expr (dstType, e);
+ c = (expr_t *) new_alias_expr (dstType, e);
}
return c;
}
diff --git a/tools/qfcc/source/expr_compound.c b/tools/qfcc/source/expr_compound.c
index 26a5694f7..79f12fd9f 100644
--- a/tools/qfcc/source/expr_compound.c
+++ b/tools/qfcc/source/expr_compound.c
@@ -57,7 +57,7 @@ ALLOC_STATE (element_t, elements);
ALLOC_STATE (designator_t, designators);
designator_t *
-new_designator (expr_t *field, expr_t *index)
+new_designator (const expr_t *field, const expr_t *index)
{
if ((!field && !index) || (field && index)) {
internal_error (0, "exactly one of field or index is required");
@@ -73,7 +73,7 @@ new_designator (expr_t *field, expr_t *index)
}
element_t *
-new_element (expr_t *expr, designator_t *designator)
+new_element (const expr_t *expr, designator_t *designator)
{
element_t *element;
ALLOC (256, element_t, elements, element);
@@ -198,7 +198,7 @@ skip_field (symbol_t *field)
void
build_element_chain (element_chain_t *element_chain, const type_t *type,
- expr_t *eles, int base_offset)
+ const expr_t *eles, int base_offset)
{
element_t *ele = eles->compound.head;
@@ -304,7 +304,7 @@ append_element (expr_t *compound, element_t *element)
}
void
-assign_elements (expr_t *local_expr, expr_t *init,
+assign_elements (expr_t *local_expr, const expr_t *init,
element_chain_t *element_chain)
{
element_t *element;
@@ -314,9 +314,9 @@ assign_elements (expr_t *local_expr, expr_t *init,
for (element = element_chain->head; element; element = element->next) {
int offset = element->offset;
type_t *type = element->type;
- expr_t *alias = new_offset_alias_expr (type, init, offset);
+ const expr_t *alias = new_offset_alias_expr (type, init, offset);
- expr_t *c;
+ const expr_t *c;
if (type_size (type) == 0)
internal_error (init, "wtw");
@@ -336,9 +336,9 @@ assign_elements (expr_t *local_expr, expr_t *init,
for (set_iter_t *in = set_first (initialized); in; in = set_next (in)) {
unsigned end = in->element;
if (end > start) {
- expr_t *dst = new_offset_alias_expr (&type_int, init, start);
- expr_t *zero = new_int_expr (0);
- expr_t *count = new_int_expr (end - start);
+ auto dst = new_offset_alias_expr (&type_int, init, start);
+ auto zero = new_int_expr (0);
+ auto count = new_int_expr (end - start);
append_expr (local_expr, new_memset_expr (dst, zero, count));
}
// skip over all the initialized locations
@@ -348,21 +348,21 @@ assign_elements (expr_t *local_expr, expr_t *init,
}
}
if (start < (unsigned) type_size (init_type)) {
- expr_t *dst = new_offset_alias_expr (&type_int, init, start);
- expr_t *zero = new_int_expr (0);
- expr_t *count = new_int_expr (type_size (init_type) - start);
+ auto dst = new_offset_alias_expr (&type_int, init, start);
+ auto zero = new_int_expr (0);
+ auto count = new_int_expr (type_size (init_type) - start);
append_expr (local_expr, new_memset_expr (dst, zero, count));
}
set_delete (initialized);
}
expr_t *
-initialized_temp_expr (const type_t *type, expr_t *compound)
+initialized_temp_expr (const type_t *type, const expr_t *compound)
{
type = unalias_type (type);
element_chain_t element_chain;
expr_t *temp = new_temp_def_expr (type);
- expr_t *block = new_block_expr ();
+ expr_t *block = new_block_expr (0);
element_chain.head = 0;
element_chain.tail = &element_chain.head;
diff --git a/tools/qfcc/source/expr_dag.c b/tools/qfcc/source/expr_dag.c
index c28bc5fb2..63c977a32 100644
--- a/tools/qfcc/source/expr_dag.c
+++ b/tools/qfcc/source/expr_dag.c
@@ -40,7 +40,7 @@
#include "tools/qfcc/include/symtab.h"
#include "tools/qfcc/include/type.h"
-typedef struct DARRAY_TYPE (expr_t *) exprset_t;
+typedef struct DARRAY_TYPE (const expr_t *) exprset_t;
static exprset_t expr_dag = DARRAY_STATIC_INIT(32);
@@ -50,14 +50,14 @@ edag_flush (void)
expr_dag.size = 0;
}
-expr_t *
-edag_add_expr (expr_t *expr)
+const expr_t *
+edag_add_expr (const expr_t *expr)
{
if (!expr) {
return expr;
}
for (size_t i = 0; i < expr_dag.size; i++) {
- expr_t *e = expr_dag.a[i];
+ auto e = expr_dag.a[i];
if (e->type != expr->type) {
continue;
}
diff --git a/tools/qfcc/source/expr_obj.c b/tools/qfcc/source/expr_obj.c
index eb589cc2b..03be29b44 100644
--- a/tools/qfcc/source/expr_obj.c
+++ b/tools/qfcc/source/expr_obj.c
@@ -86,7 +86,7 @@ new_this_expr (void)
return new_symbol_expr (sym);
}
-expr_t *
+const expr_t *
selector_expr (keywordarg_t *selector)
{
dstring_t *sel_id = dstring_newstr ();
@@ -123,7 +123,7 @@ selector_expr (keywordarg_t *selector)
return sel;
}
-expr_t *
+const expr_t *
protocol_expr (const char *protocol_name)
{
protocol_t *protocol = get_protocol (protocol_name, 0);
@@ -136,12 +136,11 @@ protocol_expr (const char *protocol_name)
return new_pointer_expr (0, proto_class->type, protocol_def (protocol));
}
-expr_t *
+const expr_t *
super_expr (class_type_t *class_type)
{
symbol_t *sym;
expr_t *super;
- expr_t *e;
expr_t *super_block;
class_t *class;
@@ -161,8 +160,9 @@ super_expr (class_type_t *class_type)
}
super = new_symbol_expr (sym);
- super_block = new_block_expr ();
+ super_block = new_block_expr (0);
+ const expr_t *e;
e = assign_expr (field_expr (super, new_name_expr ("self")),
new_name_expr ("self"));
append_expr (super_block, e);
@@ -177,22 +177,22 @@ super_expr (class_type_t *class_type)
return super_block;
}
-expr_t *
-message_expr (expr_t *receiver, keywordarg_t *message)
+const expr_t *
+message_expr (const expr_t *receiver, keywordarg_t *message)
{
- expr_t *selector = selector_expr (message);
- expr_t *call;
+ const expr_t *selector = selector_expr (message);
+ const expr_t *call;
keywordarg_t *m;
int super = 0, class_msg = 0;
type_t *rec_type = 0;
type_t *return_type;
type_t *method_type = &type_IMP;
method_t *method;
- expr_t *send_msg;
+ const expr_t *send_msg;
if (receiver->type == ex_nil) {
rec_type = &type_id;
- convert_nil (receiver, rec_type);
+ receiver = convert_nil (receiver, rec_type);
} else if (receiver->type == ex_symbol) {
if (strcmp (receiver->symbol->name, "self") == 0) {
rec_type = get_type (receiver);
@@ -229,7 +229,6 @@ message_expr (expr_t *receiver, keywordarg_t *message)
for (m = message; m; m = m->next) {
if (m->expr && m->expr->list.head) {
list_append_list (args, &m->expr->list);
- expr_file_line (selector, m->expr);
}
}
list_append_expr (args, selector);
@@ -237,7 +236,7 @@ message_expr (expr_t *receiver, keywordarg_t *message)
send_msg = expr_file_line (send_message (super), receiver);
if (method) {
- expr_t *err;
+ const expr_t *err;
if ((err = method_check_params (method, args)))
return err;
method_type = method->type;
@@ -250,6 +249,6 @@ message_expr (expr_t *receiver, keywordarg_t *message)
if (!is_function_call (call)) {
internal_error (call, "unexpected call expression type");
}
- call->block.result->branch.ret_type = return_type;
+ ((expr_t *) call->block.result)->branch.ret_type = return_type;
return call;
}
diff --git a/tools/qfcc/source/expr_vector.c b/tools/qfcc/source/expr_vector.c
index fc6e99ea9..1dced7ec1 100644
--- a/tools/qfcc/source/expr_vector.c
+++ b/tools/qfcc/source/expr_vector.c
@@ -36,12 +36,12 @@
#include "tools/qfcc/include/type.h"
#include "tools/qfcc/include/value.h"
-expr_t *
-new_vector_list (expr_t *expr_list)
+const expr_t *
+new_vector_list (const expr_t *expr_list)
{
type_t *ele_type = type_default;
int count = list_count (&expr_list->list);
- expr_t *elements[count + 1];
+ const expr_t *elements[count + 1];
list_scatter (&expr_list->list, elements);
elements[count] = 0;
@@ -91,8 +91,8 @@ new_vector_list (expr_t *expr_list)
// be only one, but futhre...)
for (int i = 1; i < count; i++) {
if (is_nonscalar (get_type (elements[i]))) {
- expr_t *t = elements[i];
- int j = i;
+ auto t = elements[i];
+ int j = i;
for (; j > 0 && is_scalar (get_type (elements[j])); j--) {
elements[j] = elements[j - 1];
}
@@ -104,7 +104,7 @@ new_vector_list (expr_t *expr_list)
if (is_scalar (get_type (elements[0]))
&& is_nonscalar (get_type (elements[1]))) {
// swap s, v to be v, s (ie, vector always comes before scalar)
- expr_t *t = elements[0];
+ auto t = elements[0];
elements[0] = elements[1];
elements[1] = t;
}
@@ -127,13 +127,14 @@ new_vector_list (expr_t *expr_list)
offs += type_size (src_type);
}
- expr_t *vec = new_value_expr (new_type_value (vec_type, value));
+ auto vec = (expr_t *) new_value_expr (new_type_value (vec_type, value));
vec->implicit = all_implicit;
return vec;
}
for (int i = 0; i < count; i++) {
- elements[i]->next = elements[i + 1];
+ //FIXME this should use ex_list
+ ((expr_t *) elements[i])->next = (expr_t *) elements[i + 1];
}
expr_t *vec = new_expr ();
diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c
index f4df88972..8dda90dc7 100644
--- a/tools/qfcc/source/function.c
+++ b/tools/qfcc/source/function.c
@@ -346,8 +346,22 @@ func_compare (const void *a, const void *b)
return 0;
}
-expr_t *
-find_function (expr_t *fexpr, expr_t *params)
+static const expr_t *
+set_func_symbol (const expr_t *fexpr, overloaded_function_t *f)
+{
+ auto sym = symtab_lookup (current_symtab, f->full_name);
+ if (!sym) {
+ internal_error (fexpr, "overloaded function %s not found",
+ f->full_name);
+ }
+ auto nf = new_expr ();
+ *nf = *fexpr;
+ nf->symbol = sym;
+ return nf;
+}
+
+const expr_t *
+find_function (const expr_t *fexpr, const expr_t *params)
{
int i, j, func_count, parm_count, reported = 0;
overloaded_function_t *f, dummy, *best = 0;
@@ -359,7 +373,7 @@ find_function (expr_t *fexpr, expr_t *params)
type.type = ev_func;
type.t.func.num_params = params ? list_count (¶ms->list) : 0;
- expr_t *args[type.t.func.num_params];
+ const expr_t *args[type.t.func.num_params];
if (params) {
list_scatter_rev (¶ms->list, args);
}
@@ -399,10 +413,7 @@ find_function (expr_t *fexpr, expr_t *params)
if (dummy_p) {
f = (overloaded_function_t *) *(void **) dummy_p;
if (f->overloaded) {
- fexpr->symbol = symtab_lookup (current_symtab, f->full_name);
- if (!fexpr->symbol)
- internal_error (fexpr, "overloaded function %s not found",
- best->full_name);
+ fexpr = set_func_symbol (fexpr, f);
}
free (funcs);
return fexpr;
@@ -447,11 +458,7 @@ find_function (expr_t *fexpr, expr_t *params)
return fexpr;
if (best) {
if (best->overloaded) {
- fexpr->symbol = symtab_lookup (current_symtab,
- best->full_name);
- if (!fexpr->symbol)
- internal_error (fexpr, "overloaded function %s not found",
- best->full_name);
+ fexpr = set_func_symbol (fexpr, best);
}
free (funcs);
return fexpr;
@@ -743,7 +750,8 @@ merge_spaces (defspace_t *dst, defspace_t *src, int alignment)
}
function_t *
-build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements)
+build_code_function (symbol_t *fsym, const expr_t *state_expr,
+ expr_t *statements)
{
if (fsym->sy_type != sy_func) // probably in error recovery
return 0;
@@ -759,7 +767,7 @@ build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements)
* optimizer gets.
*/
expr_t *e;
- expr_t *entry = new_block_expr ();
+ expr_t *entry = new_block_expr (0);
entry->file = func->def->file;
entry->line = func->def->line;
@@ -842,7 +850,7 @@ build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements)
}
function_t *
-build_builtin_function (symbol_t *sym, expr_t *bi_val, int far,
+build_builtin_function (symbol_t *sym, const expr_t *bi_val, int far,
storage_class_t storage)
{
int bi;
diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c
index 921e930e2..7604e1f51 100644
--- a/tools/qfcc/source/method.c
+++ b/tools/qfcc/source/method.c
@@ -483,7 +483,7 @@ selector_index (const char *sel_id)
}
selector_t *
-get_selector (expr_t *sel)
+get_selector (const expr_t *sel)
{
selector_t _sel = {0, 0, 0};
@@ -700,8 +700,8 @@ clear_selectors (void)
Hash_FlushTable (known_methods);
}
-expr_t *
-method_check_params (method_t *method, expr_t *args)
+const expr_t *
+method_check_params (method_t *method, const expr_t *args)
{
int i, param_count;
expr_t *err = 0;
@@ -721,10 +721,10 @@ method_check_params (method_t *method, expr_t *args)
if (mtype->t.func.num_params >= 0 && count > mtype->t.func.num_params)
return error (args, "too many arguments");
- expr_t *arg_list[count];
+ const expr_t *arg_list[count];
list_scatter_rev (&args->list, arg_list);
for (i = 2; i < count; i++) {
- expr_t *e = arg_list[i];
+ const expr_t *e = arg_list[i];
type_t *arg_type = mtype->t.func.param_types[i];
type_t *t;
diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l
index 037898396..e99e3a557 100644
--- a/tools/qfcc/source/qc-lex.l
+++ b/tools/qfcc/source/qc-lex.l
@@ -81,8 +81,8 @@ FILE *yyget_in (void) __attribute__((pure));
FILE *yyget_out (void) __attribute__((pure));
static int keyword_or_id (const char *token);
-static expr_t *parse_float_vector (const char *token, int width);
-static expr_t *parse_int_vector (const char *token, int width);
+static const expr_t *parse_float_vector (const char *token, int width);
+static const expr_t *parse_int_vector (const char *token, int width);
extern QC_YYSTYPE qc_yylval;
@@ -149,7 +149,7 @@ STRING \"(\\.|[^"\\])*\"
qc_yylval.expr = new_long_expr (i);
} else {
qc_yylval.expr = new_int_expr (i);
- qc_yylval.expr->implicit = 1;
+ ((expr_t *) qc_yylval.expr)->implicit = 1;
}
}
return VALUE;
@@ -160,8 +160,7 @@ STRING \"(\\.|[^"\\])*\"
// and extended code defaults to float
if (options.traditional < 1) {
double d = strtod (yytext, 0);
- qc_yylval.expr = new_double_expr (d);
- qc_yylval.expr->implicit = 1;
+ qc_yylval.expr = new_double_expr (d, true);
} else {
float f = strtof (yytext, 0);
qc_yylval.expr = new_float_expr (f);
@@ -178,7 +177,7 @@ STRING \"(\\.|[^"\\])*\"
// and extended code defaults to float
if (options.traditional < 1) {
double d = strtod (yytext, 0);
- qc_yylval.expr = new_double_expr (d);
+ qc_yylval.expr = new_double_expr (d, false);
} else {
float f = strtof (yytext, 0);
qc_yylval.expr = new_float_expr (f);
@@ -586,7 +585,7 @@ keyword_or_id (const char *token)
return NAME;
}
-static expr_t *
+static const expr_t *
parse_int_vector (const char *token, int width)
{
char t1 = 0, t2 = 0;
@@ -622,7 +621,7 @@ parse_int_vector (const char *token, int width)
t1 = 'f';
}
}
- expr_t *expr = 0;
+ const expr_t *expr = 0;
switch (t1) {
case 'u':
if (t2 == 'l') {
@@ -704,11 +703,11 @@ parse_int_vector (const char *token, int width)
expr = new_value_expr (new_type_value (type, data));
break;
}
- expr->implicit = !t1;
+ ((expr_t *) expr)->implicit = !t1;
return expr;
}
-static expr_t *
+static const expr_t *
parse_float_vector (const char *token, int width)
{
char t = 0;
@@ -762,7 +761,7 @@ parse_float_vector (const char *token, int width)
type = &type_double;
}
type = vector_type (type, width);
- expr_t *expr = new_value_expr (new_type_value (type, data));
+ auto expr = (expr_t *) new_value_expr (new_type_value (type, data));
expr->implicit = !t;
return expr;
}
diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y
index 9a5673f6c..bafe77927 100644
--- a/tools/qfcc/source/qc-parse.y
+++ b/tools/qfcc/source/qc-parse.y
@@ -99,7 +99,8 @@ int yylex (void);
specifier_t spec;
void *pointer; // for ensuring pointer values are null
struct type_s *type;
- struct expr_s *expr;
+ const struct expr_s *expr;
+ struct expr_s *mut_expr;
struct element_s *element;
struct function_s *function;
struct switch_block_s *switch_block;
@@ -194,20 +195,24 @@ int yylex (void);
%type methoddef
%type var_initializer local_def
-%type opt_init_semi opt_expr comma_expr expr
-%type compound_init element_list
+%type opt_init_semi opt_expr comma_expr
+%type expr
+%type compound_init
+%type element_list expr_list
%type designator designator_spec
%type element
%type method_optional_state_expr optional_state_expr
%type texpr vector_expr
-%type statement statements compound_statement
+%type statement
+%type statements compound_statement
%type else bool_label break_label continue_label
-%type unary_expr ident_expr cast_expr expr_list
-%type opt_arg_list arg_list arg_expr
+%type unary_expr ident_expr cast_expr
+%type opt_arg_list arg_list
+%type arg_expr
%type switch_block
%type identifier label
-%type identifier_list
+%type identifier_list
%type protocol_name_list selector reserved_word
%type optional_param_list unaryselector keyworddecl
%type keywordselector
@@ -227,8 +232,8 @@ int yylex (void);
%{
static switch_block_t *switch_block;
-static expr_t *break_label;
-static expr_t *continue_label;
+static const expr_t *break_label;
+static const expr_t *continue_label;
static specifier_t
make_spec (type_t *type, storage_class_t storage, int is_typedef,
@@ -645,7 +650,7 @@ qc_nocode_func
{
specifier_t spec = $0;
symbol_t *sym = $1;
- expr_t *expr = $4;
+ const expr_t *expr = $4;
sym = qc_function_symbol (spec, sym);
build_builtin_function (sym, expr, 0, spec.storage);
}
@@ -1396,7 +1401,7 @@ local_expr
: /* emtpy */
{
$$ = $0;
- local_expr = new_block_expr ();
+ local_expr = new_block_expr (0);
}
;
@@ -1507,7 +1512,7 @@ compound_statement
statements
: /*empty*/
{
- $$ = new_block_expr ();
+ $$ = new_block_expr (0);
}
| statements flush_dag statement
{
@@ -1564,7 +1569,7 @@ statement
}
| GOTO NAME
{
- expr_t *label = named_label_expr ($2);
+ const expr_t *label = named_label_expr ($2);
$$ = goto_expr (label);
}
| IF not '(' texpr ')' flush_dag statement %prec IFX
@@ -1687,7 +1692,7 @@ switch_block
opt_init_semi
: comma_expr seq_semi
- | decl /* contains ; */
+ | decl /* contains ; */ { $$ = (expr_t *) $1; }
| ';'
{
$$ = 0;
@@ -1708,7 +1713,7 @@ unary_expr
| SELF { $$ = new_self_expr (); }
| THIS { $$ = new_this_expr (); }
| const { $$ = $1; }
- | '(' expr ')' { $$ = $2; $$->paren = 1; }
+ | '(' expr ')' { $$ = $2; ((expr_t *) $$)->paren = 1; }
| unary_expr '(' opt_arg_list ')' { $$ = function_expr ($1, $3); }
| unary_expr '[' expr ']' { $$ = array_expr ($1, $3); }
| unary_expr '.' ident_expr { $$ = field_expr ($1, $3); }
@@ -1797,7 +1802,7 @@ comma_expr
if ($1->list.head->next) {
$$ = build_block_expr ($1, true);
} else {
- $$ = $1->list.head->expr;
+ $$ = (expr_t *) $1->list.head->expr;
}
}
;
@@ -1861,7 +1866,7 @@ obj_def
identifier_list
: identifier
{
- $$ = append_expr (new_block_expr (), new_symbol_expr ($1));
+ $$ = append_expr (new_block_expr (0), new_symbol_expr ($1));
}
| identifier_list ',' identifier
{
diff --git a/tools/qfcc/source/qp-parse.y b/tools/qfcc/source/qp-parse.y
index 6afa6c82b..55609327a 100644
--- a/tools/qfcc/source/qp-parse.y
+++ b/tools/qfcc/source/qp-parse.y
@@ -85,7 +85,8 @@ int yylex (void);
struct hashtab_s *def_list;
struct type_s *type;
struct typedef_s *typename;
- struct expr_s *expr;
+ const struct expr_s *expr;
+ struct expr_s *mut_expr;
struct function_s *function;
struct switch_block_s *switch_block;
struct param_s *param;
@@ -134,9 +135,11 @@ int yylex (void);
%type program_head identifier_list subprogram_head
%type param_scope
%type arguments parameter_list
-%type compound_statement else optional_statements statement_list
+%type compound_statement optional_statements statement_list
+%type else
%type statement procedure_statement
-%type expression_list expression unary_expr primary variable name
+%type expression_list
+%type expression unary_expr primary variable name
%type sign
%{
@@ -158,7 +161,7 @@ build_dotmain (symbol_t *program)
current_func = begin_function (dotmain, 0, current_symtab, 0,
current_storage);
current_symtab = current_func->locals;
- code = new_block_expr ();
+ code = new_block_expr (0);
append_expr (code, function_expr (new_symbol_expr (program), 0));
append_expr (code, return_expr (current_func, exitcode));
build_code_function (dotmain, 0, code);
@@ -389,7 +392,7 @@ opt_semi
statement_list
: statement
{
- $$ = new_block_expr ();
+ $$ = new_block_expr (0);
append_expr ($$, $1);
}
| statement_list ';' statement
@@ -419,6 +422,9 @@ statement
}
| procedure_statement
| compound_statement
+ {
+ $$ = $1;
+ }
| IF expression THEN statement else statement
{
$$ = build_if_statement (0, $2, $4, $5, $6);
diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c
index d8ed76686..c529f37e6 100644
--- a/tools/qfcc/source/statements.c
+++ b/tools/qfcc/source/statements.c
@@ -243,7 +243,7 @@ sblock_add_statement (sblock_t *sblock, statement_t *statement)
}
statement_t *
-new_statement (st_type_t type, const char *opcode, expr_t *expr)
+new_statement (st_type_t type, const char *opcode, const expr_t *expr)
{
statement_t *statement;
ALLOC (256, statement_t, statements, statement);
@@ -292,7 +292,7 @@ new_pseudoop (const char *name)
}
static operand_t *
-new_operand (op_type_e op, expr_t *expr, void *return_addr)
+new_operand (op_type_e op, const expr_t *expr, void *return_addr)
{
operand_t *operand;
ALLOC (256, operand_t, operands, operand);
@@ -344,7 +344,7 @@ free_sblock (sblock_t *sblock)
}
static operand_t *
-pseudo_operand (pseudoop_t *pseudoop, expr_t *expr)
+pseudo_operand (pseudoop_t *pseudoop, const expr_t *expr)
{
operand_t *op;
op = new_operand (op_pseudo, expr, __builtin_return_address (0));
@@ -354,7 +354,7 @@ pseudo_operand (pseudoop_t *pseudoop, expr_t *expr)
}
operand_t *
-nil_operand (type_t *type, expr_t *expr)
+nil_operand (type_t *type, const expr_t *expr)
{
operand_t *op;
op = new_operand (op_nil, expr, __builtin_return_address (0));
@@ -365,7 +365,7 @@ nil_operand (type_t *type, expr_t *expr)
}
operand_t *
-def_operand (def_t *def, type_t *type, expr_t *expr)
+def_operand (def_t *def, type_t *type, const expr_t *expr)
{
operand_t *op;
@@ -380,7 +380,7 @@ def_operand (def_t *def, type_t *type, expr_t *expr)
}
operand_t *
-return_operand (type_t *type, expr_t *expr)
+return_operand (type_t *type, const expr_t *expr)
{
symbol_t *return_symbol;
return_symbol = make_symbol (".return", &type_param, pr.symtab->space,
@@ -393,7 +393,7 @@ return_operand (type_t *type, expr_t *expr)
}
operand_t *
-value_operand (ex_value_t *value, expr_t *expr)
+value_operand (ex_value_t *value, const expr_t *expr)
{
operand_t *op;
op = new_operand (op_value, expr, __builtin_return_address (0));
@@ -405,12 +405,12 @@ value_operand (ex_value_t *value, expr_t *expr)
}
operand_t *
-temp_operand (type_t *type, expr_t *expr)
+temp_operand (const type_t *type, const expr_t *expr)
{
operand_t *op = new_operand (op_temp, expr, __builtin_return_address (0));
- op->tempop.type = type;
- op->type = type;
+ op->tempop.type = (type_t *) type;
+ op->type = (type_t *) type;
op->size = type_size (type);
op->width = type_width (type);
return op;
@@ -475,7 +475,7 @@ tempop_visit_all (tempop_t *tempop, int overlap,
}
operand_t *
-offset_alias_operand (type_t *type, int offset, operand_t *aop, expr_t *expr)
+offset_alias_operand (type_t *type, int offset, operand_t *aop, const expr_t *expr)
{
operand_t *top;
def_t *def;
@@ -534,7 +534,7 @@ offset_alias_operand (type_t *type, int offset, operand_t *aop, expr_t *expr)
}
operand_t *
-alias_operand (type_t *type, operand_t *op, expr_t *expr)
+alias_operand (type_t *type, operand_t *op, const expr_t *expr)
{
operand_t *aop;
@@ -552,7 +552,7 @@ alias_operand (type_t *type, operand_t *op, expr_t *expr)
}
operand_t *
-label_operand (expr_t *label)
+label_operand (const expr_t *label)
{
operand_t *lop;
@@ -560,12 +560,12 @@ label_operand (expr_t *label)
internal_error (label, "not a label expression");
}
lop = new_operand (op_label, label, __builtin_return_address (0));
- lop->label = &label->label;
+ lop->label = (ex_label_t *) &label->label;
return lop;
}
static operand_t *
-short_operand (short short_val, expr_t *expr)
+short_operand (short short_val, const expr_t *expr)
{
ex_value_t *val = new_short_val (short_val);
return value_operand (val, expr);
@@ -718,21 +718,21 @@ invert_conditional (statement_t *s)
s->opcode = "ifbe";
}
-typedef sblock_t *(*statement_f) (sblock_t *, expr_t *);
-typedef sblock_t *(*expr_f) (sblock_t *, expr_t *, operand_t **);
+typedef sblock_t *(*statement_f) (sblock_t *, const expr_t *);
+typedef sblock_t *(*expr_f) (sblock_t *, const expr_t *, operand_t **);
-static sblock_t *statement_subexpr (sblock_t *sblock, expr_t *e,
+static sblock_t *statement_subexpr (sblock_t *sblock, const expr_t *e,
operand_t **op);
-static sblock_t *expr_symbol (sblock_t *sblock, expr_t *e, operand_t **op);
-static sblock_t *expr_def (sblock_t *sblock, expr_t *e, operand_t **op);
-static sblock_t *statement_single (sblock_t *sblock, expr_t *e);
+static sblock_t *expr_symbol (sblock_t *sblock, const expr_t *e, operand_t **op);
+static sblock_t *expr_def (sblock_t *sblock, const expr_t *e, operand_t **op);
+static sblock_t *statement_single (sblock_t *sblock, const expr_t *e);
static sblock_t *
-expr_address (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_address (sblock_t *sblock, const expr_t *e, operand_t **op)
{
statement_t *s;
- expr_t *lvalue = e->address.lvalue;
- expr_t *offset = e->address.offset;
+ const expr_t *lvalue = e->address.lvalue;
+ const expr_t *offset = e->address.offset;
if (lvalue->type == ex_alias && offset && is_constant (offset)) {
lvalue = new_offset_alias_expr (lvalue->alias.type,
@@ -742,7 +742,8 @@ expr_address (sblock_t *sblock, expr_t *e, operand_t **op)
} else if (offset && is_constant (offset)) {
int o = expr_int (offset);
if (o < 32768 && o >= -32768) {
- offset = expr_file_line (new_short_expr (o), offset);
+ offset = new_short_expr (o);
+ //offset = expr_file_line (new_short_expr (o), offset);
}
}
@@ -758,7 +759,7 @@ expr_address (sblock_t *sblock, expr_t *e, operand_t **op)
}
static operand_t *
-operand_address (operand_t *reference, expr_t *e)
+operand_address (operand_t *reference, const expr_t *e)
{
def_t *def;
type_t *type;
@@ -798,7 +799,7 @@ operand_address (operand_t *reference, expr_t *e)
}
static __attribute__((pure)) int
-is_indirect (expr_t *e)
+is_indirect (const expr_t *e)
{
if ((e->type == ex_expr || e->type == ex_uexpr)
&& e->expr.op == '.') {
@@ -807,14 +808,14 @@ is_indirect (expr_t *e)
return 0;
}
-static sblock_t *addressing_mode (sblock_t *sblock, expr_t *ref,
+static sblock_t *addressing_mode (sblock_t *sblock, const expr_t *ref,
operand_t **base, operand_t **offset,
pr_ushort_t *mode, operand_t **target);
static statement_t *lea_statement (operand_t *pointer, operand_t *offset,
- expr_t *e);
+ const expr_t *e);
static statement_t *
-assign_statement (operand_t *dst, operand_t *src, expr_t *e)
+assign_statement (operand_t *dst, operand_t *src, const expr_t *e)
{
statement_t *s = new_statement (st_assign, "assign", e);
s->opa = dst;
@@ -823,15 +824,15 @@ assign_statement (operand_t *dst, operand_t *src, expr_t *e)
}
static sblock_t *
-expr_assign_copy (sblock_t *sblock, expr_t *e, operand_t **op, operand_t *src)
+expr_assign_copy (sblock_t *sblock, const expr_t *e, operand_t **op, operand_t *src)
{
statement_t *s;
- expr_t *dst_expr = e->assign.dst;
- expr_t *src_expr = e->assign.src;
+ const expr_t *dst_expr = e->assign.dst;
+ const expr_t *src_expr = e->assign.src;
type_t *dst_type = get_type (dst_expr);
type_t *src_type = get_type (src_expr);
unsigned count;
- expr_t *count_expr;
+ const expr_t *count_expr;
operand_t *dst = 0;
operand_t *size = 0;
static const char *opcode_sets[][2] = {
@@ -862,7 +863,8 @@ expr_assign_copy (sblock_t *sblock, expr_t *e, operand_t **op, operand_t *src)
}
} else {
if (is_indirect (src_expr)) {
- src_expr = expr_file_line (address_expr (src_expr, 0), e);
+ //src_expr = expr_file_line (address_expr (src_expr, 0), e);
+ src_expr = address_expr (src_expr, 0);
need_ptr = 1;
}
if (!src) {
@@ -911,7 +913,8 @@ expr_assign_copy (sblock_t *sblock, expr_t *e, operand_t **op, operand_t *src)
//FIXME is this even necessary? if it is, should use copy_operand
sblock = statement_subexpr (sblock, dst_expr, &kill);
}
- dst_expr = expr_file_line (address_expr (dst_expr, 0), e);
+ //dst_expr = expr_file_line (address_expr (dst_expr, 0), e);
+ dst_expr = address_expr (dst_expr, 0);
need_ptr = 1;
}
sblock = statement_subexpr (sblock, dst_expr, &dst);
@@ -922,9 +925,11 @@ expr_assign_copy (sblock_t *sblock, expr_t *e, operand_t **op, operand_t *src)
}
count = min (type_size (dst_type), type_size (src_type));
if (count < (1 << 16)) {
- count_expr = expr_file_line (new_short_expr (count), e);
+ //count_expr = expr_file_line (new_short_expr (count), e);
+ count_expr = new_short_expr (count);
} else {
- count_expr = expr_file_line (new_int_expr (count), e);
+ //count_expr = expr_file_line (new_int_expr (count), e);
+ count_expr = new_int_expr (count);
}
sblock = statement_subexpr (sblock, count_expr, &size);
@@ -947,11 +952,11 @@ expr_assign_copy (sblock_t *sblock, expr_t *e, operand_t **op, operand_t *src)
}
static sblock_t *
-expr_assign (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_assign (sblock_t *sblock, const expr_t *e, operand_t **op)
{
statement_t *s;
- expr_t *src_expr = e->assign.src;
- expr_t *dst_expr = e->assign.dst;
+ const expr_t *src_expr = e->assign.src;
+ const expr_t *dst_expr = e->assign.dst;
type_t *dst_type = get_type (dst_expr);
operand_t *src = 0;
operand_t *dst = 0;
@@ -1020,7 +1025,8 @@ dereference_dst:
// need to get a pointer type, entity.field expressions do not provide
// one directly. FIXME it was probably a mistake extracting the operand
// type from the statement expression in dags
- dst_expr = expr_file_line (address_expr (dst_expr, 0), dst_expr);
+ //dst_expr = expr_file_line (address_expr (dst_expr, 0), dst_expr);
+ dst_expr = address_expr (dst_expr, 0);
s = new_statement (st_address, "lea", dst_expr);
s->opa = dst;
s->opb = ofs;
@@ -1042,11 +1048,11 @@ dereference_dst:
}
static sblock_t *
-vector_call (sblock_t *sblock, expr_t *earg, expr_t *param, int ind,
+vector_call (sblock_t *sblock, const expr_t *earg, const expr_t *param, int ind,
operand_t **op)
{
//FIXME this should be done in the expression tree
- expr_t *a, *v, *n;
+ const expr_t *a, *v, *n;
int i;
static const char *names[] = {"x", "y", "z"};
@@ -1055,8 +1061,8 @@ vector_call (sblock_t *sblock, expr_t *earg, expr_t *param, int ind,
v = new_float_expr (earg->value->v.vector_val[i]);
a = assign_expr (field_expr (param, n), v);
param = new_param_expr (get_type (earg), ind);
- a->line = earg->line;
- a->file = earg->file;
+ //a->line = earg->line;
+ //a->file = earg->file;
sblock = statement_single (sblock, a);
}
sblock = statement_subexpr (sblock, param, op);
@@ -1064,11 +1070,11 @@ vector_call (sblock_t *sblock, expr_t *earg, expr_t *param, int ind,
}
static sblock_t *
-expr_call_v6p (sblock_t *sblock, expr_t *call, operand_t **op)
+expr_call_v6p (sblock_t *sblock, const expr_t *call, operand_t **op)
{
- expr_t *func = call->branch.target;
- expr_t *args = call->branch.args;
- expr_t *param;
+ const expr_t *func = call->branch.target;
+ const expr_t *args = call->branch.args;
+ const expr_t *param;
operand_t *arguments[2] = {0, 0};
int count = 0;
int ind;
@@ -1110,9 +1116,9 @@ expr_call_v6p (sblock_t *sblock, expr_t *call, operand_t **op)
continue;
}
if (is_struct (get_type (param)) || is_union (get_type (param))) {
- expr_t *mov = assign_expr (param, a);
- mov->line = a->line;
- mov->file = a->file;
+ const expr_t *mov = assign_expr (param, a);
+ //mov->line = a->line;
+ //mov->file = a->file;
sblock = statement_single (sblock, mov);
} else {
operand_t *p = 0;
@@ -1148,7 +1154,7 @@ expr_call_v6p (sblock_t *sblock, expr_t *call, operand_t **op)
}
static sblock_t *
-expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
+expr_call (sblock_t *sblock, const expr_t *call, operand_t **op)
{
if (options.code.progsversion < PROG_VERSION) {
return expr_call_v6p (sblock, call, op);
@@ -1157,9 +1163,9 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
current_func->arguments = defspace_new (ds_virtual);
}
defspace_t *arg_space = current_func->arguments;
- expr_t *func = call->branch.target;
- expr_t *args_va_list = 0; // .args (...) parameter
- expr_t *args_params = 0; // first arg in ...
+ const expr_t *func = call->branch.target;
+ const expr_t *args_va_list = 0; // .args (...) parameter
+ const expr_t *args_params = 0; // first arg in ...
operand_t *use = 0;
operand_t *kill = 0;
int num_params = 0;
@@ -1167,11 +1173,11 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
defspace_reset (arg_space);
int num_args = list_count (&call->branch.args->list);
- expr_t *args[num_args];
+ const expr_t *args[num_args];
list_scatter_rev (&call->branch.args->list, args);
int arg_num = 0;
for (int i = 0; i < num_args; i++) {
- expr_t *a = args[i];
+ const expr_t *a = args[i];
const char *arg_name = va (0, ".arg%d", arg_num++);
def_t *def = new_def (arg_name, 0, current_func->arguments,
sc_argument);
@@ -1185,7 +1191,7 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
alignment);
def->type = arg_type;
def->reg = current_func->temp_reg;
- expr_t *def_expr = expr_file_line (new_def_expr (def), call);
+ const expr_t *def_expr = expr_file_line (new_def_expr (def), call);
if (a->type == ex_args) {
args_va_list = def_expr;
} else {
@@ -1195,8 +1201,8 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
if (args_va_list) {
num_params++;
}
- expr_t *assign = assign_expr (def_expr, a);
- expr_file_line (assign, call);
+ const expr_t *assign = assign_expr (def_expr, a);
+ //expr_file_line (assign, call);
sblock = statement_single (sblock, assign);
}
@@ -1212,19 +1218,19 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
kill = k;
}
if (args_va_list) {
- expr_t *assign;
- expr_t *count;
- expr_t *list;
- expr_t *args_count = field_expr (args_va_list,
+ const expr_t *assign;
+ const expr_t *count;
+ const expr_t *list;
+ const expr_t *args_count = field_expr (args_va_list,
new_name_expr ("count"));
- expr_t *args_list = field_expr (args_va_list,
+ const expr_t *args_list = field_expr (args_va_list,
new_name_expr ("list"));
- expr_file_line (args_count, call);
- expr_file_line (args_list, call);
+ //expr_file_line (args_count, call);
+ //expr_file_line (args_list, call);
count = new_short_expr (num_params);
assign = assign_expr (args_count, count);
- expr_file_line (assign, call);
+ //expr_file_line (assign, call);
sblock = statement_single (sblock, assign);
if (args_params) {
@@ -1232,9 +1238,9 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
} else {
list = new_nil_expr ();
}
- expr_file_line (list, call);
+ //expr_file_line (list, call);
assign = assign_expr (args_list, list);
- expr_file_line (assign, call);
+ //expr_file_line (assign, call);
sblock = statement_single (sblock, assign);
}
statement_t *s = new_statement (st_func, "call", call);
@@ -1255,7 +1261,7 @@ expr_call (sblock_t *sblock, expr_t *call, operand_t **op)
}
static sblock_t *
-expr_branch (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_branch (sblock_t *sblock, const expr_t *e, operand_t **op)
{
if (e->branch.type != pr_branch_call) {
internal_error (e, "unexpected branch type in expression: %d",
@@ -1265,7 +1271,7 @@ expr_branch (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-statement_branch (sblock_t *sblock, expr_t *e)
+statement_branch (sblock_t *sblock, const expr_t *e)
{
static const char *opcodes[] = {
"ifz",
@@ -1305,7 +1311,7 @@ statement_branch (sblock_t *sblock, expr_t *e)
}
static operand_t *
-find_def_operand (expr_t *ref)
+find_def_operand (const expr_t *ref)
{
operand_t *op = 0;
if (ref->type == ex_alias) {
@@ -1326,7 +1332,7 @@ find_def_operand (expr_t *ref)
}
static sblock_t *
-ptr_addressing_mode (sblock_t *sblock, expr_t *ref,
+ptr_addressing_mode (sblock_t *sblock, const expr_t *ref,
operand_t **base, operand_t **offset, pr_ushort_t *mode,
operand_t **target)
{
@@ -1339,9 +1345,9 @@ ptr_addressing_mode (sblock_t *sblock, expr_t *ref,
&& ref->address.lvalue->type == ex_alias
&& (!ref->address.lvalue->alias.offset
|| is_constant (ref->address.lvalue->alias.offset))) {
- expr_t *lvalue = ref->address.lvalue;
- expr_t *offs = ref->address.offset;
- expr_t *alias;
+ const expr_t *lvalue = ref->address.lvalue;
+ const expr_t *offs = ref->address.offset;
+ const expr_t *alias;
if (lvalue->alias.offset) {
if (offs) {
offs = binary_expr ('+', offs, lvalue->alias.offset);
@@ -1351,7 +1357,7 @@ ptr_addressing_mode (sblock_t *sblock, expr_t *ref,
}
type = type->t.fldptr.type;
if (offs) {
- expr_t *lv = lvalue->alias.expr;
+ const expr_t *lv = lvalue->alias.expr;
type_t *lvtype = get_type (lv);
int o = expr_int (offs);
if (o < 0 || o + type_size (type) > type_size (lvtype)) {
@@ -1364,7 +1370,7 @@ ptr_addressing_mode (sblock_t *sblock, expr_t *ref,
} else {
alias = new_alias_expr (type, lvalue->alias.expr);
}
- expr_file_line (alias, ref);
+ //expr_file_line (alias, ref);
return addressing_mode (sblock, alias, base, offset, mode, target);
} else if (ref->type != ex_alias || ref->alias.offset) {
// probably just a pointer
@@ -1381,7 +1387,7 @@ just_a_pointer:
if (!is_integral (get_type (ref->alias.expr))) {
internal_error (ref, "expected integer expr in ref");
}
- expr_t *intptr = ref->alias.expr;
+ const expr_t *intptr = ref->alias.expr;
if (intptr->type != ex_expr
|| (intptr->expr.op != '+'
&& intptr->expr.op != '-')) {
@@ -1390,8 +1396,8 @@ just_a_pointer:
*offset = short_operand (0, ref);
*mode = 2; // mode C: ptr + constant index
} else {
- expr_t *ptr = intptr->expr.e1;
- expr_t *offs = intptr->expr.e2;
+ const expr_t *ptr = intptr->expr.e1;
+ const expr_t *offs = intptr->expr.e2;
int const_offs;
if (target) {
if (ptr->type == ex_alias
@@ -1419,7 +1425,7 @@ just_a_pointer:
}
static sblock_t *
-addressing_mode (sblock_t *sblock, expr_t *ref,
+addressing_mode (sblock_t *sblock, const expr_t *ref,
operand_t **base, operand_t **offset, pr_ushort_t *mode,
operand_t **target)
{
@@ -1427,8 +1433,8 @@ addressing_mode (sblock_t *sblock, expr_t *ref,
// ref is known to be either ex_expr or ex_uexpr, with '.' for
// the operator
if (ref->type == ex_expr) {
- expr_t *ent_expr = ref->expr.e1;
- expr_t *fld_expr = ref->expr.e2;
+ const expr_t *ent_expr = ref->expr.e1;
+ const expr_t *fld_expr = ref->expr.e2;
if (!is_entity (get_type (ent_expr))
|| !is_field (get_type (fld_expr))) {
print_expr (ref);
@@ -1454,7 +1460,7 @@ addressing_mode (sblock_t *sblock, expr_t *ref,
}
static sblock_t *
-statement_return (sblock_t *sblock, expr_t *e)
+statement_return (sblock_t *sblock, const expr_t *e)
{
const char *opcode;
statement_t *s;
@@ -1463,13 +1469,16 @@ statement_return (sblock_t *sblock, expr_t *e)
opcode = "return";
if (!e->retrn.ret_val) {
if (options.code.progsversion == PROG_ID_VERSION) {
- e->retrn.ret_val = new_float_expr (0);
+ auto n = new_expr ();
+ *n = *e;
+ n->retrn.ret_val = new_float_expr (0);
+ e = n;
}
}
s = new_statement (st_func, opcode, e);
if (options.code.progsversion < PROG_VERSION) {
if (e->retrn.ret_val) {
- expr_t *ret_val = e->retrn.ret_val;
+ const expr_t *ret_val = e->retrn.ret_val;
type_t *ret_type = get_type (ret_val);
// at_return is used for passing the result of a void_return
@@ -1483,7 +1492,7 @@ statement_return (sblock_t *sblock, expr_t *e)
}
} else {
if (!e->retrn.at_return && e->retrn.ret_val) {
- expr_t *ret_val = e->retrn.ret_val;
+ const expr_t *ret_val = e->retrn.ret_val;
type_t *ret_type = get_type (ret_val);
operand_t *target = 0;
pr_ushort_t ret_crtl = type_size (ret_type) - 1;
@@ -1495,17 +1504,17 @@ statement_return (sblock_t *sblock, expr_t *e)
statement_add_use (s, target);
} else {
if (e->retrn.at_return) {
- expr_t *call = e->retrn.ret_val;
+ const expr_t *call = e->retrn.ret_val;
if (!call || !is_function_call (call)) {
internal_error (e, "@return with no call");
}
// FIXME hard-coded reg, and assumes 3 is free
#define REG 3
- expr_t *with = new_with_expr (11, REG, new_short_expr (0));
+ const expr_t *with = new_with_expr (11, REG, new_short_expr (0));
def_t *ret_ptr = new_def (0, 0, 0, sc_local);
operand_t *ret_op = def_operand (ret_ptr, &type_void, e);
ret_ptr->reg = REG;
- expr_file_line (with, e);
+ //expr_file_line (with, e);
sblock = statement_single (sblock, with);
sblock = statement_subexpr (sblock, call, &ret_op);
}
@@ -1522,7 +1531,7 @@ statement_return (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_adjstk (sblock_t *sblock, expr_t *e)
+statement_adjstk (sblock_t *sblock, const expr_t *e)
{
statement_t *s = new_statement (st_func, "adjstk", e);
s->opa = short_operand (e->adjstk.mode, e);
@@ -1533,7 +1542,7 @@ statement_adjstk (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_with (sblock_t *sblock, expr_t *e)
+statement_with (sblock_t *sblock, const expr_t *e)
{
statement_t *s = new_statement (st_func, "with", e);
s->opa = short_operand (e->with.mode, e);
@@ -1544,7 +1553,7 @@ statement_with (sblock_t *sblock, expr_t *e)
}
static statement_t *
-lea_statement (operand_t *pointer, operand_t *offset, expr_t *e)
+lea_statement (operand_t *pointer, operand_t *offset, const expr_t *e)
{
statement_t *s = new_statement (st_address, "lea", e);
s->opa = pointer;
@@ -1554,7 +1563,8 @@ lea_statement (operand_t *pointer, operand_t *offset, expr_t *e)
}
static statement_t *
-movep_statement (operand_t *dst, operand_t *src, type_t *type, expr_t *e)
+movep_statement (operand_t *dst, operand_t *src, const type_t *type,
+ const expr_t *e)
{
operand_t *dst_addr = operand_address (dst, e);
statement_t *s = new_statement (st_ptrmove, "movep", e);
@@ -1566,7 +1576,7 @@ movep_statement (operand_t *dst, operand_t *src, type_t *type, expr_t *e)
}
static statement_t *
-load_statement (operand_t *ptr, operand_t *offs, operand_t *op, expr_t *e)
+load_statement (operand_t *ptr, operand_t *offs, operand_t *op, const expr_t *e)
{
statement_t *s = new_statement (st_expr, "load", e);
s->opa = ptr;
@@ -1576,10 +1586,10 @@ load_statement (operand_t *ptr, operand_t *offs, operand_t *op, expr_t *e)
}
static sblock_t *
-expr_deref (sblock_t *sblock, expr_t *deref, operand_t **op)
+expr_deref (sblock_t *sblock, const expr_t *deref, operand_t **op)
{
- type_t *load_type = deref->expr.type;
- expr_t *ptr_expr = deref->expr.e1;
+ const type_t *load_type = deref->expr.type;
+ const expr_t *ptr_expr = deref->expr.e1;
operand_t *base = 0;
operand_t *offset = 0;
operand_t *target = 0;
@@ -1624,7 +1634,7 @@ expr_deref (sblock_t *sblock, expr_t *deref, operand_t **op)
}
static sblock_t *
-expr_block (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_block (sblock_t *sblock, const expr_t *e, operand_t **op)
{
if (!e->block.result)
internal_error (e, "block sub-expression without result");
@@ -1634,7 +1644,7 @@ expr_block (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_alias (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_alias (sblock_t *sblock, const expr_t *e, operand_t **op)
{
operand_t *aop = 0;
type_t *type;
@@ -1650,7 +1660,7 @@ expr_alias (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_expr (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_expr (sblock_t *sblock, const expr_t *e, operand_t **op)
{
const char *opcode;
statement_t *s;
@@ -1684,10 +1694,10 @@ expr_expr (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_cast (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_cast (sblock_t *sblock, const expr_t *e, operand_t **op)
{
- type_t *src_type;
- type_t *type = e->expr.type;
+ const type_t *src_type;
+ const type_t *type = e->expr.type;
statement_t *s;
src_type = get_type (e->expr.e1);
@@ -1713,7 +1723,7 @@ expr_cast (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_negate (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_negate (sblock_t *sblock, const expr_t *e, operand_t **op)
{
expr_t *neg;
expr_t *zero;
@@ -1721,7 +1731,7 @@ expr_negate (sblock_t *sblock, expr_t *e, operand_t **op)
zero = new_nil_expr ();
zero->file = e->file;
zero->line = e->line;
- convert_nil (zero, e->expr.type);
+ zero = (expr_t *) convert_nil (zero, e->expr.type);
neg = new_binary_expr ('-', zero, e->expr.e1);
neg->expr.type = e->expr.type;
neg->file = e->file;
@@ -1730,7 +1740,7 @@ expr_negate (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_uexpr (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_uexpr (sblock_t *sblock, const expr_t *e, operand_t **op)
{
const char *opcode;
statement_t *s;
@@ -1761,7 +1771,7 @@ expr_uexpr (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_horizontal (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_horizontal (sblock_t *sblock, const expr_t *e, operand_t **op)
{
const char *opcode = "hops";
statement_t *s;
@@ -1814,7 +1824,7 @@ expr_horizontal (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_swizzle (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_swizzle (sblock_t *sblock, const expr_t *e, operand_t **op)
{
const char *opcode = "swizzle";
statement_t *s;
@@ -1840,7 +1850,7 @@ expr_swizzle (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_extend (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_extend (sblock_t *sblock, const expr_t *e, operand_t **op)
{
type_t *src_type = get_type (e->extend.src);
type_t *res_type = e->extend.type;
@@ -1876,14 +1886,14 @@ expr_extend (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_def (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_def (sblock_t *sblock, const expr_t *e, operand_t **op)
{
*op = def_operand (e->def, e->def->type, e);
return sblock;
}
static sblock_t *
-expr_symbol (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_symbol (sblock_t *sblock, const expr_t *e, operand_t **op)
{
symbol_t *sym = e->symbol;
@@ -1904,25 +1914,25 @@ expr_symbol (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_temp (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_temp (sblock_t *sblock, const expr_t *e, operand_t **op)
{
if (!e->temp.op)
- e->temp.op = temp_operand (e->temp.type, e);
+ ((expr_t *) e)->temp.op = temp_operand (e->temp.type, e);
*op = e->temp.op;
return sblock;
}
static int
-statement_copy_elements (sblock_t **sblock, expr_t *dst, expr_t *src, int base)
+statement_copy_elements (sblock_t **sblock, const expr_t *dst, const expr_t *src, int base)
{
int index = 0;
- for (expr_t *e = src->vector.list; e; e = e->next) {
+ for (const expr_t *e = src->vector.list; e; e = e->next) {
if (e->type == ex_vector) {
index += statement_copy_elements (sblock, dst, e, index + base);
} else {
int size = type_size (base_type (get_type (dst)));
type_t *src_type = get_type (e);
- expr_t *dst_ele = new_offset_alias_expr (src_type, dst,
+ const expr_t *dst_ele = new_offset_alias_expr (src_type, dst,
size * (index + base));
index += type_width (src_type);
*sblock = statement_single (*sblock, assign_expr (dst_ele, e));
@@ -1932,9 +1942,9 @@ statement_copy_elements (sblock_t **sblock, expr_t *dst, expr_t *src, int base)
}
static sblock_t *
-expr_vector_e (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_vector_e (sblock_t *sblock, const expr_t *e, operand_t **op)
{
- expr_t *tmp;
+ const expr_t *tmp;
type_t *vec_type = get_type (e);
int file = pr.source_file;
int line = pr.source_line;
@@ -1952,10 +1962,10 @@ expr_vector_e (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_nil (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_nil (sblock_t *sblock, const expr_t *e, operand_t **op)
{
type_t *nil = e->nil;
- expr_t *size_expr;
+ const expr_t *size_expr;
size_t nil_size;
operand_t *zero;
operand_t *size;
@@ -1987,20 +1997,20 @@ expr_nil (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-expr_value (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_value (sblock_t *sblock, const expr_t *e, operand_t **op)
{
*op = value_operand (e->value, e);
return sblock;
}
static sblock_t *
-expr_selector (sblock_t *sblock, expr_t *e, operand_t **op)
+expr_selector (sblock_t *sblock, const expr_t *e, operand_t **op)
{
return statement_subexpr (sblock, e->selector.sel_ref, op);
}
static sblock_t *
-statement_subexpr (sblock_t *sblock, expr_t *e, operand_t **op)
+statement_subexpr (sblock_t *sblock, const expr_t *e, operand_t **op)
{
static expr_f sfuncs[ex_count] = {
[ex_block] = expr_block,
@@ -2037,13 +2047,13 @@ statement_subexpr (sblock_t *sblock, expr_t *e, operand_t **op)
}
static sblock_t *
-statement_ignore (sblock_t *sblock, expr_t *e)
+statement_ignore (sblock_t *sblock, const expr_t *e)
{
return sblock;
}
static sblock_t *
-statement_state (sblock_t *sblock, expr_t *e)
+statement_state (sblock_t *sblock, const expr_t *e)
{
statement_t *s;
@@ -2060,7 +2070,7 @@ build_bool_block (expr_t *block, expr_t *e)
{
switch (e->type) {
case ex_bool:
- build_bool_block (block, e->boolean.e);
+ build_bool_block (block, (expr_t *) e->boolean.e);
return;
case ex_label:
e->next = 0;
@@ -2076,8 +2086,8 @@ build_bool_block (expr_t *block, expr_t *e)
return;
case ex_expr:
if (e->expr.op == OR || e->expr.op == AND) {
- build_bool_block (block, e->expr.e1);
- build_bool_block (block, e->expr.e2);
+ build_bool_block (block, (expr_t *) e->expr.e1);
+ build_bool_block (block, (expr_t *) e->expr.e2);
} else {
e->next = 0;
append_expr (block, e);
@@ -2088,7 +2098,7 @@ build_bool_block (expr_t *block, expr_t *e)
case ex_block:
if (!e->block.result) {
for (auto t = e->block.head; t; t = t->next) {
- build_bool_block (block, t->expr);
+ build_bool_block (block, (expr_t *) t->expr);
}
return;
}
@@ -2100,36 +2110,36 @@ build_bool_block (expr_t *block, expr_t *e)
}
static int
-is_goto_expr (expr_t *e)
+is_goto_expr (const expr_t *e)
{
return e && e->type == ex_branch && e->branch.type == pr_branch_jump
&& !e->branch.index;
}
static int
-is_if_expr (expr_t *e)
+is_if_expr (const expr_t *e)
{
return e && e->type == ex_branch && e->branch.type != pr_branch_jump
&& e->branch.type != pr_branch_call;;
}
static int
-is_label_expr (expr_t *e)
+is_label_expr (const expr_t *e)
{
return e && e->type == ex_label;
}
static sblock_t *
-statement_bool (sblock_t *sblock, expr_t *e)
+statement_bool (sblock_t *sblock, const expr_t *e)
{
- expr_t *l;
- expr_t *block = new_block_expr ();
+ const expr_t *l;
+ expr_t *block = new_block_expr (0);
- build_bool_block (block, e);
+ build_bool_block (block, (expr_t *) e);
int num_expr = list_count (&block->block.list);
expr_t *exprs[num_expr + 1];
- list_scatter (&block->block.list, exprs);
+ list_scatter (&block->block.list, (const expr_t **) exprs);
exprs[num_expr] = 0; // mark end of list
expr_t **d = exprs;
expr_t **s = exprs;
@@ -2138,7 +2148,7 @@ statement_bool (sblock_t *sblock, expr_t *e)
l = s[0]->branch.target;
for (auto e = s + 2; is_label_expr (e[0]); e++) {
if (e[0] == l) {
- l->label.used--;
+ ((expr_t *) l)->label.used--;
// invert logic of if
s[0]->branch.type ^= pr_branch_ne;
// use goto's label in if
@@ -2155,7 +2165,7 @@ statement_bool (sblock_t *sblock, expr_t *e)
l = s[0]->branch.target;
for (auto e = s + 1; is_label_expr (e[0]); e++) {
if (e[0] == l) {
- l->label.used--;
+ ((expr_t *) l)->label.used--;
l = 0;
break;
}
@@ -2170,22 +2180,22 @@ statement_bool (sblock_t *sblock, expr_t *e)
}
}
block->block.list = (ex_list_t) {};
- list_gather (&block->block.list, exprs, d - exprs);
+ list_gather (&block->block.list, (const expr_t **) exprs, d - exprs);
sblock = statement_slist (sblock, &block->block.list);
return sblock;
}
static sblock_t *
-statement_label (sblock_t *sblock, expr_t *e)
+statement_label (sblock_t *sblock, const expr_t *e)
{
if (sblock->statements) {
sblock->next = new_sblock ();
sblock = sblock->next;
}
if (e->label.used) {
- e->label.dest = sblock;
- e->label.next = sblock->labels;
- sblock->labels = &e->label;
+ ((expr_t *) e)->label.dest = sblock;
+ ((expr_t *) e)->label.next = sblock->labels;
+ sblock->labels = (ex_label_t *) &e->label;
} else {
if (e->label.symbol) {
warning (e, "unused label %s", e->label.symbol->name);
@@ -2197,7 +2207,7 @@ statement_label (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_block (sblock_t *sblock, expr_t *e)
+statement_block (sblock_t *sblock, const expr_t *e)
{
if (sblock->statements) {
sblock->next = new_sblock ();
@@ -2213,7 +2223,7 @@ statement_block (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_expr (sblock_t *sblock, expr_t *e)
+statement_expr (sblock_t *sblock, const expr_t *e)
{
if (e->expr.op < 256)
debug (e, "e %c", e->expr.op);
@@ -2225,7 +2235,7 @@ statement_expr (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_uexpr (sblock_t *sblock, expr_t *e)
+statement_uexpr (sblock_t *sblock, const expr_t *e)
{
debug (e, "e ue %d", e->expr.op);
if (options.warnings.executable)
@@ -2234,11 +2244,11 @@ statement_uexpr (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_memset (sblock_t *sblock, expr_t *e)
+statement_memset (sblock_t *sblock, const expr_t *e)
{
- expr_t *dst = e->memset.dst;
- expr_t *val = e->memset.val;
- expr_t *count = e->memset.count;
+ const expr_t *dst = e->memset.dst;
+ const expr_t *val = e->memset.val;
+ const expr_t *count = e->memset.count;
const char *opcode = "memset";
statement_t *s;
@@ -2260,13 +2270,13 @@ statement_memset (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_assign (sblock_t *sblock, expr_t *e)
+statement_assign (sblock_t *sblock, const expr_t *e)
{
return expr_assign (sblock, e, 0);
}
static sblock_t *
-statement_nonexec (sblock_t *sblock, expr_t *e)
+statement_nonexec (sblock_t *sblock, const expr_t *e)
{
if (!e->rvalue && options.warnings.executable)
warning (e, "Non-executable statement; executing programmer instead.");
@@ -2274,7 +2284,7 @@ statement_nonexec (sblock_t *sblock, expr_t *e)
}
static sblock_t *
-statement_single (sblock_t *sblock, expr_t *e)
+statement_single (sblock_t *sblock, const expr_t *e)
{
static statement_f sfuncs[ex_count] = {
[ex_error] = statement_ignore,
@@ -2307,7 +2317,7 @@ statement_single (sblock_t *sblock, expr_t *e)
}
sblock_t *
-statement_slist (sblock_t *sblock, ex_list_t *slist)
+statement_slist (sblock_t *sblock, const ex_list_t *slist)
{
for (auto s = slist->head; s; s = s->next) {
@@ -2549,7 +2559,7 @@ remove_dead_blocks (sblock_t *blocks)
}
static void
-super_dealloc_warning (expr_t *expr, pseudoop_t *op)
+super_dealloc_warning (const expr_t *expr, pseudoop_t *op)
{
warning (expr,
"control may reach end of derived -dealloc without invoking %s",
@@ -2582,7 +2592,7 @@ search_for_super_dealloc (sblock_t *sblock)
}
// function arguments are in reverse order, and the selector
// is the second argument (or second last in the list)
- expr_t *arg = 0;
+ const expr_t *arg = 0;
auto arguments = st->expr->branch.args;
for (auto li = arguments->list.head; li; li = li->next) {
if (li->next && !li->next->next) {
@@ -2646,13 +2656,13 @@ check_final_block (sblock_t *sblock)
}
void
-dump_dot_sblock (void *data, const char *fname)
+dump_dot_sblock (const void *data, const char *fname)
{
print_sblock ((sblock_t *) data, fname);
}
sblock_t *
-make_statements (expr_t *e)
+make_statements (const expr_t *e)
{
sblock_t *sblock = new_sblock ();
int did_something;
diff --git a/tools/qfcc/source/struct.c b/tools/qfcc/source/struct.c
index 1c61d3e0d..3dfbdc2f1 100644
--- a/tools/qfcc/source/struct.c
+++ b/tools/qfcc/source/struct.c
@@ -263,7 +263,7 @@ finish_enum (symbol_t *sym)
}
void
-add_enum (symbol_t *enm, symbol_t *name, expr_t *val)
+add_enum (symbol_t *enm, symbol_t *name, const expr_t *val)
{
type_t *enum_type = enm->type;
symtab_t *enum_tab = enum_type->t.symtab;
diff --git a/tools/qfcc/source/stub.c b/tools/qfcc/source/stub.c
index b5ba751c3..d944bc7b0 100644
--- a/tools/qfcc/source/stub.c
+++ b/tools/qfcc/source/stub.c
@@ -55,8 +55,8 @@ void codespace_addcode (codespace_t *codespace, struct dstatement_s *code, int s
__attribute__((const)) int function_parms (function_t *f, byte *parm_size) {return 0;}
void def_to_ddef (def_t *def, ddef_t *ddef, int aux) {}
__attribute__((noreturn)) void _internal_error (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {abort();}
-__attribute__((const)) expr_t *_warning (expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
-__attribute__((const)) expr_t *_error (expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
+__attribute__((const)) expr_t *_warning (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
+__attribute__((const)) expr_t *_error (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
__attribute__((const)) symbol_t *make_structure (const char *name, int su, struct_def_t *defs, type_t *type) {return 0;}
__attribute__((const)) symbol_t *symtab_addsymbol (symtab_t *symtab, symbol_t *symbol) {return 0;}
__attribute__((const)) symbol_t *new_symbol_type (const char *name, type_t *type) {return 0;}
@@ -68,8 +68,8 @@ int is_id (const type_t *type){return type->type;}
int is_SEL (const type_t *type){return 0;}
int is_Class (const type_t *type){return 0;}
int compare_protocols (protocollist_t *protos1, protocollist_t *protos2){return protos1->count - protos2->count;}
-void dump_dot (const char *stage, void *data,
- void (*dump_func) (void *data, const char *fname)){}
+void dump_dot (const char *stage, const void *data,
+ void (*dump_func) (const void *data, const char *fname)){}
void dump_dot_type (void *_t, const char *filename){}
char *fubar;
const char *file_basename(const char *p, int keepdot) { return fubar;}
diff --git a/tools/qfcc/source/switch.c b/tools/qfcc/source/switch.c
index a60a97f3f..288bd44b7 100644
--- a/tools/qfcc/source/switch.c
+++ b/tools/qfcc/source/switch.c
@@ -57,15 +57,15 @@
#include "tools/qfcc/source/qc-parse.h"
typedef struct case_node_s {
- expr_t *low;
- expr_t *high;
- expr_t **labels;
- expr_t *_label;
+ const expr_t *low;
+ const expr_t *high;
+ const expr_t **labels;
+ const expr_t *_label;
struct case_node_s *left, *right;
} case_node_t;
-static __attribute__((pure)) ex_value_t *
-get_value (expr_t *e)
+static ex_value_t * __attribute__((pure))
+get_value (const expr_t *e)
{
if (e->type == ex_symbol)
return e->symbol->s.value;
@@ -91,8 +91,8 @@ compare (const void *_cla, const void *_clb, void *unused)
{
case_label_t *cla = (case_label_t *) _cla;
case_label_t *clb = (case_label_t *) _clb;
- expr_t *v1 = cla->value;
- expr_t *v2 = clb->value;
+ const expr_t *v1 = cla->value;
+ const expr_t *v2 = clb->value;
ex_value_t *val1, *val2;
if (v1 == v2)
@@ -108,8 +108,8 @@ compare (const void *_cla, const void *_clb, void *unused)
return memcmp (&val1->v, &val2->v, sizeof (val1->v)) == 0;
}
-struct expr_s *
-case_label_expr (switch_block_t *switch_block, expr_t *value)
+const expr_t *
+case_label_expr (switch_block_t *switch_block, const expr_t *value)
{
case_label_t *cl = malloc (sizeof (case_label_t));
@@ -197,7 +197,7 @@ label_compare (const void *_a, const void *_b)
}
static case_node_t *
-new_case_node (expr_t *low, expr_t *high)
+new_case_node (const expr_t *low, const expr_t *high)
{
case_node_t *node = malloc (sizeof (case_node_t));
@@ -214,7 +214,7 @@ new_case_node (expr_t *low, expr_t *high)
if (!is_int_val (low))
internal_error (low, "switch");
size = expr_int (high) - expr_int (low) + 1;
- node->labels = calloc (size, sizeof (expr_t *));
+ node->labels = calloc (size, sizeof (const expr_t *));
}
node->left = node->right = 0;
return node;
@@ -285,13 +285,13 @@ build_case_tree (case_label_t **labels, int count, int range)
}
static void
-build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
- expr_t *temp, expr_t *default_label)
+build_switch (expr_t *sw, case_node_t *tree, int op, const expr_t *sw_val,
+ const expr_t *temp, const expr_t *default_label)
{
- expr_t *test;
- expr_t *branch;
- expr_t *high_label = default_label;
- expr_t *low_label = default_label;
+ const expr_t *test;
+ const expr_t *branch;
+ const expr_t *high_label = default_label;
+ const expr_t *low_label = default_label;
if (!tree) {
branch = goto_expr (default_label);
@@ -333,16 +333,16 @@ build_switch (expr_t *sw, case_node_t *tree, int op, expr_t *sw_val,
int low = expr_int (tree->low);
int high = expr_int (tree->high);
symbol_t *table_sym;
- expr_t *table_expr;
+ const expr_t *table_expr;
expr_t *table_init;
const char *table_name = new_label_name ();
int i;
- expr_t *range = binary_expr ('-', tree->high, tree->low);
- expr_t *label;
+ const expr_t *range = binary_expr ('-', tree->high, tree->low);
+ const expr_t *label;
table_init = new_compound_init ();
for (i = 0; i <= high - low; i++) {
- tree->labels[i]->label.used++;
+ ((expr_t *) tree->labels[i])->label.used++;
label = address_expr (tree->labels[i], 0);
append_element (table_init, new_element (label, 0));
}
@@ -393,27 +393,27 @@ check_enum_switch (switch_block_t *switch_block)
}
}
-struct expr_s *
-switch_expr (switch_block_t *switch_block, expr_t *break_label,
- expr_t *statements)
+const expr_t *
+switch_expr (switch_block_t *switch_block, const expr_t *break_label,
+ const expr_t *statements)
{
if (switch_block->test->type == ex_error) {
return switch_block->test;
}
+ int saved_line = pr.source_line;
+ pr_string_t saved_file = pr.source_file;
+ pr.source_line = switch_block->test->line;
+ pr.source_file = switch_block->test->file;
+
case_label_t **labels, **l;
case_label_t _default_label;
case_label_t *default_label = &_default_label;
- expr_t *sw = new_block_expr ();
+ expr_t *sw = new_block_expr (0);
type_t *type = get_type (switch_block->test);
- expr_t *sw_val = new_temp_def_expr (type);
- expr_t *default_expr;
+ const expr_t *sw_val = new_temp_def_expr (type);
+ const expr_t *default_expr;
int num_labels = 0;
- int saved_line = pr.source_line;
- pr_string_t saved_file = pr.source_file;
-
- pr.source_line = sw_val->line = switch_block->test->line;
- pr.source_file = sw_val->file = switch_block->test->file;
default_label->value = 0;
default_label = Hash_DelElement (switch_block->labels, default_label);
@@ -434,16 +434,16 @@ switch_expr (switch_block_t *switch_block, expr_t *break_label,
|| (!is_string(type) && !is_float(type) && !is_integral (type))
|| num_labels < 8) {
for (l = labels; *l; l++) {
- expr_t *cmp = binary_expr (EQ, sw_val, (*l)->value);
- expr_t *test = branch_expr (NE, test_expr (cmp),
- (*l)->label);
+ const expr_t *cmp = binary_expr (EQ, sw_val, (*l)->value);
+ const expr_t *test = branch_expr (NE, test_expr (cmp),
+ (*l)->label);
append_expr (sw, test);
}
default_expr = goto_expr (default_label->label);
append_expr (sw, default_expr);
} else {
- expr_t *temp;
+ const expr_t *temp;
int op;
case_node_t *case_tree;
diff --git a/tools/qfcc/source/symtab.c b/tools/qfcc/source/symtab.c
index 4b7f3c1fe..600666389 100644
--- a/tools/qfcc/source/symtab.c
+++ b/tools/qfcc/source/symtab.c
@@ -251,7 +251,7 @@ make_symbol (const char *name, type_t *type, defspace_t *space,
}
symbol_t *
-declare_symbol (specifier_t spec, expr_t *init, symtab_t *symtab)
+declare_symbol (specifier_t spec, const expr_t *init, symtab_t *symtab)
{
symbol_t *s = spec.sym;
defspace_t *space = symtab->space;
diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c
index a44ed3ea5..775c1e808 100644
--- a/tools/qfcc/source/type.c
+++ b/tools/qfcc/source/type.c
@@ -170,7 +170,7 @@ int type_cast_map[ev_type_count] = {
ALLOC_STATE (type_t, types);
etype_t
-low_level_type (type_t *type)
+low_level_type (const type_t *type)
{
if (type->type > ev_type_count)
internal_error (0, "invalid type");
@@ -630,7 +630,7 @@ field_type (type_t *aux)
}
type_t *
-pointer_type (type_t *aux)
+pointer_type (const type_t *aux)
{
type_t _new;
type_t *new = &_new;
@@ -643,7 +643,7 @@ pointer_type (type_t *aux)
new->alignment = 1;
new->width = 1;
if (aux) {
- new = find_type (append_type (new, aux));
+ new = find_type (append_type (new, (type_t *) aux));
}
return new;
}