diff mbox

Support dumping type bindings and 'mutable' qualifier in lambda diagnostics.

Message ID 1377786008-4683-1-git-send-email-adam@jessamine.co.uk
State New
Headers show

Commit Message

Adam Butcher Aug. 29, 2013, 2:20 p.m. UTC
* error.c (dump_lambda_function): New function, dependent on ...
	(maybe_dump_template_bindings): ... this new function, factored out of
	...
	(dump_function_decl): ... here.  Updated to early-out with call to
	dump_lambda_function after determining template bindings.
---
Reworked as requested.  Okay to commit?
---
 gcc/cp/error.c | 60 ++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 39 insertions(+), 21 deletions(-)

Comments

Gabriel Dos Reis Aug. 29, 2013, 3:25 p.m. UTC | #1
On Thu, Aug 29, 2013 at 9:20 AM, Adam Butcher <adam@jessamine.co.uk> wrote:
>         * error.c (dump_lambda_function): New function, dependent on ...
>         (maybe_dump_template_bindings): ... this new function, factored out of
>         ...
>         (dump_function_decl): ... here.  Updated to early-out with call to
>         dump_lambda_function after determining template bindings.
> ---
> Reworked as requested.  Okay to commit?

Document the new functions.
Use pp->translate_string ("with") instead of
pp_cxx_ws_string (pp, M_("with")).

 OK to commit with those changes.

Thanks,
-- Gaby

