]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
Implement [[deprecated]] general attribute, will mark functions as deprecated. Makin...
[xonotic/gmqcc.git] / parser.c
index 53220b51d7cb5f7f25a32a63d2cbdb69fb5b1afc..a191c535c4ddf94d8dd3a036526466c1f9a93198 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1373,18 +1373,29 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
         return false;
     }
 
+    
     if (!fun->expression.next) {
         parseerror(parser, "could not determine function return type");
         return false;
     } else {
+        ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : NULL);
+
+        if (fun->expression.flags & AST_FLAG_DEPRECATED) {
+            if (!fval)
+                return !parsewarning(parser, WARN_DEPRECATED, "call to function (which is marked deprecated)\n"
+                                    "-> it has been declared here: %s:%i",
+                                    ast_ctx(fun).file, ast_ctx(fun).line);
+            else
+                return !parsewarning(parser, WARN_DEPRECATED, "call to `%s` (which is marked deprecated)\n"
+                                    "-> `%s` declared here: %s:%i",
+                                    fval->name, fval->name, ast_ctx(fun).file, ast_ctx(fun).line);
+        }
+
         if (vec_size(fun->expression.params) != paramcount &&
             !((fun->expression.flags & AST_FLAG_VARIADIC) &&
               vec_size(fun->expression.params) < paramcount))
         {
-            ast_value *fval;
             const char *fewmany = (vec_size(fun->expression.params) > paramcount) ? "few" : "many";
-
-            fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : NULL);
             if (opts.standard == COMPILER_GMQCC)
             {
                 if (fval)
@@ -2606,6 +2617,14 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool *
                     return false;
                 }
             }
+            else if (!strcmp(parser_tokval(parser), "deprecated")) {
+                flags |= AST_FLAG_DEPRECATED;
+                if (!parser_next(parser) || parser->tok != TOKEN_ATTRIBUTE_CLOSE) {
+                    parseerror(parser, "`deprecated` attribute has no parameters, expected `]]`");
+                    *cvq = CV_WRONG;
+                    return false;
+                }
+            }
             else
             {
                 /* Skip tokens until we hit a ]] */