xref: /dflybsd-src/contrib/gcc-4.7/gcc/c-family/c-lex.c (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Mainly the interface between cpplib and the C front ends.
2*e4b17023SJohn Marino    Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
3*e4b17023SJohn Marino    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
4*e4b17023SJohn Marino    2011 Free Software Foundation, Inc.
5*e4b17023SJohn Marino 
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino 
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino 
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino 
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3.  If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
21*e4b17023SJohn Marino 
22*e4b17023SJohn Marino #include "config.h"
23*e4b17023SJohn Marino #include "system.h"
24*e4b17023SJohn Marino #include "coretypes.h"
25*e4b17023SJohn Marino #include "tm.h"
26*e4b17023SJohn Marino 
27*e4b17023SJohn Marino #include "tree.h"
28*e4b17023SJohn Marino #include "input.h"
29*e4b17023SJohn Marino #include "output.h"
30*e4b17023SJohn Marino #include "c-common.h"
31*e4b17023SJohn Marino #include "flags.h"
32*e4b17023SJohn Marino #include "timevar.h"
33*e4b17023SJohn Marino #include "cpplib.h"
34*e4b17023SJohn Marino #include "c-pragma.h"
35*e4b17023SJohn Marino #include "intl.h"
36*e4b17023SJohn Marino #include "splay-tree.h"
37*e4b17023SJohn Marino #include "debug.h"
38*e4b17023SJohn Marino #include "target.h"
39*e4b17023SJohn Marino 
40*e4b17023SJohn Marino /* We may keep statistics about how long which files took to compile.  */
41*e4b17023SJohn Marino static int header_time, body_time;
42*e4b17023SJohn Marino static splay_tree file_info_tree;
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino int pending_lang_change; /* If we need to switch languages - C++ only */
45*e4b17023SJohn Marino int c_header_level;	 /* depth in C headers - C++ only */
46*e4b17023SJohn Marino 
47*e4b17023SJohn Marino static tree interpret_integer (const cpp_token *, unsigned int);
48*e4b17023SJohn Marino static tree interpret_float (const cpp_token *, unsigned int, const char *);
49*e4b17023SJohn Marino static tree interpret_fixed (const cpp_token *, unsigned int);
50*e4b17023SJohn Marino static enum integer_type_kind narrowest_unsigned_type
51*e4b17023SJohn Marino 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
52*e4b17023SJohn Marino static enum integer_type_kind narrowest_signed_type
53*e4b17023SJohn Marino 	(unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned int);
54*e4b17023SJohn Marino static enum cpp_ttype lex_string (const cpp_token *, tree *, bool, bool);
55*e4b17023SJohn Marino static tree lex_charconst (const cpp_token *);
56*e4b17023SJohn Marino static void update_header_times (const char *);
57*e4b17023SJohn Marino static int dump_one_header (splay_tree_node, void *);
58*e4b17023SJohn Marino static void cb_line_change (cpp_reader *, const cpp_token *, int);
59*e4b17023SJohn Marino static void cb_ident (cpp_reader *, unsigned int, const cpp_string *);
60*e4b17023SJohn Marino static void cb_def_pragma (cpp_reader *, unsigned int);
61*e4b17023SJohn Marino static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *);
62*e4b17023SJohn Marino static void cb_undef (cpp_reader *, unsigned int, cpp_hashnode *);
63*e4b17023SJohn Marino 
64*e4b17023SJohn Marino void
init_c_lex(void)65*e4b17023SJohn Marino init_c_lex (void)
66*e4b17023SJohn Marino {
67*e4b17023SJohn Marino   struct cpp_callbacks *cb;
68*e4b17023SJohn Marino   struct c_fileinfo *toplevel;
69*e4b17023SJohn Marino 
70*e4b17023SJohn Marino   /* The get_fileinfo data structure must be initialized before
71*e4b17023SJohn Marino      cpp_read_main_file is called.  */
72*e4b17023SJohn Marino   toplevel = get_fileinfo ("<top level>");
73*e4b17023SJohn Marino   if (flag_detailed_statistics)
74*e4b17023SJohn Marino     {
75*e4b17023SJohn Marino       header_time = 0;
76*e4b17023SJohn Marino       body_time = get_run_time ();
77*e4b17023SJohn Marino       toplevel->time = body_time;
78*e4b17023SJohn Marino     }
79*e4b17023SJohn Marino 
80*e4b17023SJohn Marino   cb = cpp_get_callbacks (parse_in);
81*e4b17023SJohn Marino 
82*e4b17023SJohn Marino   cb->line_change = cb_line_change;
83*e4b17023SJohn Marino   cb->ident = cb_ident;
84*e4b17023SJohn Marino   cb->def_pragma = cb_def_pragma;
85*e4b17023SJohn Marino   cb->valid_pch = c_common_valid_pch;
86*e4b17023SJohn Marino   cb->read_pch = c_common_read_pch;
87*e4b17023SJohn Marino 
88*e4b17023SJohn Marino   /* Set the debug callbacks if we can use them.  */
89*e4b17023SJohn Marino   if ((debug_info_level == DINFO_LEVEL_VERBOSE
90*e4b17023SJohn Marino        && (write_symbols == DWARF2_DEBUG
91*e4b17023SJohn Marino 	   || write_symbols == VMS_AND_DWARF2_DEBUG))
92*e4b17023SJohn Marino       || flag_dump_go_spec != NULL)
93*e4b17023SJohn Marino     {
94*e4b17023SJohn Marino       cb->define = cb_define;
95*e4b17023SJohn Marino       cb->undef = cb_undef;
96*e4b17023SJohn Marino     }
97*e4b17023SJohn Marino }
98*e4b17023SJohn Marino 
99*e4b17023SJohn Marino struct c_fileinfo *
get_fileinfo(const char * name)100*e4b17023SJohn Marino get_fileinfo (const char *name)
101*e4b17023SJohn Marino {
102*e4b17023SJohn Marino   splay_tree_node n;
103*e4b17023SJohn Marino   struct c_fileinfo *fi;
104*e4b17023SJohn Marino 
105*e4b17023SJohn Marino   if (!file_info_tree)
106*e4b17023SJohn Marino     file_info_tree = splay_tree_new ((splay_tree_compare_fn) strcmp,
107*e4b17023SJohn Marino 				     0,
108*e4b17023SJohn Marino 				     (splay_tree_delete_value_fn) free);
109*e4b17023SJohn Marino 
110*e4b17023SJohn Marino   n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
111*e4b17023SJohn Marino   if (n)
112*e4b17023SJohn Marino     return (struct c_fileinfo *) n->value;
113*e4b17023SJohn Marino 
114*e4b17023SJohn Marino   fi = XNEW (struct c_fileinfo);
115*e4b17023SJohn Marino   fi->time = 0;
116*e4b17023SJohn Marino   fi->interface_only = 0;
117*e4b17023SJohn Marino   fi->interface_unknown = 1;
118*e4b17023SJohn Marino   splay_tree_insert (file_info_tree, (splay_tree_key) name,
119*e4b17023SJohn Marino 		     (splay_tree_value) fi);
120*e4b17023SJohn Marino   return fi;
121*e4b17023SJohn Marino }
122*e4b17023SJohn Marino 
123*e4b17023SJohn Marino static void
update_header_times(const char * name)124*e4b17023SJohn Marino update_header_times (const char *name)
125*e4b17023SJohn Marino {
126*e4b17023SJohn Marino   /* Changing files again.  This means currently collected time
127*e4b17023SJohn Marino      is charged against header time, and body time starts back at 0.  */
128*e4b17023SJohn Marino   if (flag_detailed_statistics)
129*e4b17023SJohn Marino     {
130*e4b17023SJohn Marino       int this_time = get_run_time ();
131*e4b17023SJohn Marino       struct c_fileinfo *file = get_fileinfo (name);
132*e4b17023SJohn Marino       header_time += this_time - body_time;
133*e4b17023SJohn Marino       file->time += this_time - body_time;
134*e4b17023SJohn Marino       body_time = this_time;
135*e4b17023SJohn Marino     }
136*e4b17023SJohn Marino }
137*e4b17023SJohn Marino 
138*e4b17023SJohn Marino static int
dump_one_header(splay_tree_node n,void * ARG_UNUSED (dummy))139*e4b17023SJohn Marino dump_one_header (splay_tree_node n, void * ARG_UNUSED (dummy))
140*e4b17023SJohn Marino {
141*e4b17023SJohn Marino   print_time ((const char *) n->key,
142*e4b17023SJohn Marino 	      ((struct c_fileinfo *) n->value)->time);
143*e4b17023SJohn Marino   return 0;
144*e4b17023SJohn Marino }
145*e4b17023SJohn Marino 
146*e4b17023SJohn Marino void
dump_time_statistics(void)147*e4b17023SJohn Marino dump_time_statistics (void)
148*e4b17023SJohn Marino {
149*e4b17023SJohn Marino   struct c_fileinfo *file = get_fileinfo (input_filename);
150*e4b17023SJohn Marino   int this_time = get_run_time ();
151*e4b17023SJohn Marino   file->time += this_time - body_time;
152*e4b17023SJohn Marino 
153*e4b17023SJohn Marino   fprintf (stderr, "\n******\n");
154*e4b17023SJohn Marino   print_time ("header files (total)", header_time);
155*e4b17023SJohn Marino   print_time ("main file (total)", this_time - body_time);
156*e4b17023SJohn Marino   fprintf (stderr, "ratio = %g : 1\n",
157*e4b17023SJohn Marino 	   (double) header_time / (double) (this_time - body_time));
158*e4b17023SJohn Marino   fprintf (stderr, "\n******\n");
159*e4b17023SJohn Marino 
160*e4b17023SJohn Marino   splay_tree_foreach (file_info_tree, dump_one_header, 0);
161*e4b17023SJohn Marino }
162*e4b17023SJohn Marino 
163*e4b17023SJohn Marino static void
cb_ident(cpp_reader * ARG_UNUSED (pfile),unsigned int ARG_UNUSED (line),const cpp_string * ARG_UNUSED (str))164*e4b17023SJohn Marino cb_ident (cpp_reader * ARG_UNUSED (pfile),
165*e4b17023SJohn Marino 	  unsigned int ARG_UNUSED (line),
166*e4b17023SJohn Marino 	  const cpp_string * ARG_UNUSED (str))
167*e4b17023SJohn Marino {
168*e4b17023SJohn Marino #ifdef ASM_OUTPUT_IDENT
169*e4b17023SJohn Marino   if (!flag_no_ident)
170*e4b17023SJohn Marino     {
171*e4b17023SJohn Marino       /* Convert escapes in the string.  */
172*e4b17023SJohn Marino       cpp_string cstr = { 0, 0 };
173*e4b17023SJohn Marino       if (cpp_interpret_string (pfile, str, 1, &cstr, CPP_STRING))
174*e4b17023SJohn Marino 	{
175*e4b17023SJohn Marino 	  ASM_OUTPUT_IDENT (asm_out_file, (const char *) cstr.text);
176*e4b17023SJohn Marino 	  free (CONST_CAST (unsigned char *, cstr.text));
177*e4b17023SJohn Marino 	}
178*e4b17023SJohn Marino     }
179*e4b17023SJohn Marino #endif
180*e4b17023SJohn Marino }
181*e4b17023SJohn Marino 
182*e4b17023SJohn Marino /* Called at the start of every non-empty line.  TOKEN is the first
183*e4b17023SJohn Marino    lexed token on the line.  Used for diagnostic line numbers.  */
184*e4b17023SJohn Marino static void
cb_line_change(cpp_reader * ARG_UNUSED (pfile),const cpp_token * token,int parsing_args)185*e4b17023SJohn Marino cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
186*e4b17023SJohn Marino 		int parsing_args)
187*e4b17023SJohn Marino {
188*e4b17023SJohn Marino   if (token->type != CPP_EOF && !parsing_args)
189*e4b17023SJohn Marino     input_location = token->src_loc;
190*e4b17023SJohn Marino }
191*e4b17023SJohn Marino 
192*e4b17023SJohn Marino void
fe_file_change(const struct line_map * new_map)193*e4b17023SJohn Marino fe_file_change (const struct line_map *new_map)
194*e4b17023SJohn Marino {
195*e4b17023SJohn Marino   if (new_map == NULL)
196*e4b17023SJohn Marino     return;
197*e4b17023SJohn Marino 
198*e4b17023SJohn Marino   if (new_map->reason == LC_ENTER)
199*e4b17023SJohn Marino     {
200*e4b17023SJohn Marino       /* Don't stack the main buffer on the input stack;
201*e4b17023SJohn Marino 	 we already did in compile_file.  */
202*e4b17023SJohn Marino       if (!MAIN_FILE_P (new_map))
203*e4b17023SJohn Marino 	{
204*e4b17023SJohn Marino 	  unsigned int included_at = LAST_SOURCE_LINE_LOCATION (new_map - 1);
205*e4b17023SJohn Marino 	  int line = 0;
206*e4b17023SJohn Marino 	  if (included_at > BUILTINS_LOCATION)
207*e4b17023SJohn Marino 	    line = SOURCE_LINE (new_map - 1, included_at);
208*e4b17023SJohn Marino 
209*e4b17023SJohn Marino 	  input_location = new_map->start_location;
210*e4b17023SJohn Marino 	  (*debug_hooks->start_source_file) (line, LINEMAP_FILE (new_map));
211*e4b17023SJohn Marino #ifndef NO_IMPLICIT_EXTERN_C
212*e4b17023SJohn Marino 	  if (c_header_level)
213*e4b17023SJohn Marino 	    ++c_header_level;
214*e4b17023SJohn Marino 	  else if (LINEMAP_SYSP (new_map) == 2)
215*e4b17023SJohn Marino 	    {
216*e4b17023SJohn Marino 	      c_header_level = 1;
217*e4b17023SJohn Marino 	      ++pending_lang_change;
218*e4b17023SJohn Marino 	    }
219*e4b17023SJohn Marino #endif
220*e4b17023SJohn Marino 	}
221*e4b17023SJohn Marino     }
222*e4b17023SJohn Marino   else if (new_map->reason == LC_LEAVE)
223*e4b17023SJohn Marino     {
224*e4b17023SJohn Marino #ifndef NO_IMPLICIT_EXTERN_C
225*e4b17023SJohn Marino       if (c_header_level && --c_header_level == 0)
226*e4b17023SJohn Marino 	{
227*e4b17023SJohn Marino 	  if (LINEMAP_SYSP (new_map) == 2)
228*e4b17023SJohn Marino 	    warning (0, "badly nested C headers from preprocessor");
229*e4b17023SJohn Marino 	  --pending_lang_change;
230*e4b17023SJohn Marino 	}
231*e4b17023SJohn Marino #endif
232*e4b17023SJohn Marino       input_location = new_map->start_location;
233*e4b17023SJohn Marino 
234*e4b17023SJohn Marino       (*debug_hooks->end_source_file) (LINEMAP_LINE (new_map));
235*e4b17023SJohn Marino     }
236*e4b17023SJohn Marino 
237*e4b17023SJohn Marino   update_header_times (LINEMAP_FILE (new_map));
238*e4b17023SJohn Marino   input_location = new_map->start_location;
239*e4b17023SJohn Marino }
240*e4b17023SJohn Marino 
241*e4b17023SJohn Marino static void
cb_def_pragma(cpp_reader * pfile,source_location loc)242*e4b17023SJohn Marino cb_def_pragma (cpp_reader *pfile, source_location loc)
243*e4b17023SJohn Marino {
244*e4b17023SJohn Marino   /* Issue a warning message if we have been asked to do so.  Ignore
245*e4b17023SJohn Marino      unknown pragmas in system headers unless an explicit
246*e4b17023SJohn Marino      -Wunknown-pragmas has been given.  */
247*e4b17023SJohn Marino   if (warn_unknown_pragmas > in_system_header)
248*e4b17023SJohn Marino     {
249*e4b17023SJohn Marino       const unsigned char *space, *name;
250*e4b17023SJohn Marino       const cpp_token *s;
251*e4b17023SJohn Marino       location_t fe_loc = loc;
252*e4b17023SJohn Marino 
253*e4b17023SJohn Marino       space = name = (const unsigned char *) "";
254*e4b17023SJohn Marino       s = cpp_get_token (pfile);
255*e4b17023SJohn Marino       if (s->type != CPP_EOF)
256*e4b17023SJohn Marino 	{
257*e4b17023SJohn Marino 	  space = cpp_token_as_text (pfile, s);
258*e4b17023SJohn Marino 	  s = cpp_get_token (pfile);
259*e4b17023SJohn Marino 	  if (s->type == CPP_NAME)
260*e4b17023SJohn Marino 	    name = cpp_token_as_text (pfile, s);
261*e4b17023SJohn Marino 	}
262*e4b17023SJohn Marino 
263*e4b17023SJohn Marino       warning_at (fe_loc, OPT_Wunknown_pragmas, "ignoring #pragma %s %s",
264*e4b17023SJohn Marino 		  space, name);
265*e4b17023SJohn Marino     }
266*e4b17023SJohn Marino }
267*e4b17023SJohn Marino 
268*e4b17023SJohn Marino /* #define callback for DWARF and DWARF2 debug info.  */
269*e4b17023SJohn Marino static void
cb_define(cpp_reader * pfile,source_location loc,cpp_hashnode * node)270*e4b17023SJohn Marino cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node)
271*e4b17023SJohn Marino {
272*e4b17023SJohn Marino   const struct line_map *map = linemap_lookup (line_table, loc);
273*e4b17023SJohn Marino   (*debug_hooks->define) (SOURCE_LINE (map, loc),
274*e4b17023SJohn Marino 			  (const char *) cpp_macro_definition (pfile, node));
275*e4b17023SJohn Marino }
276*e4b17023SJohn Marino 
277*e4b17023SJohn Marino /* #undef callback for DWARF and DWARF2 debug info.  */
278*e4b17023SJohn Marino static void
cb_undef(cpp_reader * ARG_UNUSED (pfile),source_location loc,cpp_hashnode * node)279*e4b17023SJohn Marino cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
280*e4b17023SJohn Marino 	  cpp_hashnode *node)
281*e4b17023SJohn Marino {
282*e4b17023SJohn Marino   const struct line_map *map = linemap_lookup (line_table, loc);
283*e4b17023SJohn Marino   (*debug_hooks->undef) (SOURCE_LINE (map, loc),
284*e4b17023SJohn Marino 			 (const char *) NODE_NAME (node));
285*e4b17023SJohn Marino }
286*e4b17023SJohn Marino 
287*e4b17023SJohn Marino /* Read a token and return its type.  Fill *VALUE with its value, if
288*e4b17023SJohn Marino    applicable.  Fill *CPP_FLAGS with the token's flags, if it is
289*e4b17023SJohn Marino    non-NULL.  */
290*e4b17023SJohn Marino 
291*e4b17023SJohn Marino enum cpp_ttype
c_lex_with_flags(tree * value,location_t * loc,unsigned char * cpp_flags,int lex_flags)292*e4b17023SJohn Marino c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
293*e4b17023SJohn Marino 		  int lex_flags)
294*e4b17023SJohn Marino {
295*e4b17023SJohn Marino   static bool no_more_pch;
296*e4b17023SJohn Marino   const cpp_token *tok;
297*e4b17023SJohn Marino   enum cpp_ttype type;
298*e4b17023SJohn Marino   unsigned char add_flags = 0;
299*e4b17023SJohn Marino 
300*e4b17023SJohn Marino   timevar_push (TV_CPP);
301*e4b17023SJohn Marino  retry:
302*e4b17023SJohn Marino   tok = cpp_get_token_with_location (parse_in, loc);
303*e4b17023SJohn Marino   type = tok->type;
304*e4b17023SJohn Marino 
305*e4b17023SJohn Marino  retry_after_at:
306*e4b17023SJohn Marino   switch (type)
307*e4b17023SJohn Marino     {
308*e4b17023SJohn Marino     case CPP_PADDING:
309*e4b17023SJohn Marino       goto retry;
310*e4b17023SJohn Marino 
311*e4b17023SJohn Marino     case CPP_NAME:
312*e4b17023SJohn Marino       *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
313*e4b17023SJohn Marino       break;
314*e4b17023SJohn Marino 
315*e4b17023SJohn Marino     case CPP_NUMBER:
316*e4b17023SJohn Marino       {
317*e4b17023SJohn Marino 	const char *suffix = NULL;
318*e4b17023SJohn Marino 	unsigned int flags = cpp_classify_number (parse_in, tok, &suffix);
319*e4b17023SJohn Marino 
320*e4b17023SJohn Marino 	switch (flags & CPP_N_CATEGORY)
321*e4b17023SJohn Marino 	  {
322*e4b17023SJohn Marino 	  case CPP_N_INVALID:
323*e4b17023SJohn Marino 	    /* cpplib has issued an error.  */
324*e4b17023SJohn Marino 	    *value = error_mark_node;
325*e4b17023SJohn Marino 	    break;
326*e4b17023SJohn Marino 
327*e4b17023SJohn Marino 	  case CPP_N_INTEGER:
328*e4b17023SJohn Marino 	    /* C++ uses '0' to mark virtual functions as pure.
329*e4b17023SJohn Marino 	       Set PURE_ZERO to pass this information to the C++ parser.  */
330*e4b17023SJohn Marino 	    if (tok->val.str.len == 1 && *tok->val.str.text == '0')
331*e4b17023SJohn Marino 	      add_flags = PURE_ZERO;
332*e4b17023SJohn Marino 	    *value = interpret_integer (tok, flags);
333*e4b17023SJohn Marino 	    break;
334*e4b17023SJohn Marino 
335*e4b17023SJohn Marino 	  case CPP_N_FLOATING:
336*e4b17023SJohn Marino 	    *value = interpret_float (tok, flags, suffix);
337*e4b17023SJohn Marino 	    break;
338*e4b17023SJohn Marino 
339*e4b17023SJohn Marino 	  default:
340*e4b17023SJohn Marino 	    gcc_unreachable ();
341*e4b17023SJohn Marino 	  }
342*e4b17023SJohn Marino 
343*e4b17023SJohn Marino 	if (flags & CPP_N_USERDEF)
344*e4b17023SJohn Marino 	  {
345*e4b17023SJohn Marino 	    char *str;
346*e4b17023SJohn Marino 	    tree literal;
347*e4b17023SJohn Marino 	    tree suffix_id = get_identifier (suffix);
348*e4b17023SJohn Marino 	    int len = tok->val.str.len - strlen (suffix);
349*e4b17023SJohn Marino 	    /* If this is going to be used as a C string to pass to a
350*e4b17023SJohn Marino 	       raw literal operator, we need to add a trailing NUL.  */
351*e4b17023SJohn Marino 	    tree num_string = build_string (len + 1,
352*e4b17023SJohn Marino 					    (const char *) tok->val.str.text);
353*e4b17023SJohn Marino 	    TREE_TYPE (num_string) = char_array_type_node;
354*e4b17023SJohn Marino 	    num_string = fix_string_type (num_string);
355*e4b17023SJohn Marino 	    str = CONST_CAST (char *, TREE_STRING_POINTER (num_string));
356*e4b17023SJohn Marino 	    str[len] = '\0';
357*e4b17023SJohn Marino 	    literal = build_userdef_literal (suffix_id, *value,
358*e4b17023SJohn Marino 						  num_string);
359*e4b17023SJohn Marino 	    *value = literal;
360*e4b17023SJohn Marino 	  }
361*e4b17023SJohn Marino       }
362*e4b17023SJohn Marino       break;
363*e4b17023SJohn Marino 
364*e4b17023SJohn Marino     case CPP_ATSIGN:
365*e4b17023SJohn Marino       /* An @ may give the next token special significance in Objective-C.  */
366*e4b17023SJohn Marino       if (c_dialect_objc ())
367*e4b17023SJohn Marino 	{
368*e4b17023SJohn Marino 	  location_t atloc = *loc;
369*e4b17023SJohn Marino 	  location_t newloc;
370*e4b17023SJohn Marino 
371*e4b17023SJohn Marino 	retry_at:
372*e4b17023SJohn Marino 	  tok = cpp_get_token_with_location (parse_in, &newloc);
373*e4b17023SJohn Marino 	  type = tok->type;
374*e4b17023SJohn Marino 	  switch (type)
375*e4b17023SJohn Marino 	    {
376*e4b17023SJohn Marino 	    case CPP_PADDING:
377*e4b17023SJohn Marino 	      goto retry_at;
378*e4b17023SJohn Marino 
379*e4b17023SJohn Marino 	    case CPP_STRING:
380*e4b17023SJohn Marino 	    case CPP_WSTRING:
381*e4b17023SJohn Marino 	    case CPP_STRING16:
382*e4b17023SJohn Marino 	    case CPP_STRING32:
383*e4b17023SJohn Marino 	    case CPP_UTF8STRING:
384*e4b17023SJohn Marino 	      type = lex_string (tok, value, true, true);
385*e4b17023SJohn Marino 	      break;
386*e4b17023SJohn Marino 
387*e4b17023SJohn Marino 	    case CPP_NAME:
388*e4b17023SJohn Marino 	      *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node.node));
389*e4b17023SJohn Marino 	      if (OBJC_IS_AT_KEYWORD (C_RID_CODE (*value))
390*e4b17023SJohn Marino 		  || OBJC_IS_CXX_KEYWORD (C_RID_CODE (*value)))
391*e4b17023SJohn Marino 		{
392*e4b17023SJohn Marino 		  type = CPP_AT_NAME;
393*e4b17023SJohn Marino 		  /* Note the complication: if we found an OBJC_CXX
394*e4b17023SJohn Marino 		     keyword, for example, 'class', we will be
395*e4b17023SJohn Marino 		     returning a token of type CPP_AT_NAME and rid
396*e4b17023SJohn Marino 		     code RID_CLASS (not RID_AT_CLASS).  The language
397*e4b17023SJohn Marino 		     parser needs to convert that to RID_AT_CLASS.
398*e4b17023SJohn Marino 		  */
399*e4b17023SJohn Marino 		  break;
400*e4b17023SJohn Marino 		}
401*e4b17023SJohn Marino 	      /* FALLTHROUGH */
402*e4b17023SJohn Marino 
403*e4b17023SJohn Marino 	    default:
404*e4b17023SJohn Marino 	      /* ... or not.  */
405*e4b17023SJohn Marino 	      error_at (atloc, "stray %<@%> in program");
406*e4b17023SJohn Marino 	      *loc = newloc;
407*e4b17023SJohn Marino 	      goto retry_after_at;
408*e4b17023SJohn Marino 	    }
409*e4b17023SJohn Marino 	  break;
410*e4b17023SJohn Marino 	}
411*e4b17023SJohn Marino 
412*e4b17023SJohn Marino       /* FALLTHROUGH */
413*e4b17023SJohn Marino     case CPP_HASH:
414*e4b17023SJohn Marino     case CPP_PASTE:
415*e4b17023SJohn Marino       {
416*e4b17023SJohn Marino 	unsigned char name[8];
417*e4b17023SJohn Marino 
418*e4b17023SJohn Marino 	*cpp_spell_token (parse_in, tok, name, true) = 0;
419*e4b17023SJohn Marino 
420*e4b17023SJohn Marino 	error ("stray %qs in program", name);
421*e4b17023SJohn Marino       }
422*e4b17023SJohn Marino 
423*e4b17023SJohn Marino       goto retry;
424*e4b17023SJohn Marino 
425*e4b17023SJohn Marino     case CPP_OTHER:
426*e4b17023SJohn Marino       {
427*e4b17023SJohn Marino 	cppchar_t c = tok->val.str.text[0];
428*e4b17023SJohn Marino 
429*e4b17023SJohn Marino 	if (c == '"' || c == '\'')
430*e4b17023SJohn Marino 	  error ("missing terminating %c character", (int) c);
431*e4b17023SJohn Marino 	else if (ISGRAPH (c))
432*e4b17023SJohn Marino 	  error ("stray %qc in program", (int) c);
433*e4b17023SJohn Marino 	else
434*e4b17023SJohn Marino 	  error ("stray %<\\%o%> in program", (int) c);
435*e4b17023SJohn Marino       }
436*e4b17023SJohn Marino       goto retry;
437*e4b17023SJohn Marino 
438*e4b17023SJohn Marino     case CPP_CHAR_USERDEF:
439*e4b17023SJohn Marino     case CPP_WCHAR_USERDEF:
440*e4b17023SJohn Marino     case CPP_CHAR16_USERDEF:
441*e4b17023SJohn Marino     case CPP_CHAR32_USERDEF:
442*e4b17023SJohn Marino       {
443*e4b17023SJohn Marino 	tree literal;
444*e4b17023SJohn Marino 	cpp_token temp_tok = *tok;
445*e4b17023SJohn Marino 	const char *suffix = cpp_get_userdef_suffix (tok);
446*e4b17023SJohn Marino 	temp_tok.val.str.len -= strlen (suffix);
447*e4b17023SJohn Marino 	temp_tok.type = cpp_userdef_char_remove_type (type);
448*e4b17023SJohn Marino 	literal = build_userdef_literal (get_identifier (suffix),
449*e4b17023SJohn Marino 					 lex_charconst (&temp_tok), NULL_TREE);
450*e4b17023SJohn Marino 	*value = literal;
451*e4b17023SJohn Marino       }
452*e4b17023SJohn Marino       break;
453*e4b17023SJohn Marino 
454*e4b17023SJohn Marino     case CPP_CHAR:
455*e4b17023SJohn Marino     case CPP_WCHAR:
456*e4b17023SJohn Marino     case CPP_CHAR16:
457*e4b17023SJohn Marino     case CPP_CHAR32:
458*e4b17023SJohn Marino       *value = lex_charconst (tok);
459*e4b17023SJohn Marino       break;
460*e4b17023SJohn Marino 
461*e4b17023SJohn Marino     case CPP_STRING_USERDEF:
462*e4b17023SJohn Marino     case CPP_WSTRING_USERDEF:
463*e4b17023SJohn Marino     case CPP_STRING16_USERDEF:
464*e4b17023SJohn Marino     case CPP_STRING32_USERDEF:
465*e4b17023SJohn Marino     case CPP_UTF8STRING_USERDEF:
466*e4b17023SJohn Marino       {
467*e4b17023SJohn Marino 	tree literal, string;
468*e4b17023SJohn Marino 	const char *suffix = cpp_get_userdef_suffix (tok);
469*e4b17023SJohn Marino 	string = build_string (tok->val.str.len - strlen (suffix),
470*e4b17023SJohn Marino 			       (const char *) tok->val.str.text);
471*e4b17023SJohn Marino 	literal = build_userdef_literal (get_identifier (suffix),
472*e4b17023SJohn Marino 					 string, NULL_TREE);
473*e4b17023SJohn Marino 	*value = literal;
474*e4b17023SJohn Marino       }
475*e4b17023SJohn Marino       break;
476*e4b17023SJohn Marino 
477*e4b17023SJohn Marino     case CPP_STRING:
478*e4b17023SJohn Marino     case CPP_WSTRING:
479*e4b17023SJohn Marino     case CPP_STRING16:
480*e4b17023SJohn Marino     case CPP_STRING32:
481*e4b17023SJohn Marino     case CPP_UTF8STRING:
482*e4b17023SJohn Marino       if ((lex_flags & C_LEX_STRING_NO_JOIN) == 0)
483*e4b17023SJohn Marino 	{
484*e4b17023SJohn Marino 	  type = lex_string (tok, value, false,
485*e4b17023SJohn Marino 			     (lex_flags & C_LEX_STRING_NO_TRANSLATE) == 0);
486*e4b17023SJohn Marino 	  break;
487*e4b17023SJohn Marino 	}
488*e4b17023SJohn Marino       *value = build_string (tok->val.str.len, (const char *) tok->val.str.text);
489*e4b17023SJohn Marino       break;
490*e4b17023SJohn Marino 
491*e4b17023SJohn Marino     case CPP_PRAGMA:
492*e4b17023SJohn Marino       *value = build_int_cst (integer_type_node, tok->val.pragma);
493*e4b17023SJohn Marino       break;
494*e4b17023SJohn Marino 
495*e4b17023SJohn Marino       /* These tokens should not be visible outside cpplib.  */
496*e4b17023SJohn Marino     case CPP_HEADER_NAME:
497*e4b17023SJohn Marino     case CPP_MACRO_ARG:
498*e4b17023SJohn Marino       gcc_unreachable ();
499*e4b17023SJohn Marino 
500*e4b17023SJohn Marino     /* CPP_COMMENT will appear when compiling with -C and should be
501*e4b17023SJohn Marino        ignored.  */
502*e4b17023SJohn Marino      case CPP_COMMENT:
503*e4b17023SJohn Marino        goto retry;
504*e4b17023SJohn Marino 
505*e4b17023SJohn Marino     default:
506*e4b17023SJohn Marino       *value = NULL_TREE;
507*e4b17023SJohn Marino       break;
508*e4b17023SJohn Marino     }
509*e4b17023SJohn Marino 
510*e4b17023SJohn Marino   if (cpp_flags)
511*e4b17023SJohn Marino     *cpp_flags = tok->flags | add_flags;
512*e4b17023SJohn Marino 
513*e4b17023SJohn Marino   if (!no_more_pch)
514*e4b17023SJohn Marino     {
515*e4b17023SJohn Marino       no_more_pch = true;
516*e4b17023SJohn Marino       c_common_no_more_pch ();
517*e4b17023SJohn Marino     }
518*e4b17023SJohn Marino 
519*e4b17023SJohn Marino   timevar_pop (TV_CPP);
520*e4b17023SJohn Marino 
521*e4b17023SJohn Marino   return type;
522*e4b17023SJohn Marino }
523*e4b17023SJohn Marino 
524*e4b17023SJohn Marino /* Returns the narrowest C-visible unsigned type, starting with the
525*e4b17023SJohn Marino    minimum specified by FLAGS, that can fit HIGH:LOW, or itk_none if
526*e4b17023SJohn Marino    there isn't one.  */
527*e4b17023SJohn Marino 
528*e4b17023SJohn Marino static enum integer_type_kind
narrowest_unsigned_type(unsigned HOST_WIDE_INT low,unsigned HOST_WIDE_INT high,unsigned int flags)529*e4b17023SJohn Marino narrowest_unsigned_type (unsigned HOST_WIDE_INT low,
530*e4b17023SJohn Marino 			 unsigned HOST_WIDE_INT high,
531*e4b17023SJohn Marino 			 unsigned int flags)
532*e4b17023SJohn Marino {
533*e4b17023SJohn Marino   int itk;
534*e4b17023SJohn Marino 
535*e4b17023SJohn Marino   if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
536*e4b17023SJohn Marino     itk = itk_unsigned_int;
537*e4b17023SJohn Marino   else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
538*e4b17023SJohn Marino     itk = itk_unsigned_long;
539*e4b17023SJohn Marino   else
540*e4b17023SJohn Marino     itk = itk_unsigned_long_long;
541*e4b17023SJohn Marino 
542*e4b17023SJohn Marino   for (; itk < itk_none; itk += 2 /* skip unsigned types */)
543*e4b17023SJohn Marino     {
544*e4b17023SJohn Marino       tree upper;
545*e4b17023SJohn Marino 
546*e4b17023SJohn Marino       if (integer_types[itk] == NULL_TREE)
547*e4b17023SJohn Marino 	continue;
548*e4b17023SJohn Marino       upper = TYPE_MAX_VALUE (integer_types[itk]);
549*e4b17023SJohn Marino 
550*e4b17023SJohn Marino       if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) > high
551*e4b17023SJohn Marino 	  || ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) == high
552*e4b17023SJohn Marino 	      && TREE_INT_CST_LOW (upper) >= low))
553*e4b17023SJohn Marino 	return (enum integer_type_kind) itk;
554*e4b17023SJohn Marino     }
555*e4b17023SJohn Marino 
556*e4b17023SJohn Marino   return itk_none;
557*e4b17023SJohn Marino }
558*e4b17023SJohn Marino 
559*e4b17023SJohn Marino /* Ditto, but narrowest signed type.  */
560*e4b17023SJohn Marino static enum integer_type_kind
narrowest_signed_type(unsigned HOST_WIDE_INT low,unsigned HOST_WIDE_INT high,unsigned int flags)561*e4b17023SJohn Marino narrowest_signed_type (unsigned HOST_WIDE_INT low,
562*e4b17023SJohn Marino 		       unsigned HOST_WIDE_INT high, unsigned int flags)
563*e4b17023SJohn Marino {
564*e4b17023SJohn Marino   int itk;
565*e4b17023SJohn Marino 
566*e4b17023SJohn Marino   if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
567*e4b17023SJohn Marino     itk = itk_int;
568*e4b17023SJohn Marino   else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
569*e4b17023SJohn Marino     itk = itk_long;
570*e4b17023SJohn Marino   else
571*e4b17023SJohn Marino     itk = itk_long_long;
572*e4b17023SJohn Marino 
573*e4b17023SJohn Marino 
574*e4b17023SJohn Marino   for (; itk < itk_none; itk += 2 /* skip signed types */)
575*e4b17023SJohn Marino     {
576*e4b17023SJohn Marino       tree upper;
577*e4b17023SJohn Marino 
578*e4b17023SJohn Marino       if (integer_types[itk] == NULL_TREE)
579*e4b17023SJohn Marino 	continue;
580*e4b17023SJohn Marino       upper = TYPE_MAX_VALUE (integer_types[itk]);
581*e4b17023SJohn Marino 
582*e4b17023SJohn Marino       if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) > high
583*e4b17023SJohn Marino 	  || ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (upper) == high
584*e4b17023SJohn Marino 	      && TREE_INT_CST_LOW (upper) >= low))
585*e4b17023SJohn Marino 	return (enum integer_type_kind) itk;
586*e4b17023SJohn Marino     }
587*e4b17023SJohn Marino 
588*e4b17023SJohn Marino   return itk_none;
589*e4b17023SJohn Marino }
590*e4b17023SJohn Marino 
591*e4b17023SJohn Marino /* Interpret TOKEN, an integer with FLAGS as classified by cpplib.  */
592*e4b17023SJohn Marino static tree
interpret_integer(const cpp_token * token,unsigned int flags)593*e4b17023SJohn Marino interpret_integer (const cpp_token *token, unsigned int flags)
594*e4b17023SJohn Marino {
595*e4b17023SJohn Marino   tree value, type;
596*e4b17023SJohn Marino   enum integer_type_kind itk;
597*e4b17023SJohn Marino   cpp_num integer;
598*e4b17023SJohn Marino   cpp_options *options = cpp_get_options (parse_in);
599*e4b17023SJohn Marino 
600*e4b17023SJohn Marino   integer = cpp_interpret_integer (parse_in, token, flags);
601*e4b17023SJohn Marino   integer = cpp_num_sign_extend (integer, options->precision);
602*e4b17023SJohn Marino 
603*e4b17023SJohn Marino   /* The type of a constant with a U suffix is straightforward.  */
604*e4b17023SJohn Marino   if (flags & CPP_N_UNSIGNED)
605*e4b17023SJohn Marino     itk = narrowest_unsigned_type (integer.low, integer.high, flags);
606*e4b17023SJohn Marino   else
607*e4b17023SJohn Marino     {
608*e4b17023SJohn Marino       /* The type of a potentially-signed integer constant varies
609*e4b17023SJohn Marino 	 depending on the base it's in, the standard in use, and the
610*e4b17023SJohn Marino 	 length suffixes.  */
611*e4b17023SJohn Marino       enum integer_type_kind itk_u
612*e4b17023SJohn Marino 	= narrowest_unsigned_type (integer.low, integer.high, flags);
613*e4b17023SJohn Marino       enum integer_type_kind itk_s
614*e4b17023SJohn Marino 	= narrowest_signed_type (integer.low, integer.high, flags);
615*e4b17023SJohn Marino 
616*e4b17023SJohn Marino       /* In both C89 and C99, octal and hex constants may be signed or
617*e4b17023SJohn Marino 	 unsigned, whichever fits tighter.  We do not warn about this
618*e4b17023SJohn Marino 	 choice differing from the traditional choice, as the constant
619*e4b17023SJohn Marino 	 is probably a bit pattern and either way will work.  */
620*e4b17023SJohn Marino       if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
621*e4b17023SJohn Marino 	itk = MIN (itk_u, itk_s);
622*e4b17023SJohn Marino       else
623*e4b17023SJohn Marino 	{
624*e4b17023SJohn Marino 	  /* In C99, decimal constants are always signed.
625*e4b17023SJohn Marino 	     In C89, decimal constants that don't fit in long have
626*e4b17023SJohn Marino 	     undefined behavior; we try to make them unsigned long.
627*e4b17023SJohn Marino 	     In GCC's extended C89, that last is true of decimal
628*e4b17023SJohn Marino 	     constants that don't fit in long long, too.  */
629*e4b17023SJohn Marino 
630*e4b17023SJohn Marino 	  itk = itk_s;
631*e4b17023SJohn Marino 	  if (itk_s > itk_u && itk_s > itk_long)
632*e4b17023SJohn Marino 	    {
633*e4b17023SJohn Marino 	      if (!flag_isoc99)
634*e4b17023SJohn Marino 		{
635*e4b17023SJohn Marino 		  if (itk_u < itk_unsigned_long)
636*e4b17023SJohn Marino 		    itk_u = itk_unsigned_long;
637*e4b17023SJohn Marino 		  itk = itk_u;
638*e4b17023SJohn Marino 		  warning (0, "this decimal constant is unsigned only in ISO C90");
639*e4b17023SJohn Marino 		}
640*e4b17023SJohn Marino 	      else
641*e4b17023SJohn Marino 		warning (OPT_Wtraditional,
642*e4b17023SJohn Marino 			 "this decimal constant would be unsigned in ISO C90");
643*e4b17023SJohn Marino 	    }
644*e4b17023SJohn Marino 	}
645*e4b17023SJohn Marino     }
646*e4b17023SJohn Marino 
647*e4b17023SJohn Marino   if (itk == itk_none)
648*e4b17023SJohn Marino     /* cpplib has already issued a warning for overflow.  */
649*e4b17023SJohn Marino     type = ((flags & CPP_N_UNSIGNED)
650*e4b17023SJohn Marino 	    ? widest_unsigned_literal_type_node
651*e4b17023SJohn Marino 	    : widest_integer_literal_type_node);
652*e4b17023SJohn Marino   else
653*e4b17023SJohn Marino     {
654*e4b17023SJohn Marino       type = integer_types[itk];
655*e4b17023SJohn Marino       if (itk > itk_unsigned_long
656*e4b17023SJohn Marino 	  && (flags & CPP_N_WIDTH) != CPP_N_LARGE)
657*e4b17023SJohn Marino 	emit_diagnostic
658*e4b17023SJohn Marino 	  ((c_dialect_cxx () ? cxx_dialect == cxx98 : !flag_isoc99)
659*e4b17023SJohn Marino 	   ? DK_PEDWARN : DK_WARNING,
660*e4b17023SJohn Marino 	   input_location, OPT_Wlong_long,
661*e4b17023SJohn Marino 	   (flags & CPP_N_UNSIGNED)
662*e4b17023SJohn Marino 	   ? "integer constant is too large for %<unsigned long%> type"
663*e4b17023SJohn Marino 	   : "integer constant is too large for %<long%> type");
664*e4b17023SJohn Marino     }
665*e4b17023SJohn Marino 
666*e4b17023SJohn Marino   value = build_int_cst_wide (type, integer.low, integer.high);
667*e4b17023SJohn Marino 
668*e4b17023SJohn Marino   /* Convert imaginary to a complex type.  */
669*e4b17023SJohn Marino   if (flags & CPP_N_IMAGINARY)
670*e4b17023SJohn Marino     value = build_complex (NULL_TREE, build_int_cst (type, 0), value);
671*e4b17023SJohn Marino 
672*e4b17023SJohn Marino   return value;
673*e4b17023SJohn Marino }
674*e4b17023SJohn Marino 
675*e4b17023SJohn Marino /* Interpret TOKEN, a floating point number with FLAGS as classified
676*e4b17023SJohn Marino    by cpplib.  For C++0X SUFFIX may contain a user-defined literal suffix.  */
677*e4b17023SJohn Marino static tree
interpret_float(const cpp_token * token,unsigned int flags,const char * suffix)678*e4b17023SJohn Marino interpret_float (const cpp_token *token, unsigned int flags,
679*e4b17023SJohn Marino 		 const char *suffix)
680*e4b17023SJohn Marino {
681*e4b17023SJohn Marino   tree type;
682*e4b17023SJohn Marino   tree const_type;
683*e4b17023SJohn Marino   tree value;
684*e4b17023SJohn Marino   REAL_VALUE_TYPE real;
685*e4b17023SJohn Marino   REAL_VALUE_TYPE real_trunc;
686*e4b17023SJohn Marino   char *copy;
687*e4b17023SJohn Marino   size_t copylen;
688*e4b17023SJohn Marino 
689*e4b17023SJohn Marino   /* Default (no suffix) depends on whether the FLOAT_CONST_DECIMAL64
690*e4b17023SJohn Marino      pragma has been used and is either double or _Decimal64.  Types
691*e4b17023SJohn Marino      that are not allowed with decimal float default to double.  */
692*e4b17023SJohn Marino   if (flags & CPP_N_DEFAULT)
693*e4b17023SJohn Marino     {
694*e4b17023SJohn Marino       flags ^= CPP_N_DEFAULT;
695*e4b17023SJohn Marino       flags |= CPP_N_MEDIUM;
696*e4b17023SJohn Marino 
697*e4b17023SJohn Marino       if (((flags & CPP_N_HEX) == 0) && ((flags & CPP_N_IMAGINARY) == 0))
698*e4b17023SJohn Marino 	{
699*e4b17023SJohn Marino 	  warning (OPT_Wunsuffixed_float_constants,
700*e4b17023SJohn Marino 		   "unsuffixed float constant");
701*e4b17023SJohn Marino 	  if (float_const_decimal64_p ())
702*e4b17023SJohn Marino 	    flags |= CPP_N_DFLOAT;
703*e4b17023SJohn Marino 	}
704*e4b17023SJohn Marino     }
705*e4b17023SJohn Marino 
706*e4b17023SJohn Marino   /* Decode _Fract and _Accum.  */
707*e4b17023SJohn Marino   if (flags & CPP_N_FRACT || flags & CPP_N_ACCUM)
708*e4b17023SJohn Marino     return interpret_fixed (token, flags);
709*e4b17023SJohn Marino 
710*e4b17023SJohn Marino   /* Decode type based on width and properties. */
711*e4b17023SJohn Marino   if (flags & CPP_N_DFLOAT)
712*e4b17023SJohn Marino     if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
713*e4b17023SJohn Marino       type = dfloat128_type_node;
714*e4b17023SJohn Marino     else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
715*e4b17023SJohn Marino       type = dfloat32_type_node;
716*e4b17023SJohn Marino     else
717*e4b17023SJohn Marino       type = dfloat64_type_node;
718*e4b17023SJohn Marino   else
719*e4b17023SJohn Marino     if (flags & CPP_N_WIDTH_MD)
720*e4b17023SJohn Marino       {
721*e4b17023SJohn Marino 	char suffix;
722*e4b17023SJohn Marino 	enum machine_mode mode;
723*e4b17023SJohn Marino 
724*e4b17023SJohn Marino 	if ((flags & CPP_N_WIDTH_MD) == CPP_N_MD_W)
725*e4b17023SJohn Marino 	  suffix = 'w';
726*e4b17023SJohn Marino 	else
727*e4b17023SJohn Marino 	  suffix = 'q';
728*e4b17023SJohn Marino 
729*e4b17023SJohn Marino 	mode = targetm.c.mode_for_suffix (suffix);
730*e4b17023SJohn Marino 	if (mode == VOIDmode)
731*e4b17023SJohn Marino 	  {
732*e4b17023SJohn Marino 	    error ("unsupported non-standard suffix on floating constant");
733*e4b17023SJohn Marino 
734*e4b17023SJohn Marino 	    return error_mark_node;
735*e4b17023SJohn Marino 	  }
736*e4b17023SJohn Marino 	else
737*e4b17023SJohn Marino 	  pedwarn (input_location, OPT_pedantic, "non-standard suffix on floating constant");
738*e4b17023SJohn Marino 
739*e4b17023SJohn Marino 	type = c_common_type_for_mode (mode, 0);
740*e4b17023SJohn Marino 	gcc_assert (type);
741*e4b17023SJohn Marino       }
742*e4b17023SJohn Marino     else if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
743*e4b17023SJohn Marino       type = long_double_type_node;
744*e4b17023SJohn Marino     else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
745*e4b17023SJohn Marino 	     || flag_single_precision_constant)
746*e4b17023SJohn Marino       type = float_type_node;
747*e4b17023SJohn Marino     else
748*e4b17023SJohn Marino       type = double_type_node;
749*e4b17023SJohn Marino 
750*e4b17023SJohn Marino   const_type = excess_precision_type (type);
751*e4b17023SJohn Marino   if (!const_type)
752*e4b17023SJohn Marino     const_type = type;
753*e4b17023SJohn Marino 
754*e4b17023SJohn Marino   /* Copy the constant to a nul-terminated buffer.  If the constant
755*e4b17023SJohn Marino      has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
756*e4b17023SJohn Marino      can't handle them.  */
757*e4b17023SJohn Marino   copylen = token->val.str.len;
758*e4b17023SJohn Marino   if (flags & CPP_N_USERDEF)
759*e4b17023SJohn Marino     copylen -= strlen (suffix);
760*e4b17023SJohn Marino   else if (flags & CPP_N_DFLOAT)
761*e4b17023SJohn Marino     copylen -= 2;
762*e4b17023SJohn Marino   else
763*e4b17023SJohn Marino     {
764*e4b17023SJohn Marino       if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
765*e4b17023SJohn Marino 	/* Must be an F or L or machine defined suffix.  */
766*e4b17023SJohn Marino 	copylen--;
767*e4b17023SJohn Marino       if (flags & CPP_N_IMAGINARY)
768*e4b17023SJohn Marino 	/* I or J suffix.  */
769*e4b17023SJohn Marino 	copylen--;
770*e4b17023SJohn Marino     }
771*e4b17023SJohn Marino 
772*e4b17023SJohn Marino   copy = (char *) alloca (copylen + 1);
773*e4b17023SJohn Marino   memcpy (copy, token->val.str.text, copylen);
774*e4b17023SJohn Marino   copy[copylen] = '\0';
775*e4b17023SJohn Marino 
776*e4b17023SJohn Marino   real_from_string3 (&real, copy, TYPE_MODE (const_type));
777*e4b17023SJohn Marino   if (const_type != type)
778*e4b17023SJohn Marino     /* Diagnosing if the result of converting the value with excess
779*e4b17023SJohn Marino        precision to the semantic type would overflow (with associated
780*e4b17023SJohn Marino        double rounding) is more appropriate than diagnosing if the
781*e4b17023SJohn Marino        result of converting the string directly to the semantic type
782*e4b17023SJohn Marino        would overflow.  */
783*e4b17023SJohn Marino     real_convert (&real_trunc, TYPE_MODE (type), &real);
784*e4b17023SJohn Marino 
785*e4b17023SJohn Marino   /* Both C and C++ require a diagnostic for a floating constant
786*e4b17023SJohn Marino      outside the range of representable values of its type.  Since we
787*e4b17023SJohn Marino      have __builtin_inf* to produce an infinity, this is now a
788*e4b17023SJohn Marino      mandatory pedwarn if the target does not support infinities.  */
789*e4b17023SJohn Marino   if (REAL_VALUE_ISINF (real)
790*e4b17023SJohn Marino       || (const_type != type && REAL_VALUE_ISINF (real_trunc)))
791*e4b17023SJohn Marino     {
792*e4b17023SJohn Marino       if (!MODE_HAS_INFINITIES (TYPE_MODE (type)))
793*e4b17023SJohn Marino 	pedwarn (input_location, 0, "floating constant exceeds range of %qT", type);
794*e4b17023SJohn Marino       else
795*e4b17023SJohn Marino 	warning (OPT_Woverflow, "floating constant exceeds range of %qT", type);
796*e4b17023SJohn Marino     }
797*e4b17023SJohn Marino   /* We also give a warning if the value underflows.  */
798*e4b17023SJohn Marino   else if (REAL_VALUES_EQUAL (real, dconst0)
799*e4b17023SJohn Marino 	   || (const_type != type && REAL_VALUES_EQUAL (real_trunc, dconst0)))
800*e4b17023SJohn Marino     {
801*e4b17023SJohn Marino       REAL_VALUE_TYPE realvoidmode;
802*e4b17023SJohn Marino       int overflow = real_from_string (&realvoidmode, copy);
803*e4b17023SJohn Marino       if (overflow < 0 || !REAL_VALUES_EQUAL (realvoidmode, dconst0))
804*e4b17023SJohn Marino 	warning (OPT_Woverflow, "floating constant truncated to zero");
805*e4b17023SJohn Marino     }
806*e4b17023SJohn Marino 
807*e4b17023SJohn Marino   /* Create a node with determined type and value.  */
808*e4b17023SJohn Marino   value = build_real (const_type, real);
809*e4b17023SJohn Marino   if (flags & CPP_N_IMAGINARY)
810*e4b17023SJohn Marino     {
811*e4b17023SJohn Marino       value = build_complex (NULL_TREE, convert (const_type,
812*e4b17023SJohn Marino 						 integer_zero_node), value);
813*e4b17023SJohn Marino       if (type != const_type)
814*e4b17023SJohn Marino 	{
815*e4b17023SJohn Marino 	  const_type = TREE_TYPE (value);
816*e4b17023SJohn Marino 	  type = build_complex_type (type);
817*e4b17023SJohn Marino 	}
818*e4b17023SJohn Marino     }
819*e4b17023SJohn Marino 
820*e4b17023SJohn Marino   if (type != const_type)
821*e4b17023SJohn Marino     value = build1 (EXCESS_PRECISION_EXPR, type, value);
822*e4b17023SJohn Marino 
823*e4b17023SJohn Marino   return value;
824*e4b17023SJohn Marino }
825*e4b17023SJohn Marino 
826*e4b17023SJohn Marino /* Interpret TOKEN, a fixed-point number with FLAGS as classified
827*e4b17023SJohn Marino    by cpplib.  */
828*e4b17023SJohn Marino 
829*e4b17023SJohn Marino static tree
interpret_fixed(const cpp_token * token,unsigned int flags)830*e4b17023SJohn Marino interpret_fixed (const cpp_token *token, unsigned int flags)
831*e4b17023SJohn Marino {
832*e4b17023SJohn Marino   tree type;
833*e4b17023SJohn Marino   tree value;
834*e4b17023SJohn Marino   FIXED_VALUE_TYPE fixed;
835*e4b17023SJohn Marino   char *copy;
836*e4b17023SJohn Marino   size_t copylen;
837*e4b17023SJohn Marino 
838*e4b17023SJohn Marino   copylen = token->val.str.len;
839*e4b17023SJohn Marino 
840*e4b17023SJohn Marino   if (flags & CPP_N_FRACT) /* _Fract.  */
841*e4b17023SJohn Marino     {
842*e4b17023SJohn Marino       if (flags & CPP_N_UNSIGNED) /* Unsigned _Fract.  */
843*e4b17023SJohn Marino 	{
844*e4b17023SJohn Marino 	  if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
845*e4b17023SJohn Marino 	    {
846*e4b17023SJohn Marino 	      type = unsigned_long_long_fract_type_node;
847*e4b17023SJohn Marino 	      copylen -= 4;
848*e4b17023SJohn Marino 	    }
849*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
850*e4b17023SJohn Marino 	    {
851*e4b17023SJohn Marino 	      type = unsigned_long_fract_type_node;
852*e4b17023SJohn Marino 	      copylen -= 3;
853*e4b17023SJohn Marino 	    }
854*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
855*e4b17023SJohn Marino 	    {
856*e4b17023SJohn Marino 	      type = unsigned_short_fract_type_node;
857*e4b17023SJohn Marino 	      copylen -= 3;
858*e4b17023SJohn Marino 	    }
859*e4b17023SJohn Marino           else
860*e4b17023SJohn Marino 	    {
861*e4b17023SJohn Marino 	      type = unsigned_fract_type_node;
862*e4b17023SJohn Marino 	      copylen -= 2;
863*e4b17023SJohn Marino 	    }
864*e4b17023SJohn Marino 	}
865*e4b17023SJohn Marino       else /* Signed _Fract.  */
866*e4b17023SJohn Marino 	{
867*e4b17023SJohn Marino 	  if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
868*e4b17023SJohn Marino 	    {
869*e4b17023SJohn Marino 	      type = long_long_fract_type_node;
870*e4b17023SJohn Marino 	      copylen -= 3;
871*e4b17023SJohn Marino 	    }
872*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
873*e4b17023SJohn Marino 	    {
874*e4b17023SJohn Marino 	      type = long_fract_type_node;
875*e4b17023SJohn Marino 	      copylen -= 2;
876*e4b17023SJohn Marino 	    }
877*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
878*e4b17023SJohn Marino 	    {
879*e4b17023SJohn Marino 	      type = short_fract_type_node;
880*e4b17023SJohn Marino 	      copylen -= 2;
881*e4b17023SJohn Marino 	    }
882*e4b17023SJohn Marino           else
883*e4b17023SJohn Marino 	    {
884*e4b17023SJohn Marino 	      type = fract_type_node;
885*e4b17023SJohn Marino 	      copylen --;
886*e4b17023SJohn Marino 	    }
887*e4b17023SJohn Marino 	  }
888*e4b17023SJohn Marino     }
889*e4b17023SJohn Marino   else /* _Accum.  */
890*e4b17023SJohn Marino     {
891*e4b17023SJohn Marino       if (flags & CPP_N_UNSIGNED) /* Unsigned _Accum.  */
892*e4b17023SJohn Marino 	{
893*e4b17023SJohn Marino 	  if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
894*e4b17023SJohn Marino 	    {
895*e4b17023SJohn Marino 	      type = unsigned_long_long_accum_type_node;
896*e4b17023SJohn Marino 	      copylen -= 4;
897*e4b17023SJohn Marino 	    }
898*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
899*e4b17023SJohn Marino 	    {
900*e4b17023SJohn Marino 	      type = unsigned_long_accum_type_node;
901*e4b17023SJohn Marino 	      copylen -= 3;
902*e4b17023SJohn Marino 	    }
903*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
904*e4b17023SJohn Marino 	    {
905*e4b17023SJohn Marino 	      type = unsigned_short_accum_type_node;
906*e4b17023SJohn Marino 	      copylen -= 3;
907*e4b17023SJohn Marino 	     }
908*e4b17023SJohn Marino 	  else
909*e4b17023SJohn Marino 	    {
910*e4b17023SJohn Marino 	      type = unsigned_accum_type_node;
911*e4b17023SJohn Marino 	      copylen -= 2;
912*e4b17023SJohn Marino 	    }
913*e4b17023SJohn Marino 	}
914*e4b17023SJohn Marino       else /* Signed _Accum.  */
915*e4b17023SJohn Marino         {
916*e4b17023SJohn Marino 	  if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
917*e4b17023SJohn Marino 	    {
918*e4b17023SJohn Marino 	      type = long_long_accum_type_node;
919*e4b17023SJohn Marino 	      copylen -= 3;
920*e4b17023SJohn Marino 	    }
921*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
922*e4b17023SJohn Marino 	    {
923*e4b17023SJohn Marino 	      type = long_accum_type_node;
924*e4b17023SJohn Marino 	      copylen -= 2;
925*e4b17023SJohn Marino 	    }
926*e4b17023SJohn Marino 	  else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
927*e4b17023SJohn Marino 	    {
928*e4b17023SJohn Marino 	      type = short_accum_type_node;
929*e4b17023SJohn Marino 	      copylen -= 2;
930*e4b17023SJohn Marino 	    }
931*e4b17023SJohn Marino 	  else
932*e4b17023SJohn Marino 	    {
933*e4b17023SJohn Marino 	      type = accum_type_node;
934*e4b17023SJohn Marino 	      copylen --;
935*e4b17023SJohn Marino 	    }
936*e4b17023SJohn Marino 	}
937*e4b17023SJohn Marino     }
938*e4b17023SJohn Marino 
939*e4b17023SJohn Marino   copy = (char *) alloca (copylen + 1);
940*e4b17023SJohn Marino   memcpy (copy, token->val.str.text, copylen);
941*e4b17023SJohn Marino   copy[copylen] = '\0';
942*e4b17023SJohn Marino 
943*e4b17023SJohn Marino   fixed_from_string (&fixed, copy, TYPE_MODE (type));
944*e4b17023SJohn Marino 
945*e4b17023SJohn Marino   /* Create a node with determined type and value.  */
946*e4b17023SJohn Marino   value = build_fixed (type, fixed);
947*e4b17023SJohn Marino 
948*e4b17023SJohn Marino   return value;
949*e4b17023SJohn Marino }
950*e4b17023SJohn Marino 
951*e4b17023SJohn Marino /* Convert a series of STRING, WSTRING, STRING16, STRING32 and/or
952*e4b17023SJohn Marino    UTF8STRING tokens into a tree, performing string constant
953*e4b17023SJohn Marino    concatenation.  TOK is the first of these.  VALP is the location to
954*e4b17023SJohn Marino    write the string into.  OBJC_STRING indicates whether an '@' token
955*e4b17023SJohn Marino    preceded the incoming token (in that case, the strings can either
956*e4b17023SJohn Marino    be ObjC strings, preceded by a single '@', or normal strings, not
957*e4b17023SJohn Marino    preceded by '@'.  The result will be a CPP_OBJC_STRING).  Returns
958*e4b17023SJohn Marino    the CPP token type of the result (CPP_STRING, CPP_WSTRING,
959*e4b17023SJohn Marino    CPP_STRING32, CPP_STRING16, CPP_UTF8STRING, or CPP_OBJC_STRING).
960*e4b17023SJohn Marino 
961*e4b17023SJohn Marino    This is unfortunately more work than it should be.  If any of the
962*e4b17023SJohn Marino    strings in the series has an L prefix, the result is a wide string
963*e4b17023SJohn Marino    (6.4.5p4).  Whether or not the result is a wide string affects the
964*e4b17023SJohn Marino    meaning of octal and hexadecimal escapes (6.4.4.4p6,9).  But escape
965*e4b17023SJohn Marino    sequences do not continue across the boundary between two strings in
966*e4b17023SJohn Marino    a series (6.4.5p7), so we must not lose the boundaries.  Therefore
967*e4b17023SJohn Marino    cpp_interpret_string takes a vector of cpp_string structures, which
968*e4b17023SJohn Marino    we must arrange to provide.  */
969*e4b17023SJohn Marino 
970*e4b17023SJohn Marino static enum cpp_ttype
lex_string(const cpp_token * tok,tree * valp,bool objc_string,bool translate)971*e4b17023SJohn Marino lex_string (const cpp_token *tok, tree *valp, bool objc_string, bool translate)
972*e4b17023SJohn Marino {
973*e4b17023SJohn Marino   tree value;
974*e4b17023SJohn Marino   size_t concats = 0;
975*e4b17023SJohn Marino   struct obstack str_ob;
976*e4b17023SJohn Marino   cpp_string istr;
977*e4b17023SJohn Marino   enum cpp_ttype type = tok->type;
978*e4b17023SJohn Marino 
979*e4b17023SJohn Marino   /* Try to avoid the overhead of creating and destroying an obstack
980*e4b17023SJohn Marino      for the common case of just one string.  */
981*e4b17023SJohn Marino   cpp_string str = tok->val.str;
982*e4b17023SJohn Marino   cpp_string *strs = &str;
983*e4b17023SJohn Marino 
984*e4b17023SJohn Marino   /* objc_at_sign_was_seen is only used when doing Objective-C string
985*e4b17023SJohn Marino      concatenation.  It is 'true' if we have seen an '@' before the
986*e4b17023SJohn Marino      current string, and 'false' if not.  We must see exactly one or
987*e4b17023SJohn Marino      zero '@' before each string.  */
988*e4b17023SJohn Marino   bool objc_at_sign_was_seen = false;
989*e4b17023SJohn Marino 
990*e4b17023SJohn Marino  retry:
991*e4b17023SJohn Marino   tok = cpp_get_token (parse_in);
992*e4b17023SJohn Marino   switch (tok->type)
993*e4b17023SJohn Marino     {
994*e4b17023SJohn Marino     case CPP_PADDING:
995*e4b17023SJohn Marino       goto retry;
996*e4b17023SJohn Marino     case CPP_ATSIGN:
997*e4b17023SJohn Marino       if (objc_string)
998*e4b17023SJohn Marino 	{
999*e4b17023SJohn Marino 	  if (objc_at_sign_was_seen)
1000*e4b17023SJohn Marino 	    error ("repeated %<@%> before Objective-C string");
1001*e4b17023SJohn Marino 
1002*e4b17023SJohn Marino 	  objc_at_sign_was_seen = true;
1003*e4b17023SJohn Marino 	  goto retry;
1004*e4b17023SJohn Marino 	}
1005*e4b17023SJohn Marino       /* FALLTHROUGH */
1006*e4b17023SJohn Marino 
1007*e4b17023SJohn Marino     default:
1008*e4b17023SJohn Marino       break;
1009*e4b17023SJohn Marino 
1010*e4b17023SJohn Marino     case CPP_WSTRING:
1011*e4b17023SJohn Marino     case CPP_STRING16:
1012*e4b17023SJohn Marino     case CPP_STRING32:
1013*e4b17023SJohn Marino     case CPP_UTF8STRING:
1014*e4b17023SJohn Marino       if (type != tok->type)
1015*e4b17023SJohn Marino 	{
1016*e4b17023SJohn Marino 	  if (type == CPP_STRING)
1017*e4b17023SJohn Marino 	    type = tok->type;
1018*e4b17023SJohn Marino 	  else
1019*e4b17023SJohn Marino 	    error ("unsupported non-standard concatenation of string literals");
1020*e4b17023SJohn Marino 	}
1021*e4b17023SJohn Marino 
1022*e4b17023SJohn Marino     case CPP_STRING:
1023*e4b17023SJohn Marino       if (!concats)
1024*e4b17023SJohn Marino 	{
1025*e4b17023SJohn Marino 	  gcc_obstack_init (&str_ob);
1026*e4b17023SJohn Marino 	  obstack_grow (&str_ob, &str, sizeof (cpp_string));
1027*e4b17023SJohn Marino 	}
1028*e4b17023SJohn Marino 
1029*e4b17023SJohn Marino       concats++;
1030*e4b17023SJohn Marino       obstack_grow (&str_ob, &tok->val.str, sizeof (cpp_string));
1031*e4b17023SJohn Marino       if (objc_string)
1032*e4b17023SJohn Marino 	objc_at_sign_was_seen = false;
1033*e4b17023SJohn Marino       goto retry;
1034*e4b17023SJohn Marino     }
1035*e4b17023SJohn Marino 
1036*e4b17023SJohn Marino   /* It is an error if we saw a '@' with no following string.  */
1037*e4b17023SJohn Marino   if (objc_at_sign_was_seen)
1038*e4b17023SJohn Marino     error ("stray %<@%> in program");
1039*e4b17023SJohn Marino 
1040*e4b17023SJohn Marino   /* We have read one more token than we want.  */
1041*e4b17023SJohn Marino   _cpp_backup_tokens (parse_in, 1);
1042*e4b17023SJohn Marino   if (concats)
1043*e4b17023SJohn Marino     strs = XOBFINISH (&str_ob, cpp_string *);
1044*e4b17023SJohn Marino 
1045*e4b17023SJohn Marino   if (concats && !objc_string && !in_system_header)
1046*e4b17023SJohn Marino     warning (OPT_Wtraditional,
1047*e4b17023SJohn Marino 	     "traditional C rejects string constant concatenation");
1048*e4b17023SJohn Marino 
1049*e4b17023SJohn Marino   if ((translate
1050*e4b17023SJohn Marino        ? cpp_interpret_string : cpp_interpret_string_notranslate)
1051*e4b17023SJohn Marino       (parse_in, strs, concats + 1, &istr, type))
1052*e4b17023SJohn Marino     {
1053*e4b17023SJohn Marino       value = build_string (istr.len, (const char *) istr.text);
1054*e4b17023SJohn Marino       free (CONST_CAST (unsigned char *, istr.text));
1055*e4b17023SJohn Marino     }
1056*e4b17023SJohn Marino   else
1057*e4b17023SJohn Marino     {
1058*e4b17023SJohn Marino       /* Callers cannot generally handle error_mark_node in this context,
1059*e4b17023SJohn Marino 	 so return the empty string instead.  cpp_interpret_string has
1060*e4b17023SJohn Marino 	 issued an error.  */
1061*e4b17023SJohn Marino       switch (type)
1062*e4b17023SJohn Marino 	{
1063*e4b17023SJohn Marino 	default:
1064*e4b17023SJohn Marino 	case CPP_STRING:
1065*e4b17023SJohn Marino 	case CPP_UTF8STRING:
1066*e4b17023SJohn Marino 	  value = build_string (1, "");
1067*e4b17023SJohn Marino 	  break;
1068*e4b17023SJohn Marino 	case CPP_STRING16:
1069*e4b17023SJohn Marino 	  value = build_string (TYPE_PRECISION (char16_type_node)
1070*e4b17023SJohn Marino 				/ TYPE_PRECISION (char_type_node),
1071*e4b17023SJohn Marino 				"\0");  /* char16_t is 16 bits */
1072*e4b17023SJohn Marino 	  break;
1073*e4b17023SJohn Marino 	case CPP_STRING32:
1074*e4b17023SJohn Marino 	  value = build_string (TYPE_PRECISION (char32_type_node)
1075*e4b17023SJohn Marino 				/ TYPE_PRECISION (char_type_node),
1076*e4b17023SJohn Marino 				"\0\0\0");  /* char32_t is 32 bits */
1077*e4b17023SJohn Marino 	  break;
1078*e4b17023SJohn Marino 	case CPP_WSTRING:
1079*e4b17023SJohn Marino 	  value = build_string (TYPE_PRECISION (wchar_type_node)
1080*e4b17023SJohn Marino 				/ TYPE_PRECISION (char_type_node),
1081*e4b17023SJohn Marino 				"\0\0\0");  /* widest supported wchar_t
1082*e4b17023SJohn Marino 					       is 32 bits */
1083*e4b17023SJohn Marino 	  break;
1084*e4b17023SJohn Marino         }
1085*e4b17023SJohn Marino     }
1086*e4b17023SJohn Marino 
1087*e4b17023SJohn Marino   switch (type)
1088*e4b17023SJohn Marino     {
1089*e4b17023SJohn Marino     default:
1090*e4b17023SJohn Marino     case CPP_STRING:
1091*e4b17023SJohn Marino     case CPP_UTF8STRING:
1092*e4b17023SJohn Marino       TREE_TYPE (value) = char_array_type_node;
1093*e4b17023SJohn Marino       break;
1094*e4b17023SJohn Marino     case CPP_STRING16:
1095*e4b17023SJohn Marino       TREE_TYPE (value) = char16_array_type_node;
1096*e4b17023SJohn Marino       break;
1097*e4b17023SJohn Marino     case CPP_STRING32:
1098*e4b17023SJohn Marino       TREE_TYPE (value) = char32_array_type_node;
1099*e4b17023SJohn Marino       break;
1100*e4b17023SJohn Marino     case CPP_WSTRING:
1101*e4b17023SJohn Marino       TREE_TYPE (value) = wchar_array_type_node;
1102*e4b17023SJohn Marino     }
1103*e4b17023SJohn Marino   *valp = fix_string_type (value);
1104*e4b17023SJohn Marino 
1105*e4b17023SJohn Marino   if (concats)
1106*e4b17023SJohn Marino     obstack_free (&str_ob, 0);
1107*e4b17023SJohn Marino 
1108*e4b17023SJohn Marino   return objc_string ? CPP_OBJC_STRING : type;
1109*e4b17023SJohn Marino }
1110*e4b17023SJohn Marino 
1111*e4b17023SJohn Marino /* Converts a (possibly wide) character constant token into a tree.  */
1112*e4b17023SJohn Marino static tree
lex_charconst(const cpp_token * token)1113*e4b17023SJohn Marino lex_charconst (const cpp_token *token)
1114*e4b17023SJohn Marino {
1115*e4b17023SJohn Marino   cppchar_t result;
1116*e4b17023SJohn Marino   tree type, value;
1117*e4b17023SJohn Marino   unsigned int chars_seen;
1118*e4b17023SJohn Marino   int unsignedp = 0;
1119*e4b17023SJohn Marino 
1120*e4b17023SJohn Marino   result = cpp_interpret_charconst (parse_in, token,
1121*e4b17023SJohn Marino 				    &chars_seen, &unsignedp);
1122*e4b17023SJohn Marino 
1123*e4b17023SJohn Marino   if (token->type == CPP_WCHAR)
1124*e4b17023SJohn Marino     type = wchar_type_node;
1125*e4b17023SJohn Marino   else if (token->type == CPP_CHAR32)
1126*e4b17023SJohn Marino     type = char32_type_node;
1127*e4b17023SJohn Marino   else if (token->type == CPP_CHAR16)
1128*e4b17023SJohn Marino     type = char16_type_node;
1129*e4b17023SJohn Marino   /* In C, a character constant has type 'int'.
1130*e4b17023SJohn Marino      In C++ 'char', but multi-char charconsts have type 'int'.  */
1131*e4b17023SJohn Marino   else if (!c_dialect_cxx () || chars_seen > 1)
1132*e4b17023SJohn Marino     type = integer_type_node;
1133*e4b17023SJohn Marino   else
1134*e4b17023SJohn Marino     type = char_type_node;
1135*e4b17023SJohn Marino 
1136*e4b17023SJohn Marino   /* Cast to cppchar_signed_t to get correct sign-extension of RESULT
1137*e4b17023SJohn Marino      before possibly widening to HOST_WIDE_INT for build_int_cst.  */
1138*e4b17023SJohn Marino   if (unsignedp || (cppchar_signed_t) result >= 0)
1139*e4b17023SJohn Marino     value = build_int_cst_wide (type, result, 0);
1140*e4b17023SJohn Marino   else
1141*e4b17023SJohn Marino     value = build_int_cst_wide (type, (cppchar_signed_t) result, -1);
1142*e4b17023SJohn Marino 
1143*e4b17023SJohn Marino   return value;
1144*e4b17023SJohn Marino }
1145