ast_expression now derives from ast_node
authorWolfgang Bumiller <wry.git@bumiller.com>
Mon, 19 Jan 2015 12:33:39 +0000 (13:33 +0100)
committerWolfgang Bumiller <wry.git@bumiller.com>
Mon, 19 Jan 2015 12:33:39 +0000 (13:33 +0100)
ast.cpp
ast.h
fold.cpp
parser.cpp

diff --git a/ast.cpp b/ast.cpp
index d80fd90..4c1806d 100644 (file)
--- a/ast.cpp
+++ b/ast.cpp
@@ -120,9 +120,9 @@ ast_value* ast_value_copy(const ast_value *self)
 {
     const ast_expression *fromex;
     ast_expression *selfex;
-    ast_value *cp = ast_value_new(self->expression.node.context, self->name, self->expression.vtype);
+    ast_value *cp = ast_value_new(self->expression.context, self->name, self->expression.vtype);
     if (self->expression.next) {
-        cp->expression.next = ast_type_copy(self->expression.node.context, self->expression.next);
+        cp->expression.next = ast_type_copy(self->expression.context, self->expression.next);
     }
     fromex = &self->expression;
     selfex = &cp->expression;
@@ -325,7 +325,7 @@ ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
     ast_instantiate(ast_value, ctx, ast_value_delete);
     ast_expression_init((ast_expression*)self,
                         (ast_expression_codegen*)&ast_value_codegen);
-    self->expression.node.keep_node = true; /* keep */
+    self->expression.keep_node = true; /* keep */
 
     self->name = name ? util_strdup(name) : nullptr;
     self->expression.vtype = t;
@@ -617,7 +617,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi
     }
 
     ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen);
-    self->expression.node.keep_node = true; /* keep */
+    self->expression.keep_node = true; /* keep */
 
     if (owner->vtype == TYPE_VECTOR) {
         self->expression.vtype = TYPE_FLOAT;
@@ -1139,7 +1139,7 @@ bool ast_block_add_expr(ast_block *self, ast_expression *e)
 void ast_block_collect(ast_block *self, ast_expression *expr)
 {
     self->collect.push_back(expr);
-    expr->node.keep_node = true;
+    expr->keep_node = true;
 }
 
 void ast_block_delete(ast_block *self)
diff --git a/ast.h b/ast.h
index f348e4b..e721afc 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -141,10 +141,9 @@ typedef bool ast_expression_codegen(ast_expression*,
  * type `expression`, so the ast_ident's codegen would search for
  * variables through the environment (or functions, constants...).
  */
-struct ast_expression {
+struct ast_expression : ast_node {
     ast_expression() {}
 
-    ast_node                node;
     ast_expression_codegen *codegen;
     int                     vtype;
     ast_expression         *next;
index ee0bbc1..d8f9de1 100644 (file)
--- a/fold.cpp
+++ b/fold.cpp
@@ -1070,7 +1070,7 @@ ast_expression *fold::op_mul_vec(vec3_t vec, ast_value *sel, const char *set) {
         ast_expression *out;
         ++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
         out = (ast_expression*)ast_member_new(ctx(), (ast_expression*)sel, set[0]-'x', nullptr);
-        out->node.keep_node = false;
+        out->keep_node = false;
         ((ast_member*)out)->rvalue = true;
         if (x != -1.0f)
             return (ast_expression*)ast_binary_new(ctx(), INSTR_MUL_F, constgen_float(x, false), out);
index 631adf6..fec3a22 100644 (file)
@@ -1245,7 +1245,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
          * Blub: what sorts of unreffing and resizing of
          * sy->out should I be doing here?
          */
-        sy->out[fid] = syexp(foldval->node.context, foldval);
+        sy->out[fid] = syexp(foldval->context, foldval);
         sy->out.erase(sy->out.end() - paramcount, sy->out.end());
         vec_free(exprs);
 
@@ -1283,7 +1283,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
     }
 
     /* overwrite fid, the function, with a call */
-    sy->out[fid] = syexp(call->expression.node.context, (ast_expression*)call);
+    sy->out[fid] = syexp(call->expression.context, (ast_expression*)call);
 
     if (fun->vtype != TYPE_FUNCTION) {
         parseerror(parser, "not a function (%s)", type_name[fun->vtype]);