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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
36 #ifdef DWARF_DEBUGGING_INFO
40 #ifdef MULTIBYTE_CHARS
44 /* include the keyword recognizers */
50 static int last_token
= 0;
51 /* Sun's C compiler warns about the safer sequence
53 when there's a 'return' inside the braces, so don't use it */
54 #define RETURN_TOKEN(X) { last_token = X; return (X); }
57 /* This is set non-zero to force incoming tokens to lowercase. */
58 extern int ignore_case
;
60 extern int module_number
;
61 extern int serious_errors
;
63 /* This is non-zero to recognize only uppercase special words. */
64 extern int special_UC
;
66 extern struct obstack permanent_obstack
;
67 extern struct obstack temporary_obstack
;
69 /* forward declarations */
70 static void close_input_file
PROTO((const char *));
71 static tree convert_bitstring
PROTO((char *));
72 static tree convert_integer
PROTO((char *));
73 static void maybe_downcase
PROTO((char *));
74 static int maybe_number
PROTO((const char *));
75 static tree equal_number
PROTO((void));
76 static void handle_use_seizefile_directive
PROTO((int));
77 static int handle_name
PROTO((tree
));
78 static char *readstring
PROTO((int, int *));
79 static void read_directive
PROTO((void));
80 static tree read_identifier
PROTO((int));
81 static tree read_number
PROTO((int));
82 static void skip_c_comment
PROTO((void));
83 static void skip_line_comment
PROTO((void));
84 static int skip_whitespace
PROTO((void));
85 static tree string_or_char
PROTO((int, const char *));
86 static void ch_lex_init
PROTO((void));
87 static void skip_directive
PROTO((void));
88 static int same_file
PROTO((const char *, const char *));
89 static int getlc
PROTO((FILE *));
91 /* next variables are public, because ch-actions uses them */
93 /* the default grantfile name, set by lang_init */
94 tree default_grant_file
= 0;
96 /* These tasking-related variables are NULL at the start of each
97 compiler pass, and are set to an expression tree if and when
98 a compiler directive is parsed containing an expression.
99 The NULL state is significant; it means 'no user-specified
100 signal_code (or whatever) has been parsed'. */
102 /* process type, set by <> PROCESS_TYPE = number <> */
103 tree process_type
= NULL_TREE
;
105 /* send buffer default priority,
106 set by <> SEND_BUFFER_DEFAULT_PRIORITY = number <> */
107 tree send_buffer_prio
= NULL_TREE
;
109 /* send signal default priority,
110 set by <> SEND_SIGNAL_DEFAULT_PRIORITY = number <> */
111 tree send_signal_prio
= NULL_TREE
;
113 /* signal code, set by <> SIGNAL_CODE = number <> */
114 tree signal_code
= NULL_TREE
;
116 /* flag for range checking */
117 int range_checking
= 1;
119 /* flag for NULL pointer checking */
120 int empty_checking
= 1;
122 /* flag to indicate making all procedure local variables
124 int all_static_flag
= 0;
126 /* flag to indicate -fruntime-checking command line option.
127 Needed for initializing range_checking and empty_checking
129 int runtime_checking_flag
= 1;
131 /* The elements of `ridpointers' are identifier nodes
132 for the reserved type names and storage classes.
133 It is indexed by a RID_... value. */
134 tree ridpointers
[(int) RID_MAX
];
136 /* Nonzero tells yylex to ignore \ in string constants. */
137 static int ignore_escape_flag
= 0;
139 static int maxtoken
; /* Current nominal length of token buffer. */
140 char *token_buffer
; /* Pointer to token buffer.
141 Actual allocated length is maxtoken + 2.
142 This is not static because objc-parse.y uses it. */
144 /* implement yylineno handling for flex */
145 #define yylineno lineno
147 static int inside_c_comment
= 0;
149 static int saw_eol
= 0; /* 1 if we've just seen a '\n' */
150 static int saw_eof
= 0; /* 1 if we've just seen an EOF */
152 typedef struct string_list
154 struct string_list
*next
;
158 /* list of paths specified on the compiler command line by -L options. */
159 static STRING_LIST
*seize_path_list
= (STRING_LIST
*)0;
161 /* List of seize file names. Each TREE_VALUE is an identifier
162 (file name) from a <>USE_SEIZE_FILE<> directive.
163 The TREE_PURPOSE is non-NULL if a USE_SEIZE_FILE directive has been
164 written to the grant file. */
165 static tree files_to_seize
= NULL_TREE
;
166 /* Last node on files_to_seize list. */
167 static tree last_file_to_seize
= NULL_TREE
;
168 /* Pointer into files_to_seize list: Next unparsed file to read. */
169 static tree next_file_to_seize
= NULL_TREE
;
171 /* The most recent use_seize_file directive. */
172 tree use_seizefile_name
= NULL_TREE
;
174 /* If non-NULL, the name of the seizefile we're currently processing. */
175 tree current_seizefile_name
= NULL_TREE
;
177 /* called to reset for pass 2 */
181 current_seizefile_name
= NULL_TREE
;
187 /* Initialize these compiler-directive variables. */
188 process_type
= NULL_TREE
;
189 send_buffer_prio
= NULL_TREE
;
190 send_signal_prio
= NULL_TREE
;
191 signal_code
= NULL_TREE
;
193 /* reinitialize rnage checking and empty checking */
194 range_checking
= runtime_checking_flag
;
195 empty_checking
= runtime_checking_flag
;
200 init_parse (filename
)
203 int lowercase_standard_names
= ignore_case
|| ! special_UC
;
205 /* Open input file. */
206 if (filename
== 0 || !strcmp (filename
, "-"))
212 finput
= fopen (filename
, "r");
214 pfatal_with_name (filename
);
216 #ifdef IO_BUFFER_SIZE
217 setvbuf (finput
, (char *) xmalloc (IO_BUFFER_SIZE
), _IOFBF
, IO_BUFFER_SIZE
);
220 /* Make identifier nodes long enough for the language-specific slots. */
221 set_identifier_size (sizeof (struct lang_identifier
));
223 /* Start it at 0, because check_newline is called at the very beginning
224 and will increment it to 1. */
227 /* Initialize these compiler-directive variables. */
228 process_type
= NULL_TREE
;
229 send_buffer_prio
= NULL_TREE
;
230 send_signal_prio
= NULL_TREE
;
231 signal_code
= NULL_TREE
;
234 token_buffer
= xmalloc ((unsigned)(maxtoken
+ 2));
236 init_chill_expand ();
238 #define ENTER_STANDARD_NAME(RID, LOWER, UPPER) \
239 ridpointers[(int) RID] = \
240 get_identifier (lowercase_standard_names ? LOWER : UPPER)
242 ENTER_STANDARD_NAME (RID_ALL
, "all", "ALL");
243 ENTER_STANDARD_NAME (RID_ASSERTFAIL
, "assertfail", "ASSERTFAIL");
244 ENTER_STANDARD_NAME (RID_ASSOCIATION
, "association", "ASSOCIATION");
245 ENTER_STANDARD_NAME (RID_BIN
, "bin", "BIN");
246 ENTER_STANDARD_NAME (RID_BOOL
, "bool", "BOOL");
247 ENTER_STANDARD_NAME (RID_BOOLS
, "bools", "BOOLS");
248 ENTER_STANDARD_NAME (RID_BYTE
, "byte", "BYTE");
249 ENTER_STANDARD_NAME (RID_CHAR
, "char", "CHAR");
250 ENTER_STANDARD_NAME (RID_DOUBLE
, "double", "DOUBLE");
251 ENTER_STANDARD_NAME (RID_DURATION
, "duration", "DURATION");
252 ENTER_STANDARD_NAME (RID_DYNAMIC
, "dynamic", "DYNAMIC");
253 ENTER_STANDARD_NAME (RID_ELSE
, "else", "ELSE");
254 ENTER_STANDARD_NAME (RID_EMPTY
, "empty", "EMPTY");
255 ENTER_STANDARD_NAME (RID_FALSE
, "false", "FALSE");
256 ENTER_STANDARD_NAME (RID_FLOAT
, "float", "FLOAT");
257 ENTER_STANDARD_NAME (RID_GENERAL
, "general", "GENERAL");
258 ENTER_STANDARD_NAME (RID_IN
, "in", "IN");
259 ENTER_STANDARD_NAME (RID_INLINE
, "inline", "INLINE");
260 ENTER_STANDARD_NAME (RID_INOUT
, "inout", "INOUT");
261 ENTER_STANDARD_NAME (RID_INSTANCE
, "instance", "INSTANCE");
262 ENTER_STANDARD_NAME (RID_INT
, "int", "INT");
263 ENTER_STANDARD_NAME (RID_LOC
, "loc", "LOC");
264 ENTER_STANDARD_NAME (RID_LONG
, "long", "LONG");
265 ENTER_STANDARD_NAME (RID_LONG_REAL
, "long_real", "LONG_REAL");
266 ENTER_STANDARD_NAME (RID_NULL
, "null", "NULL");
267 ENTER_STANDARD_NAME (RID_OUT
, "out", "OUT");
268 ENTER_STANDARD_NAME (RID_OVERFLOW
, "overflow", "OVERFLOW");
269 ENTER_STANDARD_NAME (RID_PTR
, "ptr", "PTR");
270 ENTER_STANDARD_NAME (RID_READ
, "read", "READ");
271 ENTER_STANDARD_NAME (RID_REAL
, "real", "REAL");
272 ENTER_STANDARD_NAME (RID_RANGE
, "range", "RANGE");
273 ENTER_STANDARD_NAME (RID_RANGEFAIL
, "rangefail", "RANGEFAIL");
274 ENTER_STANDARD_NAME (RID_RECURSIVE
, "recursive", "RECURSIVE");
275 ENTER_STANDARD_NAME (RID_SHORT
, "short", "SHORT");
276 ENTER_STANDARD_NAME (RID_SIMPLE
, "simple", "SIMPLE");
277 ENTER_STANDARD_NAME (RID_TIME
, "time", "TIME");
278 ENTER_STANDARD_NAME (RID_TRUE
, "true", "TRUE");
279 ENTER_STANDARD_NAME (RID_UBYTE
, "ubyte", "UBYTE");
280 ENTER_STANDARD_NAME (RID_UINT
, "uint", "UINT");
281 ENTER_STANDARD_NAME (RID_ULONG
, "ulong", "ULONG");
282 ENTER_STANDARD_NAME (RID_UNSIGNED
, "unsigned", "UNSIGNED");
283 ENTER_STANDARD_NAME (RID_USHORT
, "ushort", "USHORT");
284 ENTER_STANDARD_NAME (RID_VOID
, "void", "VOID");
296 static int yywrap
PROTO ((void));
297 static int yy_refill
PROTO ((void));
299 #define YY_PUTBACK_SIZE 5
300 #define YY_BUF_SIZE 1000
302 static char yy_buffer
[YY_PUTBACK_SIZE
+ YY_BUF_SIZE
];
303 static char *yy_cur
= yy_buffer
+ YY_PUTBACK_SIZE
;
304 static char *yy_lim
= yy_buffer
+ YY_PUTBACK_SIZE
;
309 char *buf
= yy_buffer
+ YY_PUTBACK_SIZE
;
311 bcopy (yy_cur
- YY_PUTBACK_SIZE
, yy_buffer
, YY_PUTBACK_SIZE
);
326 c
= check_newline ();
339 while (result
< YY_BUF_SIZE
)
349 /* Because we might switch input files on a compiler directive
350 (that end with '>', don't read past a '>', just in case. */
359 fprintf (stderr
, "-------------------------- finished Line %d\n",
367 yy_lim
= yy_cur
+ result
;
369 return yy_lim
> yy_cur
? *yy_cur
++ : EOF
;
372 #define input() (yy_cur < yy_lim ? *yy_cur++ : yy_refill ())
374 #define unput(c) (*--yy_cur = (c))
377 int starting_pass_2
= 0;
397 case ' ': case '\t': case '\n': case '\f': case '\b': case '\v': case '\r':
419 else if (nextc
== '=')
435 skip_line_comment ();
448 else if (nextc
== '=')
450 else if (nextc
== '*')
493 int len
= 0; /* Number of hex digits seen. */
501 if (!ISXDIGIT (ch
)) /* error on non-hex digit */
504 error ("invalid C'xx' ");
515 if (len
& 1) /* collected two digits, save byte */
516 obstack_1grow (&temporary_obstack
, (char) byte_val
);
519 start
= obstack_finish (&temporary_obstack
);
520 yylval
.ttype
= string_or_char (len
>> 1, start
);
521 obstack_free (&temporary_obstack
, start
);
522 return len
== 2 ? SINGLECHAR
: STRING
;
532 obstack_1grow (&temporary_obstack
, ch
);
533 obstack_1grow (&temporary_obstack
, nextc
);
538 obstack_1grow (&temporary_obstack
, ch
);
542 obstack_1grow (&temporary_obstack
, '\0');
543 start
= obstack_finish (&temporary_obstack
);
547 yylval
.ttype
= convert_integer (start
); /* Pass base? */
552 yylval
.ttype
= convert_bitstring (start
);
560 case 'F': case 'G': case 'I': case 'J':
561 case 'K': case 'L': case 'M': case 'N':
562 case 'P': case 'Q': case 'R': case 'S': case 'T':
563 case 'U': case 'V': case 'W': case 'X': case 'Y':
566 case 'f': case 'g': case 'i': case 'j':
567 case 'k': case 'l': case 'm': case 'n':
568 case 'p': case 'q': case 'r': case 's': case 't':
569 case 'u': case 'v': case 'w': case 'x': case 'y':
573 return handle_name (read_identifier (ch
));
575 tmp
= readstring ('\'', &len
);
576 yylval
.ttype
= string_or_char (len
, tmp
);
578 return len
== 1 ? SINGLECHAR
: STRING
;
580 tmp
= readstring ('\"', &len
);
581 yylval
.ttype
= build_chill_string (len
, tmp
);
587 if (ISDIGIT (nextc
)) /* || nextc == '_') we don't start numbers with '_' */
590 case '0': case '1': case '2': case '3': case '4':
591 case '5': case '6': case '7': case '8': case '9':
593 yylval
.ttype
= read_number (ch
);
594 return TREE_CODE (yylval
.ttype
) == REAL_CST
? FLOATING
: NUMBER
;
601 close_input_file (fn
)
607 if (finput
!= stdin
&& fclose (finput
) == EOF
)
609 error ("can't close %s", fn
);
615 /* Return an identifier, starting with FIRST and then reading
616 more characters using input(). Return an IDENTIFIER_NODE. */
619 read_identifier (first
)
620 int first
; /* First letter of identifier */
626 obstack_1grow (&temporary_obstack
, first
);
630 if (! ISALNUM (first
) && first
!= '_')
636 obstack_1grow (&temporary_obstack
, '\0');
637 start
= obstack_finish (&temporary_obstack
);
638 maybe_downcase (start
);
639 id
= get_identifier (start
);
640 obstack_free (&temporary_obstack
, start
);
644 /* Given an identifier ID, check to see if it is a reserved name,
645 and return the appropriate token type. */
652 tp
= in_word_set (IDENTIFIER_POINTER (id
), IDENTIFIER_LENGTH (id
));
654 && special_UC
== ISUPPER ((unsigned char) tp
->name
[0])
655 && (tp
->flags
== RESERVED
|| tp
->flags
== PREDEF
))
657 if (tp
->rid
!= NORID
)
658 yylval
.ttype
= ridpointers
[tp
->rid
];
659 else if (tp
->token
== THIS
)
660 yylval
.ttype
= lookup_name (get_identifier ("__whoami"));
669 int ch
; /* Initial character */
677 obstack_1grow (&temporary_obstack
, ch
);
679 if (! ISDIGIT (ch
) && ch
!= '_')
687 obstack_1grow (&temporary_obstack
, ch
);
689 } while (ISDIGIT (ch
) || ch
== '_');
692 if (ch
== 'd' || ch
== 'D' || ch
== 'e' || ch
== 'E')
694 /* Convert exponent indication [eEdD] to 'e'. */
695 obstack_1grow (&temporary_obstack
, 'e');
697 if (ch
== '+' || ch
== '-')
699 obstack_1grow (&temporary_obstack
, ch
);
702 if (ISDIGIT (ch
) || ch
== '_')
707 obstack_1grow (&temporary_obstack
, ch
);
709 } while (ISDIGIT (ch
) || ch
== '_');
713 error ("malformed exponent part of floating-point literal");
719 obstack_1grow (&temporary_obstack
, '\0');
720 start
= obstack_finish (&temporary_obstack
);
723 REAL_VALUE_TYPE value
;
724 tree type
= double_type_node
;
726 value
= REAL_VALUE_ATOF (start
, TYPE_MODE (type
));
727 obstack_free (&temporary_obstack
, start
);
728 if (TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
729 && REAL_VALUE_ISINF (value
) && pedantic
)
730 pedwarn ("real number exceeds range of REAL");
731 num
= build_real (type
, value
);
734 num
= convert_integer (start
);
735 CH_DERIVED_FLAG (num
) = 1;
739 /* Skip to the end of a compiler directive. */
749 error ("end-of-file in '<>' directive");
765 /* Read a compiler directive. ("<>{WS}" have already been read. ) */
771 int ch
= skip_whitespace();
772 if (ISALPHA (ch
) || ch
== '_')
773 id
= read_identifier (ch
);
776 error ("end-of-file in '<>' directive");
777 to_global_binding_level ();
782 warning ("unrecognized compiler directive");
786 tp
= in_word_set (IDENTIFIER_POINTER (id
), IDENTIFIER_LENGTH (id
));
787 if (tp
== NULL
|| special_UC
!= ISUPPER ((unsigned char) tp
->name
[0]))
790 warning ("unrecognized compiler directive `%s'",
791 IDENTIFIER_POINTER (id
));
808 case IGNORED_DIRECTIVE
:
810 case PROCESS_TYPE_TOKEN
:
811 process_type
= equal_number ();
819 case SEND_SIGNAL_DEFAULT_PRIORITY
:
820 send_signal_prio
= equal_number ();
822 case SEND_BUFFER_DEFAULT_PRIORITY
:
823 send_buffer_prio
= equal_number ();
826 signal_code
= equal_number ();
829 handle_use_seizefile_directive (0);
831 case USE_SEIZE_FILE_RESTRICTED
:
832 handle_use_seizefile_directive (1);
836 warning ("unrecognized compiler directive `%s'",
837 IDENTIFIER_POINTER (id
));
845 build_chill_string (len
, str
)
851 push_obstacks (&permanent_obstack
, &permanent_obstack
);
852 t
= build_string (len
, str
);
853 TREE_TYPE (t
) = build_string_type (char_type_node
,
854 build_int_2 (len
, 0));
855 CH_DERIVED_FLAG (t
) = 1;
862 string_or_char (len
, str
)
868 push_obstacks (&permanent_obstack
, &permanent_obstack
);
871 result
= build_int_2 ((unsigned char)str
[0], 0);
872 CH_DERIVED_FLAG (result
) = 1;
873 TREE_TYPE (result
) = char_type_node
;
876 result
= build_chill_string (len
, str
);
890 if (ISUPPER ((unsigned char) *str
))
891 *str
= TOLOWER (*str
);
903 /* check for decimal number */
904 if (*s
>= '0' && *s
<= '9')
908 if (*s
>= '0' && *s
<= '9')
926 if (*s
< '0' || *s
> '9')
931 if (!ISXDIGIT ((unsigned char) *s
))
936 if (*s
< '0' || *s
> '1')
941 if (*s
< '0' || *s
> '7')
953 readstring (terminator
, len
)
958 unsigned allocated
= 1024;
959 char *tmp
= xmalloc (allocated
);
967 if ((c
= input ()) != terminator
)
975 if (c
== '\n' || c
== EOF
)
980 if (c
== EOF
|| c
== '\n')
994 if (cc
== terminator
)
996 if (!(terminator
== '\'' && next_apos
))
998 error ("unterminated control sequence");
1003 if (cc
== EOF
|| cc
== '\n')
1013 error ("invalid integer literal in control sequence");
1019 if (cc
== ' ' || cc
== '\t')
1023 if ((c
< 0 || c
> 255) && (pass
== 1))
1024 error ("control sequence overflow");
1025 if (! count
&& pass
== 1)
1026 error ("invalid control sequence");
1031 if ((c
< 0 || c
> 255) && (pass
== 1))
1032 error ("control sequence overflow");
1033 if (! count
&& pass
== 1)
1034 error ("invalid control sequence");
1039 tmp
= xrealloc (tmp
, allocated
);
1048 if (! count
&& pass
== 1)
1049 error ("invalid integer literal in control sequence");
1054 if (cc
== 'D' || cc
== 'd')
1059 else if (cc
== 'H' || cc
== 'h')
1064 else if (cc
== 'O' || cc
== 'o')
1069 else if (cc
== 'B' || cc
== 'b')
1080 if (cc
< '0' || cc
> '1')
1087 if (cc
< '0' || cc
> '8')
1092 else if (base
== 10)
1099 else if (base
== 16)
1114 error ("invalid base in read control sequence");
1119 /* error in control sequence */
1121 error ("invalid digit in control sequence");
1124 c
= (c
* base
) + cc
;
1136 tmp
= xrealloc (tmp
, allocated
);
1140 tmp
[*len
= i
] = '\0';
1148 error ("unterminated string literal");
1149 to_global_binding_level ();
1154 /* Convert an integer INTCHARS into an INTEGER_CST.
1155 INTCHARS is on the temporary_obstack, and is popped by this function. */
1158 convert_integer (intchars
)
1167 int valid_chars
= 0;
1170 HOST_WIDE_INT val_lo
= 0, val_hi
= 0;
1173 /* determine the base */
1196 if (!ISDIGIT (*p
)) /* this test is for equal_number () */
1198 obstack_free (&temporary_obstack
, intchars
);
1207 if ((tmp
== '\'') || (tmp
== '_'))
1211 if (tmp
>= 'a') /* uppercase the char */
1213 switch (base
) /* validate the characters */
1230 if (tmp
> '9' && tmp
< 'A')
1239 if (mul_double (val_lo
, val_hi
, base
, 0, &val_lo
, &val_hi
))
1241 add_double (val_lo
, val_hi
, tmp
, 0, &val_lo
, &val_hi
);
1247 obstack_free (&temporary_obstack
, intchars
);
1251 error ("invalid number format `%s'", oldp
);
1254 val
= build_int_2 (val_lo
, val_hi
);
1255 /* We set the type to long long (or long long unsigned) so that
1256 constant fold of literals is less likely to overflow. */
1257 if (int_fits_type_p (val
, long_long_integer_type_node
))
1258 type
= long_long_integer_type_node
;
1261 if (! int_fits_type_p (val
, long_long_unsigned_type_node
))
1263 type
= long_long_unsigned_type_node
;
1265 TREE_TYPE (val
) = type
;
1266 CH_DERIVED_FLAG (val
) = 1;
1269 error ("integer literal too big");
1274 /* Convert a bitstring literal on the temporary_obstack to
1275 a bitstring CONSTRUCTOR. Free the literal from the obstack. */
1278 convert_bitstring (p
)
1284 int bl
= 0, valid_chars
= 0, bits_per_char
= 0, c
, k
;
1285 tree initlist
= NULL_TREE
;
1288 /* Move p to stack so we can re-use temporary_obstack for result. */
1289 char *oldp
= (char*) alloca (strlen (p
) + 1);
1290 if (oldp
== 0) fatal ("stack space exhausted");
1292 obstack_free (&temporary_obstack
, p
);
1315 if (c
== '_' || c
== '\'')
1324 for (k
= BYTES_BIG_ENDIAN
? bits_per_char
- 1 : 0;
1325 BYTES_BIG_ENDIAN
? k
>= 0 : k
< bits_per_char
;
1326 bl
++, BYTES_BIG_ENDIAN
? k
-- : k
++)
1329 initlist
= tree_cons (NULL_TREE
, build_int_2 (bl
, 0), initlist
);
1333 /* as long as BOOLS(0) is valid it must tbe possible to
1334 specify an empty bitstring */
1338 error ("invalid number format `%s'", oldp
);
1342 val
= build (CONSTRUCTOR
,
1343 build_bitstring_type (size_int (bl
)),
1344 NULL_TREE
, nreverse (initlist
));
1345 TREE_CONSTANT (val
) = 1;
1346 CH_DERIVED_FLAG (val
) = 1;
1350 /* Check if two filenames name the same file.
1351 This is done by stat'ing both files and comparing their inodes.
1353 Note: we have to take care of seize_path_list. Therefore do it the same
1354 way as in yywrap. FIXME: This probably can be done better. */
1357 same_file (filename1
, filename2
)
1358 const char *filename1
;
1359 const char *filename2
;
1362 const char *fn_input
[2];
1365 if (grant_only_flag
)
1366 /* do nothing in this case */
1369 /* if filenames are equal -- return 1, cause there is no need
1370 to search in the include list in this case */
1371 if (strcmp (filename1
, filename2
) == 0)
1374 fn_input
[0] = filename1
;
1375 fn_input
[1] = filename2
;
1377 for (i
= 0; i
< 2; i
++)
1379 stat_status
= stat (fn_input
[i
], &s
[i
]);
1380 if (stat_status
< 0 &&
1381 strchr (fn_input
[i
], '/') == 0)
1386 for (plp
= seize_path_list
; plp
!= 0; plp
= plp
->next
)
1388 path
= (char *)xmalloc (strlen (fn_input
[i
]) +
1389 strlen (plp
->str
) + 2);
1390 sprintf (path
, "%s/%s", plp
->str
, fn_input
[i
]);
1391 stat_status
= stat (path
, &s
[i
]);
1393 if (stat_status
>= 0)
1397 if (stat_status
< 0)
1398 pfatal_with_name (fn_input
[i
]);
1400 return s
[0].st_ino
== s
[1].st_ino
&& s
[0].st_dev
== s
[1].st_dev
;
1404 * Note that simply appending included file names to a list in this
1405 * way completely eliminates the need for nested files, and the
1406 * associated book-keeping, since the EOF processing in the lexer
1407 * will simply process the files one at a time, in the order that the
1408 * USE_SEIZE_FILE directives were scanned.
1411 handle_use_seizefile_directive (restricted
)
1416 int c
= skip_whitespace ();
1417 char *use_seizefile_str
= readstring (c
, &len
);
1422 if (c
!= '\'' && c
!= '\"')
1424 error ("USE_SEIZE_FILE directive must be followed by string");
1428 use_seizefile_name
= get_identifier (use_seizefile_str
);
1429 CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name
) = restricted
;
1431 if (!grant_only_flag
)
1433 /* If file foo.ch contains a <> use_seize_file "bar.grt" <>,
1434 and file bar.ch contains a <> use_seize_file "foo.grt" <>,
1435 then if we're compiling foo.ch, we will indirectly be
1436 asked to seize foo.grt. Don't. */
1437 extern char *grant_file_name
;
1438 if (strcmp (use_seizefile_str
, grant_file_name
) == 0)
1441 /* Check if the file is already on the list. */
1442 for (seen
= files_to_seize
; seen
!= NULL_TREE
; seen
= TREE_CHAIN (seen
))
1443 if (same_file (IDENTIFIER_POINTER (TREE_VALUE (seen
)),
1445 return; /* Previously seen; nothing to do. */
1448 /* Haven't been asked to seize this file yet, so add
1449 its name to the list. */
1451 tree pl
= perm_tree_cons (0, use_seizefile_name
, NULL_TREE
);
1452 if (files_to_seize
== NULL_TREE
)
1453 files_to_seize
= pl
;
1455 TREE_CHAIN (last_file_to_seize
) = pl
;
1456 if (next_file_to_seize
== NULL_TREE
)
1457 next_file_to_seize
= pl
;
1458 last_file_to_seize
= pl
;
1464 * get input, convert to lower case for comparison
1478 #if defined HANDLE_PRAGMA
1479 /* Local versions of these macros, that can be passed as function pointers. */
1483 return getc (finput
);
1490 ungetc (arg
, finput
);
1492 #endif /* HANDLE_PRAGMA */
1494 #ifdef HANDLE_GENERIC_PRAGMAS
1495 /* Handle a generic #pragma directive.
1496 BUFFER contains the text we read after `#pragma'. Processes the entire input
1497 line and return non-zero iff the pragma was successfully processed. */
1500 handle_generic_pragma (buffer
)
1509 handle_pragma_token (buffer
, NULL
);
1513 while (c
== ' ' || c
== '\t')
1517 if (c
== '\n' || c
== EOF
)
1518 return handle_pragma_token (NULL
, NULL
);
1520 /* Read the next word of the pragma into the buffer. */
1527 while (c
!= EOF
&& isascii (c
) && ! ISSPACE (c
) && c
!= '\n'
1528 && buff
< buffer
+ 128); /* XXX shared knowledge about size of buffer. */
1535 #endif /* HANDLE_GENERIC_PRAGMAS */
1537 /* At the beginning of a line, increment the line number and process
1538 any #-directive on this line. If the line is a #-directive, read
1539 the entire line and return a newline. Otherwise, return the line's
1540 first non-whitespace character.
1542 (Each language front end has a check_newline() function that is called
1543 from lang_init() for that language. One of the things this function
1544 must do is read the first line of the input file, and if it is a #line
1545 directive, extract the filename from it and use it to initialize
1546 main_input_filename. Proper generation of debugging information in
1547 the normal "front end calls cpp then calls cc1XXXX environment" depends
1548 upon this being done.) */
1557 /* Read first nonwhite char on the line. */
1561 while (c
== ' ' || c
== '\t')
1564 if (c
!= '#' || inside_c_comment
)
1566 /* If not #, return it so caller will use it. */
1570 /* Read first nonwhite char after the `#'. */
1573 while (c
== ' ' || c
== '\t')
1576 /* If a letter follows, then if the word here is `line', skip
1577 it and ignore it; otherwise, ignore the line, with an error
1578 if the word isn't `pragma', `ident', `define', or `undef'. */
1583 if (c
>= 'a' && c
<= 'z')
1587 if (getlc (finput
) == 'r'
1588 && getlc (finput
) == 'a'
1589 && getlc (finput
) == 'g'
1590 && getlc (finput
) == 'm'
1591 && getlc (finput
) == 'a'
1592 && (c
= getlc (finput
), ISSPACE (c
)))
1594 #ifdef HANDLE_PRAGMA
1595 static char buffer
[128];
1596 char * buff
= buffer
;
1598 /* Read the pragma name into a buffer. */
1599 while (c
= getlc (finput
), ISSPACE (c
))
1607 while (c
!= EOF
&& ! ISSPACE (c
) && c
!= '\n'
1608 && buff
< buffer
+ 128);
1614 if (HANDLE_PRAGMA (pragma_getc
, pragma_ungetc
, buffer
))
1616 #endif /* HANDLE_PRAGMA */
1618 #ifdef HANDLE_GENERIC_PRAGMAS
1619 if (handle_generic_pragma (buffer
))
1621 #endif /* HANDLE_GENERIC_PRAGMAS */
1629 if (getlc (finput
) == 'e'
1630 && getlc (finput
) == 'f'
1631 && getlc (finput
) == 'i'
1632 && getlc (finput
) == 'n'
1633 && getlc (finput
) == 'e'
1634 && (c
= getlc (finput
), ISSPACE (c
)))
1636 #if 0 /*def DWARF_DEBUGGING_INFO*/
1638 && (debug_info_level
== DINFO_LEVEL_VERBOSE
)
1639 && (write_symbols
== DWARF_DEBUG
))
1640 dwarfout_define (lineno
, get_directive_line (finput
));
1641 #endif /* DWARF_DEBUGGING_INFO */
1647 if (getlc (finput
) == 'n'
1648 && getlc (finput
) == 'd'
1649 && getlc (finput
) == 'e'
1650 && getlc (finput
) == 'f'
1651 && (c
= getlc (finput
), ISSPACE (c
)))
1653 #if 0 /*def DWARF_DEBUGGING_INFO*/
1655 && (debug_info_level
== DINFO_LEVEL_VERBOSE
)
1656 && (write_symbols
== DWARF_DEBUG
))
1657 dwarfout_undef (lineno
, get_directive_line (finput
));
1658 #endif /* DWARF_DEBUGGING_INFO */
1664 if (getlc (finput
) == 'i'
1665 && getlc (finput
) == 'n'
1666 && getlc (finput
) == 'e'
1667 && ((c
= getlc (finput
)) == ' ' || c
== '\t'))
1673 if (getlc (finput
) == 'd'
1674 && getlc (finput
) == 'e'
1675 && getlc (finput
) == 'n'
1676 && getlc (finput
) == 't'
1677 && ((c
= getlc (finput
)) == ' ' || c
== '\t'))
1679 /* #ident. The pedantic warning is now in cccp.c. */
1681 /* Here we have just seen `#ident '.
1682 A string constant should follow. */
1684 while (c
== ' ' || c
== '\t')
1687 /* If no argument, ignore the line. */
1694 || TREE_CODE (yylval
.ttype
) != STRING_CST
)
1696 error ("invalid #ident");
1702 #ifdef ASM_OUTPUT_IDENT
1703 extern FILE *asm_out_file
;
1704 ASM_OUTPUT_IDENT (asm_out_file
, TREE_STRING_POINTER (yylval
.ttype
));
1708 /* Skip the rest of this line. */
1714 error ("undefined or invalid # directive");
1719 /* Here we have either `#line' or `# <nonletter>'.
1720 In either case, it should be a line number; a digit should follow. */
1722 while (c
== ' ' || c
== '\t')
1725 /* If the # is the only nonwhite char on the line,
1726 just ignore it. Check the new newline. */
1730 /* Something follows the #; read a token. */
1734 int old_lineno
= lineno
;
1737 extern struct obstack permanent_obstack
;
1741 l
= l
* 10 + (c
- '0'); /* FIXME Not portable */
1743 } while (ISDIGIT(c
));
1744 /* subtract one, because it is the following line that
1745 gets the specified number */
1749 /* Is this the last nonwhite stuff on the line? */
1751 while (c
== ' ' || c
== '\t')
1755 /* No more: store the line number and check following line. */
1760 /* More follows: it must be a string constant (filename). */
1762 /* Read the string constant, but don't treat \ as special. */
1763 ignore_escape_flag
= 1;
1764 ignore_escape_flag
= 0;
1768 error ("invalid #line");
1775 if (c
== EOF
|| c
== '\n')
1777 error ("invalid #line");
1782 obstack_1grow(&permanent_obstack
, 0);
1783 input_filename
= obstack_finish (&permanent_obstack
);
1786 obstack_1grow(&permanent_obstack
, c
);
1791 /* Each change of file name
1792 reinitializes whether we are now in a system header. */
1793 in_system_header
= 0;
1795 if (main_input_filename
== 0)
1796 main_input_filename
= input_filename
;
1798 /* Is this the last nonwhite stuff on the line? */
1800 while (c
== ' ' || c
== '\t')
1807 /* `1' after file name means entering new file.
1808 `2' after file name means just left a file. */
1814 /* Pushing to a new file. */
1815 struct file_stack
*p
1816 = (struct file_stack
*) xmalloc (sizeof (struct file_stack
));
1817 input_file_stack
->line
= old_lineno
;
1818 p
->next
= input_file_stack
;
1819 p
->name
= input_filename
;
1820 input_file_stack
= p
;
1821 input_file_stack_tick
++;
1822 #ifdef DWARF_DEBUGGING_INFO
1823 if (debug_info_level
== DINFO_LEVEL_VERBOSE
1824 && write_symbols
== DWARF_DEBUG
)
1825 dwarfout_start_new_source_file (input_filename
);
1826 #endif /* DWARF_DEBUGGING_INFO */
1832 /* Popping out of a file. */
1833 if (input_file_stack
->next
)
1835 struct file_stack
*p
= input_file_stack
;
1836 input_file_stack
= p
->next
;
1838 input_file_stack_tick
++;
1839 #ifdef DWARF_DEBUGGING_INFO
1840 if (debug_info_level
== DINFO_LEVEL_VERBOSE
1841 && write_symbols
== DWARF_DEBUG
)
1842 dwarfout_resume_previous_source_file (input_file_stack
->line
);
1843 #endif /* DWARF_DEBUGGING_INFO */
1846 error ("#-lines for entering and leaving files don't match");
1852 /* If we have handled a `1' or a `2',
1853 see if there is another number to read. */
1856 /* Is this the last nonwhite stuff on the line? */
1858 while (c
== ' ' || c
== '\t')
1865 /* `3' after file name means this is a system header file. */
1868 in_system_header
= 1;
1871 error ("invalid #-line");
1873 /* skip the rest of this line. */
1875 while (c
!= '\n' && c
!= EOF
)
1882 get_chill_filename ()
1884 return (build_chill_string (
1885 strlen (input_filename
) + 1, /* +1 to get a zero terminated string */
1890 get_chill_linenumber ()
1892 return build_int_2 ((HOST_WIDE_INT
)lineno
, 0);
1896 /* Assuming '/' and '*' have been read, skip until we've
1897 read the terminating '*' and '/'. */
1903 int start_line
= lineno
;
1909 error_with_file_and_line (input_filename
, start_line
,
1910 "unterminated comment");
1915 else if ((c
= input ()) == '/')
1921 /* Assuming "--" has been read, skip until '\n'. */
1924 skip_line_comment ()
1948 if (c
== ' ' || c
== '\t' || c
== '\r' || c
== '\n' || c
== '\v')
1969 skip_line_comment ();
1983 * avoid recursive calls to yylex to parse the ' = digits' or
1984 * ' = SYNvalue' which are supposed to follow certain compiler
1985 * directives. Read the input stream, and return the value parsed.
1987 /* FIXME: overflow check in here */
1988 /* FIXME: check for EOF around here */
1995 tree retval
= integer_zero_node
;
1997 c
= skip_whitespace();
2001 error ("missing `=' in compiler directive");
2002 return integer_zero_node
;
2004 c
= skip_whitespace();
2006 /* collect token into tokenbuf for later analysis */
2009 if (ISSPACE (c
) || c
== '<')
2011 obstack_1grow (&temporary_obstack
, c
);
2014 unput (c
); /* put uninteresting char back */
2015 obstack_1grow (&temporary_obstack
, '\0'); /* terminate token */
2016 tokenbuf
= obstack_finish (&temporary_obstack
);
2017 maybe_downcase (tokenbuf
);
2019 if (*tokenbuf
== '-')
2020 /* will fail in the next test */
2022 else if (maybe_number (tokenbuf
))
2025 return integer_zero_node
;
2026 push_obstacks_nochange ();
2027 end_temporary_allocation ();
2028 yylval
.ttype
= convert_integer (tokenbuf
);
2029 tokenbuf
= 0; /* Was freed by convert_integer. */
2030 result
= yylval
.ttype
? NUMBER
: 0;
2036 if (result
== NUMBER
)
2038 retval
= yylval
.ttype
;
2040 else if (result
== BITSTRING
)
2043 error ("invalid value follows `=' in compiler directive");
2046 else /* not a number */
2050 if (!ISALPHA (c
) && c
!= '_')
2053 error ("invalid value follows `=' in compiler directive");
2057 for (cursor
= &tokenbuf
[1]; *cursor
!= '\0'; cursor
++)
2058 if (ISALPHA ((unsigned char) *cursor
) || *cursor
== '_' ||
2064 error ("invalid `%c' character in name", *cursor
);
2071 tree value
= lookup_name (get_identifier (tokenbuf
));
2072 if (value
== NULL_TREE
2073 || TREE_CODE (value
) != CONST_DECL
2074 || TREE_CODE (DECL_INITIAL (value
)) != INTEGER_CST
)
2077 error ("`%s' not integer constant synonym ",
2081 obstack_free (&temporary_obstack
, tokenbuf
);
2083 push_obstacks_nochange ();
2084 end_temporary_allocation ();
2085 retval
= convert (chill_taskingcode_type_node
, DECL_INITIAL (value
));
2090 /* check the value */
2091 if (TREE_CODE (retval
) != INTEGER_CST
)
2094 error ("invalid value follows `=' in compiler directive");
2096 else if (TREE_INT_CST_HIGH (retval
) != 0 ||
2097 TREE_INT_CST_LOW (retval
) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node
)))
2100 error ("value out of range in compiler directive");
2104 obstack_free (&temporary_obstack
, tokenbuf
);
2109 * add a possible grant-file path to the list
2112 register_seize_path (path
)
2115 int pathlen
= strlen (path
);
2116 char *new_path
= (char *)xmalloc (pathlen
+ 1);
2117 STRING_LIST
*pl
= (STRING_LIST
*)xmalloc (sizeof (STRING_LIST
));
2119 /* strip off trailing slash if any */
2120 if (path
[pathlen
- 1] == '/')
2123 memcpy (new_path
, path
, pathlen
);
2125 pl
->next
= seize_path_list
;
2126 seize_path_list
= pl
;
2130 /* Used by decode_decl to indicate that a <> use_seize_file NAME <>
2131 directive has been written to the grantfile. */
2134 mark_use_seizefile_written (name
)
2139 for (node
= files_to_seize
; node
!= NULL_TREE
; node
= TREE_CHAIN (node
))
2140 if (TREE_VALUE (node
) == name
)
2142 TREE_PURPOSE (node
) = integer_one_node
;
2151 extern char *chill_real_input_filename
;
2153 close_input_file (input_filename
);
2155 use_seizefile_name
= NULL_TREE
;
2157 if (next_file_to_seize
&& !grant_only_flag
)
2159 FILE *grt_in
= NULL
;
2160 char *seizefile_name_chars
2161 = IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize
));
2163 /* find a seize file, open it. If it's not at the path the
2164 * user gave us, and that path contains no slashes, look on
2165 * the seize_file paths, specified by the '-I' options.
2167 grt_in
= fopen (seizefile_name_chars
, "r");
2169 && strchr (seizefile_name_chars
, '/') == NULL
)
2174 for (plp
= seize_path_list
; plp
!= NULL
; plp
= plp
->next
)
2176 path
= (char *)xmalloc (strlen (seizefile_name_chars
)
2177 + strlen (plp
->str
) + 2);
2179 sprintf (path
, "%s/%s", plp
->str
, seizefile_name_chars
);
2180 grt_in
= fopen (path
, "r");
2185 seizefile_name_chars
= path
;
2192 pfatal_with_name (seizefile_name_chars
);
2195 input_filename
= seizefile_name_chars
;
2198 current_seizefile_name
= TREE_VALUE (next_file_to_seize
);
2200 next_file_to_seize
= TREE_CHAIN (next_file_to_seize
);
2208 next_file_to_seize
= files_to_seize
;
2209 current_seizefile_name
= NULL_TREE
;
2211 if (strcmp (main_input_filename
, "stdin"))
2212 finput
= fopen (chill_real_input_filename
, "r");
2217 error ("can't reopen %s", chill_real_input_filename
);
2220 input_filename
= main_input_filename
;
2223 /* Read a line directive if there is one. */
2224 ungetc (check_newline (), finput
);
2225 starting_pass_2
= 1;
2227 if (module_number
== 0)
2228 warning ("no modules seen");