public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %>
@ 2015-12-09 15:53 Tobias Burnus
  2015-12-09 18:16 ` Steve Kargl
  2015-12-10 22:05 ` Manuel López-Ibáñez
  0 siblings, 2 replies; 5+ messages in thread
From: Tobias Burnus @ 2015-12-09 15:53 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 864 bytes --]

This patch replaces some of the '%s' quotes of diagnostic strings
by the nicer quotes.


First, it replaces some leftovers of '%s' -> %qs in directly used
error strings.


It then also converts some (well: resolve.c only) '%s' to %%<%s%%>,
which are using with sprintf(), but which are still passed as
fmt string to the diagnostic functions.

There is still code using '%s' - but those bits have the form
  sprintf (buffer, ".... '%s' ... ");
  gfc_error ("Bla ... : %s", ..., buffer);
which prevents the use of %< ... %>. (See last comment in the PR.)


In principle, %<%c%> and %<%d%> should be convertable to %qc and
%qd (as the code is more readable), but the current function
annotation prevent this, telling that the q flag is not valid for
%c and %d. As %< is fine, I didn't dig into it.


Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias

[-- Attachment #2: qs.diff --]
[-- Type: text/x-diff, Size: 5242 bytes --]

	PR fortran/68815
	* decl.c (gfc_verify_c_interop_param, variable_decl): Use
	%< ... %> for quoting in diagnostics.
	* io.c (check_format): Ditto.
	* resolve.c (resolve_operator): Ditto.
	* symbol.c (check_conflict): Ditto.
	* trans-common.c (translate_common): Ditto.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index bff23e1..b03dadf 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1194,7 +1194,7 @@ gfc_verify_c_interop_param (gfc_symbol *sym)
 	  if (sym->as != NULL && sym->as->type == AS_ASSUMED_SHAPE
 	      && !gfc_notify_std (GFC_STD_F2008_TS, "Assumed-shape array %qs "
 				  "at %L as dummy argument to the BIND(C) "
-				  "procedure '%s' at %L", sym->name, 
+				  "procedure %qs at %L", sym->name,
 				  &(sym->declared_at), 
 				  sym->ns->proc_name->name, 
 				  &(sym->ns->proc_name->declared_at)))
@@ -2023,9 +2023,9 @@ variable_decl (int elem)
       if (sym != NULL && (sym->attr.dummy || sym->attr.result))
 	{
 	  m = MATCH_ERROR;
-	  gfc_error ("'%s' at %C is a redefinition of the declaration "
+	  gfc_error ("%qs at %C is a redefinition of the declaration "
 		     "in the corresponding interface for MODULE "
-		     "PROCEDURE '%s'", sym->name,
+		     "PROCEDURE %qs", sym->name,
 		     gfc_current_ns->proc_name->name);
 	  goto cleanup;
 	}
diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c
index 8cf952f..9a77234 100644
--- a/gcc/fortran/io.c
+++ b/gcc/fortran/io.c
@@ -549,7 +549,7 @@ check_format (bool is_input)
 {
   const char *posint_required	  = _("Positive width required");
   const char *nonneg_required	  = _("Nonnegative width required");
-  const char *unexpected_element  = _("Unexpected element %<%c%> in format "
+  const char *unexpected_element  = _("Unexpected element %qc in format "
 				      "string at %L");
   const char *unexpected_end	  = _("Unexpected end of format string");
   const char *zero_width	  = _("Zero width in format descriptor");
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 10add62..65a2b7f 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -3560,7 +3560,7 @@ resolve_operator (gfc_expr *e)
 	  break;
 	}
 
-      sprintf (msg, _("Operand of unary numeric operator '%s' at %%L is %s"),
+      sprintf (msg, _("Operand of unary numeric operator %%<%s%%> at %%L is %s"),
 	       gfc_op2string (e->value.op.op), gfc_typename (&e->ts));
       goto bad_op;
 
@@ -3576,7 +3576,7 @@ resolve_operator (gfc_expr *e)
 	}
 
       sprintf (msg,
-	       _("Operands of binary numeric operator '%s' at %%L are %s/%s"),
+	       _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"),
 	       gfc_op2string (e->value.op.op), gfc_typename (&op1->ts),
 	       gfc_typename (&op2->ts));
       goto bad_op;
@@ -3610,7 +3610,7 @@ resolve_operator (gfc_expr *e)
 	  break;
 	}
 
-      sprintf (msg, _("Operands of logical operator '%s' at %%L are %s/%s"),
+      sprintf (msg, _("Operands of logical operator %%<%s%%> at %%L are %s/%s"),
 	       gfc_op2string (e->value.op.op), gfc_typename (&op1->ts),
 	       gfc_typename (&op2->ts));
 
@@ -3695,7 +3695,7 @@ resolve_operator (gfc_expr *e)
 		 ? ".eqv." : ".neqv.", gfc_op2string (e->value.op.op));
       else
 	sprintf (msg,
-		 _("Operands of comparison operator '%s' at %%L are %s/%s"),
+		 _("Operands of comparison operator %%<%s%%> at %%L are %s/%s"),
 		 gfc_op2string (e->value.op.op), gfc_typename (&op1->ts),
 		 gfc_typename (&op2->ts));
 
@@ -3703,13 +3703,14 @@ resolve_operator (gfc_expr *e)
 
     case INTRINSIC_USER:
       if (e->value.op.uop->op == NULL)
-	sprintf (msg, _("Unknown operator '%s' at %%L"), e->value.op.uop->name);
+	sprintf (msg, _("Unknown operator %%<%s%%> at %%L"),
+		 e->value.op.uop->name);
       else if (op2 == NULL)
-	sprintf (msg, _("Operand of user operator '%s' at %%L is %s"),
+	sprintf (msg, _("Operand of user operator %%<%s%%> at %%L is %s"),
 		 e->value.op.uop->name, gfc_typename (&op1->ts));
       else
 	{
-	  sprintf (msg, _("Operands of user operator '%s' at %%L are %s/%s"),
+	  sprintf (msg, _("Operands of user operator %%<%s%%> at %%L are %s/%s"),
 		   e->value.op.uop->name, gfc_typename (&op1->ts),
 		   gfc_typename (&op2->ts));
 	  e->value.op.uop->op->sym->attr.referenced = 1;
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index ff9aff9..311f743 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -465,7 +465,7 @@ check_conflict (symbol_attribute *attr, const char *name, locus *where)
 
   if (attr->dummy && ((attr->function || attr->subroutine) && 
 			gfc_current_state () == COMP_CONTAINS))
-    gfc_error_now ("internal procedure '%s' at %L conflicts with "
+    gfc_error_now ("internal procedure %qs at %L conflicts with "
 		   "DUMMY argument", name, where);
 
   conf (dummy, entry);
diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c
index af9fadf..bbbc726 100644
--- a/gcc/fortran/trans-common.c
+++ b/gcc/fortran/trans-common.c
@@ -1166,7 +1166,7 @@ translate_common (gfc_common_head *common, gfc_symbol *var_list)
 
   if (common_segment == NULL)
     {
-      gfc_error ("COMMON '%s' at %L does not exist",
+      gfc_error ("COMMON %qs at %L does not exist",
 		 common->name, &common->where);
       return;
     }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %>
  2015-12-09 15:53 [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %> Tobias Burnus
@ 2015-12-09 18:16 ` Steve Kargl
  2015-12-10 22:05 ` Manuel López-Ibáñez
  1 sibling, 0 replies; 5+ messages in thread
From: Steve Kargl @ 2015-12-09 18:16 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

On Wed, Dec 09, 2015 at 04:53:37PM +0100, Tobias Burnus wrote:
> 
> Build and regtested on x86-64-gnu-linux.
> OK for the trunk?
> 

OK.

-- 
Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %>
  2015-12-09 15:53 [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %> Tobias Burnus
  2015-12-09 18:16 ` Steve Kargl
@ 2015-12-10 22:05 ` Manuel López-Ibáñez
  2015-12-11  0:03   ` Joseph Myers
  1 sibling, 1 reply; 5+ messages in thread
From: Manuel López-Ibáñez @ 2015-12-10 22:05 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran, Joseph Myers, Jakub Jelinek

On 12/09/2015 03:53 PM, Tobias Burnus wrote:
> In principle, %<%c%> and %<%d%> should be convertable to %qc and
> %qd (as the code is more readable), but the current function
> annotation prevent this, telling that the q flag is not valid for
> %c and %d. As %< is fine, I didn't dig into it.

You need to edit the gcc_gfc_* variables in c-family/c-format.c. The correct 
way to do that does not seem to be documented anywhere. I only got the current 
support working after painful trial and error.

Joseph, Jakub, could you advise the Fortran devs on how to edit c-format.c to 
handle %qc and %qd as the C/C++ FEs do?

Thanks,

Manuel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %>
  2015-12-10 22:05 ` Manuel López-Ibáñez
@ 2015-12-11  0:03   ` Joseph Myers
  2015-12-11 10:00     ` Tobias Burnus
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Myers @ 2015-12-11  0:03 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: Tobias Burnus, gcc-patches, fortran, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 812 bytes --]

On Thu, 10 Dec 2015, Manuel López-Ibáñez wrote:

> On 12/09/2015 03:53 PM, Tobias Burnus wrote:
> > In principle, %<%c%> and %<%d%> should be convertable to %qc and
> > %qd (as the code is more readable), but the current function
> > annotation prevent this, telling that the q flag is not valid for
> > %c and %d. As %< is fine, I didn't dig into it.
> 
> You need to edit the gcc_gfc_* variables in c-family/c-format.c. The correct
> way to do that does not seem to be documented anywhere. I only got the current
> support working after painful trial and error.
> 
> Joseph, Jakub, could you advise the Fortran devs on how to edit c-format.c to
> handle %qc and %qd as the C/C++ FEs do?

Put "q" in the first flags string for those formats in gcc_gfc_char_table.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %>
  2015-12-11  0:03   ` Joseph Myers
@ 2015-12-11 10:00     ` Tobias Burnus
  0 siblings, 0 replies; 5+ messages in thread
From: Tobias Burnus @ 2015-12-11 10:00 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Manuel López-Ibáñez, gcc-patches, fortran, Jakub Jelinek

On Fri, Dec 11, 2015 at 12:03:26AM +0000, Joseph Myers wrote:
> On Thu, 10 Dec 2015, Manuel López-Ibáñez wrote:
> > On 12/09/2015 03:53 PM, Tobias Burnus wrote:
> > > In principle, %<%c%> and %<%d%> should be convertable to %qc and
> > > %qd (as the code is more readable), but the current function
> > > annotation prevent this, telling that the q flag is not valid for
> > > %c and %d. As %< is fine, I didn't dig into it.
> > 
> > You need to edit the gcc_gfc_* variables in c-family/c-format.c. [...]
> 
> Put "q" in the first flags string for those formats in gcc_gfc_char_table.


Thanks! The attached patch works :-)

Build and regtested on x86-64-gnu-linux.
I will commit it tomorrow, unless there are comments or objections.

Tobias



gcc/c-family/
	PR fortran/68815
	* c-format.c (gcc_gfc_char_table): Add 'q' flag to remaining
	specifiers (%d, %i,%u and %c).

gcc/fortran/
	PR fortran/68815
	* check.c (gfc_check_reshape): Replace %<%d%> by %qd.
	* matchexp.c (gfc_match_defined_op_name): Use %qc.
	* symbol.c (gfc_add_new_implicit_range,
	gfc_merge_new_implicit): Ditto.

diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 6e37265..de07b6c 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -809,9 +809,9 @@ static const format_char_info gcc_cxxdiag_char_table[] =
 static const format_char_info gcc_gfc_char_table[] =
 {
   /* C89 conversion specifiers.  */
-  { "di",  0, STD_C89, { T89_I,   BADLEN,  BADLEN,  T89_L,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "", NULL },
-  { "u",   0, STD_C89, { T89_UI,  BADLEN,  BADLEN,  T89_UL,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "", NULL },
-  { "c",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "", NULL },
+  { "di",  0, STD_C89, { T89_I,   BADLEN,  BADLEN,  T89_L,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q", "", NULL },
+  { "u",   0, STD_C89, { T89_UI,  BADLEN,  BADLEN,  T89_UL,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q", "", NULL },
+  { "c",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q", "", NULL },
   { "s",   1, STD_C89, { T89_C,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q", "cR", NULL },
 
   /* gfc conversion specifiers.  */
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 6dc7f3e..3f1bdd3 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -3863,7 +3863,7 @@ gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
 		{
 		  gfc_error ("%qs argument of %qs intrinsic at %L has "
 			     "invalid permutation of dimensions (dimension "
-			     "%<%d%> duplicated)",
+			     "%qd duplicated)",
 			     gfc_current_intrinsic_arg[3]->name,
 			     gfc_current_intrinsic, &e->where, dim);
 		  return false;
diff --git a/gcc/fortran/matchexp.c b/gcc/fortran/matchexp.c
index 02f43a0..c14ef59 100644
--- a/gcc/fortran/matchexp.c
+++ b/gcc/fortran/matchexp.c
@@ -69,7 +69,7 @@ gfc_match_defined_op_name (char *result, int error_flag)
   for (i = 0; name[i]; i++)
     if (!ISALPHA (name[i]))
       {
-	gfc_error ("Bad character %<%c%> in OPERATOR name at %C", name[i]);
+	gfc_error ("Bad character %qc in OPERATOR name at %C", name[i]);
 	return MATCH_ERROR;
       }
 
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 221fef3..d241bc0 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -166,7 +166,7 @@ gfc_add_new_implicit_range (int c1, int c2)
     {
       if (new_flag[i])
 	{
-	  gfc_error ("Letter %<%c%> already set in IMPLICIT statement at %C",
+	  gfc_error ("Letter %qc already set in IMPLICIT statement at %C",
 		     i + 'A');
 	  return false;
 	}
@@ -198,7 +198,7 @@ gfc_merge_new_implicit (gfc_typespec *ts)
 	{
 	  if (gfc_current_ns->set_flag[i])
 	    {
-	      gfc_error ("Letter %c already has an IMPLICIT type at %C",
+	      gfc_error ("Letter %qc already has an IMPLICIT type at %C",
 			 i + 'A');
 	      return false;
 	    }

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-11 10:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-09 15:53 [Patch, Fortran] PR68815 - replace '%s' quotes by %< ... %> Tobias Burnus
2015-12-09 18:16 ` Steve Kargl
2015-12-10 22:05 ` Manuel López-Ibáñez
2015-12-11  0:03   ` Joseph Myers
2015-12-11 10:00     ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).