1 /* Lexical analyzer for GNU CHILL. -*- C -*-
2 Copyright (C) 1992, 1993, 1994, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
38 #ifdef DWARF_DEBUGGING_INFO
42 #ifdef MULTIBYTE_CHARS
46 /* include the keyword recognizers */
52 static int last_token
= 0;
53 /* Sun's C compiler warns about the safer sequence
55 when there's a 'return' inside the braces, so don't use it */
56 #define RETURN_TOKEN(X) { last_token = X; return (X); }
59 /* This is set non-zero to force incoming tokens to lowercase. */
60 extern int ignore_case
;
62 extern int module_number
;
63 extern int serious_errors
;
65 /* This is non-zero to recognize only uppercase special words. */
66 extern int special_UC
;
68 extern struct obstack permanent_obstack
;
69 extern struct obstack temporary_obstack
;
71 /* forward declarations */
72 static void close_input_file
PARAMS ((const char *));
73 static tree convert_bitstring
PARAMS ((char *));
74 static tree convert_integer
PARAMS ((char *));
75 static void maybe_downcase
PARAMS ((char *));
76 static int maybe_number
PARAMS ((const char *));
77 static tree equal_number
PARAMS ((void));
78 static void handle_use_seizefile_directive
PARAMS ((int));
79 static int handle_name
PARAMS ((tree
));
80 static char *readstring
PARAMS ((int, int *));
81 static void read_directive
PARAMS ((void));
82 static tree read_identifier
PARAMS ((int));
83 static tree read_number
PARAMS ((int));
84 static void skip_c_comment
PARAMS ((void));
85 static void skip_line_comment
PARAMS ((void));
86 static int skip_whitespace
PARAMS ((void));
87 static tree string_or_char
PARAMS ((int, const char *));
88 static void ch_lex_init
PARAMS ((void));
89 static void skip_directive
PARAMS ((void));
90 static int same_file
PARAMS ((const char *, const char *));
91 static int getlc
PARAMS ((FILE *));
93 /* next variables are public, because ch-actions uses them */
95 /* the default grantfile name, set by lang_init */
96 tree default_grant_file
= 0;
98 /* These tasking-related variables are NULL at the start of each
99 compiler pass, and are set to an expression tree if and when
100 a compiler directive is parsed containing an expression.
101 The NULL state is significant; it means 'no user-specified
102 signal_code (or whatever) has been parsed'. */
104 /* process type, set by <> PROCESS_TYPE = number <> */
105 tree process_type
= NULL_TREE
;
107 /* send buffer default priority,
108 set by <> SEND_BUFFER_DEFAULT_PRIORITY = number <> */
109 tree send_buffer_prio
= NULL_TREE
;
111 /* send signal default priority,
112 set by <> SEND_SIGNAL_DEFAULT_PRIORITY = number <> */
113 tree send_signal_prio
= NULL_TREE
;
115 /* signal code, set by <> SIGNAL_CODE = number <> */
116 tree signal_code
= NULL_TREE
;
118 /* flag for range checking */
119 int range_checking
= 1;
121 /* flag for NULL pointer checking */
122 int empty_checking
= 1;
124 /* flag to indicate making all procedure local variables
126 int all_static_flag
= 0;
128 /* flag to indicate -fruntime-checking command line option.
129 Needed for initializing range_checking and empty_checking
131 int runtime_checking_flag
= 1;
133 /* The elements of `ridpointers' are identifier nodes
134 for the reserved type names and storage classes.
135 It is indexed by a RID_... value. */
136 tree ridpointers
[(int) RID_MAX
];
138 /* Nonzero tells yylex to ignore \ in string constants. */
139 static int ignore_escape_flag
= 0;
141 static int maxtoken
; /* Current nominal length of token buffer. */
142 char *token_buffer
; /* Pointer to token buffer.
143 Actual allocated length is maxtoken + 2.
144 This is not static because objc-parse.y uses it. */
146 /* implement yylineno handling for flex */
147 #define yylineno lineno
149 static int inside_c_comment
= 0;
151 static int saw_eol
= 0; /* 1 if we've just seen a '\n' */
152 static int saw_eof
= 0; /* 1 if we've just seen an EOF */
154 typedef struct string_list
156 struct string_list
*next
;
160 /* list of paths specified on the compiler command line by -L options. */
161 static STRING_LIST
*seize_path_list
= (STRING_LIST
*)0;
163 /* List of seize file names. Each TREE_VALUE is an identifier
164 (file name) from a <>USE_SEIZE_FILE<> directive.
165 The TREE_PURPOSE is non-NULL if a USE_SEIZE_FILE directive has been
166 written to the grant file. */
167 static tree files_to_seize
= NULL_TREE
;
168 /* Last node on files_to_seize list. */
169 static tree last_file_to_seize
= NULL_TREE
;
170 /* Pointer into files_to_seize list: Next unparsed file to read. */
171 static tree next_file_to_seize
= NULL_TREE
;
173 /* The most recent use_seize_file directive. */
174 tree use_seizefile_name
= NULL_TREE
;
176 /* If non-NULL, the name of the seizefile we're currently processing. */
177 tree current_seizefile_name
= NULL_TREE
;
179 /* called to reset for pass 2 */
183 current_seizefile_name
= NULL_TREE
;
189 /* Initialize these compiler-directive variables. */
190 process_type
= NULL_TREE
;
191 send_buffer_prio
= NULL_TREE
;
192 send_signal_prio
= NULL_TREE
;
193 signal_code
= NULL_TREE
;
195 /* reinitialize rnage checking and empty checking */
196 range_checking
= runtime_checking_flag
;
197 empty_checking
= runtime_checking_flag
;
202 init_parse (filename
)
203 const char *filename
;
205 int lowercase_standard_names
= ignore_case
|| ! special_UC
;
207 /* Open input file. */
208 if (filename
== 0 || !strcmp (filename
, "-"))
214 finput
= fopen (filename
, "r");
216 pfatal_with_name (filename
);
218 #ifdef IO_BUFFER_SIZE
219 setvbuf (finput
, (char *) xmalloc (IO_BUFFER_SIZE
), _IOFBF
, IO_BUFFER_SIZE
);
222 /* Make identifier nodes long enough for the language-specific slots. */
223 set_identifier_size (sizeof (struct lang_identifier
));
225 /* Start it at 0, because check_newline is called at the very beginning
226 and will increment it to 1. */
229 /* Initialize these compiler-directive variables. */
230 process_type
= NULL_TREE
;
231 send_buffer_prio
= NULL_TREE
;
232 send_signal_prio
= NULL_TREE
;
233 signal_code
= NULL_TREE
;
236 token_buffer
= xmalloc ((unsigned)(maxtoken
+ 2));
238 init_chill_expand ();
240 #define ENTER_STANDARD_NAME(RID, LOWER, UPPER) \
241 ridpointers[(int) RID] = \
242 get_identifier (lowercase_standard_names ? LOWER : UPPER)
244 ENTER_STANDARD_NAME (RID_ALL
, "all", "ALL");
245 ENTER_STANDARD_NAME (RID_ASSERTFAIL
, "assertfail", "ASSERTFAIL");
246 ENTER_STANDARD_NAME (RID_ASSOCIATION
, "association", "ASSOCIATION");
247 ENTER_STANDARD_NAME (RID_BIN
, "bin", "BIN");
248 ENTER_STANDARD_NAME (RID_BOOL
, "bool", "BOOL");
249 ENTER_STANDARD_NAME (RID_BOOLS
, "bools", "BOOLS");
250 ENTER_STANDARD_NAME (RID_BYTE
, "byte", "BYTE");
251 ENTER_STANDARD_NAME (RID_CHAR
, "char", "CHAR");
252 ENTER_STANDARD_NAME (RID_DOUBLE
, "double", "DOUBLE");
253 ENTER_STANDARD_NAME (RID_DURATION
, "duration", "DURATION");
254 ENTER_STANDARD_NAME (RID_DYNAMIC
, "dynamic", "DYNAMIC");
255 ENTER_STANDARD_NAME (RID_ELSE
, "else", "ELSE");
256 ENTER_STANDARD_NAME (RID_EMPTY
, "empty", "EMPTY");
257 ENTER_STANDARD_NAME (RID_FALSE
, "false", "FALSE");
258 ENTER_STANDARD_NAME (RID_FLOAT
, "float", "FLOAT");
259 ENTER_STANDARD_NAME (RID_GENERAL
, "general", "GENERAL");
260 ENTER_STANDARD_NAME (RID_IN
, "in", "IN");
261 ENTER_STANDARD_NAME (RID_INLINE
, "inline", "INLINE");
262 ENTER_STANDARD_NAME (RID_INOUT
, "inout", "INOUT");
263 ENTER_STANDARD_NAME (RID_INSTANCE
, "instance", "INSTANCE");
264 ENTER_STANDARD_NAME (RID_INT
, "int", "INT");
265 ENTER_STANDARD_NAME (RID_LOC
, "loc", "LOC");
266 ENTER_STANDARD_NAME (RID_LONG
, "long", "LONG");
267 ENTER_STANDARD_NAME (RID_LONG_REAL
, "long_real", "LONG_REAL");
268 ENTER_STANDARD_NAME (RID_NULL
, "null", "NULL");
269 ENTER_STANDARD_NAME (RID_OUT
, "out", "OUT");
270 ENTER_STANDARD_NAME (RID_OVERFLOW
, "overflow", "OVERFLOW");
271 ENTER_STANDARD_NAME (RID_PTR
, "ptr", "PTR");
272 ENTER_STANDARD_NAME (RID_READ
, "read", "READ");
273 ENTER_STANDARD_NAME (RID_REAL
, "real", "REAL");
274 ENTER_STANDARD_NAME (RID_RANGE
, "range", "RANGE");
275 ENTER_STANDARD_NAME (RID_RANGEFAIL
, "rangefail", "RANGEFAIL");
276 ENTER_STANDARD_NAME (RID_RECURSIVE
, "recursive", "RECURSIVE");
277 ENTER_STANDARD_NAME (RID_SHORT
, "short", "SHORT");
278 ENTER_STANDARD_NAME (RID_SIMPLE
, "simple", "SIMPLE");
279 ENTER_STANDARD_NAME (RID_TIME
, "time", "TIME");
280 ENTER_STANDARD_NAME (RID_TRUE
, "true", "TRUE");
281 ENTER_STANDARD_NAME (RID_UBYTE
, "ubyte", "UBYTE");
282 ENTER_STANDARD_NAME (RID_UINT
, "uint", "UINT");
283 ENTER_STANDARD_NAME (RID_ULONG
, "ulong", "ULONG");
284 ENTER_STANDARD_NAME (RID_UNSIGNED
, "unsigned", "UNSIGNED");
285 ENTER_STANDARD_NAME (RID_USHORT
, "ushort", "USHORT");
286 ENTER_STANDARD_NAME (RID_VOID
, "void", "VOID");
298 static int yywrap
PARAMS ((void));
299 static int yy_refill
PARAMS ((void));
301 #define YY_PUTBACK_SIZE 5
302 #define YY_BUF_SIZE 1000
304 static char yy_buffer
[YY_PUTBACK_SIZE
+ YY_BUF_SIZE
];
305 static char *yy_cur
= yy_buffer
+ YY_PUTBACK_SIZE
;
306 static char *yy_lim
= yy_buffer
+ YY_PUTBACK_SIZE
;
311 char *buf
= yy_buffer
+ YY_PUTBACK_SIZE
;
313 bcopy (yy_cur
- YY_PUTBACK_SIZE
, yy_buffer
, YY_PUTBACK_SIZE
);
328 c
= check_newline ();
341 while (result
< YY_BUF_SIZE
)
351 /* Because we might switch input files on a compiler directive
352 (that end with '>', don't read past a '>', just in case. */
361 fprintf (stderr
, "-------------------------- finished Line %d\n",
369 yy_lim
= yy_cur
+ result
;
371 return yy_lim
> yy_cur
? *yy_cur
++ : EOF
;
374 #define input() (yy_cur < yy_lim ? *yy_cur++ : yy_refill ())
376 #define unput(c) (*--yy_cur = (c))
379 int starting_pass_2
= 0;
399 case ' ': case '\t': case '\n': case '\f': case '\b': case '\v': case '\r':
421 else if (nextc
== '=')
437 skip_line_comment ();
450 else if (nextc
== '=')
452 else if (nextc
== '*')
495 int len
= 0; /* Number of hex digits seen. */
503 if (!ISXDIGIT (ch
)) /* error on non-hex digit */
506 error ("invalid C'xx' ");
517 if (len
& 1) /* collected two digits, save byte */
518 obstack_1grow (&temporary_obstack
, (char) byte_val
);
521 start
= obstack_finish (&temporary_obstack
);
522 yylval
.ttype
= string_or_char (len
>> 1, start
);
523 obstack_free (&temporary_obstack
, start
);
524 return len
== 2 ? SINGLECHAR
: STRING
;
534 obstack_1grow (&temporary_obstack
, ch
);
535 obstack_1grow (&temporary_obstack
, nextc
);
540 obstack_1grow (&temporary_obstack
, ch
);
544 obstack_1grow (&temporary_obstack
, '\0');
545 start
= obstack_finish (&temporary_obstack
);
549 yylval
.ttype
= convert_integer (start
); /* Pass base? */
554 yylval
.ttype
= convert_bitstring (start
);
562 case 'F': case 'G': case 'I': case 'J':
563 case 'K': case 'L': case 'M': case 'N':
564 case 'P': case 'Q': case 'R': case 'S': case 'T':
565 case 'U': case 'V': case 'W': case 'X': case 'Y':
568 case 'f': case 'g': case 'i': case 'j':
569 case 'k': case 'l': case 'm': case 'n':
570 case 'p': case 'q': case 'r': case 's': case 't':
571 case 'u': case 'v': case 'w': case 'x': case 'y':
575 return handle_name (read_identifier (ch
));
577 tmp
= readstring ('\'', &len
);
578 yylval
.ttype
= string_or_char (len
, tmp
);
580 return len
== 1 ? SINGLECHAR
: STRING
;
582 tmp
= readstring ('\"', &len
);
583 yylval
.ttype
= build_chill_string (len
, tmp
);
589 if (ISDIGIT (nextc
)) /* || nextc == '_') we don't start numbers with '_' */
592 case '0': case '1': case '2': case '3': case '4':
593 case '5': case '6': case '7': case '8': case '9':
595 yylval
.ttype
= read_number (ch
);
596 return TREE_CODE (yylval
.ttype
) == REAL_CST
? FLOATING
: NUMBER
;
603 close_input_file (fn
)
609 if (finput
!= stdin
&& fclose (finput
) == EOF
)
611 error ("can't close %s", fn
);
617 /* Return an identifier, starting with FIRST and then reading
618 more characters using input(). Return an IDENTIFIER_NODE. */
621 read_identifier (first
)
622 int first
; /* First letter of identifier */
628 obstack_1grow (&temporary_obstack
, first
);
632 if (! ISALNUM (first
) && first
!= '_')
638 obstack_1grow (&temporary_obstack
, '\0');
639 start
= obstack_finish (&temporary_obstack
);
640 maybe_downcase (start
);
641 id
= get_identifier (start
);
642 obstack_free (&temporary_obstack
, start
);
646 /* Given an identifier ID, check to see if it is a reserved name,
647 and return the appropriate token type. */
654 tp
= in_word_set (IDENTIFIER_POINTER (id
), IDENTIFIER_LENGTH (id
));
656 && special_UC
== ISUPPER ((unsigned char) tp
->name
[0])
657 && (tp
->flags
== RESERVED
|| tp
->flags
== PREDEF
))
659 if (tp
->rid
!= NORID
)
660 yylval
.ttype
= ridpointers
[tp
->rid
];
661 else if (tp
->token
== THIS
)
662 yylval
.ttype
= lookup_name (get_identifier ("__whoami"));
671 int ch
; /* Initial character */
679 obstack_1grow (&temporary_obstack
, ch
);
681 if (! ISDIGIT (ch
) && ch
!= '_')
689 obstack_1grow (&temporary_obstack
, ch
);
691 } while (ISDIGIT (ch
) || ch
== '_');
694 if (ch
== 'd' || ch
== 'D' || ch
== 'e' || ch
== 'E')
696 /* Convert exponent indication [eEdD] to 'e'. */
697 obstack_1grow (&temporary_obstack
, 'e');
699 if (ch
== '+' || ch
== '-')
701 obstack_1grow (&temporary_obstack
, ch
);
704 if (ISDIGIT (ch
) || ch
== '_')
709 obstack_1grow (&temporary_obstack
, ch
);
711 } while (ISDIGIT (ch
) || ch
== '_');
715 error ("malformed exponent part of floating-point literal");
721 obstack_1grow (&temporary_obstack
, '\0');
722 start
= obstack_finish (&temporary_obstack
);
725 REAL_VALUE_TYPE value
;
726 tree type
= double_type_node
;
728 value
= REAL_VALUE_ATOF (start
, TYPE_MODE (type
));
729 obstack_free (&temporary_obstack
, start
);
730 if (TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
731 && REAL_VALUE_ISINF (value
) && pedantic
)
732 pedwarn ("real number exceeds range of REAL");
733 num
= build_real (type
, value
);
736 num
= convert_integer (start
);
737 CH_DERIVED_FLAG (num
) = 1;
741 /* Skip to the end of a compiler directive. */
751 error ("end-of-file in '<>' directive");
767 /* Read a compiler directive. ("<>{WS}" have already been read. ) */
773 int ch
= skip_whitespace();
774 if (ISALPHA (ch
) || ch
== '_')
775 id
= read_identifier (ch
);
778 error ("end-of-file in '<>' directive");
779 to_global_binding_level ();
784 warning ("unrecognized compiler directive");
788 tp
= in_word_set (IDENTIFIER_POINTER (id
), IDENTIFIER_LENGTH (id
));
789 if (tp
== NULL
|| special_UC
!= ISUPPER ((unsigned char) tp
->name
[0]))
792 warning ("unrecognized compiler directive `%s'",
793 IDENTIFIER_POINTER (id
));
810 case IGNORED_DIRECTIVE
:
812 case PROCESS_TYPE_TOKEN
:
813 process_type
= equal_number ();
821 case SEND_SIGNAL_DEFAULT_PRIORITY
:
822 send_signal_prio
= equal_number ();
824 case SEND_BUFFER_DEFAULT_PRIORITY
:
825 send_buffer_prio
= equal_number ();
828 signal_code
= equal_number ();
831 handle_use_seizefile_directive (0);
833 case USE_SEIZE_FILE_RESTRICTED
:
834 handle_use_seizefile_directive (1);
838 warning ("unrecognized compiler directive `%s'",
839 IDENTIFIER_POINTER (id
));
847 build_chill_string (len
, str
)
853 push_obstacks (&permanent_obstack
, &permanent_obstack
);
854 t
= build_string (len
, str
);
855 TREE_TYPE (t
) = build_string_type (char_type_node
,
856 build_int_2 (len
, 0));
857 CH_DERIVED_FLAG (t
) = 1;
864 string_or_char (len
, str
)
870 push_obstacks (&permanent_obstack
, &permanent_obstack
);
873 result
= build_int_2 ((unsigned char)str
[0], 0);
874 CH_DERIVED_FLAG (result
) = 1;
875 TREE_TYPE (result
) = char_type_node
;
878 result
= build_chill_string (len
, str
);
892 if (ISUPPER ((unsigned char) *str
))
893 *str
= TOLOWER (*str
);
905 /* check for decimal number */
906 if (*s
>= '0' && *s
<= '9')
910 if (*s
>= '0' && *s
<= '9')
928 if (*s
< '0' || *s
> '9')
933 if (!ISXDIGIT ((unsigned char) *s
))
938 if (*s
< '0' || *s
> '1')
943 if (*s
< '0' || *s
> '7')
955 readstring (terminator
, len
)
960 unsigned allocated
= 1024;
961 char *tmp
= xmalloc (allocated
);
969 if ((c
= input ()) != terminator
)
977 if (c
== '\n' || c
== EOF
)
982 if (c
== EOF
|| c
== '\n')
996 if (cc
== terminator
)
998 if (!(terminator
== '\'' && next_apos
))
1000 error ("unterminated control sequence");
1005 if (cc
== EOF
|| cc
== '\n')
1015 error ("invalid integer literal in control sequence");
1021 if (cc
== ' ' || cc
== '\t')
1025 if ((c
< 0 || c
> 255) && (pass
== 1))
1026 error ("control sequence overflow");
1027 if (! count
&& pass
== 1)
1028 error ("invalid control sequence");
1033 if ((c
< 0 || c
> 255) && (pass
== 1))
1034 error ("control sequence overflow");
1035 if (! count
&& pass
== 1)
1036 error ("invalid control sequence");
1041 tmp
= xrealloc (tmp
, allocated
);
1050 if (! count
&& pass
== 1)
1051 error ("invalid integer literal in control sequence");
1056 if (cc
== 'D' || cc
== 'd')
1061 else if (cc
== 'H' || cc
== 'h')
1066 else if (cc
== 'O' || cc
== 'o')
1071 else if (cc
== 'B' || cc
== 'b')
1082 if (cc
< '0' || cc
> '1')
1089 if (cc
< '0' || cc
> '8')
1094 else if (base
== 10)
1101 else if (base
== 16)
1116 error ("invalid base in read control sequence");
1121 /* error in control sequence */
1123 error ("invalid digit in control sequence");
1126 c
= (c
* base
) + cc
;
1138 tmp
= xrealloc (tmp
, allocated
);
1142 tmp
[*len
= i
] = '\0';
1150 error ("unterminated string literal");
1151 to_global_binding_level ();
1156 /* Convert an integer INTCHARS into an INTEGER_CST.
1157 INTCHARS is on the temporary_obstack, and is popped by this function. */
1160 convert_integer (intchars
)
1169 int valid_chars
= 0;
1172 HOST_WIDE_INT val_lo
= 0, val_hi
= 0;
1175 /* determine the base */
1198 if (!ISDIGIT (*p
)) /* this test is for equal_number () */
1200 obstack_free (&temporary_obstack
, intchars
);
1209 if ((tmp
== '\'') || (tmp
== '_'))
1213 if (tmp
>= 'a') /* uppercase the char */
1215 switch (base
) /* validate the characters */
1232 if (tmp
> '9' && tmp
< 'A')
1241 if (mul_double (val_lo
, val_hi
, base
, 0, &val_lo
, &val_hi
))
1243 add_double (val_lo
, val_hi
, tmp
, 0, &val_lo
, &val_hi
);
1249 obstack_free (&temporary_obstack
, intchars
);
1253 error ("invalid number format `%s'", oldp
);
1256 val
= build_int_2 (val_lo
, val_hi
);
1257 /* We set the type to long long (or long long unsigned) so that
1258 constant fold of literals is less likely to overflow. */
1259 if (int_fits_type_p (val
, long_long_integer_type_node
))
1260 type
= long_long_integer_type_node
;
1263 if (! int_fits_type_p (val
, long_long_unsigned_type_node
))
1265 type
= long_long_unsigned_type_node
;
1267 TREE_TYPE (val
) = type
;
1268 CH_DERIVED_FLAG (val
) = 1;
1271 error ("integer literal too big");
1276 /* Convert a bitstring literal on the temporary_obstack to
1277 a bitstring CONSTRUCTOR. Free the literal from the obstack. */
1280 convert_bitstring (p
)
1286 int bl
= 0, valid_chars
= 0, bits_per_char
= 0, c
, k
;
1287 tree initlist
= NULL_TREE
;
1290 /* Move p to stack so we can re-use temporary_obstack for result. */
1291 char *oldp
= (char*) alloca (strlen (p
) + 1);
1292 if (oldp
== 0) fatal ("stack space exhausted");
1294 obstack_free (&temporary_obstack
, p
);
1317 if (c
== '_' || c
== '\'')
1326 for (k
= BYTES_BIG_ENDIAN
? bits_per_char
- 1 : 0;
1327 BYTES_BIG_ENDIAN
? k
>= 0 : k
< bits_per_char
;
1328 bl
++, BYTES_BIG_ENDIAN
? k
-- : k
++)
1331 initlist
= tree_cons (NULL_TREE
, build_int_2 (bl
, 0), initlist
);
1335 /* as long as BOOLS(0) is valid it must tbe possible to
1336 specify an empty bitstring */
1340 error ("invalid number format `%s'", oldp
);
1344 val
= build (CONSTRUCTOR
,
1345 build_bitstring_type (size_int (bl
)),
1346 NULL_TREE
, nreverse (initlist
));
1347 TREE_CONSTANT (val
) = 1;
1348 CH_DERIVED_FLAG (val
) = 1;
1352 /* Check if two filenames name the same file.
1353 This is done by stat'ing both files and comparing their inodes.
1355 Note: we have to take care of seize_path_list. Therefore do it the same
1356 way as in yywrap. FIXME: This probably can be done better. */
1359 same_file (filename1
, filename2
)
1360 const char *filename1
;
1361 const char *filename2
;
1364 const char *fn_input
[2];
1367 if (grant_only_flag
)
1368 /* do nothing in this case */
1371 /* if filenames are equal -- return 1, cause there is no need
1372 to search in the include list in this case */
1373 if (strcmp (filename1
, filename2
) == 0)
1376 fn_input
[0] = filename1
;
1377 fn_input
[1] = filename2
;
1379 for (i
= 0; i
< 2; i
++)
1381 stat_status
= stat (fn_input
[i
], &s
[i
]);
1382 if (stat_status
< 0 &&
1383 strchr (fn_input
[i
], '/') == 0)
1388 for (plp
= seize_path_list
; plp
!= 0; plp
= plp
->next
)
1390 path
= (char *)xmalloc (strlen (fn_input
[i
]) +
1391 strlen (plp
->str
) + 2);
1392 sprintf (path
, "%s/%s", plp
->str
, fn_input
[i
]);
1393 stat_status
= stat (path
, &s
[i
]);
1395 if (stat_status
>= 0)
1399 if (stat_status
< 0)
1400 pfatal_with_name (fn_input
[i
]);
1402 return s
[0].st_ino
== s
[1].st_ino
&& s
[0].st_dev
== s
[1].st_dev
;
1406 * Note that simply appending included file names to a list in this
1407 * way completely eliminates the need for nested files, and the
1408 * associated book-keeping, since the EOF processing in the lexer
1409 * will simply process the files one at a time, in the order that the
1410 * USE_SEIZE_FILE directives were scanned.
1413 handle_use_seizefile_directive (restricted
)
1418 int c
= skip_whitespace ();
1419 char *use_seizefile_str
= readstring (c
, &len
);
1424 if (c
!= '\'' && c
!= '\"')
1426 error ("USE_SEIZE_FILE directive must be followed by string");
1430 use_seizefile_name
= get_identifier (use_seizefile_str
);
1431 CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name
) = restricted
;
1433 if (!grant_only_flag
)
1435 /* If file foo.ch contains a <> use_seize_file "bar.grt" <>,
1436 and file bar.ch contains a <> use_seize_file "foo.grt" <>,
1437 then if we're compiling foo.ch, we will indirectly be
1438 asked to seize foo.grt. Don't. */
1439 extern char *grant_file_name
;
1440 if (strcmp (use_seizefile_str
, grant_file_name
) == 0)
1443 /* Check if the file is already on the list. */
1444 for (seen
= files_to_seize
; seen
!= NULL_TREE
; seen
= TREE_CHAIN (seen
))
1445 if (same_file (IDENTIFIER_POINTER (TREE_VALUE (seen
)),
1447 return; /* Previously seen; nothing to do. */
1450 /* Haven't been asked to seize this file yet, so add
1451 its name to the list. */
1453 tree pl
= perm_tree_cons (0, use_seizefile_name
, NULL_TREE
);
1454 if (files_to_seize
== NULL_TREE
)
1455 files_to_seize
= pl
;
1457 TREE_CHAIN (last_file_to_seize
) = pl
;
1458 if (next_file_to_seize
== NULL_TREE
)
1459 next_file_to_seize
= pl
;
1460 last_file_to_seize
= pl
;
1466 * get input, convert to lower case for comparison
1480 #if defined HANDLE_PRAGMA
1481 /* Local versions of these macros, that can be passed as function pointers. */
1485 return getc (finput
);
1492 ungetc (arg
, finput
);
1494 #endif /* HANDLE_PRAGMA */
1496 #ifdef HANDLE_GENERIC_PRAGMAS
1497 /* Handle a generic #pragma directive.
1498 BUFFER contains the text we read after `#pragma'. Processes the entire input
1499 line and return non-zero iff the pragma was successfully processed. */
1502 handle_generic_pragma (buffer
)
1511 handle_pragma_token (buffer
, NULL
);
1515 while (c
== ' ' || c
== '\t')
1519 if (c
== '\n' || c
== EOF
)
1520 return handle_pragma_token (NULL
, NULL
);
1522 /* Read the next word of the pragma into the buffer. */
1529 while (c
!= EOF
&& isascii (c
) && ! ISSPACE (c
) && c
!= '\n'
1530 && buff
< buffer
+ 128); /* XXX shared knowledge about size of buffer. */
1537 #endif /* HANDLE_GENERIC_PRAGMAS */
1539 /* At the beginning of a line, increment the line number and process
1540 any #-directive on this line. If the line is a #-directive, read
1541 the entire line and return a newline. Otherwise, return the line's
1542 first non-whitespace character.
1544 (Each language front end has a check_newline() function that is called
1545 from lang_init() for that language. One of the things this function
1546 must do is read the first line of the input file, and if it is a #line
1547 directive, extract the filename from it and use it to initialize
1548 main_input_filename. Proper generation of debugging information in
1549 the normal "front end calls cpp then calls cc1XXXX environment" depends
1550 upon this being done.) */
1559 /* Read first nonwhite char on the line. */
1563 while (c
== ' ' || c
== '\t')
1566 if (c
!= '#' || inside_c_comment
)
1568 /* If not #, return it so caller will use it. */
1572 /* Read first nonwhite char after the `#'. */
1575 while (c
== ' ' || c
== '\t')
1578 /* If a letter follows, then if the word here is `line', skip
1579 it and ignore it; otherwise, ignore the line, with an error
1580 if the word isn't `pragma', `ident', `define', or `undef'. */
1585 if (c
>= 'a' && c
<= 'z')
1589 if (getlc (finput
) == 'r'
1590 && getlc (finput
) == 'a'
1591 && getlc (finput
) == 'g'
1592 && getlc (finput
) == 'm'
1593 && getlc (finput
) == 'a'
1594 && (c
= getlc (finput
), ISSPACE (c
)))
1596 #ifdef HANDLE_PRAGMA
1597 static char buffer
[128];
1598 char * buff
= buffer
;
1600 /* Read the pragma name into a buffer. */
1601 while (c
= getlc (finput
), ISSPACE (c
))
1609 while (c
!= EOF
&& ! ISSPACE (c
) && c
!= '\n'
1610 && buff
< buffer
+ 128);
1616 if (HANDLE_PRAGMA (pragma_getc
, pragma_ungetc
, buffer
))
1618 #endif /* HANDLE_PRAGMA */
1620 #ifdef HANDLE_GENERIC_PRAGMAS
1621 if (handle_generic_pragma (buffer
))
1623 #endif /* HANDLE_GENERIC_PRAGMAS */
1631 if (getlc (finput
) == 'e'
1632 && getlc (finput
) == 'f'
1633 && getlc (finput
) == 'i'
1634 && getlc (finput
) == 'n'
1635 && getlc (finput
) == 'e'
1636 && (c
= getlc (finput
), ISSPACE (c
)))
1638 #if 0 /*def DWARF_DEBUGGING_INFO*/
1640 && (debug_info_level
== DINFO_LEVEL_VERBOSE
)
1641 && (write_symbols
== DWARF_DEBUG
))
1642 dwarfout_define (lineno
, get_directive_line (finput
));
1643 #endif /* DWARF_DEBUGGING_INFO */
1649 if (getlc (finput
) == 'n'
1650 && getlc (finput
) == 'd'
1651 && getlc (finput
) == 'e'
1652 && getlc (finput
) == 'f'
1653 && (c
= getlc (finput
), ISSPACE (c
)))
1655 #if 0 /*def DWARF_DEBUGGING_INFO*/
1657 && (debug_info_level
== DINFO_LEVEL_VERBOSE
)
1658 && (write_symbols
== DWARF_DEBUG
))
1659 dwarfout_undef (lineno
, get_directive_line (finput
));
1660 #endif /* DWARF_DEBUGGING_INFO */
1666 if (getlc (finput
) == 'i'
1667 && getlc (finput
) == 'n'
1668 && getlc (finput
) == 'e'
1669 && ((c
= getlc (finput
)) == ' ' || c
== '\t'))
1675 if (getlc (finput
) == 'd'
1676 && getlc (finput
) == 'e'
1677 && getlc (finput
) == 'n'
1678 && getlc (finput
) == 't'
1679 && ((c
= getlc (finput
)) == ' ' || c
== '\t'))
1681 /* #ident. The pedantic warning is now in cpp. */
1683 /* Here we have just seen `#ident '.
1684 A string constant should follow. */
1686 while (c
== ' ' || c
== '\t')
1689 /* If no argument, ignore the line. */
1696 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
1698 error ("invalid #ident");
1704 #ifdef ASM_OUTPUT_IDENT
1705 extern FILE *asm_out_file
;
1706 ASM_OUTPUT_IDENT (asm_out_file
, TREE_STRING_POINTER (yylval
.ttype
));
1710 /* Skip the rest of this line. */
1716 error ("undefined or invalid # directive");
1721 /* Here we have either `#line' or `# <nonletter>'.
1722 In either case, it should be a line number; a digit should follow. */
1724 while (c
== ' ' || c
== '\t')
1727 /* If the # is the only nonwhite char on the line,
1728 just ignore it. Check the new newline. */
1732 /* Something follows the #; read a token. */
1736 int old_lineno
= lineno
;
1739 extern struct obstack permanent_obstack
;
1743 l
= l
* 10 + (c
- '0'); /* FIXME Not portable */
1745 } while (ISDIGIT(c
));
1746 /* subtract one, because it is the following line that
1747 gets the specified number */
1751 /* Is this the last nonwhite stuff on the line? */
1753 while (c
== ' ' || c
== '\t')
1757 /* No more: store the line number and check following line. */
1762 /* More follows: it must be a string constant (filename). */
1764 /* Read the string constant, but don't treat \ as special. */
1765 ignore_escape_flag
= 1;
1766 ignore_escape_flag
= 0;
1770 error ("invalid #line");
1777 if (c
== EOF
|| c
== '\n')
1779 error ("invalid #line");
1784 obstack_1grow(&permanent_obstack
, 0);
1785 input_filename
= obstack_finish (&permanent_obstack
);
1788 obstack_1grow(&permanent_obstack
, c
);
1793 /* Each change of file name
1794 reinitializes whether we are now in a system header. */
1795 in_system_header
= 0;
1797 if (main_input_filename
== 0)
1798 main_input_filename
= input_filename
;
1800 /* Is this the last nonwhite stuff on the line? */
1802 while (c
== ' ' || c
== '\t')
1809 /* `1' after file name means entering new file.
1810 `2' after file name means just left a file. */
1816 /* Pushing to a new file. */
1817 struct file_stack
*p
1818 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
1819 input_file_stack
->line
= old_lineno
;
1820 p
->next
= input_file_stack
;
1821 p
->name
= input_filename
;
1822 input_file_stack
= p
;
1823 input_file_stack_tick
++;
1824 #ifdef DWARF_DEBUGGING_INFO
1825 if (debug_info_level
== DINFO_LEVEL_VERBOSE
1826 && write_symbols
== DWARF_DEBUG
)
1827 dwarfout_start_new_source_file (input_filename
);
1828 #endif /* DWARF_DEBUGGING_INFO */
1834 /* Popping out of a file. */
1835 if (input_file_stack
->next
)
1837 struct file_stack
*p
= input_file_stack
;
1838 input_file_stack
= p
->next
;
1840 input_file_stack_tick
++;
1841 #ifdef DWARF_DEBUGGING_INFO
1842 if (debug_info_level
== DINFO_LEVEL_VERBOSE
1843 && write_symbols
== DWARF_DEBUG
)
1844 dwarfout_resume_previous_source_file (input_file_stack
->line
);
1845 #endif /* DWARF_DEBUGGING_INFO */
1848 error ("#-lines for entering and leaving files don't match");
1854 /* If we have handled a `1' or a `2',
1855 see if there is another number to read. */
1858 /* Is this the last nonwhite stuff on the line? */
1860 while (c
== ' ' || c
== '\t')
1867 /* `3' after file name means this is a system header file. */
1870 in_system_header
= 1;
1873 error ("invalid #-line");
1875 /* skip the rest of this line. */
1877 while (c
!= '\n' && c
!= EOF
)
1884 get_chill_filename ()
1886 return (build_chill_string (
1887 strlen (input_filename
) + 1, /* +1 to get a zero terminated string */
1892 get_chill_linenumber ()
1894 return build_int_2 ((HOST_WIDE_INT
)lineno
, 0);
1898 /* Assuming '/' and '*' have been read, skip until we've
1899 read the terminating '*' and '/'. */
1905 int start_line
= lineno
;
1911 error_with_file_and_line (input_filename
, start_line
,
1912 "unterminated comment");
1917 else if ((c
= input ()) == '/')
1923 /* Assuming "--" has been read, skip until '\n'. */
1926 skip_line_comment ()
1950 if (c
== ' ' || c
== '\t' || c
== '\r' || c
== '\n' || c
== '\v')
1971 skip_line_comment ();
1985 * avoid recursive calls to yylex to parse the ' = digits' or
1986 * ' = SYNvalue' which are supposed to follow certain compiler
1987 * directives. Read the input stream, and return the value parsed.
1989 /* FIXME: overflow check in here */
1990 /* FIXME: check for EOF around here */
1997 tree retval
= integer_zero_node
;
1999 c
= skip_whitespace();
2003 error ("missing `=' in compiler directive");
2004 return integer_zero_node
;
2006 c
= skip_whitespace();
2008 /* collect token into tokenbuf for later analysis */
2011 if (ISSPACE (c
) || c
== '<')
2013 obstack_1grow (&temporary_obstack
, c
);
2016 unput (c
); /* put uninteresting char back */
2017 obstack_1grow (&temporary_obstack
, '\0'); /* terminate token */
2018 tokenbuf
= obstack_finish (&temporary_obstack
);
2019 maybe_downcase (tokenbuf
);
2021 if (*tokenbuf
== '-')
2022 /* will fail in the next test */
2024 else if (maybe_number (tokenbuf
))
2027 return integer_zero_node
;
2028 push_obstacks_nochange ();
2029 end_temporary_allocation ();
2030 yylval
.ttype
= convert_integer (tokenbuf
);
2031 tokenbuf
= 0; /* Was freed by convert_integer. */
2032 result
= yylval
.ttype
? NUMBER
: 0;
2038 if (result
== NUMBER
)
2040 retval
= yylval
.ttype
;
2042 else if (result
== BITSTRING
)
2045 error ("invalid value follows `=' in compiler directive");
2048 else /* not a number */
2052 if (!ISALPHA (c
) && c
!= '_')
2055 error ("invalid value follows `=' in compiler directive");
2059 for (cursor
= &tokenbuf
[1]; *cursor
!= '\0'; cursor
++)
2060 if (ISALPHA ((unsigned char) *cursor
) || *cursor
== '_' ||
2066 error ("invalid `%c' character in name", *cursor
);
2073 tree value
= lookup_name (get_identifier (tokenbuf
));
2074 if (value
== NULL_TREE
2075 || TREE_CODE (value
) != CONST_DECL
2076 || TREE_CODE (DECL_INITIAL (value
)) != INTEGER_CST
)
2079 error ("`%s' not integer constant synonym ",
2083 obstack_free (&temporary_obstack
, tokenbuf
);
2085 push_obstacks_nochange ();
2086 end_temporary_allocation ();
2087 retval
= convert (chill_taskingcode_type_node
, DECL_INITIAL (value
));
2092 /* check the value */
2093 if (TREE_CODE (retval
) != INTEGER_CST
)
2096 error ("invalid value follows `=' in compiler directive");
2098 else if (TREE_INT_CST_HIGH (retval
) != 0 ||
2099 TREE_INT_CST_LOW (retval
) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node
)))
2102 error ("value out of range in compiler directive");
2106 obstack_free (&temporary_obstack
, tokenbuf
);
2111 * add a possible grant-file path to the list
2114 register_seize_path (path
)
2117 int pathlen
= strlen (path
);
2118 char *new_path
= (char *)xmalloc (pathlen
+ 1);
2119 STRING_LIST
*pl
= (STRING_LIST
*)xmalloc (sizeof (STRING_LIST
));
2121 /* strip off trailing slash if any */
2122 if (path
[pathlen
- 1] == '/')
2125 memcpy (new_path
, path
, pathlen
);
2127 pl
->next
= seize_path_list
;
2128 seize_path_list
= pl
;
2132 /* Used by decode_decl to indicate that a <> use_seize_file NAME <>
2133 directive has been written to the grantfile. */
2136 mark_use_seizefile_written (name
)
2141 for (node
= files_to_seize
; node
!= NULL_TREE
; node
= TREE_CHAIN (node
))
2142 if (TREE_VALUE (node
) == name
)
2144 TREE_PURPOSE (node
) = integer_one_node
;
2153 extern char *chill_real_input_filename
;
2155 close_input_file (input_filename
);
2157 use_seizefile_name
= NULL_TREE
;
2159 if (next_file_to_seize
&& !grant_only_flag
)
2161 FILE *grt_in
= NULL
;
2162 const char *seizefile_name_chars
2163 = IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize
));
2165 /* find a seize file, open it. If it's not at the path the
2166 * user gave us, and that path contains no slashes, look on
2167 * the seize_file paths, specified by the '-I' options.
2169 grt_in
= fopen (seizefile_name_chars
, "r");
2171 && strchr (seizefile_name_chars
, '/') == NULL
)
2176 for (plp
= seize_path_list
; plp
!= NULL
; plp
= plp
->next
)
2178 path
= (char *)xmalloc (strlen (seizefile_name_chars
)
2179 + strlen (plp
->str
) + 2);
2181 sprintf (path
, "%s/%s", plp
->str
, seizefile_name_chars
);
2182 grt_in
= fopen (path
, "r");
2187 seizefile_name_chars
= path
;
2194 pfatal_with_name (seizefile_name_chars
);
2197 input_filename
= seizefile_name_chars
;
2200 current_seizefile_name
= TREE_VALUE (next_file_to_seize
);
2202 next_file_to_seize
= TREE_CHAIN (next_file_to_seize
);
2210 next_file_to_seize
= files_to_seize
;
2211 current_seizefile_name
= NULL_TREE
;
2213 if (strcmp (main_input_filename
, "stdin"))
2214 finput
= fopen (chill_real_input_filename
, "r");
2219 error ("can't reopen %s", chill_real_input_filename
);
2222 input_filename
= main_input_filename
;
2225 /* Read a line directive if there is one. */
2226 ungetc (check_newline (), finput
);
2227 starting_pass_2
= 1;
2229 if (module_number
== 0)
2230 warning ("no modules seen");