[RFA] Add method overload resolution to expression parser

Daniel Jacobowitz drow@false.org
Tue Oct 13 21:24:00 GMT 2009


On Tue, Sep 01, 2009 at 11:06:03AM -0700, Keith Seitz wrote:
> +/* Cleanup for 'nonempty_typelist' */
> +static struct cleanup *typelist_cleanup;

Does this cleanup get more complicated uses?  As it stands after this
patch, it's just a more confusing way to write a call to free.  IMO
having cleanups created inside the parser is confusing.

> +/* Constructs a fake method with the given parameter types.  This is
> +   used to do overload resolution by the expression parser.  The
> +   logical counterpart is compare_parameters in valops.c.  */
> +
> +static struct type *
> +make_params (int num_types, struct type **param_types)
> +{
> +  struct type *type = XZALLOC (struct type);
> +  TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
> +  TYPE_LENGTH (type) = 1;
> +  TYPE_CODE (type) = TYPE_CODE_METHOD;
> +  TYPE_VPTR_FIELDNO (type) = -1;
> +  TYPE_CHAIN (type) = type;
> +  TYPE_NFIELDS (type) = num_types;
> +  TYPE_FIELDS (type) = (struct field *)
> +    TYPE_ZALLOC (type, sizeof (struct field) * num_types);
> +
> +  while (num_types-- > 0)
> +    TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
> +
> +  make_cleanup (free_param_types, type);
> +  return type;
> +}

And this is even more confusing... how does this cleanup eventually
get run?  We shouldn't leak it back to the top level.  And I suspect
that since nothing ever copies types, if this type makes it into the
value history we're going to have a problem.

I also wonder why TYPE_INSTANCE is necesary.  All it seems to do is
construct the temporary type.  Can't we do that in the parser,
instead, and use UNOP_CAST?

-- 
Daniel Jacobowitz
CodeSourcery



More information about the Gdb-patches mailing list