1*c87b03e5Sespie /* Mainly the interface between cpplib and the C front ends.
2*c87b03e5Sespie Copyright (C) 1987, 1988, 1989, 1992, 1994, 1995, 1996, 1997
3*c87b03e5Sespie 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4*c87b03e5Sespie
5*c87b03e5Sespie This file is part of GCC.
6*c87b03e5Sespie
7*c87b03e5Sespie GCC is free software; you can redistribute it and/or modify it under
8*c87b03e5Sespie the terms of the GNU General Public License as published by the Free
9*c87b03e5Sespie Software Foundation; either version 2, or (at your option) any later
10*c87b03e5Sespie version.
11*c87b03e5Sespie
12*c87b03e5Sespie GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*c87b03e5Sespie WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*c87b03e5Sespie FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15*c87b03e5Sespie for more details.
16*c87b03e5Sespie
17*c87b03e5Sespie You should have received a copy of the GNU General Public License
18*c87b03e5Sespie along with GCC; see the file COPYING. If not, write to the Free
19*c87b03e5Sespie Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20*c87b03e5Sespie 02111-1307, USA. */
21*c87b03e5Sespie
22*c87b03e5Sespie #include "config.h"
23*c87b03e5Sespie #include "system.h"
24*c87b03e5Sespie
25*c87b03e5Sespie #include "real.h"
26*c87b03e5Sespie #include "rtl.h"
27*c87b03e5Sespie #include "tree.h"
28*c87b03e5Sespie #include "expr.h"
29*c87b03e5Sespie #include "input.h"
30*c87b03e5Sespie #include "output.h"
31*c87b03e5Sespie #include "c-tree.h"
32*c87b03e5Sespie #include "c-common.h"
33*c87b03e5Sespie #include "flags.h"
34*c87b03e5Sespie #include "timevar.h"
35*c87b03e5Sespie #include "cpplib.h"
36*c87b03e5Sespie #include "c-pragma.h"
37*c87b03e5Sespie #include "toplev.h"
38*c87b03e5Sespie #include "intl.h"
39*c87b03e5Sespie #include "tm_p.h"
40*c87b03e5Sespie #include "splay-tree.h"
41*c87b03e5Sespie #include "debug.h"
42*c87b03e5Sespie
43*c87b03e5Sespie #ifdef MULTIBYTE_CHARS
44*c87b03e5Sespie #include "mbchar.h"
45*c87b03e5Sespie #include <locale.h>
46*c87b03e5Sespie #endif /* MULTIBYTE_CHARS */
47*c87b03e5Sespie
48*c87b03e5Sespie /* The current line map. */
49*c87b03e5Sespie static const struct line_map *map;
50*c87b03e5Sespie
51*c87b03e5Sespie /* The line used to refresh the lineno global variable after each token. */
52*c87b03e5Sespie static unsigned int src_lineno;
53*c87b03e5Sespie
54*c87b03e5Sespie /* We may keep statistics about how long which files took to compile. */
55*c87b03e5Sespie static int header_time, body_time;
56*c87b03e5Sespie static splay_tree file_info_tree;
57*c87b03e5Sespie
58*c87b03e5Sespie /* File used for outputting assembler code. */
59*c87b03e5Sespie extern FILE *asm_out_file;
60*c87b03e5Sespie
61*c87b03e5Sespie #undef WCHAR_TYPE_SIZE
62*c87b03e5Sespie #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
63*c87b03e5Sespie
64*c87b03e5Sespie /* Number of bytes in a wide character. */
65*c87b03e5Sespie #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
66*c87b03e5Sespie
67*c87b03e5Sespie int pending_lang_change; /* If we need to switch languages - C++ only */
68*c87b03e5Sespie int c_header_level; /* depth in C headers - C++ only */
69*c87b03e5Sespie
70*c87b03e5Sespie /* Nonzero tells yylex to ignore \ in string constants. */
71*c87b03e5Sespie static int ignore_escape_flag;
72*c87b03e5Sespie
73*c87b03e5Sespie static tree interpret_integer PARAMS ((const cpp_token *, unsigned int));
74*c87b03e5Sespie static tree interpret_float PARAMS ((const cpp_token *, unsigned int));
75*c87b03e5Sespie static enum integer_type_kind
76*c87b03e5Sespie narrowest_unsigned_type PARAMS ((tree, unsigned int));
77*c87b03e5Sespie static enum integer_type_kind
78*c87b03e5Sespie narrowest_signed_type PARAMS ((tree, unsigned int));
79*c87b03e5Sespie static tree lex_string PARAMS ((const unsigned char *, unsigned int,
80*c87b03e5Sespie int));
81*c87b03e5Sespie static tree lex_charconst PARAMS ((const cpp_token *));
82*c87b03e5Sespie static void update_header_times PARAMS ((const char *));
83*c87b03e5Sespie static int dump_one_header PARAMS ((splay_tree_node, void *));
84*c87b03e5Sespie static void cb_line_change PARAMS ((cpp_reader *, const cpp_token *, int));
85*c87b03e5Sespie static void cb_ident PARAMS ((cpp_reader *, unsigned int,
86*c87b03e5Sespie const cpp_string *));
87*c87b03e5Sespie static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *));
88*c87b03e5Sespie static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int));
89*c87b03e5Sespie static void cb_define PARAMS ((cpp_reader *, unsigned int,
90*c87b03e5Sespie cpp_hashnode *));
91*c87b03e5Sespie static void cb_undef PARAMS ((cpp_reader *, unsigned int,
92*c87b03e5Sespie cpp_hashnode *));
93*c87b03e5Sespie
94*c87b03e5Sespie const char *
init_c_lex(filename)95*c87b03e5Sespie init_c_lex (filename)
96*c87b03e5Sespie const char *filename;
97*c87b03e5Sespie {
98*c87b03e5Sespie struct cpp_callbacks *cb;
99*c87b03e5Sespie struct c_fileinfo *toplevel;
100*c87b03e5Sespie
101*c87b03e5Sespie /* Set up filename timing. Must happen before cpp_read_main_file. */
102*c87b03e5Sespie file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
103*c87b03e5Sespie 0,
104*c87b03e5Sespie (splay_tree_delete_value_fn)free);
105*c87b03e5Sespie toplevel = get_fileinfo ("<top level>");
106*c87b03e5Sespie if (flag_detailed_statistics)
107*c87b03e5Sespie {
108*c87b03e5Sespie header_time = 0;
109*c87b03e5Sespie body_time = get_run_time ();
110*c87b03e5Sespie toplevel->time = body_time;
111*c87b03e5Sespie }
112*c87b03e5Sespie
113*c87b03e5Sespie #ifdef MULTIBYTE_CHARS
114*c87b03e5Sespie /* Change to the native locale for multibyte conversions. */
115*c87b03e5Sespie setlocale (LC_CTYPE, "");
116*c87b03e5Sespie GET_ENVIRONMENT (literal_codeset, "LANG");
117*c87b03e5Sespie #endif
118*c87b03e5Sespie
119*c87b03e5Sespie cb = cpp_get_callbacks (parse_in);
120*c87b03e5Sespie
121*c87b03e5Sespie cb->line_change = cb_line_change;
122*c87b03e5Sespie cb->ident = cb_ident;
123*c87b03e5Sespie cb->file_change = cb_file_change;
124*c87b03e5Sespie cb->def_pragma = cb_def_pragma;
125*c87b03e5Sespie
126*c87b03e5Sespie /* Set the debug callbacks if we can use them. */
127*c87b03e5Sespie if (debug_info_level == DINFO_LEVEL_VERBOSE
128*c87b03e5Sespie && (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG
129*c87b03e5Sespie || write_symbols == VMS_AND_DWARF2_DEBUG))
130*c87b03e5Sespie {
131*c87b03e5Sespie cb->define = cb_define;
132*c87b03e5Sespie cb->undef = cb_undef;
133*c87b03e5Sespie }
134*c87b03e5Sespie
135*c87b03e5Sespie /* Start it at 0. */
136*c87b03e5Sespie lineno = 0;
137*c87b03e5Sespie
138*c87b03e5Sespie return cpp_read_main_file (parse_in, filename, ident_hash);
139*c87b03e5Sespie }
140*c87b03e5Sespie
141*c87b03e5Sespie /* A thin wrapper around the real parser that initializes the
142*c87b03e5Sespie integrated preprocessor after debug output has been initialized.
143*c87b03e5Sespie Also, make sure the start_source_file debug hook gets called for
144*c87b03e5Sespie the primary source file. */
145*c87b03e5Sespie
146*c87b03e5Sespie void
c_common_parse_file(set_yydebug)147*c87b03e5Sespie c_common_parse_file (set_yydebug)
148*c87b03e5Sespie int set_yydebug ATTRIBUTE_UNUSED;
149*c87b03e5Sespie {
150*c87b03e5Sespie #if YYDEBUG != 0
151*c87b03e5Sespie yydebug = set_yydebug;
152*c87b03e5Sespie #else
153*c87b03e5Sespie warning ("YYDEBUG not defined");
154*c87b03e5Sespie #endif
155*c87b03e5Sespie
156*c87b03e5Sespie (*debug_hooks->start_source_file) (lineno, input_filename);
157*c87b03e5Sespie cpp_finish_options (parse_in);
158*c87b03e5Sespie
159*c87b03e5Sespie yyparse ();
160*c87b03e5Sespie free_parser_stacks ();
161*c87b03e5Sespie }
162*c87b03e5Sespie
163*c87b03e5Sespie struct c_fileinfo *
get_fileinfo(name)164*c87b03e5Sespie get_fileinfo (name)
165*c87b03e5Sespie const char *name;
166*c87b03e5Sespie {
167*c87b03e5Sespie splay_tree_node n;
168*c87b03e5Sespie struct c_fileinfo *fi;
169*c87b03e5Sespie
170*c87b03e5Sespie n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
171*c87b03e5Sespie if (n)
172*c87b03e5Sespie return (struct c_fileinfo *) n->value;
173*c87b03e5Sespie
174*c87b03e5Sespie fi = (struct c_fileinfo *) xmalloc (sizeof (struct c_fileinfo));
175*c87b03e5Sespie fi->time = 0;
176*c87b03e5Sespie fi->interface_only = 0;
177*c87b03e5Sespie fi->interface_unknown = 1;
178*c87b03e5Sespie splay_tree_insert (file_info_tree, (splay_tree_key) name,
179*c87b03e5Sespie (splay_tree_value) fi);
180*c87b03e5Sespie return fi;
181*c87b03e5Sespie }
182*c87b03e5Sespie
183*c87b03e5Sespie static void
update_header_times(name)184*c87b03e5Sespie update_header_times (name)
185*c87b03e5Sespie const char *name;
186*c87b03e5Sespie {
187*c87b03e5Sespie /* Changing files again. This means currently collected time
188*c87b03e5Sespie is charged against header time, and body time starts back at 0. */
189*c87b03e5Sespie if (flag_detailed_statistics)
190*c87b03e5Sespie {
191*c87b03e5Sespie int this_time = get_run_time ();
192*c87b03e5Sespie struct c_fileinfo *file = get_fileinfo (name);
193*c87b03e5Sespie header_time += this_time - body_time;
194*c87b03e5Sespie file->time += this_time - body_time;
195*c87b03e5Sespie body_time = this_time;
196*c87b03e5Sespie }
197*c87b03e5Sespie }
198*c87b03e5Sespie
199*c87b03e5Sespie static int
dump_one_header(n,dummy)200*c87b03e5Sespie dump_one_header (n, dummy)
201*c87b03e5Sespie splay_tree_node n;
202*c87b03e5Sespie void *dummy ATTRIBUTE_UNUSED;
203*c87b03e5Sespie {
204*c87b03e5Sespie print_time ((const char *) n->key,
205*c87b03e5Sespie ((struct c_fileinfo *) n->value)->time);
206*c87b03e5Sespie return 0;
207*c87b03e5Sespie }
208*c87b03e5Sespie
209*c87b03e5Sespie void
dump_time_statistics()210*c87b03e5Sespie dump_time_statistics ()
211*c87b03e5Sespie {
212*c87b03e5Sespie struct c_fileinfo *file = get_fileinfo (input_filename);
213*c87b03e5Sespie int this_time = get_run_time ();
214*c87b03e5Sespie file->time += this_time - body_time;
215*c87b03e5Sespie
216*c87b03e5Sespie fprintf (stderr, "\n******\n");
217*c87b03e5Sespie print_time ("header files (total)", header_time);
218*c87b03e5Sespie print_time ("main file (total)", this_time - body_time);
219*c87b03e5Sespie fprintf (stderr, "ratio = %g : 1\n",
220*c87b03e5Sespie (double)header_time / (double)(this_time - body_time));
221*c87b03e5Sespie fprintf (stderr, "\n******\n");
222*c87b03e5Sespie
223*c87b03e5Sespie splay_tree_foreach (file_info_tree, dump_one_header, 0);
224*c87b03e5Sespie }
225*c87b03e5Sespie
226*c87b03e5Sespie static void
cb_ident(pfile,line,str)227*c87b03e5Sespie cb_ident (pfile, line, str)
228*c87b03e5Sespie cpp_reader *pfile ATTRIBUTE_UNUSED;
229*c87b03e5Sespie unsigned int line ATTRIBUTE_UNUSED;
230*c87b03e5Sespie const cpp_string *str ATTRIBUTE_UNUSED;
231*c87b03e5Sespie {
232*c87b03e5Sespie #ifdef ASM_OUTPUT_IDENT
233*c87b03e5Sespie if (! flag_no_ident)
234*c87b03e5Sespie {
235*c87b03e5Sespie /* Convert escapes in the string. */
236*c87b03e5Sespie tree value = lex_string (str->text, str->len, 0);
237*c87b03e5Sespie ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (value));
238*c87b03e5Sespie }
239*c87b03e5Sespie #endif
240*c87b03e5Sespie }
241*c87b03e5Sespie
242*c87b03e5Sespie /* Called at the start of every non-empty line. TOKEN is the first
243*c87b03e5Sespie lexed token on the line. Used for diagnostic line numbers. */
244*c87b03e5Sespie static void
cb_line_change(pfile,token,parsing_args)245*c87b03e5Sespie cb_line_change (pfile, token, parsing_args)
246*c87b03e5Sespie cpp_reader *pfile ATTRIBUTE_UNUSED;
247*c87b03e5Sespie const cpp_token *token;
248*c87b03e5Sespie int parsing_args;
249*c87b03e5Sespie {
250*c87b03e5Sespie if (token->type == CPP_EOF || parsing_args)
251*c87b03e5Sespie return;
252*c87b03e5Sespie
253*c87b03e5Sespie src_lineno = SOURCE_LINE (map, token->line);
254*c87b03e5Sespie }
255*c87b03e5Sespie
256*c87b03e5Sespie static void
cb_file_change(pfile,new_map)257*c87b03e5Sespie cb_file_change (pfile, new_map)
258*c87b03e5Sespie cpp_reader *pfile ATTRIBUTE_UNUSED;
259*c87b03e5Sespie const struct line_map *new_map;
260*c87b03e5Sespie {
261*c87b03e5Sespie unsigned int to_line = SOURCE_LINE (new_map, new_map->to_line);
262*c87b03e5Sespie
263*c87b03e5Sespie if (new_map->reason == LC_ENTER)
264*c87b03e5Sespie {
265*c87b03e5Sespie /* Don't stack the main buffer on the input stack;
266*c87b03e5Sespie we already did in compile_file. */
267*c87b03e5Sespie if (map == NULL)
268*c87b03e5Sespie main_input_filename = new_map->to_file;
269*c87b03e5Sespie else
270*c87b03e5Sespie {
271*c87b03e5Sespie int included_at = SOURCE_LINE (new_map - 1, new_map->from_line - 1);
272*c87b03e5Sespie
273*c87b03e5Sespie lineno = included_at;
274*c87b03e5Sespie push_srcloc (new_map->to_file, 1);
275*c87b03e5Sespie (*debug_hooks->start_source_file) (included_at, new_map->to_file);
276*c87b03e5Sespie #ifndef NO_IMPLICIT_EXTERN_C
277*c87b03e5Sespie if (c_header_level)
278*c87b03e5Sespie ++c_header_level;
279*c87b03e5Sespie else if (new_map->sysp == 2)
280*c87b03e5Sespie {
281*c87b03e5Sespie c_header_level = 1;
282*c87b03e5Sespie ++pending_lang_change;
283*c87b03e5Sespie }
284*c87b03e5Sespie #endif
285*c87b03e5Sespie }
286*c87b03e5Sespie }
287*c87b03e5Sespie else if (new_map->reason == LC_LEAVE)
288*c87b03e5Sespie {
289*c87b03e5Sespie #ifndef NO_IMPLICIT_EXTERN_C
290*c87b03e5Sespie if (c_header_level && --c_header_level == 0)
291*c87b03e5Sespie {
292*c87b03e5Sespie if (new_map->sysp == 2)
293*c87b03e5Sespie warning ("badly nested C headers from preprocessor");
294*c87b03e5Sespie --pending_lang_change;
295*c87b03e5Sespie }
296*c87b03e5Sespie #endif
297*c87b03e5Sespie pop_srcloc ();
298*c87b03e5Sespie
299*c87b03e5Sespie (*debug_hooks->end_source_file) (to_line);
300*c87b03e5Sespie }
301*c87b03e5Sespie
302*c87b03e5Sespie update_header_times (new_map->to_file);
303*c87b03e5Sespie in_system_header = new_map->sysp != 0;
304*c87b03e5Sespie input_filename = new_map->to_file;
305*c87b03e5Sespie lineno = to_line;
306*c87b03e5Sespie map = new_map;
307*c87b03e5Sespie
308*c87b03e5Sespie /* Hook for C++. */
309*c87b03e5Sespie extract_interface_info ();
310*c87b03e5Sespie }
311*c87b03e5Sespie
312*c87b03e5Sespie static void
cb_def_pragma(pfile,line)313*c87b03e5Sespie cb_def_pragma (pfile, line)
314*c87b03e5Sespie cpp_reader *pfile;
315*c87b03e5Sespie unsigned int line;
316*c87b03e5Sespie {
317*c87b03e5Sespie /* Issue a warning message if we have been asked to do so. Ignore
318*c87b03e5Sespie unknown pragmas in system headers unless an explicit
319*c87b03e5Sespie -Wunknown-pragmas has been given. */
320*c87b03e5Sespie if (warn_unknown_pragmas > in_system_header)
321*c87b03e5Sespie {
322*c87b03e5Sespie const unsigned char *space, *name;
323*c87b03e5Sespie const cpp_token *s;
324*c87b03e5Sespie
325*c87b03e5Sespie space = name = (const unsigned char *) "";
326*c87b03e5Sespie s = cpp_get_token (pfile);
327*c87b03e5Sespie if (s->type != CPP_EOF)
328*c87b03e5Sespie {
329*c87b03e5Sespie space = cpp_token_as_text (pfile, s);
330*c87b03e5Sespie s = cpp_get_token (pfile);
331*c87b03e5Sespie if (s->type == CPP_NAME)
332*c87b03e5Sespie name = cpp_token_as_text (pfile, s);
333*c87b03e5Sespie }
334*c87b03e5Sespie
335*c87b03e5Sespie lineno = SOURCE_LINE (map, line);
336*c87b03e5Sespie warning ("ignoring #pragma %s %s", space, name);
337*c87b03e5Sespie }
338*c87b03e5Sespie }
339*c87b03e5Sespie
340*c87b03e5Sespie /* #define callback for DWARF and DWARF2 debug info. */
341*c87b03e5Sespie static void
cb_define(pfile,line,node)342*c87b03e5Sespie cb_define (pfile, line, node)
343*c87b03e5Sespie cpp_reader *pfile;
344*c87b03e5Sespie unsigned int line;
345*c87b03e5Sespie cpp_hashnode *node;
346*c87b03e5Sespie {
347*c87b03e5Sespie (*debug_hooks->define) (SOURCE_LINE (map, line),
348*c87b03e5Sespie (const char *) cpp_macro_definition (pfile, node));
349*c87b03e5Sespie }
350*c87b03e5Sespie
351*c87b03e5Sespie /* #undef callback for DWARF and DWARF2 debug info. */
352*c87b03e5Sespie static void
cb_undef(pfile,line,node)353*c87b03e5Sespie cb_undef (pfile, line, node)
354*c87b03e5Sespie cpp_reader *pfile ATTRIBUTE_UNUSED;
355*c87b03e5Sespie unsigned int line;
356*c87b03e5Sespie cpp_hashnode *node;
357*c87b03e5Sespie {
358*c87b03e5Sespie (*debug_hooks->undef) (SOURCE_LINE (map, line),
359*c87b03e5Sespie (const char *) NODE_NAME (node));
360*c87b03e5Sespie }
361*c87b03e5Sespie
362*c87b03e5Sespie #if 0 /* not yet */
363*c87b03e5Sespie /* Returns nonzero if C is a universal-character-name. Give an error if it
364*c87b03e5Sespie is not one which may appear in an identifier, as per [extendid].
365*c87b03e5Sespie
366*c87b03e5Sespie Note that extended character support in identifiers has not yet been
367*c87b03e5Sespie implemented. It is my personal opinion that this is not a desirable
368*c87b03e5Sespie feature. Portable code cannot count on support for more than the basic
369*c87b03e5Sespie identifier character set. */
370*c87b03e5Sespie
371*c87b03e5Sespie static inline int
372*c87b03e5Sespie is_extended_char (c)
373*c87b03e5Sespie int c;
374*c87b03e5Sespie {
375*c87b03e5Sespie #ifdef TARGET_EBCDIC
376*c87b03e5Sespie return 0;
377*c87b03e5Sespie #else
378*c87b03e5Sespie /* ASCII. */
379*c87b03e5Sespie if (c < 0x7f)
380*c87b03e5Sespie return 0;
381*c87b03e5Sespie
382*c87b03e5Sespie /* None of the valid chars are outside the Basic Multilingual Plane (the
383*c87b03e5Sespie low 16 bits). */
384*c87b03e5Sespie if (c > 0xffff)
385*c87b03e5Sespie {
386*c87b03e5Sespie error ("universal-character-name '\\U%08x' not valid in identifier", c);
387*c87b03e5Sespie return 1;
388*c87b03e5Sespie }
389*c87b03e5Sespie
390*c87b03e5Sespie /* Latin */
391*c87b03e5Sespie if ((c >= 0x00c0 && c <= 0x00d6)
392*c87b03e5Sespie || (c >= 0x00d8 && c <= 0x00f6)
393*c87b03e5Sespie || (c >= 0x00f8 && c <= 0x01f5)
394*c87b03e5Sespie || (c >= 0x01fa && c <= 0x0217)
395*c87b03e5Sespie || (c >= 0x0250 && c <= 0x02a8)
396*c87b03e5Sespie || (c >= 0x1e00 && c <= 0x1e9a)
397*c87b03e5Sespie || (c >= 0x1ea0 && c <= 0x1ef9))
398*c87b03e5Sespie return 1;
399*c87b03e5Sespie
400*c87b03e5Sespie /* Greek */
401*c87b03e5Sespie if ((c == 0x0384)
402*c87b03e5Sespie || (c >= 0x0388 && c <= 0x038a)
403*c87b03e5Sespie || (c == 0x038c)
404*c87b03e5Sespie || (c >= 0x038e && c <= 0x03a1)
405*c87b03e5Sespie || (c >= 0x03a3 && c <= 0x03ce)
406*c87b03e5Sespie || (c >= 0x03d0 && c <= 0x03d6)
407*c87b03e5Sespie || (c == 0x03da)
408*c87b03e5Sespie || (c == 0x03dc)
409*c87b03e5Sespie || (c == 0x03de)
410*c87b03e5Sespie || (c == 0x03e0)
411*c87b03e5Sespie || (c >= 0x03e2 && c <= 0x03f3)
412*c87b03e5Sespie || (c >= 0x1f00 && c <= 0x1f15)
413*c87b03e5Sespie || (c >= 0x1f18 && c <= 0x1f1d)
414*c87b03e5Sespie || (c >= 0x1f20 && c <= 0x1f45)
415*c87b03e5Sespie || (c >= 0x1f48 && c <= 0x1f4d)
416*c87b03e5Sespie || (c >= 0x1f50 && c <= 0x1f57)
417*c87b03e5Sespie || (c == 0x1f59)
418*c87b03e5Sespie || (c == 0x1f5b)
419*c87b03e5Sespie || (c == 0x1f5d)
420*c87b03e5Sespie || (c >= 0x1f5f && c <= 0x1f7d)
421*c87b03e5Sespie || (c >= 0x1f80 && c <= 0x1fb4)
422*c87b03e5Sespie || (c >= 0x1fb6 && c <= 0x1fbc)
423*c87b03e5Sespie || (c >= 0x1fc2 && c <= 0x1fc4)
424*c87b03e5Sespie || (c >= 0x1fc6 && c <= 0x1fcc)
425*c87b03e5Sespie || (c >= 0x1fd0 && c <= 0x1fd3)
426*c87b03e5Sespie || (c >= 0x1fd6 && c <= 0x1fdb)
427*c87b03e5Sespie || (c >= 0x1fe0 && c <= 0x1fec)
428*c87b03e5Sespie || (c >= 0x1ff2 && c <= 0x1ff4)
429*c87b03e5Sespie || (c >= 0x1ff6 && c <= 0x1ffc))
430*c87b03e5Sespie return 1;
431*c87b03e5Sespie
432*c87b03e5Sespie /* Cyrillic */
433*c87b03e5Sespie if ((c >= 0x0401 && c <= 0x040d)
434*c87b03e5Sespie || (c >= 0x040f && c <= 0x044f)
435*c87b03e5Sespie || (c >= 0x0451 && c <= 0x045c)
436*c87b03e5Sespie || (c >= 0x045e && c <= 0x0481)
437*c87b03e5Sespie || (c >= 0x0490 && c <= 0x04c4)
438*c87b03e5Sespie || (c >= 0x04c7 && c <= 0x04c8)
439*c87b03e5Sespie || (c >= 0x04cb && c <= 0x04cc)
440*c87b03e5Sespie || (c >= 0x04d0 && c <= 0x04eb)
441*c87b03e5Sespie || (c >= 0x04ee && c <= 0x04f5)
442*c87b03e5Sespie || (c >= 0x04f8 && c <= 0x04f9))
443*c87b03e5Sespie return 1;
444*c87b03e5Sespie
445*c87b03e5Sespie /* Armenian */
446*c87b03e5Sespie if ((c >= 0x0531 && c <= 0x0556)
447*c87b03e5Sespie || (c >= 0x0561 && c <= 0x0587))
448*c87b03e5Sespie return 1;
449*c87b03e5Sespie
450*c87b03e5Sespie /* Hebrew */
451*c87b03e5Sespie if ((c >= 0x05d0 && c <= 0x05ea)
452*c87b03e5Sespie || (c >= 0x05f0 && c <= 0x05f4))
453*c87b03e5Sespie return 1;
454*c87b03e5Sespie
455*c87b03e5Sespie /* Arabic */
456*c87b03e5Sespie if ((c >= 0x0621 && c <= 0x063a)
457*c87b03e5Sespie || (c >= 0x0640 && c <= 0x0652)
458*c87b03e5Sespie || (c >= 0x0670 && c <= 0x06b7)
459*c87b03e5Sespie || (c >= 0x06ba && c <= 0x06be)
460*c87b03e5Sespie || (c >= 0x06c0 && c <= 0x06ce)
461*c87b03e5Sespie || (c >= 0x06e5 && c <= 0x06e7))
462*c87b03e5Sespie return 1;
463*c87b03e5Sespie
464*c87b03e5Sespie /* Devanagari */
465*c87b03e5Sespie if ((c >= 0x0905 && c <= 0x0939)
466*c87b03e5Sespie || (c >= 0x0958 && c <= 0x0962))
467*c87b03e5Sespie return 1;
468*c87b03e5Sespie
469*c87b03e5Sespie /* Bengali */
470*c87b03e5Sespie if ((c >= 0x0985 && c <= 0x098c)
471*c87b03e5Sespie || (c >= 0x098f && c <= 0x0990)
472*c87b03e5Sespie || (c >= 0x0993 && c <= 0x09a8)
473*c87b03e5Sespie || (c >= 0x09aa && c <= 0x09b0)
474*c87b03e5Sespie || (c == 0x09b2)
475*c87b03e5Sespie || (c >= 0x09b6 && c <= 0x09b9)
476*c87b03e5Sespie || (c >= 0x09dc && c <= 0x09dd)
477*c87b03e5Sespie || (c >= 0x09df && c <= 0x09e1)
478*c87b03e5Sespie || (c >= 0x09f0 && c <= 0x09f1))
479*c87b03e5Sespie return 1;
480*c87b03e5Sespie
481*c87b03e5Sespie /* Gurmukhi */
482*c87b03e5Sespie if ((c >= 0x0a05 && c <= 0x0a0a)
483*c87b03e5Sespie || (c >= 0x0a0f && c <= 0x0a10)
484*c87b03e5Sespie || (c >= 0x0a13 && c <= 0x0a28)
485*c87b03e5Sespie || (c >= 0x0a2a && c <= 0x0a30)
486*c87b03e5Sespie || (c >= 0x0a32 && c <= 0x0a33)
487*c87b03e5Sespie || (c >= 0x0a35 && c <= 0x0a36)
488*c87b03e5Sespie || (c >= 0x0a38 && c <= 0x0a39)
489*c87b03e5Sespie || (c >= 0x0a59 && c <= 0x0a5c)
490*c87b03e5Sespie || (c == 0x0a5e))
491*c87b03e5Sespie return 1;
492*c87b03e5Sespie
493*c87b03e5Sespie /* Gujarati */
494*c87b03e5Sespie if ((c >= 0x0a85 && c <= 0x0a8b)
495*c87b03e5Sespie || (c == 0x0a8d)
496*c87b03e5Sespie || (c >= 0x0a8f && c <= 0x0a91)
497*c87b03e5Sespie || (c >= 0x0a93 && c <= 0x0aa8)
498*c87b03e5Sespie || (c >= 0x0aaa && c <= 0x0ab0)
499*c87b03e5Sespie || (c >= 0x0ab2 && c <= 0x0ab3)
500*c87b03e5Sespie || (c >= 0x0ab5 && c <= 0x0ab9)
501*c87b03e5Sespie || (c == 0x0ae0))
502*c87b03e5Sespie return 1;
503*c87b03e5Sespie
504*c87b03e5Sespie /* Oriya */
505*c87b03e5Sespie if ((c >= 0x0b05 && c <= 0x0b0c)
506*c87b03e5Sespie || (c >= 0x0b0f && c <= 0x0b10)
507*c87b03e5Sespie || (c >= 0x0b13 && c <= 0x0b28)
508*c87b03e5Sespie || (c >= 0x0b2a && c <= 0x0b30)
509*c87b03e5Sespie || (c >= 0x0b32 && c <= 0x0b33)
510*c87b03e5Sespie || (c >= 0x0b36 && c <= 0x0b39)
511*c87b03e5Sespie || (c >= 0x0b5c && c <= 0x0b5d)
512*c87b03e5Sespie || (c >= 0x0b5f && c <= 0x0b61))
513*c87b03e5Sespie return 1;
514*c87b03e5Sespie
515*c87b03e5Sespie /* Tamil */
516*c87b03e5Sespie if ((c >= 0x0b85 && c <= 0x0b8a)
517*c87b03e5Sespie || (c >= 0x0b8e && c <= 0x0b90)
518*c87b03e5Sespie || (c >= 0x0b92 && c <= 0x0b95)
519*c87b03e5Sespie || (c >= 0x0b99 && c <= 0x0b9a)
520*c87b03e5Sespie || (c == 0x0b9c)
521*c87b03e5Sespie || (c >= 0x0b9e && c <= 0x0b9f)
522*c87b03e5Sespie || (c >= 0x0ba3 && c <= 0x0ba4)
523*c87b03e5Sespie || (c >= 0x0ba8 && c <= 0x0baa)
524*c87b03e5Sespie || (c >= 0x0bae && c <= 0x0bb5)
525*c87b03e5Sespie || (c >= 0x0bb7 && c <= 0x0bb9))
526*c87b03e5Sespie return 1;
527*c87b03e5Sespie
528*c87b03e5Sespie /* Telugu */
529*c87b03e5Sespie if ((c >= 0x0c05 && c <= 0x0c0c)
530*c87b03e5Sespie || (c >= 0x0c0e && c <= 0x0c10)
531*c87b03e5Sespie || (c >= 0x0c12 && c <= 0x0c28)
532*c87b03e5Sespie || (c >= 0x0c2a && c <= 0x0c33)
533*c87b03e5Sespie || (c >= 0x0c35 && c <= 0x0c39)
534*c87b03e5Sespie || (c >= 0x0c60 && c <= 0x0c61))
535*c87b03e5Sespie return 1;
536*c87b03e5Sespie
537*c87b03e5Sespie /* Kannada */
538*c87b03e5Sespie if ((c >= 0x0c85 && c <= 0x0c8c)
539*c87b03e5Sespie || (c >= 0x0c8e && c <= 0x0c90)
540*c87b03e5Sespie || (c >= 0x0c92 && c <= 0x0ca8)
541*c87b03e5Sespie || (c >= 0x0caa && c <= 0x0cb3)
542*c87b03e5Sespie || (c >= 0x0cb5 && c <= 0x0cb9)
543*c87b03e5Sespie || (c >= 0x0ce0 && c <= 0x0ce1))
544*c87b03e5Sespie return 1;
545*c87b03e5Sespie
546*c87b03e5Sespie /* Malayalam */
547*c87b03e5Sespie if ((c >= 0x0d05 && c <= 0x0d0c)
548*c87b03e5Sespie || (c >= 0x0d0e && c <= 0x0d10)
549*c87b03e5Sespie || (c >= 0x0d12 && c <= 0x0d28)
550*c87b03e5Sespie || (c >= 0x0d2a && c <= 0x0d39)
551*c87b03e5Sespie || (c >= 0x0d60 && c <= 0x0d61))
552*c87b03e5Sespie return 1;
553*c87b03e5Sespie
554*c87b03e5Sespie /* Thai */
555*c87b03e5Sespie if ((c >= 0x0e01 && c <= 0x0e30)
556*c87b03e5Sespie || (c >= 0x0e32 && c <= 0x0e33)
557*c87b03e5Sespie || (c >= 0x0e40 && c <= 0x0e46)
558*c87b03e5Sespie || (c >= 0x0e4f && c <= 0x0e5b))
559*c87b03e5Sespie return 1;
560*c87b03e5Sespie
561*c87b03e5Sespie /* Lao */
562*c87b03e5Sespie if ((c >= 0x0e81 && c <= 0x0e82)
563*c87b03e5Sespie || (c == 0x0e84)
564*c87b03e5Sespie || (c == 0x0e87)
565*c87b03e5Sespie || (c == 0x0e88)
566*c87b03e5Sespie || (c == 0x0e8a)
567*c87b03e5Sespie || (c == 0x0e0d)
568*c87b03e5Sespie || (c >= 0x0e94 && c <= 0x0e97)
569*c87b03e5Sespie || (c >= 0x0e99 && c <= 0x0e9f)
570*c87b03e5Sespie || (c >= 0x0ea1 && c <= 0x0ea3)
571*c87b03e5Sespie || (c == 0x0ea5)
572*c87b03e5Sespie || (c == 0x0ea7)
573*c87b03e5Sespie || (c == 0x0eaa)
574*c87b03e5Sespie || (c == 0x0eab)
575*c87b03e5Sespie || (c >= 0x0ead && c <= 0x0eb0)
576*c87b03e5Sespie || (c == 0x0eb2)
577*c87b03e5Sespie || (c == 0x0eb3)
578*c87b03e5Sespie || (c == 0x0ebd)
579*c87b03e5Sespie || (c >= 0x0ec0 && c <= 0x0ec4)
580*c87b03e5Sespie || (c == 0x0ec6))
581*c87b03e5Sespie return 1;
582*c87b03e5Sespie
583*c87b03e5Sespie /* Georgian */
584*c87b03e5Sespie if ((c >= 0x10a0 && c <= 0x10c5)
585*c87b03e5Sespie || (c >= 0x10d0 && c <= 0x10f6))
586*c87b03e5Sespie return 1;
587*c87b03e5Sespie
588*c87b03e5Sespie /* Hiragana */
589*c87b03e5Sespie if ((c >= 0x3041 && c <= 0x3094)
590*c87b03e5Sespie || (c >= 0x309b && c <= 0x309e))
591*c87b03e5Sespie return 1;
592*c87b03e5Sespie
593*c87b03e5Sespie /* Katakana */
594*c87b03e5Sespie if ((c >= 0x30a1 && c <= 0x30fe))
595*c87b03e5Sespie return 1;
596*c87b03e5Sespie
597*c87b03e5Sespie /* Bopmofo */
598*c87b03e5Sespie if ((c >= 0x3105 && c <= 0x312c))
599*c87b03e5Sespie return 1;
600*c87b03e5Sespie
601*c87b03e5Sespie /* Hangul */
602*c87b03e5Sespie if ((c >= 0x1100 && c <= 0x1159)
603*c87b03e5Sespie || (c >= 0x1161 && c <= 0x11a2)
604*c87b03e5Sespie || (c >= 0x11a8 && c <= 0x11f9))
605*c87b03e5Sespie return 1;
606*c87b03e5Sespie
607*c87b03e5Sespie /* CJK Unified Ideographs */
608*c87b03e5Sespie if ((c >= 0xf900 && c <= 0xfa2d)
609*c87b03e5Sespie || (c >= 0xfb1f && c <= 0xfb36)
610*c87b03e5Sespie || (c >= 0xfb38 && c <= 0xfb3c)
611*c87b03e5Sespie || (c == 0xfb3e)
612*c87b03e5Sespie || (c >= 0xfb40 && c <= 0xfb41)
613*c87b03e5Sespie || (c >= 0xfb42 && c <= 0xfb44)
614*c87b03e5Sespie || (c >= 0xfb46 && c <= 0xfbb1)
615*c87b03e5Sespie || (c >= 0xfbd3 && c <= 0xfd3f)
616*c87b03e5Sespie || (c >= 0xfd50 && c <= 0xfd8f)
617*c87b03e5Sespie || (c >= 0xfd92 && c <= 0xfdc7)
618*c87b03e5Sespie || (c >= 0xfdf0 && c <= 0xfdfb)
619*c87b03e5Sespie || (c >= 0xfe70 && c <= 0xfe72)
620*c87b03e5Sespie || (c == 0xfe74)
621*c87b03e5Sespie || (c >= 0xfe76 && c <= 0xfefc)
622*c87b03e5Sespie || (c >= 0xff21 && c <= 0xff3a)
623*c87b03e5Sespie || (c >= 0xff41 && c <= 0xff5a)
624*c87b03e5Sespie || (c >= 0xff66 && c <= 0xffbe)
625*c87b03e5Sespie || (c >= 0xffc2 && c <= 0xffc7)
626*c87b03e5Sespie || (c >= 0xffca && c <= 0xffcf)
627*c87b03e5Sespie || (c >= 0xffd2 && c <= 0xffd7)
628*c87b03e5Sespie || (c >= 0xffda && c <= 0xffdc)
629*c87b03e5Sespie || (c >= 0x4e00 && c <= 0x9fa5))
630*c87b03e5Sespie return 1;
631*c87b03e5Sespie
632*c87b03e5Sespie error ("universal-character-name '\\u%04x' not valid in identifier", c);
633*c87b03e5Sespie return 1;
634*c87b03e5Sespie #endif
635*c87b03e5Sespie }
636*c87b03e5Sespie
637*c87b03e5Sespie /* Add the UTF-8 representation of C to the token_buffer. */
638*c87b03e5Sespie
639*c87b03e5Sespie static void
640*c87b03e5Sespie utf8_extend_token (c)
641*c87b03e5Sespie int c;
642*c87b03e5Sespie {
643*c87b03e5Sespie int shift, mask;
644*c87b03e5Sespie
645*c87b03e5Sespie if (c <= 0x0000007f)
646*c87b03e5Sespie {
647*c87b03e5Sespie extend_token (c);
648*c87b03e5Sespie return;
649*c87b03e5Sespie }
650*c87b03e5Sespie else if (c <= 0x000007ff)
651*c87b03e5Sespie shift = 6, mask = 0xc0;
652*c87b03e5Sespie else if (c <= 0x0000ffff)
653*c87b03e5Sespie shift = 12, mask = 0xe0;
654*c87b03e5Sespie else if (c <= 0x001fffff)
655*c87b03e5Sespie shift = 18, mask = 0xf0;
656*c87b03e5Sespie else if (c <= 0x03ffffff)
657*c87b03e5Sespie shift = 24, mask = 0xf8;
658*c87b03e5Sespie else
659*c87b03e5Sespie shift = 30, mask = 0xfc;
660*c87b03e5Sespie
661*c87b03e5Sespie extend_token (mask | (c >> shift));
662*c87b03e5Sespie do
663*c87b03e5Sespie {
664*c87b03e5Sespie shift -= 6;
665*c87b03e5Sespie extend_token ((unsigned char) (0x80 | (c >> shift)));
666*c87b03e5Sespie }
667*c87b03e5Sespie while (shift);
668*c87b03e5Sespie }
669*c87b03e5Sespie #endif
670*c87b03e5Sespie
671*c87b03e5Sespie int
c_lex(value)672*c87b03e5Sespie c_lex (value)
673*c87b03e5Sespie tree *value;
674*c87b03e5Sespie {
675*c87b03e5Sespie const cpp_token *tok;
676*c87b03e5Sespie
677*c87b03e5Sespie retry:
678*c87b03e5Sespie timevar_push (TV_CPP);
679*c87b03e5Sespie do
680*c87b03e5Sespie tok = cpp_get_token (parse_in);
681*c87b03e5Sespie while (tok->type == CPP_PADDING);
682*c87b03e5Sespie timevar_pop (TV_CPP);
683*c87b03e5Sespie
684*c87b03e5Sespie /* The C++ front end does horrible things with the current line
685*c87b03e5Sespie number. To ensure an accurate line number, we must reset it
686*c87b03e5Sespie every time we return a token. */
687*c87b03e5Sespie lineno = src_lineno;
688*c87b03e5Sespie
689*c87b03e5Sespie *value = NULL_TREE;
690*c87b03e5Sespie switch (tok->type)
691*c87b03e5Sespie {
692*c87b03e5Sespie /* Issue this error here, where we can get at tok->val.c. */
693*c87b03e5Sespie case CPP_OTHER:
694*c87b03e5Sespie if (ISGRAPH (tok->val.c))
695*c87b03e5Sespie error ("stray '%c' in program", tok->val.c);
696*c87b03e5Sespie else
697*c87b03e5Sespie error ("stray '\\%o' in program", tok->val.c);
698*c87b03e5Sespie goto retry;
699*c87b03e5Sespie
700*c87b03e5Sespie case CPP_NAME:
701*c87b03e5Sespie *value = HT_IDENT_TO_GCC_IDENT (HT_NODE (tok->val.node));
702*c87b03e5Sespie break;
703*c87b03e5Sespie
704*c87b03e5Sespie case CPP_NUMBER:
705*c87b03e5Sespie {
706*c87b03e5Sespie unsigned int flags = cpp_classify_number (parse_in, tok);
707*c87b03e5Sespie
708*c87b03e5Sespie switch (flags & CPP_N_CATEGORY)
709*c87b03e5Sespie {
710*c87b03e5Sespie case CPP_N_INVALID:
711*c87b03e5Sespie /* cpplib has issued an error. */
712*c87b03e5Sespie *value = error_mark_node;
713*c87b03e5Sespie break;
714*c87b03e5Sespie
715*c87b03e5Sespie case CPP_N_INTEGER:
716*c87b03e5Sespie *value = interpret_integer (tok, flags);
717*c87b03e5Sespie break;
718*c87b03e5Sespie
719*c87b03e5Sespie case CPP_N_FLOATING:
720*c87b03e5Sespie *value = interpret_float (tok, flags);
721*c87b03e5Sespie break;
722*c87b03e5Sespie
723*c87b03e5Sespie default:
724*c87b03e5Sespie abort ();
725*c87b03e5Sespie }
726*c87b03e5Sespie }
727*c87b03e5Sespie break;
728*c87b03e5Sespie
729*c87b03e5Sespie case CPP_CHAR:
730*c87b03e5Sespie case CPP_WCHAR:
731*c87b03e5Sespie *value = lex_charconst (tok);
732*c87b03e5Sespie break;
733*c87b03e5Sespie
734*c87b03e5Sespie case CPP_STRING:
735*c87b03e5Sespie case CPP_WSTRING:
736*c87b03e5Sespie *value = lex_string (tok->val.str.text, tok->val.str.len,
737*c87b03e5Sespie tok->type == CPP_WSTRING);
738*c87b03e5Sespie break;
739*c87b03e5Sespie
740*c87b03e5Sespie /* These tokens should not be visible outside cpplib. */
741*c87b03e5Sespie case CPP_HEADER_NAME:
742*c87b03e5Sespie case CPP_COMMENT:
743*c87b03e5Sespie case CPP_MACRO_ARG:
744*c87b03e5Sespie abort ();
745*c87b03e5Sespie
746*c87b03e5Sespie default: break;
747*c87b03e5Sespie }
748*c87b03e5Sespie
749*c87b03e5Sespie return tok->type;
750*c87b03e5Sespie }
751*c87b03e5Sespie
752*c87b03e5Sespie /* Returns the narrowest C-visible unsigned type, starting with the
753*c87b03e5Sespie minimum specified by FLAGS, that can fit VALUE, or itk_none if
754*c87b03e5Sespie there isn't one. */
755*c87b03e5Sespie static enum integer_type_kind
narrowest_unsigned_type(value,flags)756*c87b03e5Sespie narrowest_unsigned_type (value, flags)
757*c87b03e5Sespie tree value;
758*c87b03e5Sespie unsigned int flags;
759*c87b03e5Sespie {
760*c87b03e5Sespie enum integer_type_kind itk;
761*c87b03e5Sespie
762*c87b03e5Sespie if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
763*c87b03e5Sespie itk = itk_unsigned_int;
764*c87b03e5Sespie else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
765*c87b03e5Sespie itk = itk_unsigned_long;
766*c87b03e5Sespie else
767*c87b03e5Sespie itk = itk_unsigned_long_long;
768*c87b03e5Sespie
769*c87b03e5Sespie /* int_fits_type_p must think the type of its first argument is
770*c87b03e5Sespie wider than its second argument, or it won't do the proper check. */
771*c87b03e5Sespie TREE_TYPE (value) = widest_unsigned_literal_type_node;
772*c87b03e5Sespie
773*c87b03e5Sespie for (; itk < itk_none; itk += 2 /* skip unsigned types */)
774*c87b03e5Sespie if (int_fits_type_p (value, integer_types[itk]))
775*c87b03e5Sespie return itk;
776*c87b03e5Sespie
777*c87b03e5Sespie return itk_none;
778*c87b03e5Sespie }
779*c87b03e5Sespie
780*c87b03e5Sespie /* Ditto, but narrowest signed type. */
781*c87b03e5Sespie static enum integer_type_kind
narrowest_signed_type(value,flags)782*c87b03e5Sespie narrowest_signed_type (value, flags)
783*c87b03e5Sespie tree value;
784*c87b03e5Sespie unsigned int flags;
785*c87b03e5Sespie {
786*c87b03e5Sespie enum integer_type_kind itk;
787*c87b03e5Sespie
788*c87b03e5Sespie if ((flags & CPP_N_WIDTH) == CPP_N_SMALL)
789*c87b03e5Sespie itk = itk_int;
790*c87b03e5Sespie else if ((flags & CPP_N_WIDTH) == CPP_N_MEDIUM)
791*c87b03e5Sespie itk = itk_long;
792*c87b03e5Sespie else
793*c87b03e5Sespie itk = itk_long_long;
794*c87b03e5Sespie
795*c87b03e5Sespie /* int_fits_type_p must think the type of its first argument is
796*c87b03e5Sespie wider than its second argument, or it won't do the proper check. */
797*c87b03e5Sespie TREE_TYPE (value) = widest_unsigned_literal_type_node;
798*c87b03e5Sespie
799*c87b03e5Sespie for (; itk < itk_none; itk += 2 /* skip signed types */)
800*c87b03e5Sespie if (int_fits_type_p (value, integer_types[itk]))
801*c87b03e5Sespie return itk;
802*c87b03e5Sespie
803*c87b03e5Sespie return itk_none;
804*c87b03e5Sespie }
805*c87b03e5Sespie
806*c87b03e5Sespie /* Interpret TOKEN, an integer with FLAGS as classified by cpplib. */
807*c87b03e5Sespie static tree
interpret_integer(token,flags)808*c87b03e5Sespie interpret_integer (token, flags)
809*c87b03e5Sespie const cpp_token *token;
810*c87b03e5Sespie unsigned int flags;
811*c87b03e5Sespie {
812*c87b03e5Sespie tree value, type;
813*c87b03e5Sespie enum integer_type_kind itk;
814*c87b03e5Sespie cpp_num integer;
815*c87b03e5Sespie cpp_options *options = cpp_get_options (parse_in);
816*c87b03e5Sespie
817*c87b03e5Sespie integer = cpp_interpret_integer (parse_in, token, flags);
818*c87b03e5Sespie integer = cpp_num_sign_extend (integer, options->precision);
819*c87b03e5Sespie value = build_int_2_wide (integer.low, integer.high);
820*c87b03e5Sespie
821*c87b03e5Sespie /* The type of a constant with a U suffix is straightforward. */
822*c87b03e5Sespie if (flags & CPP_N_UNSIGNED)
823*c87b03e5Sespie itk = narrowest_unsigned_type (value, flags);
824*c87b03e5Sespie else
825*c87b03e5Sespie {
826*c87b03e5Sespie /* The type of a potentially-signed integer constant varies
827*c87b03e5Sespie depending on the base it's in, the standard in use, and the
828*c87b03e5Sespie length suffixes. */
829*c87b03e5Sespie enum integer_type_kind itk_u = narrowest_unsigned_type (value, flags);
830*c87b03e5Sespie enum integer_type_kind itk_s = narrowest_signed_type (value, flags);
831*c87b03e5Sespie
832*c87b03e5Sespie /* In both C89 and C99, octal and hex constants may be signed or
833*c87b03e5Sespie unsigned, whichever fits tighter. We do not warn about this
834*c87b03e5Sespie choice differing from the traditional choice, as the constant
835*c87b03e5Sespie is probably a bit pattern and either way will work. */
836*c87b03e5Sespie if ((flags & CPP_N_RADIX) != CPP_N_DECIMAL)
837*c87b03e5Sespie itk = MIN (itk_u, itk_s);
838*c87b03e5Sespie else
839*c87b03e5Sespie {
840*c87b03e5Sespie /* In C99, decimal constants are always signed.
841*c87b03e5Sespie In C89, decimal constants that don't fit in long have
842*c87b03e5Sespie undefined behavior; we try to make them unsigned long.
843*c87b03e5Sespie In GCC's extended C89, that last is true of decimal
844*c87b03e5Sespie constants that don't fit in long long, too. */
845*c87b03e5Sespie
846*c87b03e5Sespie itk = itk_s;
847*c87b03e5Sespie if (itk_s > itk_u && itk_s > itk_long)
848*c87b03e5Sespie {
849*c87b03e5Sespie if (!flag_isoc99)
850*c87b03e5Sespie {
851*c87b03e5Sespie if (itk_u < itk_unsigned_long)
852*c87b03e5Sespie itk_u = itk_unsigned_long;
853*c87b03e5Sespie itk = itk_u;
854*c87b03e5Sespie warning ("this decimal constant is unsigned only in ISO C90");
855*c87b03e5Sespie }
856*c87b03e5Sespie else if (warn_traditional)
857*c87b03e5Sespie warning ("this decimal constant would be unsigned in ISO C90");
858*c87b03e5Sespie }
859*c87b03e5Sespie }
860*c87b03e5Sespie }
861*c87b03e5Sespie
862*c87b03e5Sespie if (itk == itk_none)
863*c87b03e5Sespie /* cpplib has already issued a warning for overflow. */
864*c87b03e5Sespie type = ((flags & CPP_N_UNSIGNED)
865*c87b03e5Sespie ? widest_unsigned_literal_type_node
866*c87b03e5Sespie : widest_integer_literal_type_node);
867*c87b03e5Sespie else
868*c87b03e5Sespie type = integer_types[itk];
869*c87b03e5Sespie
870*c87b03e5Sespie if (itk > itk_unsigned_long
871*c87b03e5Sespie && (flags & CPP_N_WIDTH) != CPP_N_LARGE
872*c87b03e5Sespie && ! in_system_header && ! flag_isoc99)
873*c87b03e5Sespie pedwarn ("integer constant is too large for \"%s\" type",
874*c87b03e5Sespie (flags & CPP_N_UNSIGNED) ? "unsigned long" : "long");
875*c87b03e5Sespie
876*c87b03e5Sespie TREE_TYPE (value) = type;
877*c87b03e5Sespie
878*c87b03e5Sespie /* Convert imaginary to a complex type. */
879*c87b03e5Sespie if (flags & CPP_N_IMAGINARY)
880*c87b03e5Sespie value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);
881*c87b03e5Sespie
882*c87b03e5Sespie return value;
883*c87b03e5Sespie }
884*c87b03e5Sespie
885*c87b03e5Sespie /* Interpret TOKEN, a floating point number with FLAGS as classified
886*c87b03e5Sespie by cpplib. */
887*c87b03e5Sespie static tree
interpret_float(token,flags)888*c87b03e5Sespie interpret_float (token, flags)
889*c87b03e5Sespie const cpp_token *token;
890*c87b03e5Sespie unsigned int flags;
891*c87b03e5Sespie {
892*c87b03e5Sespie tree type;
893*c87b03e5Sespie tree value;
894*c87b03e5Sespie REAL_VALUE_TYPE real;
895*c87b03e5Sespie char *copy;
896*c87b03e5Sespie size_t copylen;
897*c87b03e5Sespie const char *typename;
898*c87b03e5Sespie
899*c87b03e5Sespie /* FIXME: make %T work in error/warning, then we don't need typename. */
900*c87b03e5Sespie if ((flags & CPP_N_WIDTH) == CPP_N_LARGE)
901*c87b03e5Sespie {
902*c87b03e5Sespie type = long_double_type_node;
903*c87b03e5Sespie typename = "long double";
904*c87b03e5Sespie }
905*c87b03e5Sespie else if ((flags & CPP_N_WIDTH) == CPP_N_SMALL
906*c87b03e5Sespie || flag_single_precision_constant)
907*c87b03e5Sespie {
908*c87b03e5Sespie type = float_type_node;
909*c87b03e5Sespie typename = "float";
910*c87b03e5Sespie }
911*c87b03e5Sespie else
912*c87b03e5Sespie {
913*c87b03e5Sespie type = double_type_node;
914*c87b03e5Sespie typename = "double";
915*c87b03e5Sespie }
916*c87b03e5Sespie
917*c87b03e5Sespie /* Copy the constant to a nul-terminated buffer. If the constant
918*c87b03e5Sespie has any suffixes, cut them off; REAL_VALUE_ATOF/ REAL_VALUE_HTOF
919*c87b03e5Sespie can't handle them. */
920*c87b03e5Sespie copylen = token->val.str.len;
921*c87b03e5Sespie if ((flags & CPP_N_WIDTH) != CPP_N_MEDIUM)
922*c87b03e5Sespie /* Must be an F or L suffix. */
923*c87b03e5Sespie copylen--;
924*c87b03e5Sespie if (flags & CPP_N_IMAGINARY)
925*c87b03e5Sespie /* I or J suffix. */
926*c87b03e5Sespie copylen--;
927*c87b03e5Sespie
928*c87b03e5Sespie copy = alloca (copylen + 1);
929*c87b03e5Sespie memcpy (copy, token->val.str.text, copylen);
930*c87b03e5Sespie copy[copylen] = '\0';
931*c87b03e5Sespie
932*c87b03e5Sespie real_from_string (&real, copy);
933*c87b03e5Sespie real_convert (&real, TYPE_MODE (type), &real);
934*c87b03e5Sespie
935*c87b03e5Sespie /* A diagnostic is required for "soft" overflow by some ISO C
936*c87b03e5Sespie testsuites. This is not pedwarn, because some people don't want
937*c87b03e5Sespie an error for this.
938*c87b03e5Sespie ??? That's a dubious reason... is this a mandatory diagnostic or
939*c87b03e5Sespie isn't it? -- zw, 2001-08-21. */
940*c87b03e5Sespie if (REAL_VALUE_ISINF (real) && pedantic)
941*c87b03e5Sespie warning ("floating constant exceeds range of \"%s\"", typename);
942*c87b03e5Sespie
943*c87b03e5Sespie /* Create a node with determined type and value. */
944*c87b03e5Sespie value = build_real (type, real);
945*c87b03e5Sespie if (flags & CPP_N_IMAGINARY)
946*c87b03e5Sespie value = build_complex (NULL_TREE, convert (type, integer_zero_node), value);
947*c87b03e5Sespie
948*c87b03e5Sespie return value;
949*c87b03e5Sespie }
950*c87b03e5Sespie
951*c87b03e5Sespie static tree
lex_string(str,len,wide)952*c87b03e5Sespie lex_string (str, len, wide)
953*c87b03e5Sespie const unsigned char *str;
954*c87b03e5Sespie unsigned int len;
955*c87b03e5Sespie int wide;
956*c87b03e5Sespie {
957*c87b03e5Sespie tree value;
958*c87b03e5Sespie char *buf = alloca ((len + 1) * (wide ? WCHAR_BYTES : 1));
959*c87b03e5Sespie char *q = buf;
960*c87b03e5Sespie const unsigned char *p = str, *limit = str + len;
961*c87b03e5Sespie cppchar_t c;
962*c87b03e5Sespie
963*c87b03e5Sespie #ifdef MULTIBYTE_CHARS
964*c87b03e5Sespie /* Reset multibyte conversion state. */
965*c87b03e5Sespie (void) local_mbtowc (NULL, NULL, 0);
966*c87b03e5Sespie #endif
967*c87b03e5Sespie
968*c87b03e5Sespie while (p < limit)
969*c87b03e5Sespie {
970*c87b03e5Sespie #ifdef MULTIBYTE_CHARS
971*c87b03e5Sespie wchar_t wc;
972*c87b03e5Sespie int char_len;
973*c87b03e5Sespie
974*c87b03e5Sespie char_len = local_mbtowc (&wc, (const char *) p, limit - p);
975*c87b03e5Sespie if (char_len == -1)
976*c87b03e5Sespie {
977*c87b03e5Sespie warning ("ignoring invalid multibyte character");
978*c87b03e5Sespie char_len = 1;
979*c87b03e5Sespie c = *p++;
980*c87b03e5Sespie }
981*c87b03e5Sespie else
982*c87b03e5Sespie {
983*c87b03e5Sespie p += char_len;
984*c87b03e5Sespie c = wc;
985*c87b03e5Sespie }
986*c87b03e5Sespie #else
987*c87b03e5Sespie c = *p++;
988*c87b03e5Sespie #endif
989*c87b03e5Sespie
990*c87b03e5Sespie if (c == '\\' && !ignore_escape_flag)
991*c87b03e5Sespie c = cpp_parse_escape (parse_in, &p, limit, wide);
992*c87b03e5Sespie
993*c87b03e5Sespie /* Add this single character into the buffer either as a wchar_t,
994*c87b03e5Sespie a multibyte sequence, or as a single byte. */
995*c87b03e5Sespie if (wide)
996*c87b03e5Sespie {
997*c87b03e5Sespie unsigned charwidth = TYPE_PRECISION (char_type_node);
998*c87b03e5Sespie unsigned bytemask = (1 << charwidth) - 1;
999*c87b03e5Sespie int byte;
1000*c87b03e5Sespie
1001*c87b03e5Sespie for (byte = 0; byte < WCHAR_BYTES; ++byte)
1002*c87b03e5Sespie {
1003*c87b03e5Sespie int n;
1004*c87b03e5Sespie if (byte >= (int) sizeof (c))
1005*c87b03e5Sespie n = 0;
1006*c87b03e5Sespie else
1007*c87b03e5Sespie n = (c >> (byte * charwidth)) & bytemask;
1008*c87b03e5Sespie if (BYTES_BIG_ENDIAN)
1009*c87b03e5Sespie q[WCHAR_BYTES - byte - 1] = n;
1010*c87b03e5Sespie else
1011*c87b03e5Sespie q[byte] = n;
1012*c87b03e5Sespie }
1013*c87b03e5Sespie q += WCHAR_BYTES;
1014*c87b03e5Sespie }
1015*c87b03e5Sespie #ifdef MULTIBYTE_CHARS
1016*c87b03e5Sespie else if (char_len > 1)
1017*c87b03e5Sespie {
1018*c87b03e5Sespie /* We're dealing with a multibyte character. */
1019*c87b03e5Sespie for ( ; char_len >0; --char_len)
1020*c87b03e5Sespie {
1021*c87b03e5Sespie *q++ = *(p - char_len);
1022*c87b03e5Sespie }
1023*c87b03e5Sespie }
1024*c87b03e5Sespie #endif
1025*c87b03e5Sespie else
1026*c87b03e5Sespie {
1027*c87b03e5Sespie *q++ = c;
1028*c87b03e5Sespie }
1029*c87b03e5Sespie }
1030*c87b03e5Sespie
1031*c87b03e5Sespie /* Terminate the string value, either with a single byte zero
1032*c87b03e5Sespie or with a wide zero. */
1033*c87b03e5Sespie
1034*c87b03e5Sespie if (wide)
1035*c87b03e5Sespie {
1036*c87b03e5Sespie memset (q, 0, WCHAR_BYTES);
1037*c87b03e5Sespie q += WCHAR_BYTES;
1038*c87b03e5Sespie }
1039*c87b03e5Sespie else
1040*c87b03e5Sespie {
1041*c87b03e5Sespie *q++ = '\0';
1042*c87b03e5Sespie }
1043*c87b03e5Sespie
1044*c87b03e5Sespie value = build_string (q - buf, buf);
1045*c87b03e5Sespie
1046*c87b03e5Sespie if (wide)
1047*c87b03e5Sespie TREE_TYPE (value) = wchar_array_type_node;
1048*c87b03e5Sespie else
1049*c87b03e5Sespie TREE_TYPE (value) = char_array_type_node;
1050*c87b03e5Sespie return value;
1051*c87b03e5Sespie }
1052*c87b03e5Sespie
1053*c87b03e5Sespie /* Converts a (possibly wide) character constant token into a tree. */
1054*c87b03e5Sespie static tree
lex_charconst(token)1055*c87b03e5Sespie lex_charconst (token)
1056*c87b03e5Sespie const cpp_token *token;
1057*c87b03e5Sespie {
1058*c87b03e5Sespie cppchar_t result;
1059*c87b03e5Sespie tree type, value;
1060*c87b03e5Sespie unsigned int chars_seen;
1061*c87b03e5Sespie int unsignedp;
1062*c87b03e5Sespie
1063*c87b03e5Sespie result = cpp_interpret_charconst (parse_in, token,
1064*c87b03e5Sespie &chars_seen, &unsignedp);
1065*c87b03e5Sespie
1066*c87b03e5Sespie /* Cast to cppchar_signed_t to get correct sign-extension of RESULT
1067*c87b03e5Sespie before possibly widening to HOST_WIDE_INT for build_int_2. */
1068*c87b03e5Sespie if (unsignedp || (cppchar_signed_t) result >= 0)
1069*c87b03e5Sespie value = build_int_2 (result, 0);
1070*c87b03e5Sespie else
1071*c87b03e5Sespie value = build_int_2 ((cppchar_signed_t) result, -1);
1072*c87b03e5Sespie
1073*c87b03e5Sespie if (token->type == CPP_WCHAR)
1074*c87b03e5Sespie type = wchar_type_node;
1075*c87b03e5Sespie /* In C, a character constant has type 'int'.
1076*c87b03e5Sespie In C++ 'char', but multi-char charconsts have type 'int'. */
1077*c87b03e5Sespie else if ((c_language == clk_c) || chars_seen > 1)
1078*c87b03e5Sespie type = integer_type_node;
1079*c87b03e5Sespie else
1080*c87b03e5Sespie type = char_type_node;
1081*c87b03e5Sespie
1082*c87b03e5Sespie TREE_TYPE (value) = type;
1083*c87b03e5Sespie return value;
1084*c87b03e5Sespie }
1085