This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH]: remove some memory, speed up some parsing


Mark,
this patch stops us creating binfos for all but actual aggregates, and
prevents access checking earlier in templates (we end up collecting all
the accesses and then ignoring them later at the moment).

This patch is groundwork for reorganizing binfos themselves.

built & tested on i686-pc-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2004-06-25  Nathan Sidwell  <nathan@codesourcery.com>

	* friend.c (add_friend): Only perform access checks when context
	is a class.
	* lex.c (cxx_make_type): Only create a binfo for aggregate types.
	* parser.c (cp_parser_class_specifier): Disable access checks here
	when parsing the body of a templated class.
	* semantics.c (perform_or_defer_access_checks): Reorder to allow
	NULL binfos when not checking access.

Index: cp/friend.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/friend.c,v
retrieving revision 1.97
diff -c -3 -p -r1.97 friend.c
*** cp/friend.c	31 May 2004 22:47:56 -0000	1.97
--- cp/friend.c	25 Jun 2004 15:37:06 -0000
*************** add_friend (tree type, tree decl, bool c
*** 129,134 ****
--- 129,135 ----
    tree typedecl;
    tree list;
    tree name;
+   tree ctx;
  
    if (decl == error_mark_node)
      return;
*************** add_friend (tree type, tree decl, bool c
*** 163,174 ****
        list = TREE_CHAIN (list);
      }
  
!   if (DECL_CLASS_SCOPE_P (decl))
!     {
!       tree class_binfo = TYPE_BINFO (DECL_CONTEXT (decl));
!       if (!uses_template_parms (BINFO_TYPE (class_binfo)))
! 	perform_or_defer_access_check (class_binfo, decl);
!     }
  
    maybe_add_class_template_decl_list (type, decl, /*friend_p=*/1);
  
--- 164,172 ----
        list = TREE_CHAIN (list);
      }
  
!   ctx = DECL_CONTEXT (decl);
!   if (ctx && CLASS_TYPE_P (ctx) && !uses_template_parms (ctx))
!     perform_or_defer_access_check (TYPE_BINFO (ctx), decl);
  
    maybe_add_class_template_decl_list (type, decl, /*friend_p=*/1);
  
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.331
diff -c -3 -p -r1.331 lex.c
*** cp/lex.c	24 Jun 2004 06:48:43 -0000	1.331
--- cp/lex.c	25 Jun 2004 15:37:07 -0000
*************** cxx_make_type (enum tree_code code)
*** 779,784 ****
--- 779,786 ----
  	 presence of parse errors, the normal was of assuring this
  	 might not ever get executed, so we lay it out *immediately*.  */
        build_pointer_type (t);
+ 
+       TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
      }
    else
      /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits.  But,
*************** cxx_make_type (enum tree_code code)
*** 786,800 ****
         clear it here.  */
      TYPE_ALIAS_SET (t) = 0;
  
-   /* We need to allocate a TYPE_BINFO even for TEMPLATE_TYPE_PARMs
-      since they can be virtual base types, and we then need a
-      canonical binfo for them.  Ideally, this would be done lazily for
-      all types.  */
-   if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM
-       || code == BOUND_TEMPLATE_TEMPLATE_PARM
-       || code == TYPENAME_TYPE)
-     TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
- 
    return t;
  }
  
--- 788,793 ----
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.216
diff -c -3 -p -r1.216 parser.c
*** cp/parser.c	25 Jun 2004 04:48:53 -0000	1.216
--- cp/parser.c	25 Jun 2004 15:37:40 -0000
*************** cp_parser_class_specifier (cp_parser* pa
*** 12358,12369 ****
--- 12358,12379 ----
    if (nested_name_specifier_p)
      pop_p = push_scope (CP_DECL_CONTEXT (TYPE_MAIN_DECL (type)));
    type = begin_class_definition (type);
+   
+   if (processing_template_decl)
+     /* There are no access checks when parsing a template, as we do no
+        know if a specialization will be a friend.  */
+     push_deferring_access_checks (dk_no_check);
+   
    if (type == error_mark_node)
      /* If the type is erroneous, skip the entire body of the class.  */
      cp_parser_skip_to_closing_brace (parser);
    else
      /* Parse the member-specification.  */
      cp_parser_member_specification_opt (parser);
+   
+   if (processing_template_decl)
+     pop_deferring_access_checks ();
+   
    /* Look for the trailing `}'.  */
    cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'");
    /* We get better error messages by noticing a common problem: a
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.410
diff -c -3 -p -r1.410 semantics.c
*** cp/semantics.c	24 Jun 2004 06:48:44 -0000	1.410
--- cp/semantics.c	25 Jun 2004 15:37:46 -0000
*************** perform_or_defer_access_check (tree binf
*** 257,274 ****
  {
    tree check;
  
!   my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623);
    
    /* If we are not supposed to defer access checks, just check now.  */
    if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred)
      {
        enforce_access (binfo, decl);
        return;
      }
!   /* Exit if we are in a context that no access checking is performed.  */
!   else if (deferred_access_stack->deferring_access_checks_kind == dk_no_check)
!     return;
! 
    /* See if we are already going to perform this check.  */
    for (check = deferred_access_stack->deferred_access_checks;
         check;
--- 257,275 ----
  {
    tree check;
  
!   /* Exit if we are in a context that no access checking is performed.  */
!   if (deferred_access_stack->deferring_access_checks_kind == dk_no_check)
!     return;
    
+   my_friendly_assert (TREE_CODE (binfo) == TREE_VEC, 20030623);
+ 
    /* If we are not supposed to defer access checks, just check now.  */
    if (deferred_access_stack->deferring_access_checks_kind == dk_no_deferred)
      {
        enforce_access (binfo, decl);
        return;
      }
!   
    /* See if we are already going to perform this check.  */
    for (check = deferred_access_stack->deferred_access_checks;
         check;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]