From: Wolfgang (Blub) Bumiller Date: Sat, 18 Aug 2012 18:16:51 +0000 (+0200) Subject: data/vars.qc - when declaring a function, and it had a prototype - use the new parame... X-Git-Tag: 0.1-rc1~183 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=588cd5018f66962aa53159287c6f63b1c1ea15f5;p=xonotic%2Fgmqcc.git data/vars.qc - when declaring a function, and it had a prototype - use the new parameter names instead of the ones from the prototype, otherwise things get messy --- diff --git a/data/vars.qc b/data/vars.qc new file mode 100644 index 0000000..7438a10 --- /dev/null +++ b/data/vars.qc @@ -0,0 +1,19 @@ +/* this is the WIP test for the parser... + * constantly adding stuff here to see if things break + */ +void(string) print = #1; +void(string,string) print2 = #1; +void(string,string,string) print3 = #1; +string(float) ftos = #2; +entity() spawn = #3; +void(entity) kill = #4; + +float(vector different_name, vector b) dot; + +float(vector a, vector b) dot = { + return a * b; +}; + +void() main = { + print3("should be 1: ", ftos(dot('1 1 0', '1 0 0')), "\n"); +}; diff --git a/parser.c b/parser.c index a2b3f06..7ef5c9b 100644 --- a/parser.c +++ b/parser.c @@ -1838,6 +1838,7 @@ static bool parser_variable(parser_t *parser, ast_block *localblock) * messing with the parameter-vector etc. earlier */ if (proto) { + size_t param; if (!ast_compare_type((ast_expression*)proto, (ast_expression*)fval)) { parseerror(parser, "conflicting types for `%s`, previous declaration was here: %s:%i", proto->name, @@ -1846,6 +1847,11 @@ static bool parser_variable(parser_t *parser, ast_block *localblock) ast_value_delete(fval); return false; } + /* copy over the parameter names */ + for (param = 0; param < fval->expression.params_count; ++param) + ast_value_set_name(proto->expression.params[param], fval->expression.params[param]->name); + + /* now ditch the rest of the new data */ ast_function_delete(func); ast_value_delete(fval); fval = proto;