From patchwork Tue Sep 7 14:02:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 64022 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E0D7AB6EEE for ; Wed, 8 Sep 2010 00:52:30 +1000 (EST) Received: (qmail 15450 invoked by alias); 7 Sep 2010 14:04:01 -0000 Received: (qmail 14969 invoked by uid 22791); 7 Sep 2010 14:03:21 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Sep 2010 14:02:55 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6F3D3CB028B; Tue, 7 Sep 2010 16:02:44 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Iq7m7Pq+PWTn; Tue, 7 Sep 2010 16:02:44 +0200 (CEST) Received: from province.act-europe.fr (province.act-europe.fr [10.10.0.214]) by mel.act-europe.fr (Postfix) with ESMTP id D3E3BCB01B2; Tue, 7 Sep 2010 16:02:43 +0200 (CEST) Received: by province.act-europe.fr (Postfix, from userid 525) id CBD6B1654DA; Tue, 7 Sep 2010 16:02:43 +0200 (CEST) Date: Tue, 7 Sep 2010 16:02:43 +0200 From: Arnaud Charlet To: Mark Mitchell Cc: Jason Merrill , gcc-patches@gcc.gnu.org, Arnaud Charlet Subject: Re: [C++ patch] use better sloc for enum literals Message-ID: <20100907140243.GB90968@adacore.com> References: <20100907083232.GA22548@adacore.com> <4C8640B2.8040600@redhat.com> <20100907134244.GA89667@adacore.com> <4C864344.40704@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4C864344.40704@codesourcery.com> User-Agent: Mutt/1.5.17 (2007-11-01) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org > Be like Microsoft. Add build_lang_decl_ex, which has the location_t > parameter. Have build_lang_decl call it. Switch things to use > build_lang_decl_ex gradually. Then, rename that build_lang_decl when > you're all done. OK, makes sense. Here it is tested again, thanks in advance (note that build_lang_decl() was not documented before my patch :-): 2010-09-07 Arnaud Charlet * cp-tree.h (build_enumerator): Add new location_t parameter. (build_lang_decl_ex): New function. * decl.c (build_enumerator): New parameter loc. Use it when calling build_decl. Replace build_lang_decl with build_lang_decl_ex. * pt.c (tsubst_enum): Adjust call to build_enumerator. * parser.c (cp_parser_enumerator_definition): Ditto. * lex.c (build_lang_decl_ex): New function. Index: decl.c =================================================================== --- decl.c (revision 163920) +++ decl.c (working copy) @@ -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, 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_ex (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; Index: pt.c =================================================================== --- pt.c (revision 163920) +++ pt.c (working copy) @@ -17294,7 +17294,8 @@ tsubst_enum (tree tag, tree newtag, tree 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); Index: parser.c =================================================================== --- parser.c (revision 163920) +++ parser.c (working copy) @@ -13135,6 +13135,11 @@ cp_parser_enumerator_definition (cp_pars { 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_pars value = error_mark_node; /* Create the enumerator. */ - build_enumerator (identifier, value, type); + build_enumerator (identifier, value, type, loc); } /* Parse a namespace-name. Index: cp-tree.h =================================================================== --- cp-tree.h (revision 163920) +++ cp-tree.h (working copy) @@ -4771,7 +4771,7 @@ extern tree xref_tag_from_type (tree, 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_ex (location_t, enum tree_code, tree, tree); extern void retrofit_lang_decl (tree); extern tree copy_decl (tree); extern tree copy_type (tree); Index: lex.c =================================================================== --- lex.c (revision 163920) +++ lex.c (working copy) @@ -507,13 +507,24 @@ unqualified_fn_lookup_error (tree name) return unqualified_name_lookup_error (name); } +/* Wrapper around build_lang_decl_ex. Should gradually move to + build_lang_decl_ex. */ + tree build_lang_decl (enum tree_code code, tree name, tree type) { + build_lang_decl_ex (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_ex (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;