On 10/13/2009 02:24 PM, Tom Tromey wrote: > First, since this is an extension to C++, I wonder whether it will > introduce any parsing ambiguities once the parser is complete. I > suspect not, but I thought you might have a better view. If it does, I haven't found them yet. Unfortunately, for a vast majority of cases, I must largely rely on the test suite to highlight some errors. In this specific case, though, I don't believe the new rules are reachable except within a C++ context since they rely on OP_SCOPE. [If you try to use this with a C function, the code path is quite different. It cannot get to TYPE_INSTANCE.] > Keith> +exp : exp '(' nonempty_typelist ')' const_or_volatile > > This is an interesting production. Unfortunately, it is the only one that works. There are other rules that do a similar, sometimes non-sensical thing. The functional call rule is one example, e.g., "p (1+3)(5)" will attempt to call a function. > I would have expected it to explicitly look for maybe-qualified > identifiers -- not an arbitrary expression. Does this let us do > something we could not otherwise do? Or, what does this do: > > print (return_a_function ()) (int) This will not currently do anything -- the "(int)" part is ignored during evaluation. That's because all that the "(int)" part does is add TYPE_INSTANCE to the expression chain, which causes an expected type to be sent down to evaluate_subexp_standard. evaluate_subexp_standard largely ignores expect_type, so this acts as a nop. > Does it work to call an explicitly-specified overload? > > print overloaded(int)(5) > > (I assume from reading the patch that this works as expected.) I never tried that, but it does work (for C++ methods -- again C functions do not work at all). > Keith> func_mod: '(' ')' > Keith> { $$ = 0; } > Keith> | '(' nonempty_typelist ')' > Keith> - { free ($2); $$ = 0; } > Keith> + { do_cleanups (typelist_cleanup); $$ = 0; } > > I'm a bit surprised that the cleanup stuff works in the parser. > Interesting. Daniel also mentions this in a later message. I'm not sure why I did it this way, but the code has changed (or it was a mistake) and it is certainly not needed. I've removed this and free the {re,m}alloc'd data in the TYPE_INSTANCE-generating rule. > Keith> +static void > Keith> +free_param_types (void *arg) > > Needs a short intro comment. This function has been removed. > Keith> +static struct type * > Keith> +make_params (int num_types, struct type **param_types) > [...] > Keith> + make_cleanup (free_param_types, type); > > It is a little unusual to make a cleanup that isn't returned. Is it > really safe in this case? To know that, I think you'd have to examine > all callers of evaluate_subexp_standard. It seems somewhat safer to do > explicit cleanups in the TYPE_INSTANCE case, what do you think? This cleanup has also now been removed. I've attached an updated patch which I think addresses most of the serious concerns. From one of your follow-up messages, re: doing this in the parser: The reason this is done during evaluation is because that is where the actual lookup of symbol is performed (unlike in C, where it is done in c_lex). Keith ChangeLog 2009-11-09 Keith Seitz * c-exp.y: Add new rule for resolving method overloads. * eval.c (make_params): New function. (evaluate_subexp_standard): Pass expect_type to value_aggregate_elt. Handle case TYPE_INSTANCE. (evaluate_subexp_for_address): Pass expect_type to value_aggregate_elt. * expression.h (enum exp_opcode): Add TYPE_INSTANCE. (compare_parameters): Add declaration. * parse.c (operator_length_standard): Add TYPE_INSTANCE. * valops.c (value_aggregate_elt): Add new expect_type parameter. Pass expect_type to value_struct_elt_for_reference. (value_struct_elt_for_reference): Add expect_type parameter and use compare_parameters. Check for overload matches with and without artificial parameters. Skip artificial methods. (compare_parameters): New function. * value.h (value_aggregate_elt): Add new expect_type parameter. testsuite/ChangeLog 2009-11-09 Keith Seitz * gdb.cp/overload.exp: Add tests for resolving overloaded methods in expression parsing/evaluation.