1 /* Lexical analyzer for GNU CHILL. -*- C -*-
2 Copyright (C) 1992, 93, 94, 98, 99, 2000 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
37 #ifdef DWARF_DEBUGGING_INFO
41 #ifdef MULTIBYTE_CHARS
45 /* include the keyword recognizers */
51 static int last_token = 0;
52 /* Sun's C compiler warns about the safer sequence
54 when there's a 'return' inside the braces, so don't use it */
55 #define RETURN_TOKEN(X) { last_token = X; return (X); }
58 /* This is set non-zero to force incoming tokens to lowercase. */
59 extern int ignore_case;
61 extern int module_number;
62 extern int serious_errors;
64 /* This is non-zero to recognize only uppercase special words. */
65 extern int special_UC;
67 extern struct obstack permanent_obstack;
68 extern struct obstack temporary_obstack;
70 /* forward declarations */
71 static void close_input_file PARAMS ((const char *));
72 static tree convert_bitstring PARAMS ((char *));
73 static tree convert_integer PARAMS ((char *));
74 static void maybe_downcase PARAMS ((char *));
75 static int maybe_number PARAMS ((const char *));
76 static tree equal_number PARAMS ((void));
77 static void handle_use_seizefile_directive PARAMS ((int));
78 static int handle_name PARAMS ((tree));
79 static char *readstring PARAMS ((int, int *));
80 static void read_directive PARAMS ((void));
81 static tree read_identifier PARAMS ((int));
82 static tree read_number PARAMS ((int));
83 static void skip_c_comment PARAMS ((void));
84 static void skip_line_comment PARAMS ((void));
85 static int skip_whitespace PARAMS ((void));
86 static tree string_or_char PARAMS ((int, const char *));
87 static void ch_lex_init PARAMS ((void));
88 static void skip_directive PARAMS ((void));
89 static int same_file PARAMS ((const char *, const char *));
90 static int getlc PARAMS ((FILE *));
92 /* next variables are public, because ch-actions uses them */
94 /* the default grantfile name, set by lang_init */
95 tree default_grant_file = 0;
97 /* These tasking-related variables are NULL at the start of each
98 compiler pass, and are set to an expression tree if and when
99 a compiler directive is parsed containing an expression.
100 The NULL state is significant; it means 'no user-specified
101 signal_code (or whatever) has been parsed'. */
103 /* process type, set by <> PROCESS_TYPE = number <> */
104 tree process_type = NULL_TREE;
106 /* send buffer default priority,
107 set by <> SEND_BUFFER_DEFAULT_PRIORITY = number <> */
108 tree send_buffer_prio = NULL_TREE;
110 /* send signal default priority,
111 set by <> SEND_SIGNAL_DEFAULT_PRIORITY = number <> */
112 tree send_signal_prio = NULL_TREE;
114 /* signal code, set by <> SIGNAL_CODE = number <> */
115 tree signal_code = NULL_TREE;
117 /* flag for range checking */
118 int range_checking = 1;
120 /* flag for NULL pointer checking */
121 int empty_checking = 1;
123 /* flag to indicate making all procedure local variables
125 int all_static_flag = 0;
127 /* flag to indicate -fruntime-checking command line option.
128 Needed for initializing range_checking and empty_checking
130 int runtime_checking_flag = 1;
132 /* The elements of `ridpointers' are identifier nodes
133 for the reserved type names and storage classes.
134 It is indexed by a RID_... value. */
135 tree ridpointers[(int) RID_MAX];
137 /* Nonzero tells yylex to ignore \ in string constants. */
138 static int ignore_escape_flag = 0;
140 static int maxtoken; /* Current nominal length of token buffer. */
141 char *token_buffer; /* Pointer to token buffer.
142 Actual allocated length is maxtoken + 2.
143 This is not static because objc-parse.y uses it. */
145 /* implement yylineno handling for flex */
146 #define yylineno lineno
148 static int inside_c_comment = 0;
150 static int saw_eol = 0; /* 1 if we've just seen a '\n' */
151 static int saw_eof = 0; /* 1 if we've just seen an EOF */
153 typedef struct string_list
155 struct string_list *next;
159 /* list of paths specified on the compiler command line by -L options. */
160 static STRING_LIST *seize_path_list = (STRING_LIST *)0;
162 /* List of seize file names. Each TREE_VALUE is an identifier
163 (file name) from a <>USE_SEIZE_FILE<> directive.
164 The TREE_PURPOSE is non-NULL if a USE_SEIZE_FILE directive has been
165 written to the grant file. */
166 static tree files_to_seize = NULL_TREE;
167 /* Last node on files_to_seize list. */
168 static tree last_file_to_seize = NULL_TREE;
169 /* Pointer into files_to_seize list: Next unparsed file to read. */
170 static tree next_file_to_seize = NULL_TREE;
172 /* The most recent use_seize_file directive. */
173 tree use_seizefile_name = NULL_TREE;
175 /* If non-NULL, the name of the seizefile we're currently processing. */
176 tree current_seizefile_name = NULL_TREE;
178 /* called to reset for pass 2 */
182 current_seizefile_name = NULL_TREE;
188 /* Initialize these compiler-directive variables. */
189 process_type = NULL_TREE;
190 send_buffer_prio = NULL_TREE;
191 send_signal_prio = NULL_TREE;
192 signal_code = NULL_TREE;
194 /* reinitialize rnage checking and empty checking */
195 range_checking = runtime_checking_flag;
196 empty_checking = runtime_checking_flag;
201 init_parse (filename)
202 const char *filename;
204 int lowercase_standard_names = ignore_case || ! special_UC;
206 /* Open input file. */
207 if (filename == 0 || !strcmp (filename, "-"))
213 finput = fopen (filename, "r");
215 pfatal_with_name (filename);
217 #ifdef IO_BUFFER_SIZE
218 setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
221 /* Make identifier nodes long enough for the language-specific slots. */
222 set_identifier_size (sizeof (struct lang_identifier));
224 /* Start it at 0, because check_newline is called at the very beginning
225 and will increment it to 1. */
228 /* Initialize these compiler-directive variables. */
229 process_type = NULL_TREE;
230 send_buffer_prio = NULL_TREE;
231 send_signal_prio = NULL_TREE;
232 signal_code = NULL_TREE;
235 token_buffer = xmalloc ((unsigned)(maxtoken + 2));
237 init_chill_expand ();
239 #define ENTER_STANDARD_NAME(RID, LOWER, UPPER) \
240 ridpointers[(int) RID] = \
241 get_identifier (lowercase_standard_names ? LOWER : UPPER)
243 ENTER_STANDARD_NAME (RID_ALL, "all", "ALL");
244 ENTER_STANDARD_NAME (RID_ASSERTFAIL, "assertfail", "ASSERTFAIL");
245 ENTER_STANDARD_NAME (RID_ASSOCIATION, "association", "ASSOCIATION");
246 ENTER_STANDARD_NAME (RID_BIN, "bin", "BIN");
247 ENTER_STANDARD_NAME (RID_BOOL, "bool", "BOOL");
248 ENTER_STANDARD_NAME (RID_BOOLS, "bools", "BOOLS");
249 ENTER_STANDARD_NAME (RID_BYTE, "byte", "BYTE");
250 ENTER_STANDARD_NAME (RID_CHAR, "char", "CHAR");
251 ENTER_STANDARD_NAME (RID_DOUBLE, "double", "DOUBLE");
252 ENTER_STANDARD_NAME (RID_DURATION, "duration", "DURATION");
253 ENTER_STANDARD_NAME (RID_DYNAMIC, "dynamic", "DYNAMIC");
254 ENTER_STANDARD_NAME (RID_ELSE, "else", "ELSE");
255 ENTER_STANDARD_NAME (RID_EMPTY, "empty", "EMPTY");
256 ENTER_STANDARD_NAME (RID_FALSE, "false", "FALSE");
257 ENTER_STANDARD_NAME (RID_FLOAT, "float", "FLOAT");
258 ENTER_STANDARD_NAME (RID_GENERAL, "general", "GENERAL");
259 ENTER_STANDARD_NAME (RID_IN, "in", "IN");
260 ENTER_STANDARD_NAME (RID_INLINE, "inline", "INLINE");
261 ENTER_STANDARD_NAME (RID_INOUT, "inout", "INOUT");
262 ENTER_STANDARD_NAME (RID_INSTANCE, "instance", "INSTANCE");
263 ENTER_STANDARD_NAME (RID_INT, "int", "INT");
264 ENTER_STANDARD_NAME (RID_LOC, "loc", "LOC");
265 ENTER_STANDARD_NAME (RID_LONG, "long", "LONG");
266 ENTER_STANDARD_NAME (RID_LONG_REAL, "long_real", "LONG_REAL");
267 ENTER_STANDARD_NAME (RID_NULL, "null", "NULL");
268 ENTER_STANDARD_NAME (RID_OUT, "out", "OUT");
269 ENTER_STANDARD_NAME (RID_OVERFLOW, "overflow", "OVERFLOW");
270 ENTER_STANDARD_NAME (RID_PTR, "ptr", "PTR");
271 ENTER_STANDARD_NAME (RID_READ, "read", "READ");
272 ENTER_STANDARD_NAME (RID_REAL, "real", "REAL");
273 ENTER_STANDARD_NAME (RID_RANGE, "range", "RANGE");
274 ENTER_STANDARD_NAME (RID_RANGEFAIL, "rangefail", "RANGEFAIL");
275 ENTER_STANDARD_NAME (RID_RECURSIVE, "recursive", "RECURSIVE");
276 ENTER_STANDARD_NAME (RID_SHORT, "short", "SHORT");
277 ENTER_STANDARD_NAME (RID_SIMPLE, "simple", "SIMPLE");
278 ENTER_STANDARD_NAME (RID_TIME, "time", "TIME");
279 ENTER_STANDARD_NAME (RID_TRUE, "true", "TRUE");
280 ENTER_STANDARD_NAME (RID_UBYTE, "ubyte", "UBYTE");
281 ENTER_STANDARD_NAME (RID_UINT, "uint", "UINT");
282 ENTER_STANDARD_NAME (RID_ULONG, "ulong", "ULONG");
283 ENTER_STANDARD_NAME (RID_UNSIGNED, "unsigned", "UNSIGNED");
284 ENTER_STANDARD_NAME (RID_USHORT, "ushort", "USHORT");
285 ENTER_STANDARD_NAME (RID_VOID, "void", "VOID");
297 static int yywrap PARAMS ((void));
298 static int yy_refill PARAMS ((void));
300 #define YY_PUTBACK_SIZE 5
301 #define YY_BUF_SIZE 1000
303 static char yy_buffer[YY_PUTBACK_SIZE + YY_BUF_SIZE];
304 static char *yy_cur = yy_buffer + YY_PUTBACK_SIZE;
305 static char *yy_lim = yy_buffer + YY_PUTBACK_SIZE;
310 char *buf = yy_buffer + YY_PUTBACK_SIZE;
312 bcopy (yy_cur - YY_PUTBACK_SIZE, yy_buffer, YY_PUTBACK_SIZE);
327 c = check_newline ();
340 while (result < YY_BUF_SIZE)
350 /* Because we might switch input files on a compiler directive
351 (that end with '>', don't read past a '>', just in case. */
360 fprintf (stderr, "-------------------------- finished Line %d\n",
368 yy_lim = yy_cur + result;
370 return yy_lim > yy_cur ? *yy_cur++ : EOF;
373 #define input() (yy_cur < yy_lim ? *yy_cur++ : yy_refill ())
375 #define unput(c) (*--yy_cur = (c))
378 int starting_pass_2 = 0;
398 case ' ': case '\t': case '\n': case '\f': case '\b': case '\v': case '\r':
420 else if (nextc == '=')
436 skip_line_comment ();
449 else if (nextc == '=')
451 else if (nextc == '*')
494 int len = 0; /* Number of hex digits seen. */
502 if (!ISXDIGIT (ch)) /* error on non-hex digit */
505 error ("invalid C'xx' ");
516 if (len & 1) /* collected two digits, save byte */
517 obstack_1grow (&temporary_obstack, (char) byte_val);
520 start = obstack_finish (&temporary_obstack);
521 yylval.ttype = string_or_char (len >> 1, start);
522 obstack_free (&temporary_obstack, start);
523 return len == 2 ? SINGLECHAR : STRING;
533 obstack_1grow (&temporary_obstack, ch);
534 obstack_1grow (&temporary_obstack, nextc);
539 obstack_1grow (&temporary_obstack, ch);
543 obstack_1grow (&temporary_obstack, '\0');
544 start = obstack_finish (&temporary_obstack);
548 yylval.ttype = convert_integer (start); /* Pass base? */
553 yylval.ttype = convert_bitstring (start);
561 case 'F': case 'G': case 'I': case 'J':
562 case 'K': case 'L': case 'M': case 'N':
563 case 'P': case 'Q': case 'R': case 'S': case 'T':
564 case 'U': case 'V': case 'W': case 'X': case 'Y':
567 case 'f': case 'g': case 'i': case 'j':
568 case 'k': case 'l': case 'm': case 'n':
569 case 'p': case 'q': case 'r': case 's': case 't':
570 case 'u': case 'v': case 'w': case 'x': case 'y':
574 return handle_name (read_identifier (ch));
576 tmp = readstring ('\'', &len);
577 yylval.ttype = string_or_char (len, tmp);
579 return len == 1 ? SINGLECHAR : STRING;
581 tmp = readstring ('\"', &len);
582 yylval.ttype = build_chill_string (len, tmp);
588 if (ISDIGIT (nextc)) /* || nextc == '_') we don't start numbers with '_' */
591 case '0': case '1': case '2': case '3': case '4':
592 case '5': case '6': case '7': case '8': case '9':
594 yylval.ttype = read_number (ch);
595 return TREE_CODE (yylval.ttype) == REAL_CST ? FLOATING : NUMBER;
602 close_input_file (fn)
608 if (finput != stdin && fclose (finput) == EOF)
610 error ("can't close %s", fn);
616 /* Return an identifier, starting with FIRST and then reading
617 more characters using input(). Return an IDENTIFIER_NODE. */
620 read_identifier (first)
621 int first; /* First letter of identifier */
627 obstack_1grow (&temporary_obstack, first);
631 if (! ISALNUM (first) && first != '_')
637 obstack_1grow (&temporary_obstack, '\0');
638 start = obstack_finish (&temporary_obstack);
639 maybe_downcase (start);
640 id = get_identifier (start);
641 obstack_free (&temporary_obstack, start);
645 /* Given an identifier ID, check to see if it is a reserved name,
646 and return the appropriate token type. */
653 tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
655 && special_UC == ISUPPER ((unsigned char) tp->name[0])
656 && (tp->flags == RESERVED || tp->flags == PREDEF))
658 if (tp->rid != NORID)
659 yylval.ttype = ridpointers[tp->rid];
660 else if (tp->token == THIS)
661 yylval.ttype = lookup_name (get_identifier ("__whoami"));
670 int ch; /* Initial character */
678 obstack_1grow (&temporary_obstack, ch);
680 if (! ISDIGIT (ch) && ch != '_')
688 obstack_1grow (&temporary_obstack, ch);
690 } while (ISDIGIT (ch) || ch == '_');
693 if (ch == 'd' || ch == 'D' || ch == 'e' || ch == 'E')
695 /* Convert exponent indication [eEdD] to 'e'. */
696 obstack_1grow (&temporary_obstack, 'e');
698 if (ch == '+' || ch == '-')
700 obstack_1grow (&temporary_obstack, ch);
703 if (ISDIGIT (ch) || ch == '_')
708 obstack_1grow (&temporary_obstack, ch);
710 } while (ISDIGIT (ch) || ch == '_');
714 error ("malformed exponent part of floating-point literal");
720 obstack_1grow (&temporary_obstack, '\0');
721 start = obstack_finish (&temporary_obstack);
724 REAL_VALUE_TYPE value;
725 tree type = double_type_node;
727 value = REAL_VALUE_ATOF (start, TYPE_MODE (type));
728 obstack_free (&temporary_obstack, start);
729 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
730 && REAL_VALUE_ISINF (value) && pedantic)
731 pedwarn ("real number exceeds range of REAL");
732 num = build_real (type, value);
735 num = convert_integer (start);
736 CH_DERIVED_FLAG (num) = 1;
740 /* Skip to the end of a compiler directive. */
750 error ("end-of-file in '<>' directive");
766 /* Read a compiler directive. ("<>{WS}" have already been read. ) */
772 int ch = skip_whitespace();
773 if (ISALPHA (ch) || ch == '_')
774 id = read_identifier (ch);
777 error ("end-of-file in '<>' directive");
778 to_global_binding_level ();
783 warning ("unrecognized compiler directive");
787 tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
788 if (tp == NULL || special_UC != ISUPPER ((unsigned char) tp->name[0]))
791 warning ("unrecognized compiler directive `%s'",
792 IDENTIFIER_POINTER (id));
809 case IGNORED_DIRECTIVE:
811 case PROCESS_TYPE_TOKEN:
812 process_type = equal_number ();
820 case SEND_SIGNAL_DEFAULT_PRIORITY:
821 send_signal_prio = equal_number ();
823 case SEND_BUFFER_DEFAULT_PRIORITY:
824 send_buffer_prio = equal_number ();
827 signal_code = equal_number ();
830 handle_use_seizefile_directive (0);
832 case USE_SEIZE_FILE_RESTRICTED:
833 handle_use_seizefile_directive (1);
837 warning ("unrecognized compiler directive `%s'",
838 IDENTIFIER_POINTER (id));
846 build_chill_string (len, str)
852 push_obstacks (&permanent_obstack, &permanent_obstack);
853 t = build_string (len, str);
854 TREE_TYPE (t) = build_string_type (char_type_node,
855 build_int_2 (len, 0));
856 CH_DERIVED_FLAG (t) = 1;
863 string_or_char (len, str)
869 push_obstacks (&permanent_obstack, &permanent_obstack);
872 result = build_int_2 ((unsigned char)str[0], 0);
873 CH_DERIVED_FLAG (result) = 1;
874 TREE_TYPE (result) = char_type_node;
877 result = build_chill_string (len, str);
891 if (ISUPPER ((unsigned char) *str))
892 *str = TOLOWER (*str);
904 /* check for decimal number */
905 if (*s >= '0' && *s <= '9')
909 if (*s >= '0' && *s <= '9')
927 if (*s < '0' || *s > '9')
932 if (!ISXDIGIT ((unsigned char) *s))
937 if (*s < '0' || *s > '1')
942 if (*s < '0' || *s > '7')
954 readstring (terminator, len)
959 unsigned allocated = 1024;
960 char *tmp = xmalloc (allocated);
968 if ((c = input ()) != terminator)
976 if (c == '\n' || c == EOF)
981 if (c == EOF || c == '\n')
995 if (cc == terminator)
997 if (!(terminator == '\'' && next_apos))
999 error ("unterminated control sequence");
1004 if (cc == EOF || cc == '\n')
1014 error ("invalid integer literal in control sequence");
1020 if (cc == ' ' || cc == '\t')
1024 if ((c < 0 || c > 255) && (pass == 1))
1025 error ("control sequence overflow");
1026 if (! count && pass == 1)
1027 error ("invalid control sequence");
1032 if ((c < 0 || c > 255) && (pass == 1))
1033 error ("control sequence overflow");
1034 if (! count && pass == 1)
1035 error ("invalid control sequence");
1040 tmp = xrealloc (tmp, allocated);
1049 if (! count && pass == 1)
1050 error ("invalid integer literal in control sequence");
1055 if (cc == 'D' || cc == 'd')
1060 else if (cc == 'H' || cc == 'h')
1065 else if (cc == 'O' || cc == 'o')
1070 else if (cc == 'B' || cc == 'b')
1081 if (cc < '0' || cc > '1')
1088 if (cc < '0' || cc > '8')
1093 else if (base == 10)
1100 else if (base == 16)
1115 error ("invalid base in read control sequence");
1120 /* error in control sequence */
1122 error ("invalid digit in control sequence");
1125 c = (c * base) + cc;
1137 tmp = xrealloc (tmp, allocated);
1141 tmp [*len = i] = '\0';
1149 error ("unterminated string literal");
1150 to_global_binding_level ();
1155 /* Convert an integer INTCHARS into an INTEGER_CST.
1156 INTCHARS is on the temporary_obstack, and is popped by this function. */
1159 convert_integer (intchars)
1168 int valid_chars = 0;
1171 HOST_WIDE_INT val_lo = 0, val_hi = 0;
1174 /* determine the base */
1197 if (!ISDIGIT (*p)) /* this test is for equal_number () */
1199 obstack_free (&temporary_obstack, intchars);
1208 if ((tmp == '\'') || (tmp == '_'))
1212 if (tmp >= 'a') /* uppercase the char */
1214 switch (base) /* validate the characters */
1231 if (tmp > '9' && tmp < 'A')
1240 if (mul_double (val_lo, val_hi, base, 0, &val_lo, &val_hi))
1242 add_double (val_lo, val_hi, tmp, 0, &val_lo, &val_hi);
1248 obstack_free (&temporary_obstack, intchars);
1252 error ("invalid number format `%s'", oldp);
1255 val = build_int_2 (val_lo, val_hi);
1256 /* We set the type to long long (or long long unsigned) so that
1257 constant fold of literals is less likely to overflow. */
1258 if (int_fits_type_p (val, long_long_integer_type_node))
1259 type = long_long_integer_type_node;
1262 if (! int_fits_type_p (val, long_long_unsigned_type_node))
1264 type = long_long_unsigned_type_node;
1266 TREE_TYPE (val) = type;
1267 CH_DERIVED_FLAG (val) = 1;
1270 error ("integer literal too big");
1275 /* Convert a bitstring literal on the temporary_obstack to
1276 a bitstring CONSTRUCTOR. Free the literal from the obstack. */
1279 convert_bitstring (p)
1285 int bl = 0, valid_chars = 0, bits_per_char = 0, c, k;
1286 tree initlist = NULL_TREE;
1289 /* Move p to stack so we can re-use temporary_obstack for result. */
1290 char *oldp = (char*) alloca (strlen (p) + 1);
1291 if (oldp == 0) fatal ("stack space exhausted");
1293 obstack_free (&temporary_obstack, p);
1316 if (c == '_' || c == '\'')
1325 for (k = BYTES_BIG_ENDIAN ? bits_per_char - 1 : 0;
1326 BYTES_BIG_ENDIAN ? k >= 0 : k < bits_per_char;
1327 bl++, BYTES_BIG_ENDIAN ? k-- : k++)
1330 initlist = tree_cons (NULL_TREE, build_int_2 (bl, 0), initlist);
1334 /* as long as BOOLS(0) is valid it must tbe possible to
1335 specify an empty bitstring */
1339 error ("invalid number format `%s'", oldp);
1343 val = build (CONSTRUCTOR,
1344 build_bitstring_type (size_int (bl)),
1345 NULL_TREE, nreverse (initlist));
1346 TREE_CONSTANT (val) = 1;
1347 CH_DERIVED_FLAG (val) = 1;
1351 /* Check if two filenames name the same file.
1352 This is done by stat'ing both files and comparing their inodes.
1354 Note: we have to take care of seize_path_list. Therefore do it the same
1355 way as in yywrap. FIXME: This probably can be done better. */
1358 same_file (filename1, filename2)
1359 const char *filename1;
1360 const char *filename2;
1363 const char *fn_input[2];
1366 if (grant_only_flag)
1367 /* do nothing in this case */
1370 /* if filenames are equal -- return 1, cause there is no need
1371 to search in the include list in this case */
1372 if (strcmp (filename1, filename2) == 0)
1375 fn_input[0] = filename1;
1376 fn_input[1] = filename2;
1378 for (i = 0; i < 2; i++)
1380 stat_status = stat (fn_input[i], &s[i]);
1381 if (stat_status < 0 &&
1382 strchr (fn_input[i], '/') == 0)
1387 for (plp = seize_path_list; plp != 0; plp = plp->next)
1389 path = (char *)xmalloc (strlen (fn_input[i]) +
1390 strlen (plp->str) + 2);
1391 sprintf (path, "%s/%s", plp->str, fn_input[i]);
1392 stat_status = stat (path, &s[i]);
1394 if (stat_status >= 0)
1398 if (stat_status < 0)
1399 pfatal_with_name (fn_input[i]);
1401 return s[0].st_ino == s[1].st_ino && s[0].st_dev == s[1].st_dev;
1405 * Note that simply appending included file names to a list in this
1406 * way completely eliminates the need for nested files, and the
1407 * associated book-keeping, since the EOF processing in the lexer
1408 * will simply process the files one at a time, in the order that the
1409 * USE_SEIZE_FILE directives were scanned.
1412 handle_use_seizefile_directive (restricted)
1417 int c = skip_whitespace ();
1418 char *use_seizefile_str = readstring (c, &len);
1423 if (c != '\'' && c != '\"')
1425 error ("USE_SEIZE_FILE directive must be followed by string");
1429 use_seizefile_name = get_identifier (use_seizefile_str);
1430 CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name) = restricted;
1432 if (!grant_only_flag)
1434 /* If file foo.ch contains a <> use_seize_file "bar.grt" <>,
1435 and file bar.ch contains a <> use_seize_file "foo.grt" <>,
1436 then if we're compiling foo.ch, we will indirectly be
1437 asked to seize foo.grt. Don't. */
1438 extern char *grant_file_name;
1439 if (strcmp (use_seizefile_str, grant_file_name) == 0)
1442 /* Check if the file is already on the list. */
1443 for (seen = files_to_seize; seen != NULL_TREE; seen = TREE_CHAIN (seen))
1444 if (same_file (IDENTIFIER_POINTER (TREE_VALUE (seen)),
1446 return; /* Previously seen; nothing to do. */
1449 /* Haven't been asked to seize this file yet, so add
1450 its name to the list. */
1452 tree pl = perm_tree_cons (0, use_seizefile_name, NULL_TREE);
1453 if (files_to_seize == NULL_TREE)
1454 files_to_seize = pl;
1456 TREE_CHAIN (last_file_to_seize) = pl;
1457 if (next_file_to_seize == NULL_TREE)
1458 next_file_to_seize = pl;
1459 last_file_to_seize = pl;
1465 * get input, convert to lower case for comparison
1479 #if defined HANDLE_PRAGMA
1480 /* Local versions of these macros, that can be passed as function pointers. */
1484 return getc (finput);
1491 ungetc (arg, finput);
1493 #endif /* HANDLE_PRAGMA */
1495 #ifdef HANDLE_GENERIC_PRAGMAS
1496 /* Handle a generic #pragma directive.
1497 BUFFER contains the text we read after `#pragma'. Processes the entire input
1498 line and return non-zero iff the pragma was successfully processed. */
1501 handle_generic_pragma (buffer)
1510 handle_pragma_token (buffer, NULL);
1514 while (c == ' ' || c == '\t')
1518 if (c == '\n' || c == EOF)
1519 return handle_pragma_token (NULL, NULL);
1521 /* Read the next word of the pragma into the buffer. */
1528 while (c != EOF && isascii (c) && ! ISSPACE (c) && c != '\n'
1529 && buff < buffer + 128); /* XXX shared knowledge about size of buffer. */
1536 #endif /* HANDLE_GENERIC_PRAGMAS */
1538 /* At the beginning of a line, increment the line number and process
1539 any #-directive on this line. If the line is a #-directive, read
1540 the entire line and return a newline. Otherwise, return the line's
1541 first non-whitespace character.
1543 (Each language front end has a check_newline() function that is called
1544 from lang_init() for that language. One of the things this function
1545 must do is read the first line of the input file, and if it is a #line
1546 directive, extract the filename from it and use it to initialize
1547 main_input_filename. Proper generation of debugging information in
1548 the normal "front end calls cpp then calls cc1XXXX environment" depends
1549 upon this being done.) */
1558 /* Read first nonwhite char on the line. */
1562 while (c == ' ' || c == '\t')
1565 if (c != '#' || inside_c_comment)
1567 /* If not #, return it so caller will use it. */
1571 /* Read first nonwhite char after the `#'. */
1574 while (c == ' ' || c == '\t')
1577 /* If a letter follows, then if the word here is `line', skip
1578 it and ignore it; otherwise, ignore the line, with an error
1579 if the word isn't `pragma', `ident', `define', or `undef'. */
1584 if (c >= 'a' && c <= 'z')
1588 if (getlc (finput) == 'r'
1589 && getlc (finput) == 'a'
1590 && getlc (finput) == 'g'
1591 && getlc (finput) == 'm'
1592 && getlc (finput) == 'a'
1593 && (c = getlc (finput), ISSPACE (c)))
1595 #ifdef HANDLE_PRAGMA
1596 static char buffer [128];
1597 char * buff = buffer;
1599 /* Read the pragma name into a buffer. */
1600 while (c = getlc (finput), ISSPACE (c))
1608 while (c != EOF && ! ISSPACE (c) && c != '\n'
1609 && buff < buffer + 128);
1615 if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc, buffer))
1617 #endif /* HANDLE_PRAGMA */
1619 #ifdef HANDLE_GENERIC_PRAGMAS
1620 if (handle_generic_pragma (buffer))
1622 #endif /* HANDLE_GENERIC_PRAGMAS */
1630 if (getlc (finput) == 'e'
1631 && getlc (finput) == 'f'
1632 && getlc (finput) == 'i'
1633 && getlc (finput) == 'n'
1634 && getlc (finput) == 'e'
1635 && (c = getlc (finput), ISSPACE (c)))
1637 #if 0 /*def DWARF_DEBUGGING_INFO*/
1639 && (debug_info_level == DINFO_LEVEL_VERBOSE)
1640 && (write_symbols == DWARF_DEBUG))
1641 dwarfout_define (lineno, get_directive_line (finput));
1642 #endif /* DWARF_DEBUGGING_INFO */
1648 if (getlc (finput) == 'n'
1649 && getlc (finput) == 'd'
1650 && getlc (finput) == 'e'
1651 && getlc (finput) == 'f'
1652 && (c = getlc (finput), ISSPACE (c)))
1654 #if 0 /*def DWARF_DEBUGGING_INFO*/
1656 && (debug_info_level == DINFO_LEVEL_VERBOSE)
1657 && (write_symbols == DWARF_DEBUG))
1658 dwarfout_undef (lineno, get_directive_line (finput));
1659 #endif /* DWARF_DEBUGGING_INFO */
1665 if (getlc (finput) == 'i'
1666 && getlc (finput) == 'n'
1667 && getlc (finput) == 'e'
1668 && ((c = getlc (finput)) == ' ' || c == '\t'))
1674 if (getlc (finput) == 'd'
1675 && getlc (finput) == 'e'
1676 && getlc (finput) == 'n'
1677 && getlc (finput) == 't'
1678 && ((c = getlc (finput)) == ' ' || c == '\t'))
1680 /* #ident. The pedantic warning is now in cpp. */
1682 /* Here we have just seen `#ident '.
1683 A string constant should follow. */
1685 while (c == ' ' || c == '\t')
1688 /* If no argument, ignore the line. */
1695 || TREE_CODE (yylval.ttype) != STRING_CST)
1697 error ("invalid #ident");
1703 #ifdef ASM_OUTPUT_IDENT
1704 extern FILE *asm_out_file;
1705 ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
1709 /* Skip the rest of this line. */
1715 error ("undefined or invalid # directive");
1720 /* Here we have either `#line' or `# <nonletter>'.
1721 In either case, it should be a line number; a digit should follow. */
1723 while (c == ' ' || c == '\t')
1726 /* If the # is the only nonwhite char on the line,
1727 just ignore it. Check the new newline. */
1731 /* Something follows the #; read a token. */
1735 int old_lineno = lineno;
1738 extern struct obstack permanent_obstack;
1742 l = l * 10 + (c - '0'); /* FIXME Not portable */
1744 } while (ISDIGIT(c));
1745 /* subtract one, because it is the following line that
1746 gets the specified number */
1750 /* Is this the last nonwhite stuff on the line? */
1752 while (c == ' ' || c == '\t')
1756 /* No more: store the line number and check following line. */
1761 /* More follows: it must be a string constant (filename). */
1763 /* Read the string constant, but don't treat \ as special. */
1764 ignore_escape_flag = 1;
1765 ignore_escape_flag = 0;
1769 error ("invalid #line");
1776 if (c == EOF || c == '\n')
1778 error ("invalid #line");
1783 obstack_1grow(&permanent_obstack, 0);
1784 input_filename = obstack_finish (&permanent_obstack);
1787 obstack_1grow(&permanent_obstack, c);
1792 /* Each change of file name
1793 reinitializes whether we are now in a system header. */
1794 in_system_header = 0;
1796 if (main_input_filename == 0)
1797 main_input_filename = input_filename;
1799 /* Is this the last nonwhite stuff on the line? */
1801 while (c == ' ' || c == '\t')
1808 /* `1' after file name means entering new file.
1809 `2' after file name means just left a file. */
1815 /* Pushing to a new file. */
1816 struct file_stack *p
1817 = (struct file_stack *) xmalloc (sizeof (struct file_stack));
1818 input_file_stack->line = old_lineno;
1819 p->next = input_file_stack;
1820 p->name = input_filename;
1821 input_file_stack = p;
1822 input_file_stack_tick++;
1823 #ifdef DWARF_DEBUGGING_INFO
1824 if (debug_info_level == DINFO_LEVEL_VERBOSE
1825 && write_symbols == DWARF_DEBUG)
1826 dwarfout_start_new_source_file (input_filename);
1827 #endif /* DWARF_DEBUGGING_INFO */
1833 /* Popping out of a file. */
1834 if (input_file_stack->next)
1836 struct file_stack *p = input_file_stack;
1837 input_file_stack = p->next;
1839 input_file_stack_tick++;
1840 #ifdef DWARF_DEBUGGING_INFO
1841 if (debug_info_level == DINFO_LEVEL_VERBOSE
1842 && write_symbols == DWARF_DEBUG)
1843 dwarfout_resume_previous_source_file (input_file_stack->line);
1844 #endif /* DWARF_DEBUGGING_INFO */
1847 error ("#-lines for entering and leaving files don't match");
1853 /* If we have handled a `1' or a `2',
1854 see if there is another number to read. */
1857 /* Is this the last nonwhite stuff on the line? */
1859 while (c == ' ' || c == '\t')
1866 /* `3' after file name means this is a system header file. */
1869 in_system_header = 1;
1872 error ("invalid #-line");
1874 /* skip the rest of this line. */
1876 while (c != '\n' && c != EOF)
1883 get_chill_filename ()
1885 return (build_chill_string (
1886 strlen (input_filename) + 1, /* +1 to get a zero terminated string */
1891 get_chill_linenumber ()
1893 return build_int_2 ((HOST_WIDE_INT)lineno, 0);
1897 /* Assuming '/' and '*' have been read, skip until we've
1898 read the terminating '*' and '/'. */
1904 int start_line = lineno;
1910 error_with_file_and_line (input_filename, start_line,
1911 "unterminated comment");
1916 else if ((c = input ()) == '/')
1922 /* Assuming "--" has been read, skip until '\n'. */
1925 skip_line_comment ()
1949 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v')
1970 skip_line_comment ();
1984 * avoid recursive calls to yylex to parse the ' = digits' or
1985 * ' = SYNvalue' which are supposed to follow certain compiler
1986 * directives. Read the input stream, and return the value parsed.
1988 /* FIXME: overflow check in here */
1989 /* FIXME: check for EOF around here */
1996 tree retval = integer_zero_node;
1998 c = skip_whitespace();
2002 error ("missing `=' in compiler directive");
2003 return integer_zero_node;
2005 c = skip_whitespace();
2007 /* collect token into tokenbuf for later analysis */
2010 if (ISSPACE (c) || c == '<')
2012 obstack_1grow (&temporary_obstack, c);
2015 unput (c); /* put uninteresting char back */
2016 obstack_1grow (&temporary_obstack, '\0'); /* terminate token */
2017 tokenbuf = obstack_finish (&temporary_obstack);
2018 maybe_downcase (tokenbuf);
2020 if (*tokenbuf == '-')
2021 /* will fail in the next test */
2023 else if (maybe_number (tokenbuf))
2026 return integer_zero_node;
2027 push_obstacks_nochange ();
2028 end_temporary_allocation ();
2029 yylval.ttype = convert_integer (tokenbuf);
2030 tokenbuf = 0; /* Was freed by convert_integer. */
2031 result = yylval.ttype ? NUMBER : 0;
2037 if (result == NUMBER)
2039 retval = yylval.ttype;
2041 else if (result == BITSTRING)
2044 error ("invalid value follows `=' in compiler directive");
2047 else /* not a number */
2051 if (!ISALPHA (c) && c != '_')
2054 error ("invalid value follows `=' in compiler directive");
2058 for (cursor = &tokenbuf[1]; *cursor != '\0'; cursor++)
2059 if (ISALPHA ((unsigned char) *cursor) || *cursor == '_' ||
2065 error ("invalid `%c' character in name", *cursor);
2072 tree value = lookup_name (get_identifier (tokenbuf));
2073 if (value == NULL_TREE
2074 || TREE_CODE (value) != CONST_DECL
2075 || TREE_CODE (DECL_INITIAL (value)) != INTEGER_CST)
2078 error ("`%s' not integer constant synonym ",
2082 obstack_free (&temporary_obstack, tokenbuf);
2084 push_obstacks_nochange ();
2085 end_temporary_allocation ();
2086 retval = convert (chill_taskingcode_type_node, DECL_INITIAL (value));
2091 /* check the value */
2092 if (TREE_CODE (retval) != INTEGER_CST)
2095 error ("invalid value follows `=' in compiler directive");
2097 else if (TREE_INT_CST_HIGH (retval) != 0 ||
2098 TREE_INT_CST_LOW (retval) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node)))
2101 error ("value out of range in compiler directive");
2105 obstack_free (&temporary_obstack, tokenbuf);
2110 * add a possible grant-file path to the list
2113 register_seize_path (path)
2116 int pathlen = strlen (path);
2117 char *new_path = (char *)xmalloc (pathlen + 1);
2118 STRING_LIST *pl = (STRING_LIST *)xmalloc (sizeof (STRING_LIST));
2120 /* strip off trailing slash if any */
2121 if (path[pathlen - 1] == '/')
2124 memcpy (new_path, path, pathlen);
2126 pl->next = seize_path_list;
2127 seize_path_list = pl;
2131 /* Used by decode_decl to indicate that a <> use_seize_file NAME <>
2132 directive has been written to the grantfile. */
2135 mark_use_seizefile_written (name)
2140 for (node = files_to_seize; node != NULL_TREE; node = TREE_CHAIN (node))
2141 if (TREE_VALUE (node) == name)
2143 TREE_PURPOSE (node) = integer_one_node;
2152 extern char *chill_real_input_filename;
2154 close_input_file (input_filename);
2156 use_seizefile_name = NULL_TREE;
2158 if (next_file_to_seize && !grant_only_flag)
2160 FILE *grt_in = NULL;
2161 const char *seizefile_name_chars
2162 = IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize));
2164 /* find a seize file, open it. If it's not at the path the
2165 * user gave us, and that path contains no slashes, look on
2166 * the seize_file paths, specified by the '-I' options.
2168 grt_in = fopen (seizefile_name_chars, "r");
2170 && strchr (seizefile_name_chars, '/') == NULL)
2175 for (plp = seize_path_list; plp != NULL; plp = plp->next)
2177 path = (char *)xmalloc (strlen (seizefile_name_chars)
2178 + strlen (plp->str) + 2);
2180 sprintf (path, "%s/%s", plp->str, seizefile_name_chars);
2181 grt_in = fopen (path, "r");
2186 seizefile_name_chars = path;
2193 pfatal_with_name (seizefile_name_chars);
2196 input_filename = seizefile_name_chars;
2199 current_seizefile_name = TREE_VALUE (next_file_to_seize);
2201 next_file_to_seize = TREE_CHAIN (next_file_to_seize);
2209 next_file_to_seize = files_to_seize;
2210 current_seizefile_name = NULL_TREE;
2212 if (strcmp (main_input_filename, "stdin"))
2213 finput = fopen (chill_real_input_filename, "r");
2218 error ("can't reopen %s", chill_real_input_filename);
2221 input_filename = main_input_filename;
2224 /* Read a line directive if there is one. */
2225 ungetc (check_newline (), finput);
2226 starting_pass_2 = 1;
2228 if (module_number == 0)
2229 warning ("no modules seen");