1 /* Lexical analyzer for GNU CHILL. -*- C -*-
2 Copyright (C) 1992, 93, 1994, 1998 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/types.h>
37 #ifdef MULTIBYTE_CHARS
42 /* include the keyword recognizers */
49 static int last_token = 0;
50 /* Sun's C compiler warns about the safer sequence
52 when there's a 'return' inside the braces, so don't use it */
53 #define RETURN_TOKEN(X) { last_token = X; return (X); }
55 /* This is set non-zero to force incoming tokens to lowercase. */
56 extern int ignore_case;
58 extern int module_number;
59 extern int serious_errors;
61 /* This is non-zero to recognize only uppercase special words. */
62 extern int special_UC;
64 extern struct obstack permanent_obstack;
65 extern struct obstack temporary_obstack;
71 extern tree build_string_type PROTO((tree, tree));
72 extern void error PROTO((char *, ...));
73 extern void error_with_file_and_line PROTO((char *, int, char *, ...));
74 extern void grant_use_seizefile PROTO((char *));
75 extern void pedwarn PROTO((char *, ...));
76 extern void pfatal_with_name PROTO((char *));
77 extern void push_obstacks PROTO((struct obstack *, struct obstack *));
78 extern void set_identifier_size PROTO((int));
79 extern void sorry PROTO((char *, ...));
80 extern int target_isinf PROTO((REAL_VALUE_TYPE));
81 extern int tolower PROTO((int));
82 extern void warning PROTO((char *, ...));
84 /* forward declarations */
85 static void close_input_file PROTO((char *));
86 static tree convert_bitstring PROTO((char *));
87 static tree convert_integer PROTO((char *));
88 static void maybe_downcase PROTO((char *));
89 static int maybe_number PROTO((char *));
90 static tree equal_number PROTO((void));
91 static void handle_use_seizefile_directive PROTO((int));
92 static int handle_name PROTO((tree));
93 static void push_back PROTO((int));
94 static char *readstring PROTO((int, int *));
95 static void read_directive PROTO((void));
96 static tree read_identifier PROTO((int));
97 static tree read_number PROTO((int));
98 static void skip_c_comment PROTO((void));
99 static void skip_line_comment PROTO((void));
100 static int skip_whitespace PROTO((void));
101 static tree string_or_char PROTO((int, char *));
103 /* next variables are public, because ch-actions uses them */
105 /* the default grantfile name, set by lang_init */
106 tree default_grant_file = 0;
108 /* These tasking-related variables are NULL at the start of each
109 compiler pass, and are set to an expression tree if and when
110 a compiler directive is parsed containing an expression.
111 The NULL state is significant; it means 'no user-specified
112 signal_code (or whatever) has been parsed'. */
114 /* process type, set by <> PROCESS_TYPE = number <> */
115 tree process_type = NULL_TREE;
117 /* send buffer default priority,
118 set by <> SEND_BUFFER_DEFAULT_PRIORITY = number <> */
119 tree send_buffer_prio = NULL_TREE;
121 /* send signal default priority,
122 set by <> SEND_SIGNAL_DEFAULT_PRIORITY = number <> */
123 tree send_signal_prio = NULL_TREE;
125 /* signal code, set by <> SIGNAL_CODE = number <> */
126 tree signal_code = NULL_TREE;
128 /* flag for range checking */
129 int range_checking = 1;
131 /* flag for NULL pointer checking */
132 int empty_checking = 1;
134 /* flag to indicate making all procedure local variables
136 int all_static_flag = 0;
138 /* flag to indicate -fruntime-checking command line option.
139 Needed for initializing range_checking and empty_checking
141 int runtime_checking_flag = 1;
143 /* The elements of `ridpointers' are identifier nodes
144 for the reserved type names and storage classes.
145 It is indexed by a RID_... value. */
146 tree ridpointers[(int) RID_MAX];
148 /* Nonzero tells yylex to ignore \ in string constants. */
149 static int ignore_escape_flag = 0;
151 static int maxtoken; /* Current nominal length of token buffer. */
152 char *token_buffer; /* Pointer to token buffer.
153 Actual allocated length is maxtoken + 2.
154 This is not static because objc-parse.y uses it. */
156 /* implement yylineno handling for flex */
157 #define yylineno lineno
159 static int inside_c_comment = 0;
161 static int saw_eol = 0; /* 1 if we've just seen a '\n' */
162 static int saw_eof = 0; /* 1 if we've just seen an EOF */
164 typedef struct string_list
166 struct string_list *next;
170 /* list of paths specified on the compiler command line by -L options. */
171 static STRING_LIST *seize_path_list = (STRING_LIST *)0;
173 /* List of seize file names. Each TREE_VALUE is an identifier
174 (file name) from a <>USE_SEIZE_FILE<> directive.
175 The TREE_PURPOSE is non-NULL if a USE_SEIZE_FILE directive has been
176 written to the grant file. */
177 static tree files_to_seize = NULL_TREE;
178 /* Last node on files_to_seize list. */
179 static tree last_file_to_seize = NULL_TREE;
180 /* Pointer into files_to_seize list: Next unparsed file to read. */
181 static tree next_file_to_seize = NULL_TREE;
183 /* The most recent use_seize_file directive. */
184 tree use_seizefile_name = NULL_TREE;
186 /* If non-NULL, the name of the seizefile we're currently processing. */
187 tree current_seizefile_name = NULL_TREE;
189 /* called to reset for pass 2 */
193 current_seizefile_name = NULL_TREE;
199 /* Initialize these compiler-directive variables. */
200 process_type = NULL_TREE;
201 send_buffer_prio = NULL_TREE;
202 send_signal_prio = NULL_TREE;
203 signal_code = NULL_TREE;
205 /* reinitialize rnage checking and empty checking */
206 range_checking = runtime_checking_flag;
207 empty_checking = runtime_checking_flag;
212 init_parse (filename)
215 int lowercase_standard_names = ignore_case || ! special_UC;
217 /* Open input file. */
218 if (filename == 0 || !strcmp (filename, "-"))
224 finput = fopen (filename, "r");
226 pfatal_with_name (filename);
228 #ifdef IO_BUFFER_SIZE
229 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
232 /* Make identifier nodes long enough for the language-specific slots. */
233 set_identifier_size (sizeof (struct lang_identifier));
235 /* Start it at 0, because check_newline is called at the very beginning
236 and will increment it to 1. */
239 /* Initialize these compiler-directive variables. */
240 process_type = NULL_TREE;
241 send_buffer_prio = NULL_TREE;
242 send_signal_prio = NULL_TREE;
243 signal_code = NULL_TREE;
246 token_buffer = xmalloc ((unsigned)(maxtoken + 2));
248 init_chill_expand ();
250 #define ENTER_STANDARD_NAME(RID, LOWER, UPPER) \
251 ridpointers[(int) RID] = \
252 get_identifier (lowercase_standard_names ? LOWER : UPPER)
254 ENTER_STANDARD_NAME (RID_ALL, "all", "ALL");
255 ENTER_STANDARD_NAME (RID_ASSERTFAIL, "assertfail", "ASSERTFAIL");
256 ENTER_STANDARD_NAME (RID_ASSOCIATION, "association", "ASSOCIATION");
257 ENTER_STANDARD_NAME (RID_BIN, "bin", "BIN");
258 ENTER_STANDARD_NAME (RID_BOOL, "bool", "BOOL");
259 ENTER_STANDARD_NAME (RID_BOOLS, "bools", "BOOLS");
260 ENTER_STANDARD_NAME (RID_BYTE, "byte", "BYTE");
261 ENTER_STANDARD_NAME (RID_CHAR, "char", "CHAR");
262 ENTER_STANDARD_NAME (RID_DOUBLE, "double", "DOUBLE");
263 ENTER_STANDARD_NAME (RID_DURATION, "duration", "DURATION");
264 ENTER_STANDARD_NAME (RID_DYNAMIC, "dynamic", "DYNAMIC");
265 ENTER_STANDARD_NAME (RID_ELSE, "else", "ELSE");
266 ENTER_STANDARD_NAME (RID_EMPTY, "empty", "EMPTY");
267 ENTER_STANDARD_NAME (RID_FALSE, "false", "FALSE");
268 ENTER_STANDARD_NAME (RID_FLOAT, "float", "FLOAT");
269 ENTER_STANDARD_NAME (RID_GENERAL, "general", "GENERAL");
270 ENTER_STANDARD_NAME (RID_IN, "in", "IN");
271 ENTER_STANDARD_NAME (RID_INLINE, "inline", "INLINE");
272 ENTER_STANDARD_NAME (RID_INOUT, "inout", "INOUT");
273 ENTER_STANDARD_NAME (RID_INSTANCE, "instance", "INSTANCE");
274 ENTER_STANDARD_NAME (RID_INT, "int", "INT");
275 ENTER_STANDARD_NAME (RID_LOC, "loc", "LOC");
276 ENTER_STANDARD_NAME (RID_LONG, "long", "LONG");
277 ENTER_STANDARD_NAME (RID_LONG_REAL, "long_real", "LONG_REAL");
278 ENTER_STANDARD_NAME (RID_NULL, "null", "NULL");
279 ENTER_STANDARD_NAME (RID_OUT, "out", "OUT");
280 ENTER_STANDARD_NAME (RID_OVERFLOW, "overflow", "OVERFLOW");
281 ENTER_STANDARD_NAME (RID_PTR, "ptr", "PTR");
282 ENTER_STANDARD_NAME (RID_READ, "read", "READ");
283 ENTER_STANDARD_NAME (RID_REAL, "real", "REAL");
284 ENTER_STANDARD_NAME (RID_RANGE, "range", "RANGE");
285 ENTER_STANDARD_NAME (RID_RANGEFAIL, "rangefail", "RANGEFAIL");
286 ENTER_STANDARD_NAME (RID_RECURSIVE, "recursive", "RECURSIVE");
287 ENTER_STANDARD_NAME (RID_SHORT, "short", "SHORT");
288 ENTER_STANDARD_NAME (RID_SIMPLE, "simple", "SIMPLE");
289 ENTER_STANDARD_NAME (RID_TIME, "time", "TIME");
290 ENTER_STANDARD_NAME (RID_TRUE, "true", "TRUE");
291 ENTER_STANDARD_NAME (RID_UBYTE, "ubyte", "UBYTE");
292 ENTER_STANDARD_NAME (RID_UINT, "uint", "UINT");
293 ENTER_STANDARD_NAME (RID_ULONG, "ulong", "ULONG");
294 ENTER_STANDARD_NAME (RID_UNSIGNED, "unsigned", "UNSIGNED");
295 ENTER_STANDARD_NAME (RID_USHORT, "ushort", "USHORT");
296 ENTER_STANDARD_NAME (RID_VOID, "void", "VOID");
308 static int yywrap ();
310 #define YY_PUTBACK_SIZE 5
311 #define YY_BUF_SIZE 1000
313 static char yy_buffer[YY_PUTBACK_SIZE + YY_BUF_SIZE];
314 static char *yy_cur = yy_buffer + YY_PUTBACK_SIZE;
315 static char *yy_lim = yy_buffer + YY_PUTBACK_SIZE;
319 char *buf = yy_buffer + YY_PUTBACK_SIZE;
321 bcopy (yy_cur - YY_PUTBACK_SIZE, yy_buffer, YY_PUTBACK_SIZE);
336 c = check_newline ();
349 while (result < YY_BUF_SIZE)
359 /* Because we might switch input files on a compiler directive
360 (that end with '>', don't read past a '>', just in case. */
369 fprintf (stderr, "-------------------------- finished Line %d\n",
377 yy_lim = yy_cur + result;
379 return yy_lim > yy_cur ? *yy_cur++ : EOF;
382 #define input() (yy_cur < yy_lim ? *yy_cur++ : yy_refill ())
384 #define unput(c) (*--yy_cur = (c))
387 int starting_pass_2 = 0;
407 case ' ': case '\t': case '\n': case '\f': case '\b': case '\v': case '\r':
429 else if (nextc == '=')
445 skip_line_comment ();
458 else if (nextc == '=')
460 else if (nextc == '*')
503 int len = 0; /* Number of hex digits seen. */
511 if (!isxdigit (ch)) /* error on non-hex digit */
514 error ("invalid C'xx' ");
525 if (len & 1) /* collected two digits, save byte */
526 obstack_1grow (&temporary_obstack, (char) byte_val);
529 start = obstack_finish (&temporary_obstack);
530 yylval.ttype = string_or_char (len >> 1, start);
531 obstack_free (&temporary_obstack, start);
532 return len == 2 ? SINGLECHAR : STRING;
542 obstack_1grow (&temporary_obstack, ch);
543 obstack_1grow (&temporary_obstack, nextc);
548 obstack_1grow (&temporary_obstack, ch);
552 obstack_1grow (&temporary_obstack, '\0');
553 start = obstack_finish (&temporary_obstack);
557 yylval.ttype = convert_integer (start); /* Pass base? */
562 yylval.ttype = convert_bitstring (start);
570 case 'F': case 'G': case 'I': case 'J':
571 case 'K': case 'L': case 'M': case 'N':
572 case 'P': case 'Q': case 'R': case 'S': case 'T':
573 case 'U': case 'V': case 'W': case 'X': case 'Y':
576 case 'f': case 'g': case 'i': case 'j':
577 case 'k': case 'l': case 'm': case 'n':
578 case 'p': case 'q': case 'r': case 's': case 't':
579 case 'u': case 'v': case 'w': case 'x': case 'y':
583 return handle_name (read_identifier (ch));
585 tmp = readstring ('\'', &len);
586 yylval.ttype = string_or_char (len, tmp);
588 return len == 1 ? SINGLECHAR : STRING;
590 tmp = readstring ('\"', &len);
591 yylval.ttype = build_chill_string (len, tmp);
597 if (isdigit (nextc)) /* || nextc == '_') we don't start numbers with '_' */
600 case '0': case '1': case '2': case '3': case '4':
601 case '5': case '6': case '7': case '8': case '9':
603 yylval.ttype = read_number (ch);
604 return TREE_CODE (yylval.ttype) == REAL_CST ? FLOATING : NUMBER;
611 close_input_file (fn)
617 if (finput != stdin && fclose (finput) == EOF)
619 error ("can't close %s", fn);
625 /* Return an identifier, starting with FIRST and then reading
626 more characters using input(). Return an IDENTIFIER_NODE. */
629 read_identifier (first)
630 int first; /* First letter of identifier */
636 obstack_1grow (&temporary_obstack, first);
640 if (! isalnum (first) && first != '_')
646 obstack_1grow (&temporary_obstack, '\0');
647 start = obstack_finish (&temporary_obstack);
648 maybe_downcase (start);
649 id = get_identifier (start);
650 obstack_free (&temporary_obstack, start);
654 /* Given an identifier ID, check to see if it is a reserved name,
655 and return the appropriate token type. */
662 tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
664 && special_UC == isupper (tp->name[0])
665 && (tp->flags == RESERVED || tp->flags == PREDEF))
667 if (tp->rid != NORID)
668 yylval.ttype = ridpointers[tp->rid];
669 else if (tp->token == THIS)
670 yylval.ttype = lookup_name (get_identifier ("__whoami"));
679 int ch; /* Initial character */
687 obstack_1grow (&temporary_obstack, ch);
689 if (! isdigit (ch) && ch != '_')
697 obstack_1grow (&temporary_obstack, ch);
699 } while (isdigit (ch) || ch == '_');
702 if (ch == 'd' || ch == 'D' || ch == 'e' || ch == 'E')
704 /* Convert exponent indication [eEdD] to 'e'. */
705 obstack_1grow (&temporary_obstack, 'e');
707 if (ch == '+' || ch == '-')
709 obstack_1grow (&temporary_obstack, ch);
712 if (isdigit (ch) || ch == '_')
717 obstack_1grow (&temporary_obstack, ch);
719 } while (isdigit (ch) || ch == '_');
723 error ("malformed exponent part of floating-point literal");
729 obstack_1grow (&temporary_obstack, '\0');
730 start = obstack_finish (&temporary_obstack);
733 REAL_VALUE_TYPE value;
734 tree type = double_type_node;
736 value = REAL_VALUE_ATOF (start, TYPE_MODE (type));
737 obstack_free (&temporary_obstack, start);
738 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
739 && REAL_VALUE_ISINF (value) && pedantic)
740 pedwarn ("real number exceeds range of REAL");
741 num = build_real (type, value);
744 num = convert_integer (start);
745 CH_DERIVED_FLAG (num) = 1;
749 /* Skip to the end of a compiler directive. */
759 error ("end-of-file in '<>' directive");
775 /* Read a compiler directive. ("<>{WS}" have already been read. ) */
781 int ch = skip_whitespace();
782 if (isalpha (ch) || ch == '_')
783 id = read_identifier (ch);
786 error ("end-of-file in '<>' directive");
787 to_global_binding_level ();
792 warning ("unrecognized compiler directive");
796 tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
797 if (tp == NULL || special_UC != isupper (tp->name[0]))
800 warning ("unrecognized compiler directive `%s'",
801 IDENTIFIER_POINTER (id));
818 case IGNORED_DIRECTIVE:
820 case PROCESS_TYPE_TOKEN:
821 process_type = equal_number ();
829 case SEND_SIGNAL_DEFAULT_PRIORITY:
830 send_signal_prio = equal_number ();
832 case SEND_BUFFER_DEFAULT_PRIORITY:
833 send_buffer_prio = equal_number ();
836 signal_code = equal_number ();
839 handle_use_seizefile_directive (0);
841 case USE_SEIZE_FILE_RESTRICTED:
842 handle_use_seizefile_directive (1);
846 warning ("unrecognized compiler directive `%s'",
847 IDENTIFIER_POINTER (id));
855 build_chill_string (len, str)
861 push_obstacks (&permanent_obstack, &permanent_obstack);
862 t = build_string (len, str);
863 TREE_TYPE (t) = build_string_type (char_type_node,
864 build_int_2 (len, 0));
865 CH_DERIVED_FLAG (t) = 1;
872 string_or_char (len, str)
878 push_obstacks (&permanent_obstack, &permanent_obstack);
881 result = build_int_2 ((unsigned char)str[0], 0);
882 CH_DERIVED_FLAG (result) = 1;
883 TREE_TYPE (result) = char_type_node;
886 result = build_chill_string (len, str);
901 *str = tolower (*str);
913 /* check for decimal number */
914 if (*s >= '0' && *s <= '9')
918 if (*s >= '0' && *s <= '9')
936 if (*s < '0' || *s > '9')
946 if (*s < '0' || *s > '1')
951 if (*s < '0' || *s > '7')
972 readstring (terminator, len)
977 unsigned allocated = 1024;
978 char *tmp = xmalloc (allocated);
986 if ((c = input ()) != terminator)
994 if (c == '\n' || c == EOF)
999 if (c == EOF || c == '\n')
1013 if (cc == terminator)
1015 if (!(terminator == '\'' && next_apos))
1017 error ("unterminated control sequence");
1022 if (cc == EOF || cc == '\n')
1032 error ("invalid integer literal in control sequence");
1038 if (cc == ' ' || cc == '\t')
1042 if ((c < 0 || c > 255) && (pass == 1))
1043 error ("control sequence overflow");
1044 if (! count && pass == 1)
1045 error ("invalid control sequence");
1050 if ((c < 0 || c > 255) && (pass == 1))
1051 error ("control sequence overflow");
1052 if (! count && pass == 1)
1053 error ("invalid control sequence");
1058 tmp = xrealloc (tmp, allocated);
1067 if (! count && pass == 1)
1068 error ("invalid integer literal in control sequence");
1073 if (cc == 'D' || cc == 'd')
1078 else if (cc == 'H' || cc == 'h')
1083 else if (cc == 'O' || cc == 'o')
1088 else if (cc == 'B' || cc == 'b')
1099 if (cc < '0' || cc > '1')
1106 if (cc < '0' || cc > '8')
1111 else if (base == 10)
1118 else if (base == 16)
1133 error ("invalid base in read control sequence");
1138 /* error in control sequence */
1140 error ("invalid digit in control sequence");
1143 c = (c * base) + cc;
1155 tmp = xrealloc (tmp, allocated);
1159 tmp [*len = i] = '\0';
1167 error ("unterminated string literal");
1168 to_global_binding_level ();
1173 /* Convert an integer INTCHARS into an INTEGER_CST.
1174 INTCHARS is on the temporary_obstack, and is popped by this function. */
1177 convert_integer (intchars)
1186 int valid_chars = 0;
1189 HOST_WIDE_INT val_lo = 0, val_hi = 0;
1192 /* determine the base */
1215 if (!isdigit (*p)) /* this test is for equal_number () */
1217 obstack_free (&temporary_obstack, intchars);
1226 if ((tmp == '\'') || (tmp == '_'))
1230 if (tmp >= 'a') /* uppercase the char */
1232 switch (base) /* validate the characters */
1249 if (tmp > '9' && tmp < 'A')
1258 if (mul_double (val_lo, val_hi, base, 0, &val_lo, &val_hi))
1260 add_double (val_lo, val_hi, tmp, 0, &val_lo, &val_hi);
1266 obstack_free (&temporary_obstack, intchars);
1270 error ("invalid number format `%s'", oldp);
1273 val = build_int_2 (val_lo, val_hi);
1274 /* We set the type to long long (or long long unsigned) so that
1275 constant fold of literals is less likely to overflow. */
1276 if (int_fits_type_p (val, long_long_integer_type_node))
1277 type = long_long_integer_type_node;
1280 if (! int_fits_type_p (val, long_long_unsigned_type_node))
1282 type = long_long_unsigned_type_node;
1284 TREE_TYPE (val) = type;
1285 CH_DERIVED_FLAG (val) = 1;
1288 error ("integer literal too big");
1293 /* Convert a bitstring literal on the temporary_obstack to
1294 a bitstring CONSTRUCTOR. Free the literal from the obstack. */
1297 convert_bitstring (p)
1303 int bl = 0, valid_chars = 0, bits_per_char = 0, c, k;
1304 tree initlist = NULL_TREE;
1307 /* Move p to stack so we can re-use temporary_obstack for result. */
1308 char *oldp = (char*) alloca (strlen (p) + 1);
1309 if (oldp == 0) fatal ("stack space exhausted");
1311 obstack_free (&temporary_obstack, p);
1334 if (c == '_' || c == '\'')
1343 for (k = BYTES_BIG_ENDIAN ? bits_per_char - 1 : 0;
1344 BYTES_BIG_ENDIAN ? k >= 0 : k < bits_per_char;
1345 bl++, BYTES_BIG_ENDIAN ? k-- : k++)
1348 initlist = tree_cons (NULL_TREE, build_int_2 (bl, 0), initlist);
1352 /* as long as BOOLS(0) is valid it must tbe possible to
1353 specify an empty bitstring */
1357 error ("invalid number format `%s'", oldp);
1361 val = build (CONSTRUCTOR,
1362 build_bitstring_type (size_int (bl)),
1363 NULL_TREE, nreverse (initlist));
1364 TREE_CONSTANT (val) = 1;
1365 CH_DERIVED_FLAG (val) = 1;
1369 /* Check if two filenames name the same file.
1370 This is done by stat'ing both files and comparing their inodes.
1372 Note: we have to take care of seize_path_list. Therefore do it the same
1373 way as in yywrap. FIXME: This probably can be done better. */
1376 same_file (filename1, filename2)
1383 extern char *strchr();
1385 if (grant_only_flag)
1386 /* do nothing in this case */
1389 /* if filenames are equal -- return 1, cause there is no need
1390 to search in the include list in this case */
1391 if (strcmp (filename1, filename2) == 0)
1394 fn_input[0] = filename1;
1395 fn_input[1] = filename2;
1397 for (i = 0; i < 2; i++)
1399 stat_status = stat (fn_input[i], &s[i]);
1400 if (stat_status < 0 &&
1401 strchr (fn_input[i], '/') == 0)
1406 for (plp = seize_path_list; plp != 0; plp = plp->next)
1408 path = (char *)xmalloc (strlen (fn_input[i]) +
1409 strlen (plp->str) + 2);
1410 sprintf (path, "%s/%s", plp->str, fn_input[i]);
1411 stat_status = stat (path, &s[i]);
1413 if (stat_status >= 0)
1417 if (stat_status < 0)
1418 pfatal_with_name (fn_input[i]);
1420 return s[0].st_ino == s[1].st_ino && s[0].st_dev == s[1].st_dev;
1424 * Note that simply appending included file names to a list in this
1425 * way completely eliminates the need for nested files, and the
1426 * associated book-keeping, since the EOF processing in the lexer
1427 * will simply process the files one at a time, in the order that the
1428 * USE_SEIZE_FILE directives were scanned.
1431 handle_use_seizefile_directive (restricted)
1436 int c = skip_whitespace ();
1437 char *use_seizefile_str = readstring (c, &len);
1442 if (c != '\'' && c != '\"')
1444 error ("USE_SEIZE_FILE directive must be followed by string");
1448 use_seizefile_name = get_identifier (use_seizefile_str);
1449 CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name) = restricted;
1451 if (!grant_only_flag)
1453 /* If file foo.ch contains a <> use_seize_file "bar.grt" <>,
1454 and file bar.ch contains a <> use_seize_file "foo.grt" <>,
1455 then if we're compiling foo.ch, we will indirectly be
1456 asked to seize foo.grt. Don't. */
1457 extern char *grant_file_name;
1458 if (strcmp (use_seizefile_str, grant_file_name) == 0)
1461 /* Check if the file is already on the list. */
1462 for (seen = files_to_seize; seen != NULL_TREE; seen = TREE_CHAIN (seen))
1463 if (same_file (IDENTIFIER_POINTER (TREE_VALUE (seen)),
1465 return; /* Previously seen; nothing to do. */
1468 /* Haven't been asked to seize this file yet, so add
1469 its name to the list. */
1471 tree pl = perm_tree_cons (0, use_seizefile_name, NULL_TREE);
1472 if (files_to_seize == NULL_TREE)
1473 files_to_seize = pl;
1475 TREE_CHAIN (last_file_to_seize) = pl;
1476 if (next_file_to_seize == NULL_TREE)
1477 next_file_to_seize = pl;
1478 last_file_to_seize = pl;
1484 * get input, convert to lower case for comparison
1493 if (isupper (c) && ignore_case)
1498 #if defined HANDLE_PRAGMA
1499 /* Local versions of these macros, that can be passed as function pointers. */
1503 return getc (finput);
1510 ungetc (arg, finput);
1512 #endif /* HANDLE_PRAGMA */
1514 /* At the beginning of a line, increment the line number and process
1515 any #-directive on this line. If the line is a #-directive, read
1516 the entire line and return a newline. Otherwise, return the line's
1517 first non-whitespace character.
1519 (Each language front end has a check_newline() function that is called
1520 from lang_init() for that language. One of the things this function
1521 must do is read the first line of the input file, and if it is a #line
1522 directive, extract the filename from it and use it to initialize
1523 main_input_filename. Proper generation of debugging information in
1524 the normal "front end calls cpp then calls cc1XXXX environment" depends
1525 upon this being done.) */
1534 /* Read first nonwhite char on the line. */
1538 while (c == ' ' || c == '\t')
1541 if (c != '#' || inside_c_comment)
1543 /* If not #, return it so caller will use it. */
1547 /* Read first nonwhite char after the `#'. */
1550 while (c == ' ' || c == '\t')
1553 /* If a letter follows, then if the word here is `line', skip
1554 it and ignore it; otherwise, ignore the line, with an error
1555 if the word isn't `pragma', `ident', `define', or `undef'. */
1557 if (isupper (c) && ignore_case)
1560 if (c >= 'a' && c <= 'z')
1564 if (getlc (finput) == 'r'
1565 && getlc (finput) == 'a'
1566 && getlc (finput) == 'g'
1567 && getlc (finput) == 'm'
1568 && getlc (finput) == 'a'
1569 && (isspace (c = getlc (finput))))
1571 #ifdef HANDLE_PRAGMA
1572 static char buffer [128];
1573 char * buff = buffer;
1575 /* Read the pragma name into a buffer. */
1576 while (isspace (c = getlc (finput)))
1584 while (c != EOF && ! isspace (c) && c != '\n'
1585 && buff < buffer + 128);
1591 (void) HANDLE_PRAGMA (pragma_getc, pragma_ungetc, buffer);
1592 #endif /* HANDLE_PRAGMA */
1599 if (getlc (finput) == 'e'
1600 && getlc (finput) == 'f'
1601 && getlc (finput) == 'i'
1602 && getlc (finput) == 'n'
1603 && getlc (finput) == 'e'
1604 && (isspace (c = getlc (finput))))
1606 #if 0 /*def DWARF_DEBUGGING_INFO*/
1608 && (debug_info_level == DINFO_LEVEL_VERBOSE)
1609 && (write_symbols == DWARF_DEBUG))
1610 dwarfout_define (lineno, get_directive_line (finput));
1611 #endif /* DWARF_DEBUGGING_INFO */
1617 if (getlc (finput) == 'n'
1618 && getlc (finput) == 'd'
1619 && getlc (finput) == 'e'
1620 && getlc (finput) == 'f'
1621 && (isspace (c = getlc (finput))))
1623 #if 0 /*def DWARF_DEBUGGING_INFO*/
1625 && (debug_info_level == DINFO_LEVEL_VERBOSE)
1626 && (write_symbols == DWARF_DEBUG))
1627 dwarfout_undef (lineno, get_directive_line (finput));
1628 #endif /* DWARF_DEBUGGING_INFO */
1634 if (getlc (finput) == 'i'
1635 && getlc (finput) == 'n'
1636 && getlc (finput) == 'e'
1637 && ((c = getlc (finput)) == ' ' || c == '\t'))
1643 if (getlc (finput) == 'd'
1644 && getlc (finput) == 'e'
1645 && getlc (finput) == 'n'
1646 && getlc (finput) == 't'
1647 && ((c = getlc (finput)) == ' ' || c == '\t'))
1649 /* #ident. The pedantic warning is now in cccp.c. */
1651 /* Here we have just seen `#ident '.
1652 A string constant should follow. */
1654 while (c == ' ' || c == '\t')
1657 /* If no argument, ignore the line. */
1664 || TREE_CODE (yylval.ttype) != STRING_CST)
1666 error ("invalid #ident");
1672 #ifdef ASM_OUTPUT_IDENT
1673 extern FILE *asm_out_file;
1674 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
1678 /* Skip the rest of this line. */
1684 error ("undefined or invalid # directive");
1689 /* Here we have either `#line' or `# <nonletter>'.
1690 In either case, it should be a line number; a digit should follow. */
1692 while (c == ' ' || c == '\t')
1695 /* If the # is the only nonwhite char on the line,
1696 just ignore it. Check the new newline. */
1700 /* Something follows the #; read a token. */
1704 int old_lineno = lineno;
1707 extern struct obstack permanent_obstack;
1711 l = l * 10 + (c - '0'); /* FIXME Not portable */
1713 } while (isdigit(c));
1714 /* subtract one, because it is the following line that
1715 gets the specified number */
1719 /* Is this the last nonwhite stuff on the line? */
1721 while (c == ' ' || c == '\t')
1725 /* No more: store the line number and check following line. */
1730 /* More follows: it must be a string constant (filename). */
1732 /* Read the string constant, but don't treat \ as special. */
1733 ignore_escape_flag = 1;
1734 ignore_escape_flag = 0;
1738 error ("invalid #line");
1745 if (c == EOF || c == '\n')
1747 error ("invalid #line");
1752 obstack_1grow(&permanent_obstack, 0);
1753 input_filename = obstack_finish (&permanent_obstack);
1756 obstack_1grow(&permanent_obstack, c);
1761 /* Each change of file name
1762 reinitializes whether we are now in a system header. */
1763 in_system_header = 0;
1765 if (main_input_filename == 0)
1766 main_input_filename = input_filename;
1768 /* Is this the last nonwhite stuff on the line? */
1770 while (c == ' ' || c == '\t')
1777 /* `1' after file name means entering new file.
1778 `2' after file name means just left a file. */
1784 /* Pushing to a new file. */
1785 struct file_stack *p
1786 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1787 input_file_stack->line = old_lineno;
1788 p->next = input_file_stack;
1789 p->name = input_filename;
1790 input_file_stack = p;
1791 input_file_stack_tick++;
1792 #ifdef DWARF_DEBUGGING_INFO
1793 if (debug_info_level == DINFO_LEVEL_VERBOSE
1794 && write_symbols == DWARF_DEBUG)
1795 dwarfout_start_new_source_file (input_filename);
1796 #endif /* DWARF_DEBUGGING_INFO */
1802 /* Popping out of a file. */
1803 if (input_file_stack->next)
1805 struct file_stack *p = input_file_stack;
1806 input_file_stack = p->next;
1808 input_file_stack_tick++;
1809 #ifdef DWARF_DEBUGGING_INFO
1810 if (debug_info_level == DINFO_LEVEL_VERBOSE
1811 && write_symbols == DWARF_DEBUG)
1812 dwarfout_resume_previous_source_file (input_file_stack->line);
1813 #endif /* DWARF_DEBUGGING_INFO */
1816 error ("#-lines for entering and leaving files don't match");
1822 /* If we have handled a `1' or a `2',
1823 see if there is another number to read. */
1826 /* Is this the last nonwhite stuff on the line? */
1828 while (c == ' ' || c == '\t')
1835 /* `3' after file name means this is a system header file. */
1838 in_system_header = 1;
1841 error ("invalid #-line");
1843 /* skip the rest of this line. */
1845 while (c != '\n' && c != EOF)
1852 get_chill_filename ()
1854 return (build_chill_string (
1855 strlen (input_filename) + 1, /* +1 to get a zero terminated string */
1860 get_chill_linenumber ()
1862 return build_int_2 ((HOST_WIDE_INT)lineno, 0);
1866 /* Assuming '/' and '*' have been read, skip until we've
1867 read the terminating '*' and '/'. */
1873 int start_line = lineno;
1879 error_with_file_and_line (input_filename, start_line,
1880 "unterminated comment");
1885 else if ((c = input ()) == '/')
1891 /* Assuming "--" has been read, skip until '\n'. */
1894 skip_line_comment ()
1918 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v')
1939 skip_line_comment ();
1953 * avoid recursive calls to yylex to parse the ' = digits' or
1954 * ' = SYNvalue' which are supposed to follow certain compiler
1955 * directives. Read the input stream, and return the value parsed.
1957 /* FIXME: overflow check in here */
1958 /* FIXME: check for EOF around here */
1965 tree retval = integer_zero_node;
1967 c = skip_whitespace();
1971 error ("missing `=' in compiler directive");
1972 return integer_zero_node;
1974 c = skip_whitespace();
1976 /* collect token into tokenbuf for later analysis */
1979 if (isspace (c) || c == '<')
1981 obstack_1grow (&temporary_obstack, c);
1984 unput (c); /* put uninteresting char back */
1985 obstack_1grow (&temporary_obstack, '\0'); /* terminate token */
1986 tokenbuf = obstack_finish (&temporary_obstack);
1987 maybe_downcase (tokenbuf);
1989 if (*tokenbuf == '-')
1990 /* will fail in the next test */
1992 else if (maybe_number (tokenbuf))
1995 return integer_zero_node;
1996 push_obstacks_nochange ();
1997 end_temporary_allocation ();
1998 yylval.ttype = convert_integer (tokenbuf);
1999 tokenbuf = 0; /* Was freed by convert_integer. */
2000 result = yylval.ttype ? NUMBER : 0;
2006 if (result == NUMBER)
2008 retval = yylval.ttype;
2010 else if (result == BITSTRING)
2013 error ("invalid value follows `=' in compiler directive");
2016 else /* not a number */
2020 if (!isalpha (c) && c != '_')
2023 error ("invalid value follows `=' in compiler directive");
2027 for (cursor = &tokenbuf[1]; *cursor != '\0'; cursor++)
2028 if (isalpha (*cursor) || *cursor == '_' || isdigit (*cursor))
2033 error ("invalid `%c' character in name", *cursor);
2040 tree value = lookup_name (get_identifier (tokenbuf));
2041 if (value == NULL_TREE
2042 || TREE_CODE (value) != CONST_DECL
2043 || TREE_CODE (DECL_INITIAL (value)) != INTEGER_CST)
2046 error ("`%s' not integer constant synonym ",
2050 obstack_free (&temporary_obstack, tokenbuf);
2052 push_obstacks_nochange ();
2053 end_temporary_allocation ();
2054 retval = convert (chill_taskingcode_type_node, DECL_INITIAL (value));
2059 /* check the value */
2060 if (TREE_CODE (retval) != INTEGER_CST)
2063 error ("invalid value follows `=' in compiler directive");
2065 else if (TREE_INT_CST_HIGH (retval) != 0 ||
2066 TREE_INT_CST_LOW (retval) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node)))
2069 error ("value out of range in compiler directive");
2073 obstack_free (&temporary_obstack, tokenbuf);
2078 * add a possible grant-file path to the list
2081 register_seize_path (path)
2084 int pathlen = strlen (path);
2085 char *new_path = (char *)xmalloc (pathlen + 1);
2086 STRING_LIST *pl = (STRING_LIST *)xmalloc (sizeof (STRING_LIST));
2088 /* strip off trailing slash if any */
2089 if (path[pathlen - 1] == '/')
2092 memcpy (new_path, path, pathlen);
2094 pl->next = seize_path_list;
2095 seize_path_list = pl;
2099 /* Used by decode_decl to indicate that a <> use_seize_file NAME <>
2100 directive has been written to the grantfile. */
2103 mark_use_seizefile_written (name)
2108 for (node = files_to_seize; node != NULL_TREE; node = TREE_CHAIN (node))
2109 if (TREE_VALUE (node) == name)
2111 TREE_PURPOSE (node) = integer_one_node;
2120 extern char *strchr ();
2121 extern char *chill_real_input_filename;
2124 close_input_file (input_filename);
2126 use_seizefile_name = NULL_TREE;
2128 if (next_file_to_seize && !grant_only_flag)
2130 FILE *grt_in = NULL;
2131 char *seizefile_name_chars
2132 = IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize));
2134 /* find a seize file, open it. If it's not at the path the
2135 * user gave us, and that path contains no slashes, look on
2136 * the seize_file paths, specified by the '-I' options.
2138 grt_in = fopen (seizefile_name_chars, "r");
2140 && strchr (seizefile_name_chars, '/') == NULL)
2145 for (plp = seize_path_list; plp != NULL; plp = plp->next)
2147 path = (char *)xmalloc (strlen (seizefile_name_chars)
2148 + strlen (plp->str) + 2);
2150 sprintf (path, "%s/%s", plp->str, seizefile_name_chars);
2151 grt_in = fopen (path, "r");
2156 seizefile_name_chars = path;
2163 pfatal_with_name (seizefile_name_chars);
2166 input_filename = seizefile_name_chars;
2169 current_seizefile_name = TREE_VALUE (next_file_to_seize);
2171 next_file_to_seize = TREE_CHAIN (next_file_to_seize);
2179 next_file_to_seize = files_to_seize;
2180 current_seizefile_name = NULL_TREE;
2182 if (strcmp (main_input_filename, "stdin"))
2183 finput = fopen (chill_real_input_filename, "r");
2188 error ("can't reopen %s", chill_real_input_filename);
2191 input_filename = main_input_filename;
2194 /* Read a line directive if there is one. */
2195 ungetc (check_newline (), finput);
2196 starting_pass_2 = 1;
2198 if (module_number == 0)
2199 warning ("no modules seen");