C++ PATCH: Yet more cleanups

Mark Mitchell mark@codesourcery.com
Tue Jul 9 16:42:00 GMT 2002


More stuff from the new parser branch...

Tested on i686-pc-linux-gnu, applied on the mainline.

The new parser is getting closer to compilation, and Geoff Keating is
helping me unravel the gengtype stuff that needs to be done.  Then the
real fun -- figuring out why the new parser doesn't *work* anymore --
begins...

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-07-09  Mark Mitchell  <mark@codesourcery.com>

	* cp-tree.h (constructor_name_p): Declare it.
	(check_template_template_default_arg): Likewise.
	* class.c (handle_using_decl): Use constructor_name_p.
	* decl.c (grokdeclarator): Likewise.
	* decl2.c (constructor_name_p): Define it.
	* init.c (build_member_call): Use constructor_name_p.
	* parse.y (template_parm): Use check_template_template_default_arg.
	* pt.c (check_explicit_specialization): Use constructor_name_p.
	* semantics.c (check_template_template_default_arg): New function.
	
Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.454
diff -c -p -r1.454 class.c
*** class.c	25 Jun 2002 15:35:23 -0000	1.454
--- class.c	9 Jul 2002 23:20:39 -0000
*************** handle_using_decl (using_decl, t)
*** 1212,1225 ****
    if (! binfo)
      return;
    
!   if (name == constructor_name (ctype)
!       || name == constructor_name_full (ctype))
      {
        cp_error_at ("`%D' names constructor", using_decl);
        return;
      }
