diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2009-02-11 23:49:30 +0000 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2009-02-11 23:49:30 +0000 |
commit | 961652cae1dbdfe0b57964bf7106b52f624efeb8 (patch) | |
tree | 8bdb67d66f73cbca365ad0f8e9fe6ddd6e4b6b88 | |
parent | d4bb08742bd7fbd5194abcb7c9ab629351e1b033 (diff) |
* c-tree.h: (struct c_declarator): Add comment to id_loc.
(build_array_declarator): New argument.
* c-decl.c (build_array_declarator): Add location argument.
(grokdeclarator): Set id_loc for cdk_array.
* c-parser.c (c_parser_direct_declarator_inner): Pass location to
build_array_declarator.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/diagnostics-branch@144113 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog.diagnostics | 9 | ||||
-rw-r--r-- | gcc/c-decl.c | 33 | ||||
-rw-r--r-- | gcc/c-parser.c | 5 | ||||
-rw-r--r-- | gcc/c-tree.h | 5 |
4 files changed, 35 insertions, 17 deletions
diff --git a/gcc/ChangeLog.diagnostics b/gcc/ChangeLog.diagnostics index 25968c8dc0f..a54a3359f1d 100644 --- a/gcc/ChangeLog.diagnostics +++ b/gcc/ChangeLog.diagnostics @@ -1,3 +1,12 @@ +2009-02-11 Aldy Hernandez <aldyh@redhat.com> + + * c-tree.h: (struct c_declarator): Add comment to id_loc. + (build_array_declarator): New argument. + * c-decl.c (build_array_declarator): Add location argument. + (grokdeclarator): Set id_loc for cdk_array. + * c-parser.c (c_parser_direct_declarator_inner): Pass location to + build_array_declarator. + 2009-02-09 Aldy Hernandez <aldyh@redhat.com> * tree.c (build_omp_clause): Add location argument. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index a85b2262258..9e994cd8480 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -3034,21 +3034,24 @@ quals_from_declspecs (const struct c_declspecs *specs) return quals; } -/* Construct an array declarator. EXPR is the expression inside [], - or NULL_TREE. QUALS are the type qualifiers inside the [] (to be - applied to the pointer to which a parameter array is converted). - STATIC_P is true if "static" is inside the [], false otherwise. - VLA_UNSPEC_P is true if the array is [*], a VLA of unspecified - length which is nevertheless a complete type, false otherwise. The - field for the contained declarator is left to be filled in by - set_array_declarator_inner. */ +/* Construct an array declarator. LOC is the location of the + beginning of the array (usually the opening brace). EXPR is the + expression inside [], or NULL_TREE. QUALS are the type qualifiers + inside the [] (to be applied to the pointer to which a parameter + array is converted). STATIC_P is true if "static" is inside the + [], false otherwise. VLA_UNSPEC_P is true if the array is [*], a + VLA of unspecified length which is nevertheless a complete type, + false otherwise. The field for the contained declarator is left to + be filled in by set_array_declarator_inner. */ struct c_declarator * -build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, +build_array_declarator (location_t loc, + tree expr, struct c_declspecs *quals, bool static_p, bool vla_unspec_p) { struct c_declarator *declarator = XOBNEW (&parser_obstack, struct c_declarator); + declarator->id_loc = loc; declarator->kind = cdk_array; declarator->declarator = 0; declarator->u.array.dimen = expr; @@ -3067,11 +3070,11 @@ build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, if (!flag_isoc99) { if (static_p || quals != NULL) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C90 does not support %<static%> or type " "qualifiers in parameter array declarators"); if (vla_unspec_p) - pedwarn (input_location, OPT_pedantic, + pedwarn (loc, OPT_pedantic, "ISO C90 does not support %<[*]%> array declarators"); } if (vla_unspec_p) @@ -3079,7 +3082,8 @@ build_array_declarator (tree expr, struct c_declspecs *quals, bool static_p, if (!current_scope->parm_flag) { /* C99 6.7.5.2p4 */ - error ("%<[*]%> not allowed in other than function prototype scope"); + error_at (loc, "%<[*]%> not allowed in other than " + "function prototype scope"); declarator->u.array.vla_unspec_p = false; return NULL; } @@ -4009,8 +4013,11 @@ grokdeclarator (const struct c_declarator *declarator, while (decl) switch (decl->kind) { - case cdk_function: case cdk_array: + loc = decl->id_loc; + /* FALL THRU. */ + + case cdk_function: case cdk_pointer: funcdef_syntax = (decl->kind == cdk_function); decl = decl->declarator; diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 455b5de690d..7e40beaa431 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -2343,6 +2343,7 @@ c_parser_direct_declarator_inner (c_parser *parser, bool id_present, /* Parse a sequence of array declarators and parameter lists. */ if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) { + location_t brace_loc = c_parser_peek_token (parser)->location; struct c_declarator *declarator; struct c_declspecs *quals_attrs = build_null_declspecs (); bool static_seen; @@ -2400,8 +2401,8 @@ c_parser_direct_declarator_inner (c_parser *parser, bool id_present, "expected %<]%>"); return NULL; } - declarator = build_array_declarator (dimen, quals_attrs, static_seen, - star_seen); + declarator = build_array_declarator (brace_loc, dimen, quals_attrs, + static_seen, star_seen); if (declarator == NULL) return NULL; inner = set_array_declarator_inner (declarator, inner); diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 34c6594572d..2d27b6527c7 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -329,7 +329,7 @@ struct c_declarator { enum c_declarator_kind kind; /* Except for cdk_id, the contained declarator. For cdk_id, NULL. */ struct c_declarator *declarator; - location_t id_loc; /* Currently only set for cdk_id. */ + location_t id_loc; /* Currently only set for cdk_id, cdk_array. */ union { /* For identifiers, an IDENTIFIER_NODE or NULL_TREE if an abstract declarator. */ @@ -461,7 +461,8 @@ extern void c_init_decl_processing (void); extern void c_dup_lang_specific_decl (tree); extern void c_print_identifier (FILE *, tree, int); extern int quals_from_declspecs (const struct c_declspecs *); -extern struct c_declarator *build_array_declarator (tree, struct c_declspecs *, +extern struct c_declarator *build_array_declarator (location_t, tree, + struct c_declspecs *, bool, bool); extern tree build_enumerator (location_t, struct c_enum_contents *, tree, tree); extern tree check_for_loop_decls (location_t); |