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. */
35 #ifdef MULTIBYTE_CHARS
39 /* include the keyword recognizers */
45 static int last_token = 0;
46 /* Sun's C compiler warns about the safer sequence
48 when there's a 'return' inside the braces, so don't use it */
49 #define RETURN_TOKEN(X) { last_token = X; return (X); }
52 /* This is set non-zero to force incoming tokens to lowercase. */
53 extern int ignore_case;
55 extern int module_number;
56 extern int serious_errors;
58 /* This is non-zero to recognize only uppercase special words. */
59 extern int special_UC;
61 extern struct obstack permanent_obstack;
62 extern struct obstack temporary_obstack;
64 /* forward declarations */
65 static void close_input_file PROTO((char *));
66 static tree convert_bitstring PROTO((char *));
67 static tree convert_integer PROTO((char *));
68 static void maybe_downcase PROTO((char *));
69 static int maybe_number PROTO((char *));
70 static tree equal_number PROTO((void));
71 static void handle_use_seizefile_directive PROTO((int));
72 static int handle_name PROTO((tree));
73 static char *readstring PROTO((int, int *));
74 static void read_directive PROTO((void));
75 static tree read_identifier PROTO((int));
76 static tree read_number PROTO((int));
77 static void skip_c_comment PROTO((void));
78 static void skip_line_comment PROTO((void));
79 static int skip_whitespace PROTO((void));
80 static tree string_or_char PROTO((int, char *));
82 /* next variables are public, because ch-actions uses them */
84 /* the default grantfile name, set by lang_init */
85 tree default_grant_file = 0;
87 /* These tasking-related variables are NULL at the start of each
88 compiler pass, and are set to an expression tree if and when
89 a compiler directive is parsed containing an expression.
90 The NULL state is significant; it means 'no user-specified
91 signal_code (or whatever) has been parsed'. */
93 /* process type, set by <> PROCESS_TYPE = number <> */
94 tree process_type = NULL_TREE;
96 /* send buffer default priority,
97 set by <> SEND_BUFFER_DEFAULT_PRIORITY = number <> */
98 tree send_buffer_prio = NULL_TREE;
100 /* send signal default priority,
101 set by <> SEND_SIGNAL_DEFAULT_PRIORITY = number <> */
102 tree send_signal_prio = NULL_TREE;
104 /* signal code, set by <> SIGNAL_CODE = number <> */
105 tree signal_code = NULL_TREE;
107 /* flag for range checking */
108 int range_checking = 1;
110 /* flag for NULL pointer checking */
111 int empty_checking = 1;
113 /* flag to indicate making all procedure local variables
115 int all_static_flag = 0;
117 /* flag to indicate -fruntime-checking command line option.
118 Needed for initializing range_checking and empty_checking
120 int runtime_checking_flag = 1;
122 /* The elements of `ridpointers' are identifier nodes
123 for the reserved type names and storage classes.
124 It is indexed by a RID_... value. */
125 tree ridpointers[(int) RID_MAX];
127 /* Nonzero tells yylex to ignore \ in string constants. */
128 static int ignore_escape_flag = 0;
130 static int maxtoken; /* Current nominal length of token buffer. */
131 char *token_buffer; /* Pointer to token buffer.
132 Actual allocated length is maxtoken + 2.
133 This is not static because objc-parse.y uses it. */
135 /* implement yylineno handling for flex */
136 #define yylineno lineno
138 static int inside_c_comment = 0;
140 static int saw_eol = 0; /* 1 if we've just seen a '\n' */
141 static int saw_eof = 0; /* 1 if we've just seen an EOF */
143 typedef struct string_list
145 struct string_list *next;
149 /* list of paths specified on the compiler command line by -L options. */
150 static STRING_LIST *seize_path_list = (STRING_LIST *)0;
152 /* List of seize file names. Each TREE_VALUE is an identifier
153 (file name) from a <>USE_SEIZE_FILE<> directive.
154 The TREE_PURPOSE is non-NULL if a USE_SEIZE_FILE directive has been
155 written to the grant file. */
156 static tree files_to_seize = NULL_TREE;
157 /* Last node on files_to_seize list. */
158 static tree last_file_to_seize = NULL_TREE;
159 /* Pointer into files_to_seize list: Next unparsed file to read. */
160 static tree next_file_to_seize = NULL_TREE;
162 /* The most recent use_seize_file directive. */
163 tree use_seizefile_name = NULL_TREE;
165 /* If non-NULL, the name of the seizefile we're currently processing. */
166 tree current_seizefile_name = NULL_TREE;
168 /* called to reset for pass 2 */
172 current_seizefile_name = NULL_TREE;
178 /* Initialize these compiler-directive variables. */
179 process_type = NULL_TREE;
180 send_buffer_prio = NULL_TREE;
181 send_signal_prio = NULL_TREE;
182 signal_code = NULL_TREE;
184 /* reinitialize rnage checking and empty checking */
185 range_checking = runtime_checking_flag;
186 empty_checking = runtime_checking_flag;
191 init_parse (filename)
194 int lowercase_standard_names = ignore_case || ! special_UC;
196 /* Open input file. */
197 if (filename == 0 || !strcmp (filename, "-"))
203 finput = fopen (filename, "r");
205 pfatal_with_name (filename);
207 #ifdef IO_BUFFER_SIZE
208 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
211 /* Make identifier nodes long enough for the language-specific slots. */
212 set_identifier_size (sizeof (struct lang_identifier));
214 /* Start it at 0, because check_newline is called at the very beginning
215 and will increment it to 1. */
218 /* Initialize these compiler-directive variables. */
219 process_type = NULL_TREE;
220 send_buffer_prio = NULL_TREE;
221 send_signal_prio = NULL_TREE;
222 signal_code = NULL_TREE;
225 token_buffer = xmalloc ((unsigned)(maxtoken + 2));
227 init_chill_expand ();
229 #define ENTER_STANDARD_NAME(RID, LOWER, UPPER) \
230 ridpointers[(int) RID] = \
231 get_identifier (lowercase_standard_names ? LOWER : UPPER)
233 ENTER_STANDARD_NAME (RID_ALL, "all", "ALL");
234 ENTER_STANDARD_NAME (RID_ASSERTFAIL, "assertfail", "ASSERTFAIL");
235 ENTER_STANDARD_NAME (RID_ASSOCIATION, "association", "ASSOCIATION");
236 ENTER_STANDARD_NAME (RID_BIN, "bin", "BIN");
237 ENTER_STANDARD_NAME (RID_BOOL, "bool", "BOOL");
238 ENTER_STANDARD_NAME (RID_BOOLS, "bools", "BOOLS");
239 ENTER_STANDARD_NAME (RID_BYTE, "byte", "BYTE");
240 ENTER_STANDARD_NAME (RID_CHAR, "char", "CHAR");
241 ENTER_STANDARD_NAME (RID_DOUBLE, "double", "DOUBLE");
242 ENTER_STANDARD_NAME (RID_DURATION, "duration", "DURATION");
243 ENTER_STANDARD_NAME (RID_DYNAMIC, "dynamic", "DYNAMIC");
244 ENTER_STANDARD_NAME (RID_ELSE, "else", "ELSE");
245 ENTER_STANDARD_NAME (RID_EMPTY, "empty", "EMPTY");
246 ENTER_STANDARD_NAME (RID_FALSE, "false", "FALSE");
247 ENTER_STANDARD_NAME (RID_FLOAT, "float", "FLOAT");
248 ENTER_STANDARD_NAME (RID_GENERAL, "general", "GENERAL");
249 ENTER_STANDARD_NAME (RID_IN, "in", "IN");
250 ENTER_STANDARD_NAME (RID_INLINE, "inline", "INLINE");
251 ENTER_STANDARD_NAME (RID_INOUT, "inout", "INOUT");
252 ENTER_STANDARD_NAME (RID_INSTANCE, "instance", "INSTANCE");
253 ENTER_STANDARD_NAME (RID_INT, "int", "INT");
254 ENTER_STANDARD_NAME (RID_LOC, "loc", "LOC");
255 ENTER_STANDARD_NAME (RID_LONG, "long", "LONG");
256 ENTER_STANDARD_NAME (RID_LONG_REAL, "long_real", "LONG_REAL");
257 ENTER_STANDARD_NAME (RID_NULL, "null", "NULL");
258 ENTER_STANDARD_NAME (RID_OUT, "out", "OUT");
259 ENTER_STANDARD_NAME (RID_OVERFLOW, "overflow", "OVERFLOW");
260 ENTER_STANDARD_NAME (RID_PTR, "ptr", "PTR");
261 ENTER_STANDARD_NAME (RID_READ, "read", "READ");
262 ENTER_STANDARD_NAME (RID_REAL, "real", "REAL");
263 ENTER_STANDARD_NAME (RID_RANGE, "range", "RANGE");
264 ENTER_STANDARD_NAME (RID_RANGEFAIL, "rangefail", "RANGEFAIL");
265 ENTER_STANDARD_NAME (RID_RECURSIVE, "recursive", "RECURSIVE");
266 ENTER_STANDARD_NAME (RID_SHORT, "short", "SHORT");
267 ENTER_STANDARD_NAME (RID_SIMPLE, "simple", "SIMPLE");
268 ENTER_STANDARD_NAME (RID_TIME, "time", "TIME");
269 ENTER_STANDARD_NAME (RID_TRUE, "true", "TRUE");
270 ENTER_STANDARD_NAME (RID_UBYTE, "ubyte", "UBYTE");
271 ENTER_STANDARD_NAME (RID_UINT, "uint", "UINT");
272 ENTER_STANDARD_NAME (RID_ULONG, "ulong", "ULONG");
273 ENTER_STANDARD_NAME (RID_UNSIGNED, "unsigned", "UNSIGNED");
274 ENTER_STANDARD_NAME (RID_USHORT, "ushort", "USHORT");
275 ENTER_STANDARD_NAME (RID_VOID, "void", "VOID");
287 static int yywrap ();
289 #define YY_PUTBACK_SIZE 5
290 #define YY_BUF_SIZE 1000
292 static char yy_buffer[YY_PUTBACK_SIZE + YY_BUF_SIZE];
293 static char *yy_cur = yy_buffer + YY_PUTBACK_SIZE;
294 static char *yy_lim = yy_buffer + YY_PUTBACK_SIZE;
298 char *buf = yy_buffer + YY_PUTBACK_SIZE;
300 bcopy (yy_cur - YY_PUTBACK_SIZE, yy_buffer, YY_PUTBACK_SIZE);
315 c = check_newline ();
328 while (result < YY_BUF_SIZE)
338 /* Because we might switch input files on a compiler directive
339 (that end with '>', don't read past a '>', just in case. */
348 fprintf (stderr, "-------------------------- finished Line %d\n",
356 yy_lim = yy_cur + result;
358 return yy_lim > yy_cur ? *yy_cur++ : EOF;
361 #define input() (yy_cur < yy_lim ? *yy_cur++ : yy_refill ())
363 #define unput(c) (*--yy_cur = (c))
366 int starting_pass_2 = 0;
386 case ' ': case '\t': case '\n': case '\f': case '\b': case '\v': case '\r':
408 else if (nextc == '=')
424 skip_line_comment ();
437 else if (nextc == '=')
439 else if (nextc == '*')
482 int len = 0; /* Number of hex digits seen. */
490 if (!ISXDIGIT (ch)) /* error on non-hex digit */
493 error ("invalid C'xx' ");
504 if (len & 1) /* collected two digits, save byte */
505 obstack_1grow (&temporary_obstack, (char) byte_val);
508 start = obstack_finish (&temporary_obstack);
509 yylval.ttype = string_or_char (len >> 1, start);
510 obstack_free (&temporary_obstack, start);
511 return len == 2 ? SINGLECHAR : STRING;
521 obstack_1grow (&temporary_obstack, ch);
522 obstack_1grow (&temporary_obstack, nextc);
527 obstack_1grow (&temporary_obstack, ch);
531 obstack_1grow (&temporary_obstack, '\0');
532 start = obstack_finish (&temporary_obstack);
536 yylval.ttype = convert_integer (start); /* Pass base? */
541 yylval.ttype = convert_bitstring (start);
549 case 'F': case 'G': case 'I': case 'J':
550 case 'K': case 'L': case 'M': case 'N':
551 case 'P': case 'Q': case 'R': case 'S': case 'T':
552 case 'U': case 'V': case 'W': case 'X': case 'Y':
555 case 'f': case 'g': case 'i': case 'j':
556 case 'k': case 'l': case 'm': case 'n':
557 case 'p': case 'q': case 'r': case 's': case 't':
558 case 'u': case 'v': case 'w': case 'x': case 'y':
562 return handle_name (read_identifier (ch));
564 tmp = readstring ('\'', &len);
565 yylval.ttype = string_or_char (len, tmp);
567 return len == 1 ? SINGLECHAR : STRING;
569 tmp = readstring ('\"', &len);
570 yylval.ttype = build_chill_string (len, tmp);
576 if (ISDIGIT (nextc)) /* || nextc == '_') we don't start numbers with '_' */
579 case '0': case '1': case '2': case '3': case '4':
580 case '5': case '6': case '7': case '8': case '9':
582 yylval.ttype = read_number (ch);
583 return TREE_CODE (yylval.ttype) == REAL_CST ? FLOATING : NUMBER;
590 close_input_file (fn)
596 if (finput != stdin && fclose (finput) == EOF)
598 error ("can't close %s", fn);
604 /* Return an identifier, starting with FIRST and then reading
605 more characters using input(). Return an IDENTIFIER_NODE. */
608 read_identifier (first)
609 int first; /* First letter of identifier */
615 obstack_1grow (&temporary_obstack, first);
619 if (! ISALNUM (first) && first != '_')
625 obstack_1grow (&temporary_obstack, '\0');
626 start = obstack_finish (&temporary_obstack);
627 maybe_downcase (start);
628 id = get_identifier (start);
629 obstack_free (&temporary_obstack, start);
633 /* Given an identifier ID, check to see if it is a reserved name,
634 and return the appropriate token type. */
641 tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
643 && special_UC == ISUPPER ((unsigned char) tp->name[0])
644 && (tp->flags == RESERVED || tp->flags == PREDEF))
646 if (tp->rid != NORID)
647 yylval.ttype = ridpointers[tp->rid];
648 else if (tp->token == THIS)
649 yylval.ttype = lookup_name (get_identifier ("__whoami"));
658 int ch; /* Initial character */
666 obstack_1grow (&temporary_obstack, ch);
668 if (! ISDIGIT (ch) && ch != '_')
676 obstack_1grow (&temporary_obstack, ch);
678 } while (ISDIGIT (ch) || ch == '_');
681 if (ch == 'd' || ch == 'D' || ch == 'e' || ch == 'E')
683 /* Convert exponent indication [eEdD] to 'e'. */
684 obstack_1grow (&temporary_obstack, 'e');
686 if (ch == '+' || ch == '-')
688 obstack_1grow (&temporary_obstack, ch);
691 if (ISDIGIT (ch) || ch == '_')
696 obstack_1grow (&temporary_obstack, ch);
698 } while (ISDIGIT (ch) || ch == '_');
702 error ("malformed exponent part of floating-point literal");
708 obstack_1grow (&temporary_obstack, '\0');
709 start = obstack_finish (&temporary_obstack);
712 REAL_VALUE_TYPE value;
713 tree type = double_type_node;
715 value = REAL_VALUE_ATOF (start, TYPE_MODE (type));
716 obstack_free (&temporary_obstack, start);
717 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
718 && REAL_VALUE_ISINF (value) && pedantic)
719 pedwarn ("real number exceeds range of REAL");
720 num = build_real (type, value);
723 num = convert_integer (start);
724 CH_DERIVED_FLAG (num) = 1;
728 /* Skip to the end of a compiler directive. */
738 error ("end-of-file in '<>' directive");
754 /* Read a compiler directive. ("<>{WS}" have already been read. ) */
760 int ch = skip_whitespace();
761 if (ISALPHA (ch) || ch == '_')
762 id = read_identifier (ch);
765 error ("end-of-file in '<>' directive");
766 to_global_binding_level ();
771 warning ("unrecognized compiler directive");
775 tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
776 if (tp == NULL || special_UC != ISUPPER ((unsigned char) tp->name[0]))
779 warning ("unrecognized compiler directive `%s'",
780 IDENTIFIER_POINTER (id));
797 case IGNORED_DIRECTIVE:
799 case PROCESS_TYPE_TOKEN:
800 process_type = equal_number ();
808 case SEND_SIGNAL_DEFAULT_PRIORITY:
809 send_signal_prio = equal_number ();
811 case SEND_BUFFER_DEFAULT_PRIORITY:
812 send_buffer_prio = equal_number ();
815 signal_code = equal_number ();
818 handle_use_seizefile_directive (0);
820 case USE_SEIZE_FILE_RESTRICTED:
821 handle_use_seizefile_directive (1);
825 warning ("unrecognized compiler directive `%s'",
826 IDENTIFIER_POINTER (id));
834 build_chill_string (len, str)
840 push_obstacks (&permanent_obstack, &permanent_obstack);
841 t = build_string (len, str);
842 TREE_TYPE (t) = build_string_type (char_type_node,
843 build_int_2 (len, 0));
844 CH_DERIVED_FLAG (t) = 1;
851 string_or_char (len, str)
857 push_obstacks (&permanent_obstack, &permanent_obstack);
860 result = build_int_2 ((unsigned char)str[0], 0);
861 CH_DERIVED_FLAG (result) = 1;
862 TREE_TYPE (result) = char_type_node;
865 result = build_chill_string (len, str);
879 if (ISUPPER ((unsigned char) *str))
880 *str = tolower ((unsigned char)*str);
892 /* check for decimal number */
893 if (*s >= '0' && *s <= '9')
897 if (*s >= '0' && *s <= '9')
915 if (*s < '0' || *s > '9')
920 if (!ISXDIGIT ((unsigned char) *s))
925 if (*s < '0' || *s > '1')
930 if (*s < '0' || *s > '7')
942 readstring (terminator, len)
947 unsigned allocated = 1024;
948 char *tmp = xmalloc (allocated);
956 if ((c = input ()) != terminator)
964 if (c == '\n' || c == EOF)
969 if (c == EOF || c == '\n')
983 if (cc == terminator)
985 if (!(terminator == '\'' && next_apos))
987 error ("unterminated control sequence");
992 if (cc == EOF || cc == '\n')
1002 error ("invalid integer literal in control sequence");
1008 if (cc == ' ' || cc == '\t')
1012 if ((c < 0 || c > 255) && (pass == 1))
1013 error ("control sequence overflow");
1014 if (! count && pass == 1)
1015 error ("invalid control sequence");
1020 if ((c < 0 || c > 255) && (pass == 1))
1021 error ("control sequence overflow");
1022 if (! count && pass == 1)
1023 error ("invalid control sequence");
1028 tmp = xrealloc (tmp, allocated);
1037 if (! count && pass == 1)
1038 error ("invalid integer literal in control sequence");
1043 if (cc == 'D' || cc == 'd')
1048 else if (cc == 'H' || cc == 'h')
1053 else if (cc == 'O' || cc == 'o')
1058 else if (cc == 'B' || cc == 'b')
1069 if (cc < '0' || cc > '1')
1076 if (cc < '0' || cc > '8')
1081 else if (base == 10)
1088 else if (base == 16)
1103 error ("invalid base in read control sequence");
1108 /* error in control sequence */
1110 error ("invalid digit in control sequence");
1113 c = (c * base) + cc;
1125 tmp = xrealloc (tmp, allocated);
1129 tmp [*len = i] = '\0';
1137 error ("unterminated string literal");
1138 to_global_binding_level ();
1143 /* Convert an integer INTCHARS into an INTEGER_CST.
1144 INTCHARS is on the temporary_obstack, and is popped by this function. */
1147 convert_integer (intchars)
1156 int valid_chars = 0;
1159 HOST_WIDE_INT val_lo = 0, val_hi = 0;
1162 /* determine the base */
1185 if (!ISDIGIT (*p)) /* this test is for equal_number () */
1187 obstack_free (&temporary_obstack, intchars);
1196 if ((tmp == '\'') || (tmp == '_'))
1200 if (tmp >= 'a') /* uppercase the char */
1202 switch (base) /* validate the characters */
1219 if (tmp > '9' && tmp < 'A')
1228 if (mul_double (val_lo, val_hi, base, 0, &val_lo, &val_hi))
1230 add_double (val_lo, val_hi, tmp, 0, &val_lo, &val_hi);
1236 obstack_free (&temporary_obstack, intchars);
1240 error ("invalid number format `%s'", oldp);
1243 val = build_int_2 (val_lo, val_hi);
1244 /* We set the type to long long (or long long unsigned) so that
1245 constant fold of literals is less likely to overflow. */
1246 if (int_fits_type_p (val, long_long_integer_type_node))
1247 type = long_long_integer_type_node;
1250 if (! int_fits_type_p (val, long_long_unsigned_type_node))
1252 type = long_long_unsigned_type_node;
1254 TREE_TYPE (val) = type;
1255 CH_DERIVED_FLAG (val) = 1;
1258 error ("integer literal too big");
1263 /* Convert a bitstring literal on the temporary_obstack to
1264 a bitstring CONSTRUCTOR. Free the literal from the obstack. */
1267 convert_bitstring (p)
1273 int bl = 0, valid_chars = 0, bits_per_char = 0, c, k;
1274 tree initlist = NULL_TREE;
1277 /* Move p to stack so we can re-use temporary_obstack for result. */
1278 char *oldp = (char*) alloca (strlen (p) + 1);
1279 if (oldp == 0) fatal ("stack space exhausted");
1281 obstack_free (&temporary_obstack, p);
1304 if (c == '_' || c == '\'')
1313 for (k = BYTES_BIG_ENDIAN ? bits_per_char - 1 : 0;
1314 BYTES_BIG_ENDIAN ? k >= 0 : k < bits_per_char;
1315 bl++, BYTES_BIG_ENDIAN ? k-- : k++)
1318 initlist = tree_cons (NULL_TREE, build_int_2 (bl, 0), initlist);
1322 /* as long as BOOLS(0) is valid it must tbe possible to
1323 specify an empty bitstring */
1327 error ("invalid number format `%s'", oldp);
1331 val = build (CONSTRUCTOR,
1332 build_bitstring_type (size_int (bl)),
1333 NULL_TREE, nreverse (initlist));
1334 TREE_CONSTANT (val) = 1;
1335 CH_DERIVED_FLAG (val) = 1;
1339 /* Check if two filenames name the same file.
1340 This is done by stat'ing both files and comparing their inodes.
1342 Note: we have to take care of seize_path_list. Therefore do it the same
1343 way as in yywrap. FIXME: This probably can be done better. */
1346 same_file (filename1, filename2)
1354 if (grant_only_flag)
1355 /* do nothing in this case */
1358 /* if filenames are equal -- return 1, cause there is no need
1359 to search in the include list in this case */
1360 if (strcmp (filename1, filename2) == 0)
1363 fn_input[0] = filename1;
1364 fn_input[1] = filename2;
1366 for (i = 0; i < 2; i++)
1368 stat_status = stat (fn_input[i], &s[i]);
1369 if (stat_status < 0 &&
1370 strchr (fn_input[i], '/') == 0)
1375 for (plp = seize_path_list; plp != 0; plp = plp->next)
1377 path = (char *)xmalloc (strlen (fn_input[i]) +
1378 strlen (plp->str) + 2);
1379 sprintf (path, "%s/%s", plp->str, fn_input[i]);
1380 stat_status = stat (path, &s[i]);
1382 if (stat_status >= 0)
1386 if (stat_status < 0)
1387 pfatal_with_name (fn_input[i]);
1389 return s[0].st_ino == s[1].st_ino && s[0].st_dev == s[1].st_dev;
1393 * Note that simply appending included file names to a list in this
1394 * way completely eliminates the need for nested files, and the
1395 * associated book-keeping, since the EOF processing in the lexer
1396 * will simply process the files one at a time, in the order that the
1397 * USE_SEIZE_FILE directives were scanned.
1400 handle_use_seizefile_directive (restricted)
1405 int c = skip_whitespace ();
1406 char *use_seizefile_str = readstring (c, &len);
1411 if (c != '\'' && c != '\"')
1413 error ("USE_SEIZE_FILE directive must be followed by string");
1417 use_seizefile_name = get_identifier (use_seizefile_str);
1418 CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name) = restricted;
1420 if (!grant_only_flag)
1422 /* If file foo.ch contains a <> use_seize_file "bar.grt" <>,
1423 and file bar.ch contains a <> use_seize_file "foo.grt" <>,
1424 then if we're compiling foo.ch, we will indirectly be
1425 asked to seize foo.grt. Don't. */
1426 extern char *grant_file_name;
1427 if (strcmp (use_seizefile_str, grant_file_name) == 0)
1430 /* Check if the file is already on the list. */
1431 for (seen = files_to_seize; seen != NULL_TREE; seen = TREE_CHAIN (seen))
1432 if (same_file (IDENTIFIER_POINTER (TREE_VALUE (seen)),
1434 return; /* Previously seen; nothing to do. */
1437 /* Haven't been asked to seize this file yet, so add
1438 its name to the list. */
1440 tree pl = perm_tree_cons (0, use_seizefile_name, NULL_TREE);
1441 if (files_to_seize == NULL_TREE)
1442 files_to_seize = pl;
1444 TREE_CHAIN (last_file_to_seize) = pl;
1445 if (next_file_to_seize == NULL_TREE)
1446 next_file_to_seize = pl;
1447 last_file_to_seize = pl;
1453 * get input, convert to lower case for comparison
1462 if (ISUPPER (c) && ignore_case)
1467 #if defined HANDLE_PRAGMA
1468 /* Local versions of these macros, that can be passed as function pointers. */
1472 return getc (finput);
1479 ungetc (arg, finput);
1481 #endif /* HANDLE_PRAGMA */
1483 /* At the beginning of a line, increment the line number and process
1484 any #-directive on this line. If the line is a #-directive, read
1485 the entire line and return a newline. Otherwise, return the line's
1486 first non-whitespace character.
1488 (Each language front end has a check_newline() function that is called
1489 from lang_init() for that language. One of the things this function
1490 must do is read the first line of the input file, and if it is a #line
1491 directive, extract the filename from it and use it to initialize
1492 main_input_filename. Proper generation of debugging information in
1493 the normal "front end calls cpp then calls cc1XXXX environment" depends
1494 upon this being done.) */
1503 /* Read first nonwhite char on the line. */
1507 while (c == ' ' || c == '\t')
1510 if (c != '#' || inside_c_comment)
1512 /* If not #, return it so caller will use it. */
1516 /* Read first nonwhite char after the `#'. */
1519 while (c == ' ' || c == '\t')
1522 /* If a letter follows, then if the word here is `line', skip
1523 it and ignore it; otherwise, ignore the line, with an error
1524 if the word isn't `pragma', `ident', `define', or `undef'. */
1526 if (ISUPPER (c) && ignore_case)
1529 if (c >= 'a' && c <= 'z')
1533 if (getlc (finput) == 'r'
1534 && getlc (finput) == 'a'
1535 && getlc (finput) == 'g'
1536 && getlc (finput) == 'm'
1537 && getlc (finput) == 'a'
1538 && (c = getlc (finput), ISSPACE (c)))
1540 #ifdef HANDLE_PRAGMA
1541 static char buffer [128];
1542 char * buff = buffer;
1544 /* Read the pragma name into a buffer. */
1545 while (c = getlc (finput), ISSPACE (c))
1553 while (c != EOF && ! ISSPACE (c) && c != '\n'
1554 && buff < buffer + 128);
1560 (void) HANDLE_PRAGMA (pragma_getc, pragma_ungetc, buffer);
1561 #endif /* HANDLE_PRAGMA */
1568 if (getlc (finput) == 'e'
1569 && getlc (finput) == 'f'
1570 && getlc (finput) == 'i'
1571 && getlc (finput) == 'n'
1572 && getlc (finput) == 'e'
1573 && (c = getlc (finput), ISSPACE (c)))
1575 #if 0 /*def DWARF_DEBUGGING_INFO*/
1577 && (debug_info_level == DINFO_LEVEL_VERBOSE)
1578 && (write_symbols == DWARF_DEBUG))
1579 dwarfout_define (lineno, get_directive_line (finput));
1580 #endif /* DWARF_DEBUGGING_INFO */
1586 if (getlc (finput) == 'n'
1587 && getlc (finput) == 'd'
1588 && getlc (finput) == 'e'
1589 && getlc (finput) == 'f'
1590 && (c = getlc (finput), ISSPACE (c)))
1592 #if 0 /*def DWARF_DEBUGGING_INFO*/
1594 && (debug_info_level == DINFO_LEVEL_VERBOSE)
1595 && (write_symbols == DWARF_DEBUG))
1596 dwarfout_undef (lineno, get_directive_line (finput));
1597 #endif /* DWARF_DEBUGGING_INFO */
1603 if (getlc (finput) == 'i'
1604 && getlc (finput) == 'n'
1605 && getlc (finput) == 'e'
1606 && ((c = getlc (finput)) == ' ' || c == '\t'))
1612 if (getlc (finput) == 'd'
1613 && getlc (finput) == 'e'
1614 && getlc (finput) == 'n'
1615 && getlc (finput) == 't'
1616 && ((c = getlc (finput)) == ' ' || c == '\t'))
1618 /* #ident. The pedantic warning is now in cccp.c. */
1620 /* Here we have just seen `#ident '.
1621 A string constant should follow. */
1623 while (c == ' ' || c == '\t')
1626 /* If no argument, ignore the line. */
1633 || TREE_CODE (yylval.ttype) != STRING_CST)
1635 error ("invalid #ident");
1641 #ifdef ASM_OUTPUT_IDENT
1642 extern FILE *asm_out_file;
1643 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
1647 /* Skip the rest of this line. */
1653 error ("undefined or invalid # directive");
1658 /* Here we have either `#line' or `# <nonletter>'.
1659 In either case, it should be a line number; a digit should follow. */
1661 while (c == ' ' || c == '\t')
1664 /* If the # is the only nonwhite char on the line,
1665 just ignore it. Check the new newline. */
1669 /* Something follows the #; read a token. */
1673 int old_lineno = lineno;
1676 extern struct obstack permanent_obstack;
1680 l = l * 10 + (c - '0'); /* FIXME Not portable */
1682 } while (ISDIGIT(c));
1683 /* subtract one, because it is the following line that
1684 gets the specified number */
1688 /* Is this the last nonwhite stuff on the line? */
1690 while (c == ' ' || c == '\t')
1694 /* No more: store the line number and check following line. */
1699 /* More follows: it must be a string constant (filename). */
1701 /* Read the string constant, but don't treat \ as special. */
1702 ignore_escape_flag = 1;
1703 ignore_escape_flag = 0;
1707 error ("invalid #line");
1714 if (c == EOF || c == '\n')
1716 error ("invalid #line");
1721 obstack_1grow(&permanent_obstack, 0);
1722 input_filename = obstack_finish (&permanent_obstack);
1725 obstack_1grow(&permanent_obstack, c);
1730 /* Each change of file name
1731 reinitializes whether we are now in a system header. */
1732 in_system_header = 0;
1734 if (main_input_filename == 0)
1735 main_input_filename = input_filename;
1737 /* Is this the last nonwhite stuff on the line? */
1739 while (c == ' ' || c == '\t')
1746 /* `1' after file name means entering new file.
1747 `2' after file name means just left a file. */
1753 /* Pushing to a new file. */
1754 struct file_stack *p
1755 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1756 input_file_stack->line = old_lineno;
1757 p->next = input_file_stack;
1758 p->name = input_filename;
1759 input_file_stack = p;
1760 input_file_stack_tick++;
1761 #ifdef DWARF_DEBUGGING_INFO
1762 if (debug_info_level == DINFO_LEVEL_VERBOSE
1763 && write_symbols == DWARF_DEBUG)
1764 dwarfout_start_new_source_file (input_filename);
1765 #endif /* DWARF_DEBUGGING_INFO */
1771 /* Popping out of a file. */
1772 if (input_file_stack->next)
1774 struct file_stack *p = input_file_stack;
1775 input_file_stack = p->next;
1777 input_file_stack_tick++;
1778 #ifdef DWARF_DEBUGGING_INFO
1779 if (debug_info_level == DINFO_LEVEL_VERBOSE
1780 && write_symbols == DWARF_DEBUG)
1781 dwarfout_resume_previous_source_file (input_file_stack->line);
1782 #endif /* DWARF_DEBUGGING_INFO */
1785 error ("#-lines for entering and leaving files don't match");
1791 /* If we have handled a `1' or a `2',
1792 see if there is another number to read. */
1795 /* Is this the last nonwhite stuff on the line? */
1797 while (c == ' ' || c == '\t')
1804 /* `3' after file name means this is a system header file. */
1807 in_system_header = 1;
1810 error ("invalid #-line");
1812 /* skip the rest of this line. */
1814 while (c != '\n' && c != EOF)
1821 get_chill_filename ()
1823 return (build_chill_string (
1824 strlen (input_filename) + 1, /* +1 to get a zero terminated string */
1829 get_chill_linenumber ()
1831 return build_int_2 ((HOST_WIDE_INT)lineno, 0);
1835 /* Assuming '/' and '*' have been read, skip until we've
1836 read the terminating '*' and '/'. */
1842 int start_line = lineno;
1848 error_with_file_and_line (input_filename, start_line,
1849 "unterminated comment");
1854 else if ((c = input ()) == '/')
1860 /* Assuming "--" has been read, skip until '\n'. */
1863 skip_line_comment ()
1887 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v')
1908 skip_line_comment ();
1922 * avoid recursive calls to yylex to parse the ' = digits' or
1923 * ' = SYNvalue' which are supposed to follow certain compiler
1924 * directives. Read the input stream, and return the value parsed.
1926 /* FIXME: overflow check in here */
1927 /* FIXME: check for EOF around here */
1934 tree retval = integer_zero_node;
1936 c = skip_whitespace();
1940 error ("missing `=' in compiler directive");
1941 return integer_zero_node;
1943 c = skip_whitespace();
1945 /* collect token into tokenbuf for later analysis */
1948 if (ISSPACE (c) || c == '<')
1950 obstack_1grow (&temporary_obstack, c);
1953 unput (c); /* put uninteresting char back */
1954 obstack_1grow (&temporary_obstack, '\0'); /* terminate token */
1955 tokenbuf = obstack_finish (&temporary_obstack);
1956 maybe_downcase (tokenbuf);
1958 if (*tokenbuf == '-')
1959 /* will fail in the next test */
1961 else if (maybe_number (tokenbuf))
1964 return integer_zero_node;
1965 push_obstacks_nochange ();
1966 end_temporary_allocation ();
1967 yylval.ttype = convert_integer (tokenbuf);
1968 tokenbuf = 0; /* Was freed by convert_integer. */
1969 result = yylval.ttype ? NUMBER : 0;
1975 if (result == NUMBER)
1977 retval = yylval.ttype;
1979 else if (result == BITSTRING)
1982 error ("invalid value follows `=' in compiler directive");
1985 else /* not a number */
1989 if (!ISALPHA (c) && c != '_')
1992 error ("invalid value follows `=' in compiler directive");
1996 for (cursor = &tokenbuf[1]; *cursor != '\0'; cursor++)
1997 if (ISALPHA ((unsigned char) *cursor) || *cursor == '_' ||
2003 error ("invalid `%c' character in name", *cursor);
2010 tree value = lookup_name (get_identifier (tokenbuf));
2011 if (value == NULL_TREE
2012 || TREE_CODE (value) != CONST_DECL
2013 || TREE_CODE (DECL_INITIAL (value)) != INTEGER_CST)
2016 error ("`%s' not integer constant synonym ",
2020 obstack_free (&temporary_obstack, tokenbuf);
2022 push_obstacks_nochange ();
2023 end_temporary_allocation ();
2024 retval = convert (chill_taskingcode_type_node, DECL_INITIAL (value));
2029 /* check the value */
2030 if (TREE_CODE (retval) != INTEGER_CST)
2033 error ("invalid value follows `=' in compiler directive");
2035 else if (TREE_INT_CST_HIGH (retval) != 0 ||
2036 TREE_INT_CST_LOW (retval) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node)))
2039 error ("value out of range in compiler directive");
2043 obstack_free (&temporary_obstack, tokenbuf);
2048 * add a possible grant-file path to the list
2051 register_seize_path (path)
2054 int pathlen = strlen (path);
2055 char *new_path = (char *)xmalloc (pathlen + 1);
2056 STRING_LIST *pl = (STRING_LIST *)xmalloc (sizeof (STRING_LIST));
2058 /* strip off trailing slash if any */
2059 if (path[pathlen - 1] == '/')
2062 memcpy (new_path, path, pathlen);
2064 pl->next = seize_path_list;
2065 seize_path_list = pl;
2069 /* Used by decode_decl to indicate that a <> use_seize_file NAME <>
2070 directive has been written to the grantfile. */
2073 mark_use_seizefile_written (name)
2078 for (node = files_to_seize; node != NULL_TREE; node = TREE_CHAIN (node))
2079 if (TREE_VALUE (node) == name)
2081 TREE_PURPOSE (node) = integer_one_node;
2090 extern char *chill_real_input_filename;
2092 close_input_file (input_filename);
2094 use_seizefile_name = NULL_TREE;
2096 if (next_file_to_seize && !grant_only_flag)
2098 FILE *grt_in = NULL;
2099 char *seizefile_name_chars
2100 = IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize));
2102 /* find a seize file, open it. If it's not at the path the
2103 * user gave us, and that path contains no slashes, look on
2104 * the seize_file paths, specified by the '-I' options.
2106 grt_in = fopen (seizefile_name_chars, "r");
2108 && strchr (seizefile_name_chars, '/') == NULL)
2113 for (plp = seize_path_list; plp != NULL; plp = plp->next)
2115 path = (char *)xmalloc (strlen (seizefile_name_chars)
2116 + strlen (plp->str) + 2);
2118 sprintf (path, "%s/%s", plp->str, seizefile_name_chars);
2119 grt_in = fopen (path, "r");
2124 seizefile_name_chars = path;
2131 pfatal_with_name (seizefile_name_chars);
2134 input_filename = seizefile_name_chars;
2137 current_seizefile_name = TREE_VALUE (next_file_to_seize);
2139 next_file_to_seize = TREE_CHAIN (next_file_to_seize);
2147 next_file_to_seize = files_to_seize;
2148 current_seizefile_name = NULL_TREE;
2150 if (strcmp (main_input_filename, "stdin"))
2151 finput = fopen (chill_real_input_filename, "r");
2156 error ("can't reopen %s", chill_real_input_filename);
2159 input_filename = main_input_filename;
2162 /* Read a line directive if there is one. */
2163 ungetc (check_newline (), finput);
2164 starting_pass_2 = 1;
2166 if (module_number == 0)
2167 warning ("no modules seen");