OSDN Git Service

* c-tree.h (struct c_declarator): New id_loc field.
authorbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 12 Mar 2005 06:37:46 +0000 (06:37 +0000)
committerbothner <bothner@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 12 Mar 2005 06:37:46 +0000 (06:37 +0000)
* c-pragma.h (c_lex_with_flags): Take position reference.
* c-lex.c (c_lex_with_flags): Set passed-in location from cpp token,
iff USE_MAPPED_LOCATION. (Type doesn't match otherwise.)
(c_lex): Pass dummy location to c_lex_with_flags.
* c-parser.c (c_lex_one_token): Set c_token's location using
c_lex_with_flags, instead of input_location, which might be "ahead".
(c_parser_direct_declarator): Set declarator's id_loc from
c_token's id_loc.
* c-decl.c (grokdeclarator): Set DECL_SOURCE_LOCATION from
declarator's id_loc, rather than probably-imprecise input_location.
(build_id_declarator): Initialize c_declarator's id_loc field.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96329 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-decl.c
gcc/c-lex.c
gcc/c-parser.c
gcc/c-pragma.h
gcc/c-tree.h

index 3e9f384..5d85aba 100644 (file)
@@ -1,3 +1,18 @@
+2005-03-11  Per Bothner  <per@bothner.com>
+
+       * c-tree.h (struct c_declarator): New id_loc field.
+       * c-pragma.h (c_lex_with_flags): Take position reference.
+       * c-lex.c (c_lex_with_flags): Set passed-in location from cpp token,
+       iff USE_MAPPED_LOCATION. (Type doesn't match otherwise.)
+       (c_lex): Pass dummy location to c_lex_with_flags.
+       * c-parser.c (c_lex_one_token): Set c_token's location using
+       c_lex_with_flags, instead of input_location, which might be "ahead".
+       (c_parser_direct_declarator): Set declarator's id_loc from
+       c_token's id_loc.
+       * c-decl.c (grokdeclarator): Set DECL_SOURCE_LOCATION from
+       declarator's id_loc, rather than probably-imprecise input_location.
+       (build_id_declarator): Initialize c_declarator's id_loc field.
+
 2005-03-11  Roger Sayle  <roger@eyesopen.com>
 
        PR middle-end/20419
index 42f8bad..070a94b 100644 (file)
@@ -4584,6 +4584,7 @@ grokdeclarator (const struct c_declarator *declarator,
          }
 
        decl = build_decl (VAR_DECL, declarator->u.id, type);
+       DECL_SOURCE_LOCATION (decl) = declarator->id_loc;
        if (size_varies)
          C_DECL_VARIABLE_SIZE (decl) = 1;
 
@@ -6709,6 +6710,8 @@ build_id_declarator (tree ident)
   ret->kind = cdk_id;
   ret->declarator = 0;
   ret->u.id = ident;
+  /* Default value - may get reset to a more precise location. */
+  ret->id_loc = input_location;
   return ret;
 }
 
index f5425ce..fdc1ff6 100644 (file)
@@ -332,7 +332,7 @@ cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
    non-NULL.  */
 
 enum cpp_ttype
-c_lex_with_flags (tree *value, unsigned char *cpp_flags)
+c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags)
 {
   static bool no_more_pch;
   const cpp_token *tok;
@@ -344,6 +344,11 @@ c_lex_with_flags (tree *value, unsigned char *cpp_flags)
   type = tok->type;
   
  retry_after_at:
+#ifdef USE_MAPPED_LOCATION
+  *loc = tok->src_loc;
+#else
+  *loc = input_location;
+#endif
   switch (type)
     {
     case CPP_PADDING:
@@ -487,7 +492,8 @@ c_lex_with_flags (tree *value, unsigned char *cpp_flags)
 enum cpp_ttype
 c_lex (tree *value)
 {
-  return c_lex_with_flags (value, NULL);
+  location_t loc;
+  return c_lex_with_flags (value, &loc, NULL);
 }
 
 /* Returns the narrowest C-visible unsigned type, starting with the
index 9487422..6fd09b9 100644 (file)
@@ -295,8 +295,7 @@ static void
 c_lex_one_token (c_token *token)
 {
   timevar_push (TV_LEX);
-  token->type = c_lex (&token->value);
-  token->location = input_location;
+  token->type = c_lex_with_flags (&token->value, &token->location, NULL);
   token->in_system_header = in_system_header;
   switch (token->type)
     {
@@ -2179,6 +2178,7 @@ c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
       struct c_declarator *inner
        = build_id_declarator (c_parser_peek_token (parser)->value);
       *seen_id = true;
+      inner->id_loc = c_parser_peek_token (parser)->location;
       c_parser_consume_token (parser);
       return c_parser_direct_declarator_inner (parser, *seen_id, inner);
     }
index f7f609c..9a7895a 100644 (file)
@@ -65,7 +65,7 @@ extern tree maybe_apply_renaming_pragma (tree, tree);
 extern void add_to_renaming_pragma_list (tree, tree);
 
 extern enum cpp_ttype c_lex (tree *);
-extern enum cpp_ttype c_lex_with_flags (tree *, unsigned char *);
+extern enum cpp_ttype c_lex_with_flags (tree *, location_t *, unsigned char *);
 
 /* If 1, then lex strings into the execution character set.  
    If 0, lex strings into the host character set.
index 18b2634..adace27 100644 (file)
@@ -287,6 +287,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. */
   union {
     /* For identifiers, an IDENTIFIER_NODE or NULL_TREE if an abstract
        declarator.  */