From patchwork Tue Mar 26 20:02:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Dos Reis X-Patchwork-Id: 231529 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A35662C0090 for ; Wed, 27 Mar 2013 07:03:42 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=MHBJfch7xkacT9uUcOGhHz3qe28OG+/tz3dBw/rK3zZSfLjZR7 KuJBP03A5McXzr33LiqdTDreWmaFeQ6v/qrDNoFzXd5sJ/6HkUogkqnwlGFIrrvy EfyY5SCgRlhLUNKM/Mf4/PMOo8meW2ZkoLnFOZ6YTyuBRio2CdpNgypOg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=FdQBFtkpsXcEjydDj46tYd5rzQQ=; b=luOhUKG5M2oUrANP8elW LEqH1RRHURTLsSxFpy3J+v8CsLHFYtkG093qGnhibMTCFCKuPjfQBLW8LttC9gmC zS48ptyc7FsoGgKBJF19CIEWfUcyfC/RUIbQ5xbbGeCq28gWx1vlUhAHTqrz2Ol1 SmmjfctbW3KDIUVRdS3e9qU= Received: (qmail 8150 invoked by alias); 26 Mar 2013 20:02:29 -0000 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 Received: (qmail 7716 invoked by uid 89); 26 Mar 2013 20:02:20 -0000 X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_00, KAM_STOCKTIP, RP_MATCHES_RCVD autolearn=no version=3.3.1 Received: from www.axiomatics.org (HELO mail.axiomatics.org) (66.228.53.191) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 26 Mar 2013 20:02:16 +0000 Received: by mail.axiomatics.org (Postfix, from userid 1000) id D798FED4F; Tue, 26 Mar 2013 15:02:13 -0500 (CDT) From: Gabriel Dos Reis To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com Subject: C++ PATCH: use VAR_OR_FUNCTION_DECL_P more often Date: Tue, 26 Mar 2013 15:02:13 -0500 Message-ID: <87wqsu2am2.fsf@euclid.axiomatics.org> Lines: 241 MIME-Version: 1.0 The C++ front-end isn't very systematic in using existing predicates to test node kinds. This patch makes us use VAR_OR_FUNCTION_DECL_P in places where we were explicitly testing VAR_DECL || FUNCTION_DECL. Tested on an x86_64-suse-linux. Applying to trunk as obvious. -- Gaby 2013-03-26 Gabriel Dos Reis * cp-gimplify.c (cp_genericize_r): Use VAR_OR_FUNCTION_DECL_P. * decl.c (duplicate_decls): Likewise. (cp_finish_decl): Likewise. (check_class_member_definition_namespace): Likewise. * decl2.c (grokfield): Likewise. (decl_needed_p): Likewise. (import_export_decl): Likewise. (mark_used): Likewise. * name-lookup.c (pushdecl_maybe_friend_1): Likewise. * pt.c (push_access_scope): Likewise. (instantiate_decl): Likewise. * ptree.c (cxx_print_decl): Likewise. * repo.c (repo_emit_p): Likewise. * semantics.c (note_decl_for_pch): Likewise. * tree.c (decl_linkage): Likewise. Index: cp-gimplify.c =================================================================== --- cp-gimplify.c (revision 196984) +++ cp-gimplify.c (working copy) @@ -857,7 +857,7 @@ /* Map block scope extern declarations to visible declarations with the same name and type in outer scopes if any. */ if (cp_function_chain->extern_decl_map - && (TREE_CODE (stmt) == FUNCTION_DECL || TREE_CODE (stmt) == VAR_DECL) + && VAR_OR_FUNCTION_DECL_P (stmt) && DECL_EXTERNAL (stmt)) { struct cxx_int_tree_map *h, in; Index: decl.c =================================================================== --- decl.c (revision 196984) +++ decl.c (working copy) @@ -1620,8 +1620,7 @@ warning_at (DECL_SOURCE_LOCATION (olddecl), 0, "follows non-prototype definition here"); } - else if ((TREE_CODE (olddecl) == FUNCTION_DECL - || TREE_CODE (olddecl) == VAR_DECL) + else if (VAR_OR_FUNCTION_DECL_P (olddecl) && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) { /* [dcl.link] @@ -6398,8 +6397,7 @@ /* Let the middle end know about variables and functions -- but not static data members in uninstantiated class templates. */ - if (TREE_CODE (decl) == VAR_DECL - || TREE_CODE (decl) == FUNCTION_DECL) + if (VAR_OR_FUNCTION_DECL_P (decl)) { if (TREE_CODE (decl) == VAR_DECL) { @@ -7220,8 +7218,7 @@ { /* These checks only apply to member functions and static data members. */ - gcc_assert (TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == VAR_DECL); + gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); /* We check for problems with specializations in pt.c in check_specialization_namespace, where we can issue better diagnostics. */ Index: decl2.c =================================================================== --- decl2.c (revision 196984) +++ decl2.c (working copy) @@ -955,8 +955,7 @@ } } - if (processing_template_decl - && (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == FUNCTION_DECL)) + if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value)) { value = push_template_decl (value); if (error_operand_p (value)) @@ -1799,8 +1798,7 @@ bool decl_needed_p (tree decl) { - gcc_assert (TREE_CODE (decl) == VAR_DECL - || TREE_CODE (decl) == FUNCTION_DECL); + gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); /* This function should only be called at the end of the translation unit. We cannot be sure of whether or not something will be COMDAT until that point. */ @@ -2002,8 +2000,7 @@ STRIP_NOPS (arg); if (TREE_CODE (arg) == ADDR_EXPR) arg = TREE_OPERAND (arg, 0); - if (TREE_CODE (arg) == VAR_DECL - || TREE_CODE (arg) == FUNCTION_DECL) + if (VAR_OR_FUNCTION_DECL_P (arg)) { if (! TREE_PUBLIC (arg)) vis = VISIBILITY_ANON; @@ -2419,8 +2416,7 @@ definition available in this translation unit. The following assertions check these conditions. */ - gcc_assert (TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == VAR_DECL); + gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); /* Any code that creates entities with TREE_PUBLIC cleared should also set DECL_INTERFACE_KNOWN. */ gcc_assert (TREE_PUBLIC (decl)); @@ -4528,7 +4524,7 @@ /* We can only check DECL_ODR_USED on variables or functions with DECL_LANG_SPECIFIC set, and these are also the only decls that we might need special handling for. */ - if ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL) + if (!VAR_OR_FUNCTION_DECL_P (decl) || DECL_LANG_SPECIFIC (decl) == NULL || DECL_THUNK_P (decl)) { @@ -4664,7 +4660,7 @@ /* If this is a synthesized method we don't need to do the instantiation test below. */ } - else if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) + else if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_TEMPLATE_INFO (decl) && (!DECL_EXPLICIT_INSTANTIATION (decl) || always_instantiate_p (decl))) Index: name-lookup.c =================================================================== --- name-lookup.c (revision 196984) +++ name-lookup.c (working copy) @@ -678,7 +678,7 @@ block scope declaration declares that same entity and receives the linkage of the previous declaration. */ if (! t && current_function_decl && x != current_function_decl - && (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) + && VAR_OR_FUNCTION_DECL_P (x) && DECL_EXTERNAL (x)) { /* Look in block scope. */ Index: pt.c =================================================================== --- pt.c (revision 196984) +++ pt.c (working copy) @@ -213,9 +213,8 @@ static void push_access_scope (tree t) { - gcc_assert (TREE_CODE (t) == FUNCTION_DECL - || TREE_CODE (t) == TYPE_DECL - || TREE_CODE (t) == VAR_DECL); + gcc_assert (VAR_OR_FUNCTION_DECL_P (t) + || TREE_CODE (t) == TYPE_DECL); if (DECL_FRIEND_CONTEXT (t)) push_nested_class (DECL_FRIEND_CONTEXT (t)); @@ -18598,8 +18597,7 @@ /* This function should only be used to instantiate templates for functions and static member variables. */ - gcc_assert (TREE_CODE (d) == FUNCTION_DECL - || TREE_CODE (d) == VAR_DECL); + gcc_assert (VAR_OR_FUNCTION_DECL_P (d)); /* Variables are never deferred; if instantiation is required, they are instantiated right away. That allows for better code in the Index: ptree.c =================================================================== --- ptree.c (revision 196984) +++ ptree.c (working copy) @@ -63,7 +63,7 @@ && DECL_PENDING_INLINE_INFO (node)) fprintf (file, " pending-inline-info %p", (void *) DECL_PENDING_INLINE_INFO (node)); - if ((TREE_CODE (node) == FUNCTION_DECL || TREE_CODE (node) == VAR_DECL) + if (VAR_OR_FUNCTION_DECL_P (node) && DECL_TEMPLATE_INFO (node)) fprintf (file, " template-info %p", (void *) DECL_TEMPLATE_INFO (node)); Index: repo.c =================================================================== --- repo.c (revision 196984) +++ repo.c (working copy) @@ -291,8 +291,7 @@ { int ret = 0; gcc_assert (TREE_PUBLIC (decl)); - gcc_assert (TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == VAR_DECL); + gcc_assert (VAR_OR_FUNCTION_DECL_P (decl)); gcc_assert (!DECL_REALLY_EXTERN (decl)); /* When not using the repository, emit everything. */ Index: semantics.c =================================================================== --- semantics.c (revision 196984) +++ semantics.c (working copy) @@ -2771,8 +2771,7 @@ /* There's a good chance that we'll have to mangle names at some point, even if only for emission in debugging information. */ - if ((TREE_CODE (decl) == VAR_DECL - || TREE_CODE (decl) == FUNCTION_DECL) + if (VAR_OR_FUNCTION_DECL_P (decl) && !processing_template_decl) mangle_decl (decl); } Index: tree.c =================================================================== --- tree.c (revision 196984) +++ tree.c (working copy) @@ -3579,8 +3579,7 @@ template instantiations have internal linkage (in the object file), but the symbols should still be treated as having external linkage from the point of view of the language. */ - if ((TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == VAR_DECL) + if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_COMDAT (decl)) return lk_external; @@ -3594,7 +3593,7 @@ really meant to have internal linkage have DECL_THIS_STATIC set. */ if (TREE_CODE (decl) == TYPE_DECL) return lk_external; - if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) + if (VAR_OR_FUNCTION_DECL_P (decl)) { if (!DECL_THIS_STATIC (decl)) return lk_external;