]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
Remove trailing whitespace
[xonotic/gmqcc.git] / parser.c
index 5d4ea7d0650de50c505d809dd36cab0c7a52cf5c..b3e98823604b553363ff9db41caa7151d1551e51 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2,7 +2,7 @@
  * Copyright (C) 2012, 2013
  *     Wolfgang Bumiller
  *     Dale Weiler
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  * this software and associated documentation files (the "Software"), to deal in
  * the Software without restriction, including without limitation the rights to
@@ -47,6 +47,8 @@ typedef struct parser_s {
     ast_value    **imm_vector;
     size_t         translated;
 
+    ht ht_imm_string;
+
     /* must be deleted first, they reference immediates and values */
     ast_value    **accessors;
 
@@ -253,12 +255,22 @@ static char *parser_strdup(const char *str)
 
 static ast_value* parser_const_string(parser_t *parser, const char *str, bool dotranslate)
 {
-    size_t i;
+    size_t hash = util_hthash(parser->ht_imm_string, str);
     ast_value *out;
+    if ( (out = util_htgeth(parser->ht_imm_string, str, hash)) ) {
+        if (dotranslate && out->name[0] == '#') {
+            char name[32];
+            snprintf(name, sizeof(name), "dotranslate_%lu", (unsigned long)(parser->translated++));
+            ast_value_set_name(out, name);
+        }
+        return out;
+    }
+    /*
     for (i = 0; i < vec_size(parser->imm_string); ++i) {
         if (!strcmp(parser->imm_string[i]->constval.vstring, str))
             return parser->imm_string[i];
     }
+    */
     if (dotranslate) {
         char name[32];
         snprintf(name, sizeof(name), "dotranslate_%lu", (unsigned long)(parser->translated++));
@@ -269,6 +281,7 @@ static ast_value* parser_const_string(parser_t *parser, const char *str, bool do
     out->hasvalue = true;
     out->constval.vstring = parser_strdup(str);
     vec_push(parser->imm_string, out);
+    util_htseth(parser->ht_imm_string, str, hash, out);
     return out;
 }
 
@@ -1889,7 +1902,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels)
             } else {
                 var = intrin_func(parser, parser_tokval(parser));
             }
-                
+
             if (!var) {
                 char *correct = NULL;
                 size_t i;
@@ -5158,7 +5171,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
         /*
          * store the vstring back to var for alias and
          * deprecation messages.
-         */   
+         */
         if (var->expression.flags & AST_FLAG_DEPRECATED ||
             var->expression.flags & AST_FLAG_ALIAS)
             var->desc = vstring;
@@ -5255,7 +5268,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                         ast_value_set_name(proto->expression.params[i], var->expression.params[i]->name);
                     if (!parser_check_qualifiers(parser, var, proto)) {
                         retval = false;
-                        if (proto->desc) 
+                        if (proto->desc)
                             mem_d(proto->desc);
                         proto = NULL;
                         goto cleanup;
@@ -5396,13 +5409,13 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                         /*
                          * add alias to aliases table and to corrector
                          * so corrections can apply for aliases as well.
-                         */  
+                         */
                         util_htset(parser->aliases, var->name, find);
 
                         /*
                          * add to corrector so corrections can work
                          * even for aliases too.
-                         */ 
+                         */
                         correct_add (
                              vec_last(parser->correct_variables),
                             &vec_last(parser->correct_variables_score),
@@ -5428,7 +5441,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
                             /*
                              * add to corrector so corrections can work
                              * even for aliases too.
-                             */  
+                             */
                             correct_add (
                                  vec_last(parser->correct_variables),
                                 &vec_last(parser->correct_variables_score),
@@ -5942,6 +5955,8 @@ parser_t *parser_create()
 
     parser->aliases = util_htnew(PARSER_HT_SIZE);
 
+    parser->ht_imm_string = util_htnew(512);
+
     /* corrector */
     vec_push(parser->correct_variables, correct_trie_new());
     vec_push(parser->correct_variables_score, NULL);
@@ -6054,6 +6069,7 @@ void parser_cleanup(parser_t *parser)
     vec_free(parser->functions);
     vec_free(parser->imm_vector);
     vec_free(parser->imm_string);
+    util_htdel(parser->ht_imm_string);
     vec_free(parser->imm_float);
     vec_free(parser->globals);
     vec_free(parser->fields);