From: Dale Weiler Date: Wed, 6 Feb 2013 05:51:05 +0000 (+0000) Subject: Some sanity checks for aliases (undeclared variable checks, and incompatible types... X-Git-Tag: before-library~145 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=060bc0be10d0ffceb52d43f8f037249a1a2a5a24;p=xonotic%2Fgmqcc.git Some sanity checks for aliases (undeclared variable checks, and incompatible types in alias checks.) --- diff --git a/parser.c b/parser.c index 80b9522..7e86b23 100644 --- a/parser.c +++ b/parser.c @@ -5275,6 +5275,25 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield } } } else { + ast_expression *find = parser_find_var(parser, var->desc); + if (!find) { + compile_error(parser_ctx(parser), "undeclared variable `%s` for alias `%s", var->desc, var->name); + return false; + } + + if (var->expression.vtype != find->expression.vtype) { + char ty1[1024]; + char ty2[1024]; + + ast_type_to_string(find, ty1, sizeof(ty1)); + ast_type_to_string((ast_expression*)var, ty2, sizeof(ty2)); + + compile_error(parser_ctx(parser), "incompatible types `%s` and `%s` for alias `%s`", + ty1, ty2, var->name + ); + return false; + } + util_htset(parser->aliases, var->name, (void*)var->desc); /* * TODO: vector, find . or _ (last of), and build