[cxx-reflection] PATCH to mangle decltype

Gabriel Dos Reis gdr@integrable-solutions.net
Sun Oct 5 21:35:00 GMT 2003


Nathan Sidwell <nathan@codesourcery.com> writes:

[...]

| I suggest an extensible scheme
| X <digit1> <digit2> <sourcename> <type>...[n1] <expr>...[n2]
| <digit1> is the number of types encoded
| <digit2> is the number of exprs encoded

this patch implements your suggestion.

Something like this should be done for __alignof__/__typeof__ on
mainline, for which we have numerous PRs.

Thanks,

-- Gaby

Index: ChangeLog.cxx-reflection
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Attic/ChangeLog.cxx-reflection,v
retrieving revision 1.1.2.4
diff -p -r1.1.2.4 ChangeLog.cxx-reflection
*** ChangeLog.cxx-reflection	19 Jun 2003 12:55:02 -0000	1.1.2.4
--- ChangeLog.cxx-reflection	5 Oct 2003 21:29:55 -0000
***************
*** 1,3 ****
--- 1,9 ----
+ 2003-10-05  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+ 
+ 	Mangle decltype in a reversible way. 
+ 	* mangle.c (write_declared_type): New function.
+ 	(write_type): Use it.
+ 
  2003-06-19  Gabriel Dos Reis <gdr@integrable-solutions.net>
  
  	* mangle.c (write_type): Handle DECLARED_TYPE.
Index: mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.67.4.8
diff -p -r1.67.4.8 mangle.c
*** mangle.c	4 Oct 2003 13:54:25 -0000	1.67.4.8
--- mangle.c	5 Oct 2003 21:30:15 -0000
*************** static void write_discriminator (const i
*** 201,206 ****
--- 201,207 ----
  static void write_local_name (const tree, const tree, const tree);
  static void dump_substitution_candidates (void);
  static const char *mangle_decl_string (const tree);
+ static void write_declared_type (tree); 
  
  /* Control functions.  */
  
*************** write_local_name (const tree function, c
*** 1405,1411 ****
              ::= R <type>    # reference-to
              ::= C <type>    # complex pair (C 2000)
              ::= G <type>    # imaginary (C 2000)     [not supported]
!             ::= U <source-name> <type>   # vendor extended type qualifier 
  
     TYPE is a type node.  */
  
--- 1406,1413 ----
              ::= R <type>    # reference-to
              ::= C <type>    # complex pair (C 2000)
              ::= G <type>    # imaginary (C 2000)     [not supported]
!             ::= U <source-name> <type>   # vendor extended type qualifier
!             ::= <declared-type>  # C++0x extension.
  
     TYPE is a type node.  */
  
*************** write_type (tree type)
*** 1513,1518 ****
--- 1515,1524 ----
  	  write_type (TREE_TYPE (type));
  	  break;
  
+         case DECLARED_TYPE:
+           write_declared_type (type);
+           break;
+ 
  	default:
  	  abort ();
  	}
*************** write_substitution (const int seq_id)
*** 2288,2293 ****
--- 2294,2340 ----
      write_number (seq_id - 1, /*unsigned=*/1, 36);
    write_char ('_');
  }
+ 
+ /* Non terminal <declared-type.  This is a C++0x extension.  The mangling
+    scheme used here is derived as a special case from a scheme suggested by
+    Nathan Sidwell <nathan@codesourcery.com>:
+    X <digit1> <digit2> <source-name> <type1>...[n1] <expr1> ...[n2]
+    where:
+      <digit1> is the number of types encoded
+      <digit2> is the number of expressions encoded.
+   
+ 
+    <declared-type> ::= X 1 0 <decltype-source-name> <type>
+                    ::= X 0 1 <decltype-source-name> <expression>
+ 
+    <decltype-source-name> ::= 8decltype   */
+ 
+ static void
+ write_declared_type (tree t)
+ {
+   write_char ('X');
+   t = TYPE_FIELDS (t);
+ 
+   if (TYPE_P (t))
+     {
+       write_unsigned_number (1);
+       write_unsigned_number (0);
+     }
+   else
+     {
+       write_unsigned_number (0);
+       write_unsigned_number (1);
+     }
+ 
+   write_unsigned_number (8);
+   write_identifier ("decltype");
+ 
+   if (TYPE_P (t))
+     write_type (t);
+   else
+     write_expression (t);  
+ }
+ 
  
  /* Start mangling ENTITY.  */
  



More information about the Gcc-patches mailing list