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]

(C++) patch for __typeof in templates


Applied.  Fixes g++.ext/typeof1.C.

1998-10-26  Jason Merrill  <jason@yorick.cygnus.com>

	* cp-tree.def (TYPEOF_TYPE): New code.
	* error.c (dump_type_real): Handle it.
	* pt.c (tsubst): Likewise.
	* tree.c (search_tree): Likewise.
	* semantics.c (finish_typeof): New fn.
	* parse.y (typespec): Use it.
	* cp-tree.h: Declare it.

Index: cp-tree.def
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.def,v
retrieving revision 1.21
diff -c -p -r1.21 cp-tree.def
*** cp-tree.def	1998/10/15 11:27:39	1.21
--- cp-tree.def	1998/10/26 10:04:39
*************** DEFTREECODE (TEMPLATE_TEMPLATE_PARM, "te
*** 149,154 ****
--- 149,158 ----
     TREE_TYPE is a _TYPE from a baseclass of `T'.  */
  DEFTREECODE (TYPENAME_TYPE, "typename_type", 't', 0)
  
+ /* A type designated by `__typeof (expr)'.  TYPE_FIELDS is the
+    expression in question.  */
+ DEFTREECODE (TYPEOF_TYPE, "typeof_type", 't', 0)
+ 
  /* A thunk is a stub function.
  
     Thunks are used to implement multiple inheritance:
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.159
diff -c -p -r1.159 cp-tree.h
*** cp-tree.h	1998/10/23 14:52:56	1.159
--- cp-tree.h	1998/10/26 10:04:40
*************** extern void enter_scope_of              
*** 3033,3038 ****
--- 3033,3039 ----
  extern tree finish_base_specifier               PROTO((tree, tree, int));
  extern void finish_member_declaration           PROTO((tree));
  extern void check_multiple_declarators          PROTO((void));
+ extern tree finish_typeof			PROTO((tree));
  
  /* in sig.c */
  extern tree build_signature_pointer_type	PROTO((tree));
Index: error.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/error.c,v
retrieving revision 1.57
diff -c -p -r1.57 error.c
*** error.c	1998/10/23 14:53:02	1.57
--- error.c	1998/10/26 10:04:40
*************** dump_type_real (t, v, canonical_name)
*** 328,333 ****
--- 328,339 ----
        OB_PUTID (TYPE_IDENTIFIER (t));
        break;
  
+     case TYPEOF_TYPE:
+       OB_PUTS ("__typeof (");
+       dump_expr (TYPE_FIELDS (t), 1);
+       OB_PUTC (')');
+       break;
+ 
      default:
        sorry ("`%s' not supported by dump_type",
  	     tree_code_name[(int) TREE_CODE (t)]);
Index: parse.y
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/parse.y,v
retrieving revision 1.98
diff -c -p -r1.98 parse.y
*** parse.y	1998/10/24 00:35:31	1.98
--- parse.y	1998/10/26 10:04:40
*************** typespec:
*** 1789,1795 ****
  	| complete_type_name
  		{ $$.t = $1; $$.new_type_flag = 0; }
  	| TYPEOF '(' expr ')'
! 		{ $$.t = TREE_TYPE ($3);
  		  $$.new_type_flag = 0; }
  	| TYPEOF '(' type_id ')'
  		{ $$.t = groktypename ($3.t);
--- 1789,1795 ----
  	| complete_type_name
  		{ $$.t = $1; $$.new_type_flag = 0; }
  	| TYPEOF '(' expr ')'
! 		{ $$.t = finish_typeof ($3);
  		  $$.new_type_flag = 0; }
  	| TYPEOF '(' type_id ')'
  		{ $$.t = groktypename ($3.t);
Index: pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.219
diff -c -p -r1.219 pt.c
*** pt.c	1998/10/23 14:53:21	1.219
--- pt.c	1998/10/26 10:04:40
*************** tsubst (t, args, in_decl)
*** 5841,5846 ****
--- 5841,5849 ----
  	(TREE_CODE (t), tsubst (TREE_OPERAND (t, 0), args, in_decl),
  	 tsubst (TREE_OPERAND (t, 1), args, in_decl));
  
+     case TYPEOF_TYPE:
+       return TREE_TYPE (tsubst_expr (TYPE_FIELDS (t), args, in_decl));
+ 
      default:
        sorry ("use of `%s' in template",
  	     tree_code_name [(int) TREE_CODE (t)]);
Index: semantics.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/semantics.c,v
retrieving revision 1.33
diff -c -p -r1.33 semantics.c
*** semantics.c	1998/10/08 16:04:13	1.33
--- semantics.c	1998/10/26 10:04:40
*************** check_multiple_declarators ()
*** 1604,1606 ****
--- 1604,1628 ----
      cp_error ("multiple declarators in template declaration");
  }
  
+ tree
+ finish_typeof (expr)
+      tree expr;
+ {
+   if (processing_template_decl)
+     {
+       tree t;
+ 
+       push_obstacks_nochange ();
+       end_temporary_allocation ();
+ 
+       t = make_lang_type (TYPEOF_TYPE);
+       CLASSTYPE_GOT_SEMICOLON (t) = 1;
+       TYPE_FIELDS (t) = expr;
+ 
+       pop_obstacks ();
+ 
+       return t;
+     }
+ 
+   return TREE_TYPE (expr);
+ }
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.74
diff -c -p -r1.74 tree.c
*** tree.c	1998/10/23 14:53:27	1.74
--- tree.c	1998/10/26 10:04:41
*************** search_tree (t, func)
*** 1686,1691 ****
--- 1686,1692 ----
      case TYPENAME_TYPE:
      case UNION_TYPE:
      case ENUMERAL_TYPE:
+     case TYPEOF_TYPE:
        break;
  
      case POINTER_TYPE:


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