From 4cc2a7227aa8965ce50784b13a0c87b18082fdde Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Tue, 7 Sep 2010 16:12:09 +0000 Subject: [PATCH] cp-tree.h (build_enumerator): Add new location_t parameter. * cp-tree.h (build_enumerator): Add new location_t parameter. (build_lang_decl_loc): New function. * decl.c (build_enumerator): New parameter loc. Use it when calling build_decl. Replace build_lang_decl with build_lang_decl_loc. * pt.c (tsubst_enum): Adjust call to build_enumerator. * parser.c (cp_parser_enumerator_definition): Ditto. * lex.c (build_lang_decl_loc): New function. From-SVN: r163959 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/cp-tree.h | 3 ++- gcc/cp/decl.c | 11 ++++++----- gcc/cp/lex.c | 16 ++++++++++++++-- gcc/cp/parser.c | 7 ++++++- gcc/cp/pt.c | 3 ++- 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f777ae9a23f..d4171b0fc02 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2010-09-07 Arnaud Charlet + + * cp-tree.h (build_enumerator): Add new location_t parameter. + (build_lang_decl_loc): New function. + * decl.c (build_enumerator): New parameter loc. Use it when calling + build_decl. Replace build_lang_decl with build_lang_decl_loc. + * pt.c (tsubst_enum): Adjust call to build_enumerator. + * parser.c (cp_parser_enumerator_definition): Ditto. + * lex.c (build_lang_decl_loc): New function. + 2010-09-06 Dodji Seketeli PR c++/45200 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index dce28dfcaaf..cb3b55f484f 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4771,7 +4771,7 @@ extern tree xref_tag_from_type (tree, tree, tag_scope); 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 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); @@ -4943,6 +4943,7 @@ extern void yyungetc (int, int); extern tree unqualified_name_lookup_error (tree); extern tree unqualified_fn_lookup_error (tree); extern tree build_lang_decl (enum tree_code, tree, tree); +extern tree build_lang_decl_loc (location_t, enum tree_code, tree, tree); extern void retrofit_lang_decl (tree); extern tree copy_decl (tree); extern tree copy_type (tree); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 409836c76f3..ad4a0973d9d 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11627,10 +11627,11 @@ finish_enum (tree enumtype) /* 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) +build_enumerator (tree name, tree value, tree enumtype, location_t loc) { tree decl; tree context; @@ -11745,12 +11746,12 @@ build_enumerator (tree name, tree value, tree enumtype) if (context && context == current_class_type) /* This enum declaration is local to the class. We need the full lang_decl so that we can record DECL_CLASS_CONTEXT, for example. */ - decl = build_lang_decl (CONST_DECL, name, type); + decl = build_lang_decl_loc (loc, 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); - + 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; diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 9e3b57b75ef..0488149c390 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -507,13 +507,25 @@ unqualified_fn_lookup_error (tree name) return unqualified_name_lookup_error (name); } +/* Wrapper around build_lang_decl_loc(). Should gradually move to + build_lang_decl_loc() and then rename build_lang_decl_loc() back to + build_lang_decl(). */ + tree build_lang_decl (enum tree_code code, tree name, tree type) +{ + return build_lang_decl_loc (input_location, code, name, type); +} + +/* Build a decl from CODE, NAME, TYPE declared at LOC, and then add + DECL_LANG_SPECIFIC info to the result. */ + +tree +build_lang_decl_loc (location_t loc, enum tree_code code, tree name, tree type) { tree t; - t = build_decl (input_location, - code, name, type); + t = build_decl (loc, code, name, type); retrofit_lang_decl (t); return t; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index db2073ba03f..8faf21d8850 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13135,6 +13135,11 @@ cp_parser_enumerator_definition (cp_parser* parser, tree type) { 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); @@ -13160,7 +13165,7 @@ cp_parser_enumerator_definition (cp_parser* parser, tree type) value = error_mark_node; /* Create the enumerator. */ - build_enumerator (identifier, value, type); + build_enumerator (identifier, value, type, loc); } /* Parse a namespace-name. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index eb47ac41600..75a9d1b25a4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17294,7 +17294,8 @@ tsubst_enum (tree tag, tree newtag, tree args) set_current_access_from_decl (decl); /* Actually build the enumerator itself. */ - build_enumerator (DECL_NAME (decl), value, newtag); + build_enumerator + (DECL_NAME (decl), value, newtag, DECL_SOURCE_LOCATION (decl)); } finish_enum (newtag); -- 2.30.2