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]

Patch to add -fshort-wchar


This patch adds a flag to change wchar_t to be a short, for MS
compatibility.  The implementation is not very clean, but I don't really
see a better way.  Thoughts?

Index: ChangeLog
Tue May 25 09:22:06 1999  Jason Merrill  <jason@yorick.cygnus.com>

	* toplev.c (documented_lang_options): Add -fshort-wchar.
	* c-decl.c (c_decode_option): Likewise.
	(init_decl_processing): If -fshort-wchar, use 'short unsigned int'
	for wchar_t.
	* c-common.c, c-lex.c: Get WCHAR_TYPE_SIZE from wchar_type_node.
	* gcc.c (default_compilers): If -fshort-wchar, 
	override __WCHAR_TYPE__.

Index: cp/ChangeLog
1999-05-25  Jason Merrill  <jason@yorick.cygnus.com>

	* lex.c: Get WCHAR_TYPE_SIZE from wchar_type_node.
	* lang-specs.h: If -fshort-wchar, override __WCHAR_TYPE__.

1999-05-24  Jason Merrill  <jason@yorick.cygnus.com>

	* decl2.c (lang_f_options): Add -fshort-wchar.
	* lang-options.h: Likewise.
	* cp-tree.h: Declare flag_short_wchar.
	* decl.c (init_decl_processing): If -fshort-wchar, use 'short unsigned 
	int' for wchar_t.

Index: c-common.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/c-common.c,v
retrieving revision 1.115.2.2
diff -c -p -r1.115.2.2 c-common.c
*** c-common.c	1999/05/24 22:53:53	1.115.2.2
--- c-common.c	1999/05/26 04:35:31
*************** cpp_options parse_options;
*** 37,49 ****
  enum cpp_token cpp_token;
  #endif
  
! #ifndef WCHAR_TYPE_SIZE
! #ifdef INT_TYPE_SIZE
! #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
! #else
! #define WCHAR_TYPE_SIZE	BITS_PER_WORD
! #endif
! #endif
  
  extern struct obstack permanent_obstack;
  
--- 37,44 ----
  enum cpp_token cpp_token;
  #endif
  
! #undef WCHAR_TYPE_SIZE
! #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
  
  extern struct obstack permanent_obstack;
  
Index: c-decl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/c-decl.c,v
retrieving revision 1.224.2.1
diff -c -p -r1.224.2.1 c-decl.c
*** c-decl.c	1999/05/24 22:35:41	1.224.2.1
--- c-decl.c	1999/05/26 04:35:31
*************** int flag_cond_mismatch;
*** 449,454 ****
--- 449,458 ----
  
  int flag_short_double;
  
+ /* Nonzero means give `wchar_t' the same size as `short'.  */
+ 
+ int flag_short_wchar;
+ 
  /* Nonzero means don't recognize the keyword `asm'.  */
  
  int flag_no_asm;
*************** c_decode_option (argc, argv)
*** 724,729 ****
--- 728,737 ----
      flag_short_enums = 1;
    else if (!strcmp (p, "-fno-short-enums"))
      flag_short_enums = 0;
+   else if (!strcmp (p, "-fshort-wchar"))
+     flag_short_wchar = 1;
+   else if (!strcmp (p, "-fno-short-wchar"))
+     flag_short_wchar = 0;
    else if (!strcmp (p, "-fcond-mismatch"))
      flag_cond_mismatch = 1;
    else if (!strcmp (p, "-fno-cond-mismatch"))
*************** init_decl_processing ()
*** 3182,3189 ****
    TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
    layout_type (complex_long_double_type_node);
  
!   wchar_type_node
!     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
    wchar_type_size = TYPE_PRECISION (wchar_type_node);
    signed_wchar_type_node = signed_type (wchar_type_node);
    unsigned_wchar_type_node = unsigned_type (wchar_type_node);
--- 3190,3199 ----
    TREE_TYPE (complex_long_double_type_node) = long_double_type_node;
    layout_type (complex_long_double_type_node);
  
!   wchar_type_node = get_identifier (flag_short_wchar
! 				    ? "short unsigned int"
! 				    : WCHAR_TYPE);
!   wchar_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (wchar_type_node));
    wchar_type_size = TYPE_PRECISION (wchar_type_node);
    signed_wchar_type_node = signed_type (wchar_type_node);
    unsigned_wchar_type_node = unsigned_type (wchar_type_node);
