introduce {class,type}_of_this_parm functions
authorNathan Froyd <froydnj@codesourcery.com>
Fri, 6 May 2011 17:03:08 +0000 (17:03 +0000)
committerNathan Froyd <froydnj@gcc.gnu.org>
Fri, 6 May 2011 17:03:08 +0000 (17:03 +0000)
introduce {class,type}_of_this_parm functions
* cp-tree.h (type_of_this_parm, class_of_this_parm): New functions.
* call.c (standard_conversion): Call class_of_this_parm.
* cxx-pretty-print.c (pp_cxx_implicit_parameter_type): Likewise.
(pp_cxx_direct_abstract_declarator): Likewise.
* decl2.c (change_return_type): Likewise.
(cp_reconstruct_complex_type): Likewise.
* error.c (dump_type_suffix, dump_function_decl): Likewise.
* mangle.c (write_function_type): Likewise.
* pt.c (unify): Likewise.
* typeck.c (merge_types, type_memfn_quals): Likewise.
* decl.c (build_this_parm): Call type_of_this_parm.

From-SVN: r173496

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/cxx-pretty-print.c
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/error.c
gcc/cp/mangle.c
gcc/cp/pt.c
gcc/cp/typeck.c

index dfaaeaa54c1e262037201b8ee504d89b0100702a..f19c0c1d1c796dc2bae13840401584c13b49ec6d 100644 (file)
@@ -1,3 +1,17 @@
+2011-05-06  Nathan Froyd  <froydnj@codesourcery.com>
+
+       * cp-tree.h (type_of_this_parm, class_of_this_parm): New functions.
+       * call.c (standard_conversion): Call class_of_this_parm.
+       * cxx-pretty-print.c (pp_cxx_implicit_parameter_type): Likewise.
+       (pp_cxx_direct_abstract_declarator): Likewise.
+       * decl2.c (change_return_type): Likewise.
+       (cp_reconstruct_complex_type): Likewise.
+       * error.c (dump_type_suffix, dump_function_decl): Likewise.
+       * mangle.c (write_function_type): Likewise.
+       * pt.c (unify): Likewise.
+       * typeck.c (merge_types, type_memfn_quals): Likewise.
+       * decl.c (build_this_parm): Call type_of_this_parm.
+
 2011-05-06  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/48838
index f5bd521ddaa564631fd2a99b7678ae39ba972e5a..3a71572b67dd2a066146186ad0894e74143097be 100644 (file)
@@ -1146,8 +1146,8 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
     {
       tree fromfn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (from));
       tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
-      tree fbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn)));
-      tree tbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn)));
+      tree fbase = class_of_this_parm (fromfn);
+      tree tbase = class_of_this_parm (tofn);
 
       if (!DERIVED_FROM_P (fbase, tbase)
          || !same_type_p (TREE_TYPE (fromfn), TREE_TYPE (tofn))
index 9d13393502d202c5d6e1fa0dc2885212fa936f80..ad298dfd57545abe25db58b264113e3cdb16328d 100644 (file)
@@ -4616,6 +4616,25 @@ struct GTY(()) tinst_level {
   bool in_system_header_p;
 };
 
+/* Return the type of the `this' parameter of FNTYPE.  */
+
+static inline tree
+type_of_this_parm (const_tree fntype)
+{
+  function_args_iterator iter;
+  gcc_assert (TREE_CODE (fntype) == METHOD_TYPE);
+  function_args_iter_init (&iter, fntype);
+  return function_args_iter_cond (&iter);
+}
+
+/* Return the class of the `this' parameter of FNTYPE.  */
+
+static inline tree
+class_of_this_parm (const_tree fntype)
+{
+  return TREE_TYPE (type_of_this_parm (fntype));
+}
+
 /* A parameter list indicating for a function with no parameters,
    e.g  "int f(void)".  */
 extern cp_parameter_declarator *no_parameters;
index bd0381bf438aea0bd820ec8ff256867d8918723b..04f8f7b2adf9ae6a9f0f380922a8649a862e5d18 100644 (file)
@@ -1363,7 +1363,7 @@ pp_cxx_ptr_operator (cxx_pretty_printer *pp, tree t)
 static inline tree
 pp_cxx_implicit_parameter_type (tree mf)
 {
-  return TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (mf))));
+  return class_of_this_parm (TREE_TYPE (mf));
 }
 
 /*
@@ -1652,8 +1652,7 @@ pp_cxx_direct_abstract_declarator (cxx_pretty_printer *pp, tree t)
       if (TREE_CODE (t) == METHOD_TYPE)
        {
          pp_base (pp)->padding = pp_before;
-         pp_cxx_cv_qualifier_seq
-           (pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
+         pp_cxx_cv_qualifier_seq (pp, class_of_this_parm (t));
        }
       pp_cxx_exception_specification (pp, t);
       break;
index 3622c2ceae6d579b5e26f80f30b6b7159376d3eb..e766503b82039e916525c7e1d50fffe723f4d417 100644 (file)
@@ -6924,7 +6924,7 @@ build_this_parm (tree type, cp_cv_quals quals)
   tree parm;
   cp_cv_quals this_quals;
 
-  this_type = TREE_VALUE (TYPE_ARG_TYPES (type));
+  this_type = type_of_this_parm (type);
   /* The `this' parameter is implicitly `const'; it cannot be
      assigned to.  */
   this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
