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]

[C++ patch] use better sloc for enum literals


Hi,

This patch sets better locations for enumeration literals in the C++
front-end by using the sloc of the enumeration rather than input_location
which would typically point to the end of the literal decl, and be e.g.
past the value of the enumeration.

Tested on x86_64-pc-linux-gnu, OK for trunk?

cp/

2010-09-06  Arnaud Charlet  <charlet@adacore.com>

	* cp-tree.h (build_enumerator): Add new location_t parameter.
	* decl.c (build_enumerator): New parameter loc. Use it when calling
	build_decl.
	* pt.c (tsubst_enum): Adjust call to build_enumerator.
	* parser.c (cp_parser_enumerator_definition): Ditto.

--
Index: decl.c
===================================================================
*** decl.c	(revision 163920)
--- decl.c	(working copy)
*************** finish_enum (tree enumtype)
*** 11627,11636 ****
  
  /* Build and install a CONST_DECL for an enumeration constant of the
     enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
     Assignment of sequential values by default is handled here.  */
  
  void
! build_enumerator (tree name, tree value, tree enumtype)
  {
    tree decl;
    tree context;
--- 11627,11637 ----
  
  /* Build and install a CONST_DECL for an enumeration constant of the
     enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
+    LOC is the location of NAME.
     Assignment of sequential values by default is handled here.  */
  
  void
! build_enumerator (tree name, tree value, tree enumtype, location_t loc)
  {
    tree decl;
    tree context;
*************** build_enumerator (tree name, tree value,
*** 11748,11756 ****
      decl = build_lang_decl (CONST_DECL, name, type);
    else
      /* It's a global enum, or it's local to a function.  (Note local to
!       a function could mean local to a class method.  */
!     decl = build_decl (input_location, CONST_DECL, name, type);
! 
    DECL_CONTEXT (decl) = FROB_CONTEXT (context);
    TREE_CONSTANT (decl) = 1;
    TREE_READONLY (decl) = 1;
--- 11749,11757 ----
      decl = build_lang_decl (CONST_DECL, name, type);
    else
      /* It's a global enum, or it's local to a function.  (Note local to
!        a function could mean local to a class method.  */
!     decl = build_decl (loc, CONST_DECL, name, type);
!   
    DECL_CONTEXT (decl) = FROB_CONTEXT (context);
    TREE_CONSTANT (decl) = 1;
    TREE_READONLY (decl) = 1;
Index: pt.c
===================================================================
*** pt.c	(revision 163920)
--- pt.c	(working copy)
*************** tsubst_enum (tree tag, tree newtag, tree
*** 17294,17300 ****
        set_current_access_from_decl (decl);
  
        /* Actually build the enumerator itself.  */
!       build_enumerator (DECL_NAME (decl), value, newtag);
      }
  
    finish_enum (newtag);
--- 17294,17301 ----
        set_current_access_from_decl (decl);
  
        /* Actually build the enumerator itself.  */
!       build_enumerator
! 	(DECL_NAME (decl), value, newtag, DECL_SOURCE_LOCATION (decl));
      }
  
    finish_enum (newtag);
Index: parser.c
===================================================================
*** parser.c	(revision 163920)
--- parser.c	(working copy)
*************** cp_parser_enumerator_definition (cp_pars
*** 13135,13140 ****
--- 13135,13145 ----
  {
    tree identifier;
    tree value;
+   location_t loc;
+ 
+   /* Save the input location because we are interested in the location
+      of the identifier and not the location of the explicit value.  */
+   loc = cp_lexer_peek_token (parser->lexer)->location;
  
    /* Look for the identifier.  */
    identifier = cp_parser_identifier (parser);
*************** cp_parser_enumerator_definition (cp_pars
*** 13160,13166 ****
      value = error_mark_node;
  
    /* Create the enumerator.  */
!   build_enumerator (identifier, value, type);
  }
  
  /* Parse a namespace-name.
--- 13165,13171 ----
      value = error_mark_node;
  
    /* Create the enumerator.  */
!   build_enumerator (identifier, value, type, loc);
  }
  
  /* Parse a namespace-name.
Index: cp-tree.h
===================================================================
*** cp-tree.h	(revision 163920)
--- cp-tree.h	(working copy)
*************** extern tree xref_tag_from_type			(tree, 
*** 4771,4777 ****
  extern bool xref_basetypes			(tree, tree);
  extern tree start_enum				(tree, tree, bool);
  extern void finish_enum				(tree);
! extern void build_enumerator			(tree, tree, tree);
  extern tree lookup_enumerator			(tree, tree);
  extern void start_preparsed_function		(tree, tree, int);
  extern int start_function			(cp_decl_specifier_seq *, const cp_declarator *, tree);
--- 4771,4777 ----
  extern bool xref_basetypes			(tree, tree);
  extern tree start_enum				(tree, tree, bool);
  extern void finish_enum				(tree);
! extern void build_enumerator			(tree, tree, tree, location_t);
  extern tree lookup_enumerator			(tree, tree);
  extern void start_preparsed_function		(tree, tree, int);
  extern int start_function			(cp_decl_specifier_seq *, const cp_declarator *, tree);


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