This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: make grokfield handle locations
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: Manuel L?pez-Ib??ez <lopezibanez at gmail dot com>
- Cc: joseph at codesourcery dot com, tromey at redhat dot com, mark at codesourcery dot com, Gcc Patch List <gcc-patches at gcc dot gnu dot org>, janis187 at us dot ibm dot com
- Date: Tue, 19 Aug 2008 11:24:43 -0400
- Subject: Re: make grokfield handle locations
- References: <20080819105753.GA1373@redhat.com> <6c33472e0808190441n16a30708nff3372fe860ca58b@mail.gmail.com>
> You can enable column numbers explicitly with dg-options
> "-fshow-column". It will (*should*) override any global settings. Then
> you can test by doing:
>
> dg-error "11: error"
>
> which is cumbersome and ugly but is what we have now. And it is going
> to grow unless someone fixes the testsuite to handle column numbers in
> a nicer way.
I would prefer to fix the dejagnu machinery instead of testing for
explicit column numbers like:
> /* { dg-warning "does not declare anything" "" { target *-*-* } "5" "11" }
If we make it tedious for testcase writers, no one will ever annotate
column information in tests.
I'm open for suggestions of something simple and easy to annotate. If
it turns it's next to impossible in dejagnu, then I suppose we can use
the existing machinery and some additional fields like you mention.
Janis, do you have any input?
> I think this is not correct. Between this line and the next one, the
> next token may have changed and the location pointed by tok would be
> not valid anymore.
Fixed.
How does this look?
* c-tree.h (grokfield): New argument.
* c-decl.c (grokfield): Handle new location argument.
* c-parser.c (c_parser_struct_declaration): Pass location to
grokfield.
Index: c-tree.h
===================================================================
--- c-tree.h (revision 139207)
+++ c-tree.h (working copy)
@@ -475,8 +475,8 @@ extern tree finish_enum (tree, tree, tre
extern void finish_function (void);
extern tree finish_struct (tree, tree, tree);
extern struct c_arg_info *get_parm_info (bool);
-extern tree grokfield (struct c_declarator *, struct c_declspecs *,
- tree, tree *);
+extern tree grokfield (location_t, struct c_declarator *,
+ struct c_declspecs *, tree, tree *);
extern tree groktypename (struct c_type_name *);
extern tree grokparm (const struct c_parm *);
extern tree implicitly_declare (tree);
Index: c-decl.c
===================================================================
--- c-decl.c (revision 139207)
+++ c-decl.c (working copy)
@@ -5342,12 +5342,15 @@ start_struct (enum tree_code code, tree
WIDTH is non-NULL for bit-fields only, and is an INTEGER_CST node.
DECL_ATTRS is as for grokdeclarator.
+ LOC is the location of the structure component.
+
This is done during the parsing of the struct declaration.
The FIELD_DECL nodes are chained together and the lot of them
are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
tree
-grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs,
+grokfield (location_t loc,
+ struct c_declarator *declarator, struct c_declspecs *declspecs,
tree width, tree *decl_attrs)
{
tree value;
@@ -5393,10 +5396,11 @@ grokfield (struct c_declarator *declarat
}
if (!ok)
{
- pedwarn (0, "declaration does not declare anything");
+ pedwarn_at (loc, 0, "declaration does not declare anything");
return NULL_TREE;
}
- pedwarn (OPT_pedantic, "ISO C doesn%'t support unnamed structs/unions");
+ pedwarn_at (loc, OPT_pedantic,
+ "ISO C doesn%'t support unnamed structs/unions");
}
value = grokdeclarator (declarator, declspecs, FIELD, false,
Index: c-parser.c
===================================================================
--- c-parser.c (revision 139207)
+++ c-parser.c (working copy)
@@ -1966,7 +1966,9 @@ c_parser_struct_declaration (c_parser *p
structs or unions (which is [a] useful and [b] supports
MS P-SDK). */
tree attrs = NULL;
- ret = grokfield (build_id_declarator (NULL_TREE), specs,
+
+ ret = grokfield (c_parser_peek_token (parser)->location,
+ build_id_declarator (NULL_TREE), specs,
NULL_TREE, &attrs);
if (ret)
decl_attributes (&ret, attrs, 0);
@@ -2009,7 +2011,8 @@ c_parser_struct_declaration (c_parser *p
}
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
postfix_attrs = c_parser_attributes (parser);
- d = grokfield (declarator, specs, width, &all_prefix_attrs);
+ d = grokfield (c_parser_peek_token (parser)->location,
+ declarator, specs, width, &all_prefix_attrs);
decl_attributes (&d, chainon (postfix_attrs,
all_prefix_attrs), 0);
TREE_CHAIN (d) = decls;