>
> +static void
> +maybe_dump_template_bindings (cxx_pretty_printer *pp,
> +                             tree t, tree template_parms, tree template_args,
> +                             int flags)
> +{
> +  if (template_parms != NULL_TREE && template_args != NULL_TREE
> +      && !(flags & TFF_NO_TEMPLATE_BINDINGS))
> +    {
> +      vec<tree, va_gc> *typenames = find_typenames (t);
> +      pp_cxx_whitespace (pp);
> +      pp_cxx_left_bracket (pp);
> +      pp_cxx_ws_string (pp, M_("with"));
> +      pp_cxx_whitespace (pp);
> +      dump_template_bindings (pp, template_parms, template_args, typenames);
> +      pp_cxx_right_bracket (pp);
> +    }
> +}
> +
> +static void
> +dump_lambda_function (cxx_pretty_printer *pp,
> +                     tree fn, tree template_parms, tree template_args,
> +                     int flags)
> +{
> +  /* A lambda's signature is essentially its "type".  */
> +  dump_type (pp, DECL_CONTEXT (fn), flags);
> +  if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST))
> +    {
> +      pp->padding = pp_before;
> +      pp_c_ws_string (pp, "mutable");
> +    }
> +  maybe_dump_template_bindings (pp, fn, template_parms, template_args, flags);
> +}
> +
>  /* Pretty print a function decl. There are several ways we want to print a
>     function declaration. The TFF_ bits in FLAGS tells us how to behave.
>     As error can only apply the '#' flag once to give 0 and 1 for V, there
> @@ -1379,15 +1412,6 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
>    int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
>    int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME);
>    tree exceptions;
> -  vec<tree, va_gc> *typenames = NULL;
> -
> -  if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
> -    {
> -      /* A lambda's signature is essentially its "type", so defer.  */
> -      gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t)));
> -      dump_type (pp, DECL_CONTEXT (t), flags);
> -      return;
> -    }
>
>    flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME);
>    if (TREE_CODE (t) == TEMPLATE_DECL)
> @@ -1409,10 +1433,13 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
>         {
>           template_parms = DECL_TEMPLATE_PARMS (tmpl);
>           t = tmpl;
> -         typenames = find_typenames (t);
>         }
>      }
>
> +  if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
> +    return dump_lambda_function (pp, t, template_parms, template_args,
> +                                flags);
> +
>    fntype = TREE_TYPE (t);
>    parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
>
> @@ -1476,17 +1503,8 @@ dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
>        if (show_return)
>         dump_type_suffix (pp, TREE_TYPE (fntype), flags);
>
> -      /* If T is a template instantiation, dump the parameter binding.  */
> -      if (template_parms != NULL_TREE && template_args != NULL_TREE
> -         && !(flags & TFF_NO_TEMPLATE_BINDINGS))
> -       {
> -         pp_cxx_whitespace (pp);
> -         pp_cxx_left_bracket (pp);
> -         pp_cxx_ws_string (pp, M_("with"));
> -         pp_cxx_whitespace (pp);
> -         dump_template_bindings (pp, template_parms, template_args, typenames);
> -         pp_cxx_right_bracket (pp);
> -       }
> +      maybe_dump_template_bindings (pp, t, template_parms, template_args,
> +                                   flags);
>      }
>    else if (template_args)
>      {
> --
> 1.8.4
>
Adam Butcher Aug. 29, 2013, 5:04 p.m. UTC | #2
On 29.08.2013 16:25, Gabriel Dos Reis wrote:
> On Thu, Aug 29, 2013 at 9:20 AM, Adam Butcher <adam@jessamine.co.uk> 
> wrote:
>>         * error.c (dump_lambda_function): New function, dependent on 
>> ...
>>         (maybe_dump_template_bindings): ... this new function, 
>> factored out of
>>         ...
>>         (dump_function_decl): ... here.  Updated to early-out with 
>> call to
>>         dump_lambda_function after determining template bindings.
>> ---
>> Reworked as requested.  Okay to commit?
>
> Document the new functions.
> Use pp->translate_string ("with") instead of
> pp_cxx_ws_string (pp, M_("with")).
>
Done.  In documenting 'maybe_dump_template_bindings' and reviewing it 
again I'm not sure it's got the right name.  It wraps 
'dump_template_bindings' in "[with " and "]".  So it does more than just 
filter a call to 'dump_template_bindings'.

Any suggestions?  What do you think of 'maybe_dump_with_clause' or 
something similar?

Cheers,
Adam

>
> Thanks,
> -- Gaby
>
>>
>> +static void
>> +maybe_dump_template_bindings (cxx_pretty_printer *pp,
>> +                             tree t, tree template_parms, tree 
>> template_args,
>> +                             int flags)
>> +{
>> +  if (template_parms != NULL_TREE && template_args != NULL_TREE
>> +      && !(flags & TFF_NO_TEMPLATE_BINDINGS))
>> +    {
>> +      vec<tree, va_gc> *typenames = find_typenames (t);
>> +      pp_cxx_whitespace (pp);
>> +      pp_cxx_left_bracket (pp);
>> +      pp_cxx_ws_string (pp, M_("with"));
>> +      pp_cxx_whitespace (pp);
>> +      dump_template_bindings (pp, template_parms, template_args, 
>> typenames);
>> +      pp_cxx_right_bracket (pp);
>> +    }
>> +}
>> +
>> +static void
>> +dump_lambda_function (cxx_pretty_printer *pp,
>> +                     tree fn, tree template_parms, tree 
>> template_args,
>> +                     int flags)
>> +{
>> +  /* A lambda's signature is essentially its "type".  */
>> +  dump_type (pp, DECL_CONTEXT (fn), flags);
>> +  if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & 
>> TYPE_QUAL_CONST))
>> +    {
>> +      pp->padding = pp_before;
>> +      pp_c_ws_string (pp, "mutable");
>> +    }
>> +  maybe_dump_template_bindings (pp, fn, template_parms, 
>> template_args, flags);
>> +}
>> +
>>  /* Pretty print a function decl. There are several ways we want to 
>> print a
>>     function declaration. The TFF_ bits in FLAGS tells us how to 
>> behave.
>>     As error can only apply the '#' flag once to give 0 and 1 for V, 
>> there
>> @@ -1379,15 +1412,6 @@ dump_function_decl (cxx_pretty_printer *pp, 
>> tree t, int flags)
>>    int show_return = flags & TFF_RETURN_TYPE || flags & 
>> TFF_DECL_SPECIFIERS;
>>    int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME);
>>    tree exceptions;
>> -  vec<tree, va_gc> *typenames = NULL;
>> -
>> -  if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
>> -    {
>> -      /* A lambda's signature is essentially its "type", so defer.  
>> */
>> -      gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t)));
>> -      dump_type (pp, DECL_CONTEXT (t), flags);
>> -      return;
>> -    }
>>
>>    flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME);
>>    if (TREE_CODE (t) == TEMPLATE_DECL)
>> @@ -1409,10 +1433,13 @@ dump_function_decl (cxx_pretty_printer *pp, 
>> tree t, int flags)
>>         {
>>           template_parms = DECL_TEMPLATE_PARMS (tmpl);
>>           t = tmpl;
>> -         typenames = find_typenames (t);
>>         }
>>      }
>>
>> +  if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
>> +    return dump_lambda_function (pp, t, template_parms, 
>> template_args,
>> +                                flags);
>> +
>>    fntype = TREE_TYPE (t);
>>    parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
>>
>> @@ -1476,17 +1503,8 @@ dump_function_decl (cxx_pretty_printer *pp, 
>> tree t, int flags)
>>        if (show_return)
>>         dump_type_suffix (pp, TREE_TYPE (fntype), flags);
>>
>> -      /* If T is a template instantiation, dump the parameter 
>> binding.  */
>> -      if (template_parms != NULL_TREE && template_args != NULL_TREE
>> -         && !(flags & TFF_NO_TEMPLATE_BINDINGS))
>> -       {
>> -         pp_cxx_whitespace (pp);
>> -         pp_cxx_left_bracket (pp);
>> -         pp_cxx_ws_string (pp, M_("with"));
>> -         pp_cxx_whitespace (pp);
>> -         dump_template_bindings (pp, template_parms, template_args, 
>> typenames);
>> -         pp_cxx_right_bracket (pp);
>> -       }
>> +      maybe_dump_template_bindings (pp, t, template_parms, 
>> template_args,
>> +                                   flags);
>>      }
>>    else if (template_args)
>>      {
>> --
>> 1.8.4
>>
diff mbox

Patch

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index c82a0ce..1edfa0b 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1363,6 +1363,39 @@  find_typenames (tree t)
   return ft.typenames;
 }
 