!   if (name == constructor_name (t)
!       || name == constructor_name_full (t))
      {
        cp_error_at ("`%D' invalid in `%T'", using_decl, t);
        return;
--- 1212,1223 ----
    if (! binfo)
      return;
    
!   if (constructor_name_p (name, ctype))
      {
        cp_error_at ("`%D' names constructor", using_decl);
        return;
      }
!   if (constructor_name_p (name, t))
      {
        cp_error_at ("`%D' invalid in `%T'", using_decl, t);
        return;
Index: cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.727
diff -c -p -r1.727 cp-tree.h
*** cp-tree.h	8 Jul 2002 07:49:56 -0000	1.727
--- cp-tree.h	9 Jul 2002 23:20:40 -0000
*************** extern tree grokoptypename			PARAMS ((tr
*** 3926,3931 ****
--- 3926,3932 ----
  extern void cplus_decl_attributes		PARAMS ((tree *, tree, int));
  extern tree constructor_name_full		PARAMS ((tree));
  extern tree constructor_name			PARAMS ((tree));
+ extern bool constructor_name_p                  (tree, tree);
  extern void defer_fn            		PARAMS ((tree));
  extern void finish_anon_union			PARAMS ((tree));
  extern tree finish_table			PARAMS ((tree, tree, tree, int));
*************** extern void setup_vtbl_ptr			PARAMS ((tr
*** 4318,4324 ****
  extern void clear_out_block                     PARAMS ((void));
  extern tree begin_global_stmt_expr              PARAMS ((void));
  extern tree finish_global_stmt_expr             PARAMS ((tree));
! 
  
  /* in spew.c */
  extern void init_spew				PARAMS ((void));
--- 4319,4325 ----
  extern void clear_out_block                     PARAMS ((void));
  extern tree begin_global_stmt_expr              PARAMS ((void));
  extern tree finish_global_stmt_expr             PARAMS ((tree));
! extern tree check_template_template_default_arg (tree);
  
  /* in spew.c */
  extern void init_spew				PARAMS ((void));
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.917
diff -c -p -r1.917 decl.c
*** decl.c	8 Jul 2002 07:49:57 -0000	1.917
--- decl.c	9 Jul 2002 23:20:43 -0000
*************** grokdeclarator (declarator, declspecs, d
*** 9848,9857 ****
  	    if (ctype
  		&& TREE_OPERAND (decl, 0)
  		&& (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL
! 		    && ((DECL_NAME (TREE_OPERAND (decl, 0))
! 			 == constructor_name_full (ctype))
! 			|| (DECL_NAME (TREE_OPERAND (decl, 0))
! 			    == constructor_name (ctype)))))
  	      TREE_OPERAND (decl, 0) = constructor_name (ctype);
  	    next = &TREE_OPERAND (decl, 0);
  	    decl = *next;
--- 9848,9855 ----
  	    if (ctype
  		&& TREE_OPERAND (decl, 0)
  		&& (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL
! 		    && constructor_name_p (DECL_NAME (TREE_OPERAND (decl, 0)),
! 					   ctype)))
  	      TREE_OPERAND (decl, 0) = constructor_name (ctype);
  	    next = &TREE_OPERAND (decl, 0);
  	    decl = *next;
*************** grokdeclarator (declarator, declspecs, d
*** 9958,9967 ****
  		}
  
  	      if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL
! 		  && ((DECL_NAME (TREE_OPERAND (decl, 1))
! 		       == constructor_name_full (ctype))
! 		      || (DECL_NAME (TREE_OPERAND (decl, 1))
! 			  == constructor_name (ctype))))
  		TREE_OPERAND (decl, 1) = constructor_name (ctype);
  	      next = &TREE_OPERAND (decl, 1);
  	      decl = *next;
--- 9956,9963 ----
  		}
  
  	      if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL
! 		  && constructor_name_p (DECL_NAME (TREE_OPERAND (decl, 1)),
! 					 ctype))
  		TREE_OPERAND (decl, 1) = constructor_name (ctype);
  	      next = &TREE_OPERAND (decl, 1);
  	      decl = *next;
*************** grokdeclarator (declarator, declspecs, d
*** 9975,9982 ****
  		    }
  		  else if (TREE_CODE (decl) == BIT_NOT_EXPR
  			   && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
! 			   && (constructor_name (ctype) == TREE_OPERAND (decl, 0)
! 			       || constructor_name_full (ctype) == TREE_OPERAND (decl, 0)))
  		    {
  		      sfk = sfk_destructor;
  		      ctor_return_type = ctype;
--- 9971,9978 ----
  		    }
  		  else if (TREE_CODE (decl) == BIT_NOT_EXPR
  			   && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
! 			   && constructor_name_p (TREE_OPERAND (decl, 0),
! 						  ctype))
  		    {
  		      sfk = sfk_destructor;
  		      ctor_return_type = ctype;
Index: decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.544
diff -c -p -r1.544 decl2.c
*** decl2.c	5 Jul 2002 10:40:47 -0000	1.544
--- decl2.c	9 Jul 2002 23:20:44 -0000
*************** constructor_name (thing)
*** 1810,1815 ****
--- 1810,1825 ----
      return thing;
    return t;
  }
+ 
+ /* Returns TRUE if NAME is the name for the constructor for TYPE.  */
+ 
+ bool
+ constructor_name_p (tree name, tree type)
+ {
+   return (name == constructor_name (type)
+ 	  || name == constructor_name_full (type));
+ }
+ 
  
  /* Defer the compilation of the FN until the end of compilation.  */
  
Index: init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.283
diff -c -p -r1.283 init.c
*** init.c	3 Jul 2002 15:46:17 -0000	1.283
--- init.c	9 Jul 2002 23:20:45 -0000
*************** build_member_call (type, name, parmlist)
*** 1522,1529 ****
  	return error_mark_node;
      }
  
!   if (method_name == constructor_name (type)
!       || method_name == constructor_name_full (type))
      return build_functional_cast (type, parmlist);
    if (lookup_fnfields (basetype_path, method_name, 0))
      return build_method_call (decl, 
--- 1522,1528 ----
  	return error_mark_node;
      }
  
!   if (constructor_name_p (method_name, type))
      return build_functional_cast (type, parmlist);
    if (lookup_fnfields (basetype_path, method_name, 0))
      return build_method_call (decl, 
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parse.y,v
retrieving revision 1.269
diff -c -p -r1.269 parse.y
*** parse.y	8 Jul 2002 07:49:58 -0000	1.269
--- parse.y	9 Jul 2002 23:20:46 -0000
*************** template_parm:
*** 710,723 ****
  		{ $$ = build_tree_list (NULL_TREE, $1); }
  	| template_template_parm '=' template_arg
  		{
! 		  if (TREE_CODE ($3) != TEMPLATE_DECL
! 		      && TREE_CODE ($3) != TEMPLATE_TEMPLATE_PARM
! 		      && TREE_CODE ($3) != TYPE_DECL
! 		      && TREE_CODE ($3) != UNBOUND_CLASS_TEMPLATE)
! 		    {
! 		      error ("invalid default template argument");
! 		      $3 = error_mark_node;
! 		    }
  		  $$ = build_tree_list ($3, $1);
  		}
  	;
--- 710,716 ----
  		{ $$ = build_tree_list (NULL_TREE, $1); }
  	| template_template_parm '=' template_arg
  		{
! 		  $3 = check_template_template_default_arg ($3);
  		  $$ = build_tree_list ($3, $1);
  		}
  	;
Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.598
diff -c -p -r1.598 pt.c
*** pt.c	8 Jul 2002 02:25:19 -0000	1.598
--- pt.c	9 Jul 2002 23:20:47 -0000
*************** check_explicit_specialization (declarato
*** 1529,1536 ****
  	  tree fns = NULL_TREE;
  	  int idx;
  
! 	  if (name == constructor_name (ctype) 
! 	      || name == constructor_name_full (ctype))
  	    {
  	      int is_constructor = DECL_CONSTRUCTOR_P (decl);
  	      
--- 1529,1535 ----
  	  tree fns = NULL_TREE;
  	  int idx;
  
! 	  if (constructor_name_p (name, ctype))
  	    {
  	      int is_constructor = DECL_CONSTRUCTOR_P (decl);
  	      
Index: semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.266
diff -c -p -r1.266 semantics.c
*** semantics.c	25 Jun 2002 15:35:27 -0000	1.266
--- semantics.c	9 Jul 2002 23:28:14 -0000
*************** finish_template_template_parm (aggr, ide
*** 1625,1630 ****
--- 1625,1649 ----
    return finish_template_type_parm (aggr, tmpl);
  }
  
+ /* ARGUMENT is the default-argument value for a template template
+    parameter.  If ARGUMENT is invalid, issue error messages and return
+    the ERROR_MARK_NODE.  Otherwise, ARGUMENT itself is returned.  */
+ 
+ tree
+ check_template_template_default_arg (tree argument)
+ {
+   if (TREE_CODE (argument) != TEMPLATE_DECL
+       && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
+       && TREE_CODE (argument) != TYPE_DECL
+       && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
+     {
+       error ("invalid default template argument");
+       return error_mark_node;
+     }
+ 
+   return argument;
+ }
+ 
  /* Finish a parameter list, indicated by PARMS.  If ELLIPSIS is
     non-zero, the parameter list was terminated by a `...'.  */
  



More information about the Gcc-patches mailing list