Hi Richard,
Passerby comment below.
On 11/07/2015 01:21 PM, Richard Sandiford wrote:
> -/* Lookup the identifier ID. */
> +/* Lookup the identifier ID. Allow "null" if ALLOW_NULL. */
>
> id_base *
> -get_operator (const char *id)
> +get_operator (const char *id, bool allow_null = false)
> {
> + if (allow_null && strcmp (id, "null") == 0)
> + return null_id;
> +
> id_base tem (id_base::CODE, id);
Boolean params are best avoided if possible, IMO. In this case,
it seems this could instead be a new wrapper function, like:
id_base *
get_operator_allow_null (const char *id)
{
if (strcmp (id, "null") == 0)
return null_id;
return get_operator (id);
}
Then callers are more obvious as you no longer have to know
what true/false mean:
const char *id = get_ident ();
- if (get_operator (id) != NULL)
+ if (get_operator_allow_null (id) != NULL)
fatal_at (token, "operator already defined");
vs:
const char *id = get_ident ();
- if (get_operator (id) != NULL)
+ if (get_operator (id, true) != NULL)
fatal_at (token, "operator already defined");
Thanks,
Pedro Alves