+static void
+maybe_dump_template_bindings (cxx_pretty_printer *pp,
+			      tree t, tree template_parms, tree template_args,
+			      int flags)
+{
+  if (template_parms != NULL_TREE && template_args != NULL_TREE
+      && !(flags & TFF_NO_TEMPLATE_BINDINGS))
+    {
+      vec<tree, va_gc> *typenames = find_typenames (t);
+      pp_cxx_whitespace (pp);
+      pp_cxx_left_bracket (pp);
+      pp_cxx_ws_string (pp, M_("with"));
+      pp_cxx_whitespace (pp);
+      dump_template_bindings (pp, template_parms, template_args, typenames);
+      pp_cxx_right_bracket (pp);
+    }
+}
+
+static void
+dump_lambda_function (cxx_pretty_printer *pp,
+		      tree fn, tree template_parms, tree template_args,
+		      int flags)
+{
+  /* A lambda's signature is essentially its "type".  */
+  dump_type (pp, DECL_CONTEXT (fn), flags);
+  if (!(TYPE_QUALS (class_of_this_parm (TREE_TYPE (fn))) & TYPE_QUAL_CONST))
+    {
+      pp->padding = pp_before;
+      pp_c_ws_string (pp, "mutable");
+    }
+  maybe_dump_template_bindings (pp, fn, template_parms, template_args, flags);
+}
+
 /* Pretty print a function decl. There are several ways we want to print a
    function declaration. The TFF_ bits in FLAGS tells us how to behave.
    As error can only apply the '#' flag once to give 0 and 1 for V, there
@@ -1379,15 +1412,6 @@  dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
   int show_return = flags & TFF_RETURN_TYPE || flags & TFF_DECL_SPECIFIERS;
   int do_outer_scope = ! (flags & TFF_UNQUALIFIED_NAME);
   tree exceptions;
-  vec<tree, va_gc> *typenames = NULL;
-
-  if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
-    {
-      /* A lambda's signature is essentially its "type", so defer.  */
-      gcc_assert (LAMBDA_TYPE_P (DECL_CONTEXT (t)));
-      dump_type (pp, DECL_CONTEXT (t), flags);
-      return;
-    }
 
   flags &= ~(TFF_UNQUALIFIED_NAME | TFF_TEMPLATE_NAME);
   if (TREE_CODE (t) == TEMPLATE_DECL)
@@ -1409,10 +1433,13 @@  dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
 	{
 	  template_parms = DECL_TEMPLATE_PARMS (tmpl);
 	  t = tmpl;
-	  typenames = find_typenames (t);
 	}
     }
 
+  if (DECL_NAME (t) && LAMBDA_FUNCTION_P (t))
+    return dump_lambda_function (pp, t, template_parms, template_args,
+				 flags);
+
   fntype = TREE_TYPE (t);
   parmtypes = FUNCTION_FIRST_USER_PARMTYPE (t);
 
@@ -1476,17 +1503,8 @@  dump_function_decl (cxx_pretty_printer *pp, tree t, int flags)
       if (show_return)
 	dump_type_suffix (pp, TREE_TYPE (fntype), flags);
 
-      /* If T is a template instantiation, dump the parameter binding.  */
-      if (template_parms != NULL_TREE && template_args != NULL_TREE
-	  && !(flags & TFF_NO_TEMPLATE_BINDINGS))
-	{
-	  pp_cxx_whitespace (pp);
-	  pp_cxx_left_bracket (pp);
-	  pp_cxx_ws_string (pp, M_("with"));
-	  pp_cxx_whitespace (pp);
-	  dump_template_bindings (pp, template_parms, template_args, typenames);
-	  pp_cxx_right_bracket (pp);
-	}
+      maybe_dump_template_bindings (pp, t, template_parms, template_args,
+				    flags);
     }
   else if (template_args)
     {