index ef8de31b8077b7d2c1396ae932384e32eae0381b..2e08dd730d92bc5bc5aa9c8899837ed74b4111e9 100644 (file)
@@ -161,8 +161,7 @@ change_return_type (tree new_ret, tree fntype)
     }
   else
     newtype = build_method_type_directly
-      (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))),
-       new_ret, TREE_CHAIN (args));
+      (class_of_this_parm (fntype), new_ret, TREE_CHAIN (args));
   if (raises)
     newtype = build_exception_variant (newtype, raises);
   if (attrs)
@@ -1249,8 +1248,7 @@ cp_reconstruct_complex_type (tree type, tree bottom)
         so we must compensate by getting rid of it.  */
       outer
        = build_method_type_directly
-           (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
-            inner,
+           (class_of_this_parm (type), inner,
             TREE_CHAIN (TYPE_ARG_TYPES (type)));
     }
   else if (TREE_CODE (type) == OFFSET_TYPE)
index fce74036b0235c8e2cf0af21750f754647ebf741..e580fd92158df4bf180cfbbcdc663015a8f9cf8c 100644 (file)
@@ -794,8 +794,7 @@ dump_type_suffix (tree t, int flags)
        dump_parameters (arg, flags & ~TFF_FUNCTION_DEFAULT_ARGUMENTS);
 
        if (TREE_CODE (t) == METHOD_TYPE)
-         pp_cxx_cv_qualifier_seq
-           (cxx_pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))));
+         pp_cxx_cv_qualifier_seq (cxx_pp, class_of_this_parm (t));
        else
          pp_cxx_cv_qualifier_seq (cxx_pp, t);
        dump_exception_spec (TYPE_RAISES_EXCEPTIONS (t), flags);
@@ -1360,8 +1359,7 @@ dump_function_decl (tree t, int flags)
       if (TREE_CODE (fntype) == METHOD_TYPE)
        {
          pp_base (cxx_pp)->padding = pp_before;
-         pp_cxx_cv_qualifier_seq
-           (cxx_pp, TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))));
+         pp_cxx_cv_qualifier_seq (cxx_pp, class_of_this_parm (fntype));
        }
 
       if (flags & TFF_EXCEPTION_SPECIFICATION)
index 3dbc3b7782a5a69b16833501b56328fbc47296aa..c72e6d2fc64af7ae8419fc37d69ab8a36ba3ec2c 100644 (file)
@@ -2247,7 +2247,7 @@ write_function_type (const tree type)
     {
       /* The first parameter must be a POINTER_TYPE pointing to the
         `this' parameter.  */
-      tree this_type = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type)));
+      tree this_type = class_of_this_parm (type);
       write_CV_qualifiers_for_type (this_type);
     }
 
index d109e1bd739c4e3d113da523021b7cce24d046b3..76fc69bc0efd905e6a4bfdfa7e950971314805ac 100644 (file)
@@ -15600,8 +15600,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict)
        if (TREE_CODE (parm) == METHOD_TYPE
            && (!check_cv_quals_for_unify
                (UNIFY_ALLOW_NONE,
-                TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (arg))),
-                TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (parm))))))
+                class_of_this_parm (arg),
+                class_of_this_parm (parm))))
          return 1;
 
        if (unify (tparms, targs, TREE_TYPE (parm),
index afe0dbcf2b258623c76c16adb7c677883ac5f8a2..4d0c0d7b06befc2dbc9f5dc4db61ff32a1d4e7f2 100644 (file)
@@ -834,7 +834,7 @@ merge_types (tree t1, tree t2)
       {
        /* Get this value the long way, since TYPE_METHOD_BASETYPE
           is just the main variant of this.  */
-       tree basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
+       tree basetype = class_of_this_parm (t2);
        tree raises = merge_exception_specifiers (TYPE_RAISES_EXCEPTIONS (t1),
                                                  TYPE_RAISES_EXCEPTIONS (t2));
        tree t3;
@@ -8034,7 +8034,7 @@ type_memfn_quals (const_tree type)
   if (TREE_CODE (type) == FUNCTION_TYPE)
     return TYPE_QUALS (type);
   else if (TREE_CODE (type) == METHOD_TYPE)
-    return cp_type_quals (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))));
+    return cp_type_quals (class_of_this_parm (type));
   else
     gcc_unreachable ();
 }