]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.cpp
Merge pull request #187 from divVerent/patch-1
[xonotic/gmqcc.git] / parser.cpp
index 9bfd7517a26aea26b9671f362f6e9be58dcdfd50..9345760ad2d83b3e4825dbe7fb3d729e40f0cbcc 100644 (file)
@@ -135,22 +135,17 @@ static ast_expression* parser_find_local(parser_t *parser, const char *name, siz
 {
     size_t          i, hash;
     ast_expression *e;
-    ast_expression *p;
 
     hash = util_hthash(parser->htglobals, name);
 
     *isparam = false;
-    p = parser_find_param(parser, name);
-    if (p) {
-        *isparam = true;
-        return p;
-    }
     for (i = parser->variables.size(); i > upto;) {
         --i;
         if ( (e = (ast_expression*)util_htgeth(parser->variables[i], name, hash)) )
             return e;
     }
-    return NULL;
+    *isparam = true;
+    return parser_find_param(parser, name);
 }
 
 static ast_expression* parser_find_local(parser_t *parser, const std::string &name, size_t upto, bool *isparam) {
@@ -161,7 +156,7 @@ static ast_expression* parser_find_var(parser_t *parser, const char *name)
 {
     bool dummy;
     ast_expression *v;
-    v         = parser_find_local(parser, name, 0, &dummy);
+    v         = parser_find_local(parser, name, PARSER_HT_LOCALS, &dummy);
     if (!v) v = parser_find_global(parser, name);
     return v;
 }
@@ -1193,6 +1188,12 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
 
 static bool parser_close_call(parser_t *parser, shunt *sy)
 {
+    if (!parser->function)
+    {
+        parseerror(parser, "cannot call functions from global scope");
+        return false;
+    }
+
     /* was a function call */
     ast_expression *fun;
     ast_value      *funval = nullptr;
@@ -2762,6 +2763,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool *
         { "noreturn",   AST_FLAG_NORETURN   },
         { "inline",     AST_FLAG_INLINE     },
         { "eraseable",  AST_FLAG_ERASEABLE  },
+        { "noerase",    AST_FLAG_NOERASE    },
         { "accumulate", AST_FLAG_ACCUMULATE },
         { "last",       AST_FLAG_FINAL_DECL }
     };
@@ -2795,7 +2797,6 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool *
             if (i != GMQCC_ARRAY_COUNT(attributes))
                 goto leave;
 
-
             if (!strcmp(parser_tokval(parser), "noref")) {
                 had_noref = true;
                 if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
@@ -5196,8 +5197,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->m_flags & AST_FLAG_DEPRECATED ||
-            var->m_flags & AST_FLAG_ALIAS)
+        if (var->m_flags & AST_FLAG_DEPRECATED || var->m_flags & AST_FLAG_ALIAS)
             var->m_desc = vstring;
 
         if (parser_find_global(parser, var->m_name) && var->m_flags & AST_FLAG_ALIAS) {