From patchwork Wed May 17 11:23:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 763467 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wSX5H4d90z9s84 for ; Wed, 17 May 2017 21:24:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="fjNvIUKp"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=RfJJTxbGx54UoHAzcbW+mcCHudLE7rSMoq9iav9rUy0bcoXsCW zON+mSgdd0cgxZCD3gQLAFLo/Ca9El5RfEnX9Z19t6eDMyEW+OB7DTo73/sqtbQO JCMhpuLjO/2ADLgPDI/JmAsVUodveyxvbIyaZKNhD2M9Wgrto0JQPEPSM= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=kg5j1ruAGgAAB/Xu4KM/wjqmzGw=; b=fjNvIUKpTwCVaaj4ijsg 7RTrdT+aNned+DE+RG8lnYxvSJTTG/3jCoKD0hAAWvO7A1M6Grq7M+RIx6ufHqdN QRrYjQ0GYp+1U35CqjlZBF0R7d9wTGy1Df1TqXaoLP5yDk9WHXGD6VcDi+pmNe5x mnBoRdb02B2o20TMUcEdxPQ= Received: (qmail 55185 invoked by alias); 17 May 2017 11:23:45 -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 55170 invoked by uid 89); 17 May 2017 11:23:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=tpl, Plus X-HELO: mail-yw0-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 May 2017 11:23:42 +0000 Received: by mail-yw0-f173.google.com with SMTP id l74so4149317ywe.2 for ; Wed, 17 May 2017 04:23:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=Li/57rd77IipICwGiQz2cuFaH+NL3Ti3RueZcYoisrY=; b=Ew4q8MVaItKO9KIhrhIh24fRcHJlhVWzW3ODa1E1yK1NzUfq8CEf4OD2Fi/l0zllPc R/EqasnmMmrvIjjwImJHbS09ZwUVwDPS8MaZCq+fUzDlM8Rfo+Xh1faEvg1N58fGGafO +Y5Yq6xilzc7gMSrf5A3FBJXXoVIeE+6Necs2YGzKkC48xDd83kxTmQ81QjYWWrmxtpd 82XUpK7dcjpXn2ZSo/sNhl9t1By9/nudMf0Yw6FN1AnxBT7QI1kvdKI3T/Y/ntY7yA+5 Lc+Zi/WEA11rZUXt0Z+AmY/dxvCIJdlm0NHDjVQEBe6diHifWCdq2LuL9mVPWlOWclmc UAPw== X-Gm-Message-State: AODbwcAypHHPCO36N254Ftf74PeEaJNOYsvB4Cse52CG7bcL4Yy/3iCL lI8TsZ+qJGVtEA== X-Received: by 10.13.249.67 with SMTP id j64mr2028803ywf.19.1495020223884; Wed, 17 May 2017 04:23:43 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::7:4a1a]) by smtp.googlemail.com with ESMTPSA id d81sm810118ywe.41.2017.05.17.04.23.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 04:23:43 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] OVERLOAD iterators #4 Message-ID: <9d330e17-b43e-890b-8a9b-a8a0123cce69@acm.org> Date: Wed, 17 May 2017 07:23:41 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 This patch converts pieces of class member function handling. Plus a couple of constraint pieces and an address-of where we wrap an fn in an overload. nathan 2017-05-17 Nathan Sidwell * class.c (handle_using_decl): Use OVL_FIRST, ovl_iterator. (maybe_warn_about_overly_private_class): Use ovl_iterator. (method_name_cmp, resort_method_name_cmp): Use OVL_NAME. (resort_type_method_vec, finish_struct_methods): Use OVL_FIRST. (get_base_fndecls): Use ovl_iterator. (warn_hidden): Use OVL_NAME, ovl_iterator. (add_implicitly_declared_members): Use ovl_iterator. * constraint.cc (normalize_template_id_expression): Use OVL_FIRST, flatten nested if. (finish_shorthand_constraint): Simplify, use ovl_make. * pt.c (make_constrained_auto): Simplify. Use ovl_make. * search.c (shared_member_p): Use ovl_iterator. (lookup_field_fuzzy_info::fuzzy_lookup_fn): Use OVL_NAME. (lookup_conversion_operator): Use OVL_FIRST. (lookup_fnfiels_idx_nolazy): Use OVL_FIRST, OVL_NAME. (look_for_overrides_here): Use ovl_iterator. (lookup_conversions_r): Use OVL_FIRST, OVL_NAME, ovl_iterator. * typeck.c (build_x_unary_op): Use ovl_make. Index: class.c =================================================================== --- class.c (revision 248127) +++ class.c (working copy) @@ -1359,7 +1359,7 @@ handle_using_decl (tree using_decl, tree tf_warning_or_error); if (old_value) { - old_value = OVL_CURRENT (old_value); + old_value = OVL_FIRST (old_value); if (DECL_P (old_value) && DECL_CONTEXT (old_value) == t) /* OK */; @@ -1396,10 +1396,10 @@ handle_using_decl (tree using_decl, tree /* Make type T see field decl FDECL with access ACCESS. */ if (flist) - for (; flist; flist = OVL_NEXT (flist)) + for (ovl_iterator iter (flist); iter; ++iter) { - add_method (t, OVL_CURRENT (flist), using_decl); - alter_access (t, OVL_CURRENT (flist), access); + add_method (t, *iter, true); + alter_access (t, *iter, access); } else alter_access (t, decl, access); @@ -2245,7 +2245,7 @@ maybe_warn_about_overly_private_class (t && (!CLASSTYPE_LAZY_DEFAULT_CTOR (t) || !CLASSTYPE_LAZY_COPY_CTOR (t))) { - int nonprivate_ctor = 0; + bool nonprivate_ctor = false; /* If a non-template class does not define a copy constructor, one is defined for it, enabling it to avoid @@ -2258,25 +2258,20 @@ maybe_warn_about_overly_private_class (t complete non-template or fully instantiated classes have this flag set. */ if (!TYPE_HAS_COPY_CTOR (t)) - nonprivate_ctor = 1; + nonprivate_ctor = true; else - for (fn = CLASSTYPE_CONSTRUCTORS (t); fn; fn = OVL_NEXT (fn)) - { - tree ctor = OVL_CURRENT (fn); - /* Ideally, we wouldn't count copy constructors (or, in - fact, any constructor that takes an argument of the - class type as a parameter) because such things cannot - be used to construct an instance of the class unless - you already have one. But, for now at least, we're - more generous. */ - if (! TREE_PRIVATE (ctor)) - { - nonprivate_ctor = 1; - break; - } - } + for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); + !nonprivate_ctor && iter; ++iter) + /* Ideally, we wouldn't count copy constructors (or, in + fact, any constructor that takes an argument of the class + type as a parameter) because such things cannot be used + to construct an instance of the class unless you already + have one. But, for now at least, we're more + generous. */ + if (! TREE_PRIVATE (*iter)) + nonprivate_ctor = true; - if (nonprivate_ctor == 0) + if (!nonprivate_ctor) { warning (OPT_Wctor_dtor_privacy, "%q#T only defines private constructors and has no friends", @@ -2305,7 +2300,7 @@ method_name_cmp (const void* m1_p, const return -1; if (*m2 == NULL_TREE) return 1; - if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2))) + if (OVL_NAME (*m1) < OVL_NAME (*m2)) return -1; return 1; } @@ -2325,8 +2320,8 @@ resort_method_name_cmp (const void* m1_p if (*m2 == NULL_TREE) return 1; { - tree d1 = DECL_NAME (OVL_CURRENT (*m1)); - tree d2 = DECL_NAME (OVL_CURRENT (*m2)); + tree d1 = OVL_NAME (*m1); + tree d2 = OVL_NAME (*m2); resort_data.new_value (&d1, resort_data.cookie); resort_data.new_value (&d2, resort_data.cookie); if (d1 < d2) @@ -2353,7 +2348,7 @@ resort_type_method_vec (void* obj, for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; vec_safe_iterate (method_vec, slot, &fn); ++slot) - if (!DECL_CONV_FN_P (OVL_CURRENT (fn))) + if (!DECL_CONV_FN_P (OVL_FIRST (fn))) break; if (len - slot > 1) @@ -2398,7 +2393,7 @@ finish_struct_methods (tree t) for (slot = CLASSTYPE_FIRST_CONVERSION_SLOT; method_vec->iterate (slot, &fn_fields); ++slot) - if (!DECL_CONV_FN_P (OVL_CURRENT (fn_fields))) + if (!DECL_CONV_FN_P (OVL_FIRST (fn_fields))) break; if (len - slot > 1) qsort (method_vec->address () + slot, @@ -2973,7 +2968,6 @@ modify_all_vtables (tree t, tree virtual static void get_basefndecls (tree name, tree t, vec *base_fndecls) { - tree methods; int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); int i; @@ -2981,11 +2975,9 @@ get_basefndecls (tree name, tree t, vec< i = lookup_fnfields_1 (t, name); bool found_decls = false; if (i != -1) - for (methods = (*CLASSTYPE_METHOD_VEC (t))[i]; - methods; - methods = OVL_NEXT (methods)) + for (ovl_iterator iter ((*CLASSTYPE_METHOD_VEC (t))[i]); iter; ++iter) { - tree method = OVL_CURRENT (methods); + tree method = *iter; if (TREE_CODE (method) == FUNCTION_DECL && DECL_VINDEX (method)) @@ -3065,8 +3057,6 @@ warn_hidden (tree t) vec_safe_iterate (method_vec, i, &fns); ++i) { - tree fn; - tree name; tree fndecl; tree base_binfo; tree binfo; @@ -3074,7 +3064,7 @@ warn_hidden (tree t) /* All functions in this slot in the CLASSTYPE_METHOD_VEC will have the same name. Figure out what name that is. */ - name = DECL_NAME (OVL_CURRENT (fns)); + tree name = OVL_NAME (fns); /* There are no possibly hidden functions yet. */ auto_vec base_fndecls; /* Iterate through all of the base classes looking for possibly @@ -3091,9 +3081,9 @@ warn_hidden (tree t) continue; /* Remove any overridden functions. */ - for (fn = fns; fn; fn = OVL_NEXT (fn)) + for (ovl_iterator iter (fns); iter; ++iter) { - fndecl = OVL_CURRENT (fn); + fndecl = *iter; if (TREE_CODE (fndecl) == FUNCTION_DECL && DECL_VINDEX (fndecl)) { @@ -3455,9 +3445,8 @@ add_implicitly_declared_members (tree t, tree ctor_list = decl; location_t loc = input_location; input_location = DECL_SOURCE_LOCATION (using_decl); - if (ctor_list) - for (; ctor_list; ctor_list = OVL_NEXT (ctor_list)) - one_inherited_ctor (OVL_CURRENT (ctor_list), t, using_decl); + for (ovl_iterator iter (ctor_list); iter; ++iter) + one_inherited_ctor (*iter, t, using_decl); *access_decls = TREE_CHAIN (*access_decls); input_location = loc; } Index: constraint.cc =================================================================== --- constraint.cc (revision 248127) +++ constraint.cc (working copy) @@ -738,17 +738,13 @@ normalize_template_id_expression (tree t } /* Check that we didn't refer to a function concept like a variable. */ - tree tmpl = TREE_OPERAND (t, 0); - if (TREE_CODE (tmpl) == OVERLOAD) + tree fn = OVL_FIRST (TREE_OPERAND (t, 0)); + if (TREE_CODE (fn) == TEMPLATE_DECL + && DECL_DECLARED_CONCEPT_P (DECL_TEMPLATE_RESULT (fn))) { - tree fn = OVL_FUNCTION (tmpl); - if (TREE_CODE (fn) == TEMPLATE_DECL - && DECL_DECLARED_CONCEPT_P (DECL_TEMPLATE_RESULT (fn))) - { - error_at (location_of (t), - "invalid reference to function concept %qD", fn); - return error_mark_node; - } + error_at (location_of (t), + "invalid reference to function concept %qD", fn); + return error_mark_node; } return build_nt (PRED_CONSTR, t); @@ -1283,15 +1279,9 @@ finish_shorthand_constraint (tree decl, /* Build the concept check. If it the constraint needs to be applied to all elements of the parameter pack, then make the constraint an expansion. */ - tree check; tree tmpl = DECL_TI_TEMPLATE (con); - if (VAR_P (con)) - check = build_concept_check (tmpl, arg, args); - else - { - tree ovl = build_overload (tmpl, NULL_TREE); - check = build_concept_check (ovl, arg, args); - } + tree check = VAR_P (con) ? tmpl : ovl_make (tmpl); + check = build_concept_check (check, arg, args); /* Make the check a pack expansion if needed. Index: pt.c =================================================================== --- pt.c (revision 248127) +++ pt.c (working copy) @@ -24653,11 +24652,8 @@ make_constrained_auto (tree con, tree ar /* Build the constraint. */ tree tmpl = DECL_TI_TEMPLATE (con); - tree expr; - if (VAR_P (con)) - expr = build_concept_check (tmpl, type, args); - else - expr = build_concept_check (build_overload (tmpl, NULL_TREE), type, args); + tree expr = VAR_P (con) ? tmpl : ovl_make (tmpl); + expr = build_concept_check (expr, type, args); tree constr = normalize_expression (expr); PLACEHOLDER_TYPE_CONSTRAINTS (type) = constr; Index: search.c =================================================================== --- search.c (revision 248127) +++ search.c (working copy) @@ -1047,13 +1047,9 @@ shared_member_p (tree t) return 1; if (is_overloaded_fn (t)) { - t = get_fns (t); - for (; t; t = OVL_NEXT (t)) - { - tree fn = OVL_CURRENT (t); - if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)) - return 0; - } + for (ovl_iterator iter (get_fns (t)); iter; ++iter) + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (*iter)) + return 0; return 1; } return 0; @@ -1394,7 +1390,7 @@ lookup_field_fuzzy_info::fuzzy_lookup_fn for (i = 0; vec_safe_iterate (method_vec, i, &fn); ++i) if (fn) - m_candidates.safe_push (DECL_NAME (OVL_CURRENT (fn))); + m_candidates.safe_push (OVL_NAME (fn)); } /* Locate all fields within TYPE, append them to m_candidates. */ @@ -1548,7 +1544,7 @@ lookup_conversion_operator (tree class_t the class. Therefore, if FN is not a conversion operator, there is no matching conversion operator in CLASS_TYPE. */ - fn = OVL_CURRENT (fn); + fn = OVL_FIRST (fn); if (!DECL_CONV_FN_P (fn)) break; @@ -1573,7 +1569,6 @@ lookup_fnfields_idx_nolazy (tree type, t { vec *method_vec; tree fn; - tree tmp; size_t i; if (!CLASS_TYPE_P (type)) @@ -1605,7 +1600,7 @@ lookup_fnfields_idx_nolazy (tree type, t for (i = CLASSTYPE_FIRST_CONVERSION_SLOT; vec_safe_iterate (method_vec, i, &fn); ++i) - if (!DECL_CONV_FN_P (OVL_CURRENT (fn))) + if (!DECL_CONV_FN_P (OVL_FIRST (fn))) break; /* If the type is complete, use binary search. */ @@ -1623,8 +1618,8 @@ lookup_fnfields_idx_nolazy (tree type, t if (GATHER_STATISTICS) n_outer_fields_searched++; - tmp = (*method_vec)[i]; - tmp = DECL_NAME (OVL_CURRENT (tmp)); + tree tmp = (*method_vec)[i]; + tmp = OVL_NAME (tmp); if (tmp > name) hi = i; else if (tmp < name) @@ -1638,7 +1633,7 @@ lookup_fnfields_idx_nolazy (tree type, t { if (GATHER_STATISTICS) n_outer_fields_searched++; - if (DECL_NAME (OVL_CURRENT (fn)) == name) + if (OVL_NAME (fn) == name) return i; } @@ -2199,28 +2194,25 @@ look_for_overrides_here (tree type, tree else ix = lookup_fnfields_1 (type, DECL_NAME (fndecl)); if (ix >= 0) - { - tree fns = (*CLASSTYPE_METHOD_VEC (type))[ix]; + for (ovl_iterator iter ((*CLASSTYPE_METHOD_VEC (type))[ix]); iter; ++iter) + { + tree fn = *iter; - for (; fns; fns = OVL_NEXT (fns)) - { - tree fn = OVL_CURRENT (fns); + if (!DECL_VIRTUAL_P (fn)) + /* Not a virtual. */; + else if (DECL_CONTEXT (fn) != type) + /* Introduced with a using declaration. */; + else if (DECL_STATIC_FUNCTION_P (fndecl)) + { + tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn)); + tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); + if (compparms (TREE_CHAIN (btypes), dtypes)) + return fn; + } + else if (same_signature_p (fndecl, fn)) + return fn; + } - if (!DECL_VIRTUAL_P (fn)) - /* Not a virtual. */; - else if (DECL_CONTEXT (fn) != type) - /* Introduced with a using declaration. */; - else if (DECL_STATIC_FUNCTION_P (fndecl)) - { - tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn)); - tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); - if (compparms (TREE_CHAIN (btypes), dtypes)) - return fn; - } - else if (same_signature_p (fndecl, fn)) - return fn; - } - } return NULL_TREE; } @@ -2563,35 +2555,31 @@ lookup_conversions_r (tree binfo, vec_safe_iterate (method_vec, i, &conv); ++i) { - tree cur = OVL_CURRENT (conv); + tree cur = OVL_FIRST (conv); if (!DECL_CONV_FN_P (cur)) break; if (TREE_CODE (cur) == TEMPLATE_DECL) - { - /* Only template conversions can be overloaded, and we must - flatten them out and check each one individually. */ - tree tpls; - - for (tpls = conv; tpls; tpls = OVL_NEXT (tpls)) - { - tree tpl = OVL_CURRENT (tpls); - tree type = DECL_CONV_FN_TYPE (tpl); - - if (check_hidden_convs (binfo, virtual_depth, virtualness, - type, parent_tpl_convs, other_tpl_convs)) - { - my_tpl_convs = tree_cons (binfo, tpl, my_tpl_convs); - TREE_TYPE (my_tpl_convs) = type; - if (virtual_depth) - { - TREE_STATIC (my_tpl_convs) = 1; - my_virtualness = 1; - } - } - } - } + /* Only template conversions can be overloaded, and we must + flatten them out and check each one individually. */ + for (ovl_iterator iter (conv); iter; ++iter) + { + tree tpl = *iter; + tree type = DECL_CONV_FN_TYPE (tpl); + + if (check_hidden_convs (binfo, virtual_depth, virtualness, + type, parent_tpl_convs, other_tpl_convs)) + { + my_tpl_convs = tree_cons (binfo, tpl, my_tpl_convs); + TREE_TYPE (my_tpl_convs) = type; + if (virtual_depth) + { + TREE_STATIC (my_tpl_convs) = 1; + my_virtualness = 1; + } + } + } else { tree name = DECL_NAME (cur); @@ -2657,7 +2645,7 @@ lookup_conversions_r (tree binfo, /* Unmark the conversions found at this level */ for (conv = my_convs; conv; conv = TREE_CHAIN (conv)) - IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (conv)))) = 0; + IDENTIFIER_MARKED (OVL_NAME (TREE_VALUE (conv))) = 0; *convs = split_conversions (my_convs, parent_convs, child_convs, other_convs); Index: typeck.c =================================================================== --- typeck.c (revision 248127) +++ typeck.c (working copy) @@ -5476,7 +5476,7 @@ build_x_unary_op (location_t loc, enum t pointer-to-member. */ xarg = build2 (OFFSET_REF, TREE_TYPE (xarg), TREE_OPERAND (xarg, 0), - ovl_cons (TREE_OPERAND (xarg, 1), NULL_TREE)); + ovl_make (TREE_OPERAND (xarg, 1))); PTRMEM_OK_P (xarg) = ptrmem; } }