This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[diagnostics] add location to array declarators


Same old.

Tested on x86-64 Linux.

Next on the list is our friend fold*.  Blah.

	* 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.

Index: c-tree.h
===================================================================
--- c-tree.h	(revision 144056)
+++ c-tree.h	(working copy)
@@ -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);
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 143874)
+++ c-decl.c	(working copy)
@@ -3034,21 +3034,24 @@ quals_from_declspecs (const struct c_dec
   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, struc
   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, struc
       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_declarato
     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;
Index: c-parser.c
===================================================================
--- c-parser.c	(revision 144056)
+++ c-parser.c	(working copy)
@@ -2343,6 +2343,7 @@ c_parser_direct_declarator_inner (c_pars
   /* 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_pars
 				     "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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]