]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge branch 'master' into ftepp
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 18 Nov 2012 12:06:29 +0000 (13:06 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 18 Nov 2012 12:06:29 +0000 (13:06 +0100)
1  2 
parser.c

diff --combined parser.c
index a292c9083afd311f335849065206a20a859599f4,5738869e2ca1e639e39e23beb5abfe3f1965b692..38af9a9e0dacc6997bcc9ede49a1e496fc4c3ce9
+++ b/parser.c
@@@ -20,6 -20,9 +20,9 @@@ typedef struct 
      ast_value    **imm_string;
      ast_value    **imm_vector;
  
+     /* must be deleted first, they reference immediates and values */
+     ast_value    **accessors;
      ast_value *imm_float_zero;
      ast_value *imm_vector_zero;
  
@@@ -2396,6 -2399,7 +2399,7 @@@ static bool parser_create_array_accesso
  {
      ast_function   *func = NULL;
      ast_value      *fval = NULL;
+     ast_block      *body = NULL;
  
      fval = ast_value_new(ast_ctx(array), funcname, TYPE_FUNCTION);
      if (!fval) {
          return false;
      }
  
+     body = ast_block_new(ast_ctx(array));
+     if (!body) {
+         parseerror(parser, "failed to create block for array accessor");
+         ast_delete(fval);
+         ast_delete(func);
+         return false;
+     }
+     vec_push(func->blocks, body);
      *out = fval;
  
+     vec_push(parser->accessors, fval);
      return true;
  }
  
  static bool parser_create_array_setter(parser_t *parser, ast_value *array, const char *funcname)
  {
      ast_expression *root = NULL;
-     ast_block      *body = NULL;
      ast_value      *index = NULL;
      ast_value      *value = NULL;
      ast_function   *func;
      func = fval->constval.vfunc;
      fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
  
-     body = ast_block_new(ast_ctx(array));
-     if (!body) {
-         parseerror(parser, "failed to create block for array accessor");
-         goto cleanup;
-     }
      index = ast_value_new(ast_ctx(array), "index", TYPE_FLOAT);
      value = ast_value_copy((ast_value*)array->expression.next);
  
          goto cleanup;
      }
  
-     vec_push(body->exprs, root);
-     vec_push(func->blocks, body);
+     vec_push(func->blocks[0]->exprs, root);
      array->setter = fval;
      return true;
  cleanup:
-     if (body)  ast_delete(body);
      if (index) ast_delete(index);
      if (value) ast_delete(value);
      if (root)  ast_delete(root);
  static bool parser_create_array_field_setter(parser_t *parser, ast_value *array, const char *funcname)
  {
      ast_expression *root = NULL;
-     ast_block      *body = NULL;
      ast_value      *entity = NULL;
      ast_value      *index = NULL;
      ast_value      *value = NULL;
      func = fval->constval.vfunc;
      fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
  
-     body = ast_block_new(ast_ctx(array));
-     if (!body) {
-         parseerror(parser, "failed to create block for array accessor");
-         goto cleanup;
-     }
      entity = ast_value_new(ast_ctx(array), "entity", TYPE_ENTITY);
      index  = ast_value_new(ast_ctx(array), "index",  TYPE_FLOAT);
      value  = ast_value_copy((ast_value*)array->expression.next);
          goto cleanup;
      }
  
-     vec_push(body->exprs, root);
-     vec_push(func->blocks, body);
+     vec_push(func->blocks[0]->exprs, root);
      array->setter = fval;
      return true;
  cleanup:
-     if (body)   ast_delete(body);
      if (entity) ast_delete(entity);
      if (index)  ast_delete(index);
      if (value)  ast_delete(value);
  static bool parser_create_array_getter(parser_t *parser, ast_value *array, const ast_expression *elemtype, const char *funcname)
  {
      ast_expression *root = NULL;
-     ast_block      *body = NULL;
      ast_value      *index = NULL;
      ast_value      *fval;
      ast_function   *func;
      func = fval->constval.vfunc;
      fval->expression.next = ast_type_copy(ast_ctx(array), elemtype);
  
-     body = ast_block_new(ast_ctx(array));
-     if (!body) {
-         parseerror(parser, "failed to create block for array accessor");
-         goto cleanup;
-     }
      index = ast_value_new(ast_ctx(array), "index", TYPE_FLOAT);
  
      if (!index) {
          goto cleanup;
      }
  
-     vec_push(body->exprs, root);
-     vec_push(func->blocks, body);
+     vec_push(func->blocks[0]->exprs, root);
      array->getter = fval;
      return true;
  cleanup:
-     if (body)  ast_delete(body);
      if (index) ast_delete(index);
      if (root)  ast_delete(root);
      ast_delete(func);
@@@ -3431,7 -3419,7 +3419,7 @@@ bool parser_compile_file(const char *fi
  {
      parser->lex = lex_open(filename);
      if (!parser->lex) {
 -        con_out("failed to open file \"%s\"\n", filename);
 +        con_err("failed to open file \"%s\"\n", filename);
          return false;
      }
      return parser_compile();
@@@ -3441,7 -3429,7 +3429,7 @@@ bool parser_compile_string(const char *
  {
      parser->lex = lex_open_string(str, strlen(str), name);
      if (!parser->lex) {
 -        con_out("failed to create lexer for string \"%s\"\n", name);
 +        con_err("failed to create lexer for string \"%s\"\n", name);
          return false;
      }
      return parser_compile();
  void parser_cleanup()
  {
      size_t i;
+     for (i = 0; i < vec_size(parser->accessors); ++i) {
+         ast_delete(parser->accessors[i]->constval.vfunc);
+         parser->accessors[i]->constval.vfunc = NULL;
+         ast_delete(parser->accessors[i]);
+     }
      for (i = 0; i < vec_size(parser->functions); ++i) {
          ast_delete(parser->functions[i]);
      }
          ast_delete(parser->globals[i].var);
          mem_d(parser->globals[i].name);
      }
+     vec_free(parser->accessors);
      vec_free(parser->functions);
      vec_free(parser->imm_vector);
      vec_free(parser->imm_string);