* [patch] Change gcc/c-format.c to add new specifiers to the Fortran front-end format
@ 2007-08-09 21:57 FX Coudert
2007-08-11 23:35 ` Joseph S. Myers
0 siblings, 1 reply; 3+ messages in thread
From: FX Coudert @ 2007-08-09 21:57 UTC (permalink / raw)
To: gcc-patches list, GNU Fortran; +Cc: jsm, rth
[-- Attachment #1: Type: text/plain, Size: 455 bytes --]
Hi all,
This patch allows the Fortran front-end to use format specifier %u,
as well as the l length modifier (for formats %lu, %li and %ld), by
modifying gcc/c-format.c. This only changes the gcc_gfc format type,
which is for use by the Fortran front-end, but I still need a review
by a C front-end maintainer and would welcome a review by a Fortran
maintainer for the Fortran part.
Bootstrapped and regtested on x86_64-linux, OK to commit?
[-- Attachment #2: error_print_longer.ChangeLog --]
[-- Type: application/octet-stream, Size: 572 bytes --]
2007-08-09 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/32860
* error.c (error_uinteger): New function.
(error_integer): Call error_uinteger.
(error_print): Handle %u, %lu, %li and %ld format specifiers.
* interface.c (compare_actual_formal): Use the new %lu specifier.
2007-08-09 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/32860
* ../c-format.c (gcc_gfc_length_specs): New array.
(gcc_gfc_char_table): Add unsigned specifier, and references to
the l length modifier.
(format_types_orig): Use the new gcc_gfc_length_specs.
[-- Attachment #3: error_print_longer.diff --]
[-- Type: application/octet-stream, Size: 5614 bytes --]
Index: error.c
===================================================================
--- error.c (revision 127224)
+++ error.c (working copy)
@@ -113,19 +113,13 @@ error_string (const char *p)
/* Print a formatted integer to the error buffer or output. */
-#define IBUF_LEN 30
+#define IBUF_LEN 60
static void
-error_integer (int i)
+error_uinteger (unsigned long int i)
{
char *p, int_buf[IBUF_LEN];
- if (i < 0)
- {
- i = -i;
- error_char ('-');
- }
-
p = int_buf + IBUF_LEN - 1;
*p-- = '\0';
@@ -141,6 +135,22 @@ error_integer (int i)
error_string (p + 1);
}
+static void
+error_integer (long int i)
+{
+ unsigned long int u;
+
+ if (i < 0)
+ {
+ u = (unsigned long int) -i;
+ error_char ('-');
+ }
+ else
+ u = i;
+
+ error_uinteger (u);
+}
+
/* Show the file, where it was included, and the source line, give a
locus. Calls error_printf() recursively, but the recursion is at
@@ -368,7 +378,8 @@ show_loci (locus *l1, locus *l2)
static void ATTRIBUTE_GCC_GFC(2,0)
error_print (const char *type, const char *format0, va_list argp)
{
- enum { TYPE_CURRENTLOC, TYPE_LOCUS, TYPE_INTEGER, TYPE_CHAR, TYPE_STRING,
+ enum { TYPE_CURRENTLOC, TYPE_LOCUS, TYPE_INTEGER, TYPE_UINTEGER,
+ TYPE_LONGINT, TYPE_ULONGINT, TYPE_CHAR, TYPE_STRING,
NOTYPE };
struct
{
@@ -377,6 +388,9 @@ error_print (const char *type, const cha
union
{
int intval;
+ unsigned int uintval;
+ long int longintval;
+ unsigned long int ulongintval;
char charval;
const char * stringval;
} u;
@@ -453,6 +467,19 @@ error_print (const char *type, const cha
arg[pos].type = TYPE_INTEGER;
break;
+ case 'u':
+ arg[pos].type = TYPE_UINTEGER;
+
+ case 'l':
+ c = *format++;
+ if (c == 'u')
+ arg[pos].type = TYPE_ULONGINT;
+ else if (c == 'i' || c == 'd')
+ arg[pos].type = TYPE_LONGINT;
+ else
+ gcc_unreachable ();
+ break;
+
case 'c':
arg[pos].type = TYPE_CHAR;
break;
@@ -499,6 +526,18 @@ error_print (const char *type, const cha
arg[pos].u.intval = va_arg (argp, int);
break;
+ case TYPE_UINTEGER:
+ arg[pos].u.uintval = va_arg (argp, unsigned int);
+ break;
+
+ case TYPE_LONGINT:
+ arg[pos].u.longintval = va_arg (argp, long int);
+ break;
+
+ case TYPE_ULONGINT:
+ arg[pos].u.ulongintval = va_arg (argp, unsigned long int);
+ break;
+
case TYPE_CHAR:
arg[pos].u.charval = (char) va_arg (argp, int);
break;
@@ -568,6 +607,19 @@ error_print (const char *type, const cha
case 'i':
error_integer (spec[n++].u.intval);
break;
+
+ case 'u':
+ error_uinteger (spec[n++].u.uintval);
+ break;
+
+ case 'l':
+ format++;
+ if (*format == 'u')
+ error_uinteger (spec[n++].u.ulongintval);
+ else
+ error_integer (spec[n++].u.longintval);
+ break;
+
}
}
Index: interface.c
===================================================================
--- interface.c (revision 127224)
+++ interface.c (working copy)
@@ -1680,14 +1680,14 @@ compare_actual_formal (gfc_actual_arglis
{
if (a->expr->ts.type == BT_CHARACTER && !f->sym->as && where)
gfc_warning ("Character length of actual argument shorter "
- "than of dummy argument '%s' (%d/%d) at %L",
- f->sym->name, (int) actual_size,
- (int) formal_size, &a->expr->where);
+ "than of dummy argument '%s' (%lu/%lu) at %L",
+ f->sym->name, actual_size, formal_size,
+ &a->expr->where);
else if (where)
gfc_warning ("Actual argument contains too few "
- "elements for dummy argument '%s' (%d/%d) at %L",
- f->sym->name, (int) actual_size,
- (int) formal_size, &a->expr->where);
+ "elements for dummy argument '%s' (%lu/%lu) at %L",
+ f->sym->name, actual_size, formal_size,
+ &a->expr->where);
return 0;
}
Index: ../c-format.c
===================================================================
--- ../c-format.c (revision 127224)
+++ ../c-format.c (working copy)
@@ -342,6 +342,15 @@ static const format_length_info strfmon_
{ NULL, 0, 0, NULL, 0, 0 }
};
+
+/* For now, the Fortran front-end routines only use l as length modifier. */
+static const format_length_info gcc_gfc_length_specs[] =
+{
+ { "l", FMT_LEN_l, STD_C89, NULL, 0, 0 },
+ { NULL, 0, 0, NULL, 0, 0 }
+};
+
+
static const format_flag_spec printf_flag_specs[] =
{
{ ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89 },
@@ -631,7 +640,8 @@ static const format_char_info gcc_cxxdia
static const format_char_info gcc_gfc_char_table[] =
{
/* C89 conversion specifiers. */
- { "di", 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 }, "", "", 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 },
{ "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL },
@@ -738,7 +748,7 @@ static const format_kind_info format_typ
0, 0, 'p', 0, 'L',
NULL, &integer_type_node
},
- { "gcc_gfc", NULL, gcc_gfc_char_table, "", NULL,
+ { "gcc_gfc", gcc_gfc_length_specs, gcc_gfc_char_table, "", NULL,
NULL, gcc_gfc_flag_pairs,
FMT_FLAG_ARG_CONVERT,
0, 0, 0, 0, 0,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] Change gcc/c-format.c to add new specifiers to the Fortran front-end format
2007-08-09 21:57 [patch] Change gcc/c-format.c to add new specifiers to the Fortran front-end format FX Coudert
@ 2007-08-11 23:35 ` Joseph S. Myers
2007-08-12 20:42 ` FX Coudert
0 siblings, 1 reply; 3+ messages in thread
From: Joseph S. Myers @ 2007-08-11 23:35 UTC (permalink / raw)
To: FX Coudert; +Cc: gcc-patches list, GNU Fortran, rth
On Thu, 9 Aug 2007, FX Coudert wrote:
> Hi all,
>
> This patch allows the Fortran front-end to use format specifier %u, as well as
> the l length modifier (for formats %lu, %li and %ld), by modifying
> gcc/c-format.c. This only changes the gcc_gfc format type, which is for use by
> the Fortran front-end, but I still need a review by a C front-end maintainer
> and would welcome a review by a Fortran maintainer for the Fortran part.
>
> Bootstrapped and regtested on x86_64-linux, OK to commit?
The C parts are OK if you also update gcc.dg/format/gcc_gfc-1.c to test
the new formats.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] Change gcc/c-format.c to add new specifiers to the Fortran front-end format
2007-08-11 23:35 ` Joseph S. Myers
@ 2007-08-12 20:42 ` FX Coudert
0 siblings, 0 replies; 3+ messages in thread
From: FX Coudert @ 2007-08-12 20:42 UTC (permalink / raw)
To: Joseph S. Myers; +Cc: gcc-patches list, GNU Fortran
> The C parts are OK if you also update gcc.dg/format/gcc_gfc-1.c to
> test
> the new formats.
Committed along with the changes to the testcase (of which I was
unaware). Thanks for the review and pointing at the testcase!
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127382
FX
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-08-12 20:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-09 21:57 [patch] Change gcc/c-format.c to add new specifiers to the Fortran front-end format FX Coudert
2007-08-11 23:35 ` Joseph S. Myers
2007-08-12 20:42 ` FX Coudert
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).