Index: c-lex.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/c-lex.c,v
retrieving revision 1.74.2.4
diff -c -p -r1.74.2.4 c-lex.c
*** c-lex.c	1999/05/25 05:51:07	1.74.2.4
--- c-lex.c	1999/05/26 04:35:31
*************** extern int yydebug;
*** 96,108 ****
  /* File used for outputting assembler code.  */
  extern FILE *asm_out_file;
  
! #ifndef WCHAR_TYPE_SIZE
! #ifdef INT_TYPE_SIZE
! #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
! #else
! #define WCHAR_TYPE_SIZE	BITS_PER_WORD
! #endif
! #endif
  
  /* Number of bytes in a wide character.  */
  #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
--- 96,103 ----
  /* File used for outputting assembler code.  */
  extern FILE *asm_out_file;
  
! #undef WCHAR_TYPE_SIZE
! #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
  
  /* Number of bytes in a wide character.  */
  #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
Index: gcc.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/gcc.c,v
retrieving revision 1.255.2.3
diff -c -p -r1.255.2.3 gcc.c
*** gcc.c	1999/05/24 23:09:11	1.255.2.3
--- gcc.c	1999/05/26 04:35:31
*************** static struct compiler default_compilers
*** 612,617 ****
--- 612,618 ----
  	%{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
          %{traditional} %{ftraditional:-traditional}\
          %{traditional-cpp:-traditional}\
  	%{fleading-underscore} %{fno-leading-underscore}\
*************** static struct compiler default_compilers
*** 628,633 ****
--- 629,635 ----
                    %{!undef:%{!ansi:%p} %P} %{trigraphs} \
                    %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  		  %{ffast-math:-D__FAST_MATH__}\
+ 		  %{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
                    %{H} %C %{D*} %{U*} %{i*} %Z\
                    %{ftraditional:-traditional}\
                    %{traditional-cpp:-traditional}\
*************** static struct compiler default_compilers
*** 653,658 ****
--- 655,661 ----
  		  %{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
                    %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  		  %{ffast-math:-D__FAST_MATH__}\
+ 		  %{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
                    %{H} %C %{D*} %{U*} %{i*} %Z\
                    %{ftraditional:-traditional}\
                    %{traditional-cpp:-traditional}\
*************** static struct compiler default_compilers
*** 679,684 ****
--- 682,688 ----
  	%{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
          %{traditional} %{ftraditional:-traditional}\
          %{traditional-cpp:-traditional}\
  	%{fleading-underscore} %{fno-leading-underscore}\
*************** static struct compiler default_compilers
*** 727,732 ****
--- 731,737 ----
  	%{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
          %{traditional} %{ftraditional:-traditional}\
          %{traditional-cpp:-traditional}\
  	%{fleading-underscore} %{fno-leading-underscore}\
*************** static struct compiler default_compilers
*** 743,748 ****
--- 748,754 ----
  	%{!undef:%{!ansi:%p} %P} %{trigraphs}\
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
          %{traditional} %{ftraditional:-traditional}\
          %{traditional-cpp:-traditional}\
  	%{fleading-underscore} %{fno-leading-underscore}\
*************** static struct compiler default_compilers
*** 791,796 ****
--- 797,803 ----
  	%{!undef:%{!std=*:%p}%{std=gnu*:%p} %P} %{trigraphs}\
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
          %{traditional} %{ftraditional:-traditional}\
          %{traditional-cpp:-traditional}\
  	%{fleading-underscore} %{fno-leading-underscore}\
*************** static struct compiler default_compilers
*** 839,844 ****
--- 846,852 ----
          -$ %{!undef:%p %P} -D__ASSEMBLER__ \
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
          %{traditional} %{ftraditional:-traditional}\
          %{traditional-cpp:-traditional}\
  	%{fleading-underscore} %{fno-leading-underscore}\
Index: toplev.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/toplev.c,v
retrieving revision 1.354.2.7
diff -c -p -r1.354.2.7 toplev.c
*** toplev.c	1999/05/24 23:09:12	1.354.2.7
--- toplev.c	1999/05/26 04:35:31
*************** documented_lang_options[] =
*** 1125,1130 ****
--- 1125,1132 ----
    { "-fno-short-double", "" },
    { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
    { "-fno-short-enums", "" },
+   { "-fshort-wchar", "Override the underlying type for wchar_t to `unsigned short'" },
+   { "-fno-short-wchar", "" },
  
    { "-Wall", "Enable most warning messages" },
    { "-Wbad-function-cast",
Index: cp/decl2.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/decl2.c,v
retrieving revision 1.441.2.9
diff -c -p -r1.441.2.9 decl2.c
*** cp/decl2.c	1999/05/25 07:31:14	1.441.2.9
--- cp/decl2.c	1999/05/26 04:35:32
*************** lang_f_options[] =
*** 475,480 ****
--- 475,481 ----
    {"unsigned-bitfields", &flag_signed_bitfields, 0},
    {"short-enums", &flag_short_enums, 1},
    {"short-double", &flag_short_double, 1},
+   {"short-wchar", &flag_short_wchar, 1},
    {"cond-mismatch", &flag_cond_mismatch, 1},
    {"asm", &flag_no_asm, 0},
    {"builtin", &flag_no_builtin, 0},
*************** lang_f_options[] =
*** 508,514 ****
    {"permissive", &flag_permissive, 1},
    {"repo", &flag_use_repository, 1},
    {"rtti", &flag_rtti, 1},
-   {"short-wchar", &flag_short_wchar, 1},
    {"squangle", &flag_do_squangling, 1},
    {"stats", &flag_detailed_statistics, 1},
    {"strict-prototype", &flag_strict_prototype, 1},
--- 509,514 ----
Index: cp/lang-options.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/lang-options.h,v
retrieving revision 1.34.30.2
diff -c -p -r1.34.30.2 lang-options.h
*** cp/lang-options.h	1999/05/25 07:31:15	1.34.30.2
--- cp/lang-options.h	1999/05/26 04:35:32
*************** DEFINE_LANG_NAME ("C++")
*** 92,99 ****
    { "-fno-repo", "" },
    { "-fsave-memoized", "" },
    { "-fno-save-memoized", "" },
-   { "-fshort-wchar", "Override the underlying type for wchar_t to `unsigned short'" },
-   { "-fno-short-wchar", "" },
    { "-fsquangle", "Enable squashed name mangling" },
    { "-fno-squangle", "" },
    { "-fstats", "Display statistics accumulated during compilation" },
--- 92,97 ----
Index: cp/lang-specs.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/lang-specs.h,v
retrieving revision 1.25.2.2
diff -c -p -r1.25.2.2 lang-specs.h
*** cp/lang-specs.h	1999/04/16 08:44:15	1.25.2.2
--- cp/lang-specs.h	1999/05/26 04:35:32
*************** Boston, MA 02111-1307, USA.  */
*** 40,45 ****
--- 40,46 ----
  	%{fembedded-cxx:-D__EMBEDDED_CXX__} \
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}} %{trigraphs}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
  	%{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
          %i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n}\
        %{!E:%{!M:%{!MM:cc1plus %i %1 %2\
*************** Boston, MA 02111-1307, USA.  */
*** 52,57 ****
--- 53,59 ----
                              %{fembedded-cxx:-D__EMBEDDED_CXX__} \
                              %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
  			    %{ffast-math:-D__FAST_MATH__}\
+ 			    %{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
                              %{trigraphs}\
  			    %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\
  			    %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
*************** Boston, MA 02111-1307, USA.  */
*** 75,80 ****
--- 77,83 ----
  	%{fembedded-cxx:-D__EMBEDDED_CXX__} \
          %c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}} %{trigraphs}\
  	%{ffast-math:-D__FAST_MATH__}\
+ 	%{fshort-wchar:-D__WCHAR_TYPE__=short\\ unsigned\\ int}\
  	%{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
          %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n",
  /* END CYGNUS LOCAL Embedded C++ */
Index: cp/lex.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/lex.c,v
retrieving revision 1.258.2.7
diff -c -p -r1.258.2.7 lex.c
*** cp/lex.c	1999/05/24 22:35:56	1.258.2.7
--- cp/lex.c	1999/05/26 04:35:32
*************** cp/lex.c		/* whether or no
*** 312,324 ****
  
  /* lexical analyzer */
  
! #ifndef WCHAR_TYPE_SIZE
! #ifdef INT_TYPE_SIZE
! #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
! #else
! #define WCHAR_TYPE_SIZE	BITS_PER_WORD
! #endif
! #endif
  
  /* Number of bytes in a wide character.  */
  #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
--- 312,319 ----
  
  /* lexical analyzer */
  
! #undef WCHAR_TYPE_SIZE
! #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
  
  /* Number of bytes in a wide character.  */
  #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/cp-tree.h,v
retrieving revision 1.381.2.5
diff -c -p -r1.381.2.5 cp-tree.h
*** cp-tree.h	1999/05/24 23:09:17	1.381.2.5
--- cp-tree.h	1999/05/25 07:30:34
*************** extern int name_mangling_version;
*** 524,529 ****
--- 524,533 ----
  /* Nonzero means that guiding declarations are allowed.  */
  extern int flag_guiding_decls;
  
+ /* Nonzero if wchar_t should be `unsigned short' instead of whatever it
+    would normally be, for use with WINE.  */
+ extern int flag_short_wchar;
+ 
  /* Nonzero if squashed mangling is to be performed. 
     This uses the B and K codes to reference previously seen class types 
     and class qualifiers.       */
Index: cp/decl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/decl.c,v
retrieving revision 1.840.2.9
diff -c -p -r1.840.2.9 decl.c
*** decl.c	1999/05/25 05:31:38	1.840.2.9
--- decl.c	1999/05/25 07:30:34
*************** init_decl_processing ()
*** 6618,6625 ****
    record_builtin_type (RID_MAX, 0, opaque_type_node);
  
    /* This is special for C++ so functions can be overloaded.  */
!   wchar_type_node
!     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
    wchar_type_size = TYPE_PRECISION (wchar_type_node);
    signed_wchar_type_node = make_signed_type (wchar_type_size);
    unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
--- 6618,6627 ----
    record_builtin_type (RID_MAX, 0, opaque_type_node);
  
    /* This is special for C++ so functions can be overloaded.  */
!   wchar_type_node = get_identifier (flag_short_wchar
! 				    ? "short unsigned int"
! 				    : WCHAR_TYPE);
!   wchar_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (wchar_type_node));
    wchar_type_size = TYPE_PRECISION (wchar_type_node);
    signed_wchar_type_node = make_signed_type (wchar_type_size);
    unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
Index: cp/decl2.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/decl2.c,v
retrieving revision 1.441.2.8
diff -c -p -r1.441.2.8 decl2.c
*** decl2.c	1999/05/24 23:09:18	1.441.2.8
--- decl2.c	1999/05/25 07:30:34
*************** int name_mangling_version = 2;
*** 441,446 ****
--- 441,450 ----
  /* Nonzero means that guiding declarations are allowed.  */
  int flag_guiding_decls;
  
+ /* Nonzero if wchar_t should be `unsigned short' instead of whatever it
+    would normally be, for use with WINE.  */
+ int flag_short_wchar;
+ 
  /* Nonzero if squashed mangling is to be performed. 
     This uses the B and K codes to reference previously seen class types 
     and class qualifiers.       */
*************** lang_f_options[] =
*** 504,509 ****
--- 508,514 ----
    {"permissive", &flag_permissive, 1},
    {"repo", &flag_use_repository, 1},
    {"rtti", &flag_rtti, 1},
+   {"short-wchar", &flag_short_wchar, 1},
    {"squangle", &flag_do_squangling, 1},
    {"stats", &flag_detailed_statistics, 1},
    {"strict-prototype", &flag_strict_prototype, 1},
Index: cp/lang-options.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cp/lang-options.h,v
retrieving revision 1.34.30.1
diff -c -p -r1.34.30.1 lang-options.h
*** lang-options.h	1999/04/16 08:44:15	1.34.30.1
--- lang-options.h	1999/05/25 07:30:34
*************** DEFINE_LANG_NAME ("C++")
*** 92,97 ****
--- 92,99 ----
    { "-fno-repo", "" },
    { "-fsave-memoized", "" },
    { "-fno-save-memoized", "" },
+   { "-fshort-wchar", "Override the underlying type for wchar_t to `unsigned short'" },
+   { "-fno-short-wchar", "" },
    { "-fsquangle", "Enable squashed name mangling" },
    { "-fno-squangle", "" },
    { "-fstats", "Display statistics accumulated during compilation" },





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