summaryrefslogtreecommitdiffstats
path: root/gcc/ch/lex.c
blob: 44029b99d209b1cce9832d2367f9ae7f6aec1e25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
/* Lexical analyzer for GNU CHILL. -*- C -*-
   Copyright (C) 1992, 93, 1994, 1998 Free Software Foundation, Inc.

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	 General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include "config.h"
#include "system.h"
#include <setjmp.h>
#include <sys/stat.h>

#include "tree.h"
#include "input.h"

#include "lex.h"
#include "ch-tree.h"
#include "flags.h"
#include "parse.h"
#include "obstack.h"
#include "toplev.h"

#ifdef DWARF_DEBUGGING_INFO
#include "dwarfout.h"
#endif

#ifdef MULTIBYTE_CHARS
#include <locale.h>
#endif

/* include the keyword recognizers */
#include "hash.h"

FILE* finput;

#if 0
static int	last_token = 0;
/* Sun's C compiler warns about the safer sequence 
   do { .. } while 0 
   when there's a 'return' inside the braces, so don't use it */
#define RETURN_TOKEN(X) { last_token = X; return (X); }
#endif

/* This is set non-zero to force incoming tokens to lowercase. */
extern int ignore_case;

extern int module_number;
extern int serious_errors;

/* This is non-zero to recognize only uppercase special words. */
extern int special_UC;

extern struct obstack permanent_obstack;
extern struct obstack temporary_obstack;

/* forward declarations */
static void close_input_file         PROTO((const char *));
static tree convert_bitstring        PROTO((char *));
static tree convert_integer          PROTO((char *));
static void maybe_downcase           PROTO((char *));
static int  maybe_number             PROTO((const char *));
static tree equal_number             PROTO((void));
static void handle_use_seizefile_directive PROTO((int));
static int  handle_name		     PROTO((tree));
static char *readstring              PROTO((int, int *));
static void read_directive	     PROTO((void));
static tree read_identifier	     PROTO((int));
static tree read_number              PROTO((int));
static void skip_c_comment           PROTO((void));
static void skip_line_comment        PROTO((void));
static int  skip_whitespace          PROTO((void));
static tree string_or_char           PROTO((int, const char *));
static void ch_lex_init              PROTO((void));
static void skip_directive           PROTO((void));
static int same_file                 PROTO((const char *, const char *));
static int getlc                     PROTO((FILE *));

/* next variables are public, because ch-actions uses them */

/* the default grantfile name, set by lang_init */
tree default_grant_file = 0;

/* These tasking-related variables are NULL at the start of each 
   compiler pass, and are set to an expression tree if and when
   a compiler directive is parsed containing an expression.
   The NULL state is significant;  it means 'no user-specified
   signal_code (or whatever) has been parsed'. */

/* process type, set by <> PROCESS_TYPE = number <> */
tree process_type = NULL_TREE;

/* send buffer default priority,
   set by <> SEND_BUFFER_DEFAULT_PRIORITY = number <> */
tree send_buffer_prio = NULL_TREE;

/* send signal default priority,
   set by <> SEND_SIGNAL_DEFAULT_PRIORITY = number <> */
tree send_signal_prio = NULL_TREE;

/* signal code, set by <> SIGNAL_CODE = number <> */
tree signal_code = NULL_TREE;

/* flag for range checking */
int range_checking = 1;

/* flag for NULL pointer checking */
int empty_checking = 1;

/* flag to indicate making all procedure local variables
   to be STATIC */
int all_static_flag = 0;

/* flag to indicate -fruntime-checking command line option.
   Needed for initializing range_checking and empty_checking
   before pass 2 */
int runtime_checking_flag = 1;

/* The elements of `ridpointers' are identifier nodes
   for the reserved type names and storage classes.
   It is indexed by a RID_... value.  */
tree ridpointers[(int) RID_MAX];

/* Nonzero tells yylex to ignore \ in string constants.  */
static int ignore_escape_flag = 0;

static int maxtoken;		/* Current nominal length of token buffer.  */
char *token_buffer;	/* Pointer to token buffer.
			   Actual allocated length is maxtoken + 2.
			   This is not static because objc-parse.y uses it.  */

/* implement yylineno handling for flex */
#define yylineno lineno

static int inside_c_comment = 0;

static int saw_eol = 0; /* 1 if we've just seen a '\n' */
static int saw_eof = 0; /* 1 if we've just seen an EOF */

typedef struct string_list
  {
    struct string_list *next;
    char               *str;
  } STRING_LIST;

/* list of paths specified on the compiler command line by -L options. */
static STRING_LIST *seize_path_list = (STRING_LIST *)0;

/* List of seize file names.  Each TREE_VALUE is an identifier
   (file name) from a <>USE_SEIZE_FILE<> directive.
   The TREE_PURPOSE is non-NULL if a USE_SEIZE_FILE directive has been
   written to the grant file. */
static tree files_to_seize     = NULL_TREE;
/* Last node on files_to_seize list. */
static tree last_file_to_seize = NULL_TREE;
/* Pointer into files_to_seize list:  Next unparsed file to read. */
static tree next_file_to_seize = NULL_TREE;

/* The most recent use_seize_file directive. */
tree use_seizefile_name = NULL_TREE;

/* If non-NULL, the name of the seizefile we're currently processing. */
tree current_seizefile_name = NULL_TREE;

/* called to reset for pass 2 */
static void
ch_lex_init ()
{
  current_seizefile_name = NULL_TREE;

  lineno = 0;

  saw_eol = 0;
  saw_eof = 0;
  /* Initialize these compiler-directive variables. */
  process_type     = NULL_TREE;
  send_buffer_prio = NULL_TREE;
  send_signal_prio = NULL_TREE;
  signal_code      = NULL_TREE;
  all_static_flag  = 0;
  /* reinitialize rnage checking and empty checking */
  range_checking = runtime_checking_flag;
  empty_checking = runtime_checking_flag;
}


char *
init_parse (filename)
     char *filename;
{
  int lowercase_standard_names = ignore_case || ! special_UC;

  /* Open input file.  */
  if (filename == 0 || !strcmp (filename, "-"))
    {
      finput = stdin;
      filename = "stdin";
    }
  else
    finput = fopen (filename, "r");
  if (finput == 0)
    pfatal_with_name (filename);

#ifdef IO_BUFFER_SIZE
  setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
#endif

  /* Make identifier nodes long enough for the language-specific slots.  */
  set_identifier_size (sizeof (struct lang_identifier));

  /* Start it at 0, because check_newline is called at the very beginning
     and will increment it to 1.  */
  lineno = 0;

  /* Initialize these compiler-directive variables. */
  process_type     = NULL_TREE;
  send_buffer_prio = NULL_TREE;
  send_signal_prio = NULL_TREE;
  signal_code      = NULL_TREE;

  maxtoken         = 40;
  token_buffer     = xmalloc ((unsigned)(maxtoken + 2));

  init_chill_expand ();

#define ENTER_STANDARD_NAME(RID, LOWER, UPPER) \
  ridpointers[(int) RID] = \
    get_identifier (lowercase_standard_names ? LOWER : UPPER)

  ENTER_STANDARD_NAME (RID_ALL,		"all",		"ALL");
  ENTER_STANDARD_NAME (RID_ASSERTFAIL,	"assertfail",	"ASSERTFAIL");
  ENTER_STANDARD_NAME (RID_ASSOCIATION,	"association",	"ASSOCIATION");
  ENTER_STANDARD_NAME (RID_BIN,         "bin",          "BIN");
  ENTER_STANDARD_NAME (RID_BOOL,	"bool",		"BOOL");
  ENTER_STANDARD_NAME (RID_BOOLS,	"bools",	"BOOLS");
  ENTER_STANDARD_NAME (RID_BYTE,	"byte",		"BYTE");
  ENTER_STANDARD_NAME (RID_CHAR,	"char",		"CHAR");
  ENTER_STANDARD_NAME (RID_DOUBLE,	"double",	"DOUBLE");
  ENTER_STANDARD_NAME (RID_DURATION,    "duration",     "DURATION");
  ENTER_STANDARD_NAME (RID_DYNAMIC,	"dynamic",	"DYNAMIC");
  ENTER_STANDARD_NAME (RID_ELSE,	"else",		"ELSE");
  ENTER_STANDARD_NAME (RID_EMPTY,	"empty",	"EMPTY");
  ENTER_STANDARD_NAME (RID_FALSE,	"false",	"FALSE");
  ENTER_STANDARD_NAME (RID_FLOAT,	"float",	"FLOAT");
  ENTER_STANDARD_NAME (RID_GENERAL,	"general",	"GENERAL");
  ENTER_STANDARD_NAME (RID_IN,		"in",		"IN");
  ENTER_STANDARD_NAME (RID_INLINE,	"inline",	"INLINE");
  ENTER_STANDARD_NAME (RID_INOUT,	"inout",	"INOUT");
  ENTER_STANDARD_NAME (RID_INSTANCE,	"instance",	"INSTANCE");
  ENTER_STANDARD_NAME (RID_INT,		"int",		"INT");
  ENTER_STANDARD_NAME (RID_LOC,		"loc",		"LOC");
  ENTER_STANDARD_NAME (RID_LONG,	"long",		"LONG");
  ENTER_STANDARD_NAME (RID_LONG_REAL,	"long_real",	"LONG_REAL");
  ENTER_STANDARD_NAME (RID_NULL,	"null",		"NULL");
  ENTER_STANDARD_NAME (RID_OUT,		"out",		"OUT");
  ENTER_STANDARD_NAME (RID_OVERFLOW,	"overflow",	"OVERFLOW");
  ENTER_STANDARD_NAME (RID_PTR,		"ptr",		"PTR");
  ENTER_STANDARD_NAME (RID_READ,	"read",		"READ");
  ENTER_STANDARD_NAME (RID_REAL,	"real",		"REAL");
  ENTER_STANDARD_NAME (RID_RANGE,	"range",	"RANGE");
  ENTER_STANDARD_NAME (RID_RANGEFAIL,	"rangefail",	"RANGEFAIL");
  ENTER_STANDARD_NAME (RID_RECURSIVE,	"recursive",	"RECURSIVE");
  ENTER_STANDARD_NAME (RID_SHORT,	"short",	"SHORT");
  ENTER_STANDARD_NAME (RID_SIMPLE,	"simple",	"SIMPLE");
  ENTER_STANDARD_NAME (RID_TIME,        "time",         "TIME");
  ENTER_STANDARD_NAME (RID_TRUE,	"true",		"TRUE");
  ENTER_STANDARD_NAME (RID_UBYTE,	"ubyte",	"UBYTE");
  ENTER_STANDARD_NAME (RID_UINT,	"uint",		"UINT");
  ENTER_STANDARD_NAME (RID_ULONG,	"ulong",	"ULONG");
  ENTER_STANDARD_NAME (RID_UNSIGNED,	"unsigned",	"UNSIGNED");
  ENTER_STANDARD_NAME (RID_USHORT,	"ushort",	"USHORT");
  ENTER_STANDARD_NAME (RID_VOID,	"void",		"VOID");

  return filename;
}

void
finish_parse ()
{
  if (finput != NULL)
    fclose (finput);
}

static int yywrap PROTO ((void));
static int yy_refill PROTO ((void));

#define YY_PUTBACK_SIZE 5
#define YY_BUF_SIZE 1000

static char yy_buffer[YY_PUTBACK_SIZE + YY_BUF_SIZE];
static char *yy_cur = yy_buffer + YY_PUTBACK_SIZE;
static char *yy_lim = yy_buffer + YY_PUTBACK_SIZE;

static int
yy_refill ()
{
  char *buf = yy_buffer + YY_PUTBACK_SIZE;
  int c, result;
  bcopy (yy_cur - YY_PUTBACK_SIZE, yy_buffer, YY_PUTBACK_SIZE);
  yy_cur = buf;

 retry:
  if (saw_eof)
    {
      if (yywrap ())
	return EOF;
      saw_eof = 0;
      goto retry;
    }

  result = 0;
  while (saw_eol)
    {
      c = check_newline ();
      if (c == EOF)
        {
	  saw_eof = 1;
	  goto retry;
	}
      else if (c != '\n')
	{
	  saw_eol = 0;
	  buf[result++] = c;
	}
    }
  
  while (result < YY_BUF_SIZE)
    {
      c = getc(finput);
      if (c == EOF)
        {
	  saw_eof = 1;
	  break;
	}
      buf[result++] = c;
      
      /* Because we might switch input files on a compiler directive
	 (that end with '>', don't read past a '>', just in case. */
      if (c == '>')
	break;
      
      if (c == '\n')
	{
#ifdef YYDEBUG
	  extern int yydebug;
	  if (yydebug)
            fprintf (stderr, "-------------------------- finished Line %d\n",
		     yylineno);
#endif
	  saw_eol = 1;
	  break;
	}
    }

  yy_lim = yy_cur + result;

  return yy_lim > yy_cur ? *yy_cur++ : EOF;
}

#define input() (yy_cur < yy_lim ? *yy_cur++ : yy_refill ())

#define unput(c) (*--yy_cur = (c))


int starting_pass_2 = 0;

int
yylex ()
{
  int nextc;
  int len;
  char* tmp;
  int base;
  int ch;
 retry:
  ch = input ();
  if (starting_pass_2)
    {
      starting_pass_2 = 0;
      unput (ch);
      return END_PASS_1;
    }
  switch (ch)
    {
    case ' ': case '\t': case '\n': case '\f': case '\b': case '\v': case '\r':
      goto retry;
    case '[':
      return LPC;
    case ']':
      return RPC;
    case '{':
      return LC;
    case '}':
      return RC;
    case '(':
      nextc = input ();
      if (nextc == ':')
	return LPC;
      unput (nextc);
      return LPRN;
    case ')':
      return RPRN;
    case ':':
      nextc = input ();
      if (nextc == ')')
	return RPC;
      else if (nextc == '=')
	return ASGN;
      unput (nextc);
      return COLON;
    case ',':
      return COMMA;
    case ';':
      return SC;
    case '+':
      return PLUS;
    case '-':
      nextc = input ();
      if (nextc == '>')
	return ARROW;
      if (nextc == '-')
	{
	  skip_line_comment ();
	  goto retry;
	}
      unput (nextc);
      return SUB;
    case '*':
      return MUL;
    case '=':
      return EQL;
    case '/':
      nextc = input ();
      if (nextc == '/')
	return CONCAT;
      else if (nextc == '=')
	return NE;
      else if (nextc == '*')
	{
	  skip_c_comment ();
	  goto retry;
	}
      unput (nextc);
      return DIV;
    case '<':
      nextc = input ();
      if (nextc == '=')
	return LTE;
      if (nextc == '>')
	{
	  read_directive ();
	  goto retry;
	}
      unput (nextc);
      return LT;
    case '>':
      nextc = input ();
      if (nextc == '=')
	return GTE;
      unput (nextc);
      return GT;

    case 'D': case 'd':
      base = 10;
      goto maybe_digits;
    case 'B': case 'b':
      base = 2;
      goto maybe_digits;
    case 'H': case 'h':
      base = 16;
      goto maybe_digits;
    case 'O': case 'o':
      base = 8;
      goto maybe_digits;
    case 'C': case 'c':
      nextc = input ();
      if (nextc == '\'')
	{
	  int byte_val = 0;
	  char *start;
	  int len = 0;  /* Number of hex digits seen. */
	  for (;;)
	    {
	      ch = input ();
	      if (ch == '\'')
		break;
	      if (ch == '_')
		continue;
	      if (!ISXDIGIT (ch))           /* error on non-hex digit */
		{
		  if (pass == 1)
		    error ("invalid C'xx' ");
		  break;
		}
	      if (ch >= 'a')
		ch -= ' ';
	      ch -= '0';
	      if (ch > 9)
		ch -= 7;
	      byte_val *= 16;
	      byte_val += (int)ch;

	      if (len & 1) /* collected two digits, save byte */
		obstack_1grow (&temporary_obstack, (char) byte_val);
	      len++;
	    }
	  start = obstack_finish (&temporary_obstack);
	  yylval.ttype = string_or_char (len >> 1, start);
	  obstack_free (&temporary_obstack, start);
	  return len == 2 ? SINGLECHAR : STRING;
	}
      unput (nextc);
      goto letter;

    maybe_digits:
      nextc = input ();
      if (nextc == '\'')
	{
	  char *start;
	  obstack_1grow (&temporary_obstack, ch);
	  obstack_1grow (&temporary_obstack, nextc);
	  for (;;)
	    {
	      ch = input ();
	      if (ISALNUM (ch))
		obstack_1grow (&temporary_obstack, ch);
	      else if (ch != '_')
		break;
	    }
	  obstack_1grow (&temporary_obstack, '\0');
	  start = obstack_finish (&temporary_obstack);
	  if (ch != '\'')
	    {
	      unput (ch);
	      yylval.ttype = convert_integer (start); /* Pass base? */
	      return NUMBER;
	    }
	  else
	    {
	      yylval.ttype = convert_bitstring (start);
	      return BITSTRING;
	    }
	}
      unput (nextc);
      goto letter;

    case 'A':                                   case 'E':
    case 'F':  case 'G':             case 'I':  case 'J':
    case 'K':  case 'L':  case 'M':  case 'N':
    case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
    case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
    case 'Z':
    case 'a':                                   case 'e':
    case 'f':  case 'g':             case 'i':  case 'j':
    case 'k':  case 'l':  case 'm':  case 'n':
    case 'p':  case 'q':  case 'r':  case 's':  case 't':
    case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
    case 'z':
    case '_':
    letter:
      return handle_name (read_identifier (ch));
    case '\'':
      tmp = readstring ('\'', &len);
      yylval.ttype = string_or_char (len, tmp);
      free (tmp);
      return len == 1 ? SINGLECHAR : STRING;
    case '\"':
      tmp = readstring ('\"', &len);
      yylval.ttype = build_chill_string (len, tmp);
      free (tmp);
      return STRING;
    case '.':
      nextc = input ();
      unput (nextc);
      if (ISDIGIT (nextc)) /* || nextc == '_')  we don't start numbers with '_' */
	goto number;
      return DOT;
    case '0': case '1': case '2': case '3': case '4':
    case '5': case '6': case '7': case '8': case '9':
    number:
      yylval.ttype = read_number (ch);
      return TREE_CODE (yylval.ttype) == REAL_CST ? FLOATING : NUMBER;
    default:
      return ch;
    }
}

static void
close_input_file (fn)
  const char *fn;
{
  if (finput == NULL)
    abort ();

  if (finput != stdin && fclose (finput) == EOF)
    {
      error ("can't close %s", fn);
      abort ();
    }
  finput = NULL;
}

/* Return an identifier, starting with FIRST and then reading
   more characters using input().  Return an IDENTIFIER_NODE. */

static tree
read_identifier (first)
     int first; /* First letter of identifier */
{
  tree id;
  char *start;
  for (;;)
    {
      obstack_1grow (&temporary_obstack, first);
      first = input ();
      if (first == EOF)
	break;
      if (! ISALNUM (first) && first != '_')
	{
	  unput (first);
	  break;
	}
    }
  obstack_1grow (&temporary_obstack, '\0');
  start = obstack_finish (&temporary_obstack);
  maybe_downcase (start);
  id = get_identifier (start);
  obstack_free (&temporary_obstack, start);
  return id;
}

/* Given an identifier ID, check to see if it is a reserved name,
   and return the appropriate token type. */

static int
handle_name (id)
     tree id;
{
  struct resword *tp;
  tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
  if (tp != NULL
      && special_UC == ISUPPER ((unsigned char) tp->name[0])
      && (tp->flags == RESERVED || tp->flags == PREDEF))
    {
      if (tp->rid != NORID)
	yylval.ttype = ridpointers[tp->rid];
      else if (tp->token == THIS)
	yylval.ttype = lookup_name (get_identifier ("__whoami"));
      return tp->token;
    }
  yylval.ttype = id;
  return NAME;
}

static tree
read_number (ch)
     int ch; /* Initial character */
{
  tree num;
  char *start;
  int is_float = 0;
  for (;;)
    {
      if (ch != '_')
	obstack_1grow (&temporary_obstack, ch);
      ch = input ();
      if (! ISDIGIT (ch) && ch != '_')
	break;
    }
  if (ch == '.')
    {
      do
	{
	  if (ch != '_')
	    obstack_1grow (&temporary_obstack, ch);
	  ch = input ();
	} while (ISDIGIT (ch) || ch == '_');
      is_float++;
    }
  if (ch == 'd' || ch == 'D' || ch == 'e' || ch == 'E')
    {
      /* Convert exponent indication [eEdD] to 'e'. */
      obstack_1grow (&temporary_obstack, 'e');
      ch = input ();
      if (ch == '+' || ch == '-')
	{
	  obstack_1grow (&temporary_obstack, ch);
	  ch = input ();
	}
      if (ISDIGIT (ch) || ch == '_')
	{
	  do
	    {
	      if (ch != '_')
		obstack_1grow (&temporary_obstack, ch);
	      ch = input ();
	    } while (ISDIGIT (ch) || ch == '_');
	}
      else
	{
	  error ("malformed exponent part of floating-point literal");
	}
      is_float++;
    }
  if (ch != EOF)
    unput (ch);
  obstack_1grow (&temporary_obstack, '\0');
  start = obstack_finish (&temporary_obstack);
  if (is_float)
    {
      REAL_VALUE_TYPE value;
      tree  type = double_type_node;
      errno = 0;
      value = REAL_VALUE_ATOF (start, TYPE_MODE (type));
      obstack_free (&temporary_obstack, start);
      if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
	  && REAL_VALUE_ISINF (value) && pedantic)
	pedwarn ("real number exceeds range of REAL");
      num = build_real (type, value);
    }
  else
    num = convert_integer (start);
  CH_DERIVED_FLAG (num) = 1;
  return num;
}

/* Skip to the end of a compiler directive. */

static void
skip_directive ()
{
  int ch = input ();
  for (;;)
    {
      if (ch == EOF)
	{
	  error ("end-of-file in '<>' directive");
	  break;
	}
      if (ch == '\n')
	break;
      if (ch == '<')
	{
	  ch = input ();
	  if (ch == '>')
	    break;
	}
      ch = input ();
    }
  starting_pass_2 = 0;
}

/* Read a compiler directive.  ("<>{WS}" have already been read. ) */
static void
read_directive ()
{
  struct resword *tp;
  tree id;
  int ch = skip_whitespace();
  if (ISALPHA (ch) || ch == '_')
    id = read_identifier (ch);
  else if (ch == EOF)
    {
      error ("end-of-file in '<>' directive"); 
      to_global_binding_level (); 
      return;
    }
  else
    {
      warning ("unrecognized compiler directive");
      skip_directive ();
      return;
    }
  tp = in_word_set (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
  if (tp == NULL || special_UC != ISUPPER ((unsigned char) tp->name[0]))
    {
      if (pass == 1)
	warning ("unrecognized compiler directive `%s'",
		 IDENTIFIER_POINTER (id));
    }
  else
    switch (tp->token)
      {
      case ALL_STATIC_OFF:
	all_static_flag = 0;
	break;
      case ALL_STATIC_ON:
	all_static_flag = 1;
	break;
      case EMPTY_OFF:
	empty_checking = 0;
	break;
      case EMPTY_ON:
	empty_checking = 1;
	break;
      case IGNORED_DIRECTIVE:
	break;
      case PROCESS_TYPE_TOKEN:
	process_type = equal_number ();
	break;
      case RANGE_OFF:
	range_checking = 0;
	break;
      case RANGE_ON:
	range_checking = 1;
	break;
      case SEND_SIGNAL_DEFAULT_PRIORITY: 
	send_signal_prio = equal_number ();
	break;
      case SEND_BUFFER_DEFAULT_PRIORITY:
	send_buffer_prio = equal_number ();
	break;
      case SIGNAL_CODE:
	signal_code = equal_number ();
	break;
      case USE_SEIZE_FILE:
	handle_use_seizefile_directive (0);
	break;
      case USE_SEIZE_FILE_RESTRICTED:
	handle_use_seizefile_directive (1);
	break;
      default:
	if (pass == 1)
	  warning ("unrecognized compiler directive `%s'", 
		   IDENTIFIER_POINTER (id));
	break;
      }
  skip_directive ();
}


tree
build_chill_string (len, str)
    int   len;
    const char  *str;
{
  tree t;

  push_obstacks (&permanent_obstack, &permanent_obstack);
  t = build_string (len, str);
  TREE_TYPE (t) = build_string_type (char_type_node, 
				     build_int_2 (len, 0));
  CH_DERIVED_FLAG (t) = 1;
  pop_obstacks ();
  return t;
}


static tree
string_or_char (len, str)
     int   len;
     const char *str;
{
  tree result;
  
  push_obstacks (&permanent_obstack, &permanent_obstack);
  if (len == 1)
    {
      result = build_int_2 ((unsigned char)str[0], 0);
      CH_DERIVED_FLAG (result) = 1;
      TREE_TYPE (result) = char_type_node;
    }
  else
    result = build_chill_string (len, str);
  pop_obstacks ();
  return result;
}


static void
maybe_downcase (str)
    char        *str;
{
  if (! ignore_case)
    return;
  while (*str)
    {
      if (ISUPPER ((unsigned char) *str))
	*str = TOLOWER (*str);
      str++;
    }
}


static int
maybe_number (s)
  const char *s;
{
  char	fc;
  
  /* check for decimal number */
  if (*s >= '0' && *s <= '9')
    {
      while (*s)
	{
	  if (*s >= '0' && *s <= '9')
	    s++;
	  else
	    return 0;
	}
      return 1;
    }
  
  fc = *s;
  if (s[1] != '\'')
    return 0;
  s += 2;
  while (*s)
    {
      switch (fc)
	{
	case 'd':
	case 'D':
	  if (*s < '0' || *s > '9')
	    return 0;
	  break;
	case 'h':
	case 'H':
	  if (!ISXDIGIT ((unsigned char) *s))
	    return 0;
	  break;
	case 'b':
	case 'B':
	  if (*s < '0' || *s > '1')
	    return 0;
	  break;
	case 'o':
	case 'O':
	  if (*s < '0' || *s > '7')
	    return 0;
	  break;
	default:
	  return 0;
	}
      s++;
    }
  return 1;
}

static char *
readstring (terminator, len)
     char terminator;
     int *len;
{
  int      c;
  unsigned allocated = 1024;
  char    *tmp = xmalloc (allocated);
  unsigned i = 0;
  
  for (;;)
    {
      c = input ();
      if (c == terminator)
	{
	  if ((c = input ()) != terminator)
	    {
	      unput (c);
	      break;
	    }
	  else
	    c = terminator;
	}
      if (c == '\n' || c == EOF)
	  goto unterminated;
      if (c == '^')
	{
	  c = input();
	  if (c == EOF || c == '\n')
	    goto unterminated;
	  if (c == '^')
	    goto storeit;
	  if (c == '(')
	    {
	      int cc, count = 0;
	      int base = 10;
	      int next_apos = 0;
	      int check_base = 1;
	      c = 0;
	      while (1)
		{
		  cc = input ();
		  if (cc == terminator)
		    {
		      if (!(terminator == '\'' && next_apos))
			{
			  error ("unterminated control sequence");
			  serious_errors++;
			  goto done;
			}
		    }
		  if (cc == EOF || cc == '\n')
		    {
		      c = cc;
		      goto unterminated;
		    }
		  if (next_apos)
		    {
		      next_apos = 0;
		      if (cc != '\'')
			{
			  error ("invalid integer literal in control sequence");
			  serious_errors++;
			  goto done;
			}
		      continue;
		    }
		  if (cc == ' ' || cc == '\t')
		    continue;
		  if (cc == ')')
		    {
		      if ((c < 0 || c > 255) && (pass == 1))
			error ("control sequence overflow");
		      if (! count && pass == 1)
			error ("invalid control sequence");
		      break;
		    }
		  else if (cc == ',')
		    {
		      if ((c < 0 || c > 255) && (pass == 1))
			error ("control sequence overflow");
		      if (! count && pass == 1)
			error ("invalid control sequence");
		      tmp[i++] = c;
		      if (i == allocated)
			{
			  allocated += 1024;
			  tmp = xrealloc (tmp, allocated);
			}
		      c = count = 0;
		      base = 10;
		      check_base = 1;
		      continue;
		    }
		  else if (cc == '_')
		    {
		      if (! count && pass == 1)
			error ("invalid integer literal in control sequence");
		      continue;
		    }
		  if (check_base)
		    {
		      if (cc == 'D' || cc == 'd')
			{
			  base = 10;
			  next_apos = 1;
			}
		      else if (cc == 'H' || cc == 'h')
			{
			  base = 16;
			  next_apos = 1;
			}
		      else if (cc == 'O' || cc == 'o')
			{
			  base = 8;
			  next_apos = 1;
			}
		      else if (cc == 'B' || cc == 'b')
			{
			  base = 2;
			  next_apos = 1;
			}
		      check_base = 0;
		      if (next_apos)
			continue;
		    }
		  if (base == 2)
		    {
		      if (cc < '0' || cc > '1')
			cc = -1;
		      else
			cc -= '0';
		    }
		  else if (base == 8)
		    {
		      if (cc < '0' || cc > '8')
			cc = -1;
		      else
			cc -= '0';
		    }
		  else if (base == 10)
		    {
		      if (! ISDIGIT (cc))
			cc = -1;
		      else
			cc -= '0';
		    }
		  else if (base == 16)
		    {
		      if (!ISXDIGIT (cc))
			cc = -1;
		      else
			{
			  if (cc >= 'a')
			    cc -= ' ';
			  cc -= '0';
			  if (cc > 9)
			    cc -= 7;
			}
		    }
		  else
		    {
		      error ("invalid base in read control sequence");
		      abort ();
		    }
		  if (cc == -1)
		    {
		      /* error in control sequence */
		      if (pass == 1)
			error ("invalid digit in control sequence");
		      cc = 0;
		    }
		  c = (c * base) + cc;
		  count++;
		}
	    }
	  else
	    c ^= 64;
	}
    storeit:
      tmp[i++] = c;
      if (i == allocated)
	{
	  allocated += 1024;
	  tmp = xrealloc (tmp, allocated);
	}
    }
 done:
  tmp [*len = i] = '\0';
  return tmp;

unterminated:
  if (c == '\n')
    unput ('\n');
  *len = 1;
  if (pass == 1)
    error ("unterminated string literal");  
  to_global_binding_level ();
  tmp[0] = '\0';
  return tmp;
}

/* Convert an integer INTCHARS into an INTEGER_CST.
   INTCHARS is on the temporary_obstack, and is popped by this function. */

static tree
convert_integer (intchars)
     char *intchars;
{
#ifdef YYDEBUG
  extern int yydebug;
#endif
  char *p = intchars;
  char         *oldp = p;
  int		base = 10, tmp;
  int           valid_chars = 0;
  int		overflow = 0;
  tree		type;
  HOST_WIDE_INT val_lo = 0, val_hi = 0;
  tree		val;
  
  /* determine the base */
  switch (*p)
    {
    case 'd':
    case 'D':
      p += 2;
      break;
    case 'o':
    case 'O':
      p += 2;
      base = 8;
      break;
    case 'h':
    case 'H':
      p += 2;
      base = 16;
      break;
    case 'b':
    case 'B':
      p += 2;
      base = 2;
      break;
    default:
      if (!ISDIGIT (*p))   /* this test is for equal_number () */
	{
	  obstack_free (&temporary_obstack, intchars);
	  return 0;
	}
      break;
    }
  
  while (*p)
    {
      tmp = *p++;
      if ((tmp == '\'') || (tmp == '_'))
	continue;
      if (tmp < '0')
	goto bad_char;
      if (tmp >= 'a')      /* uppercase the char */
	tmp -= ' ';
      switch (base)        /* validate the characters */
	{
	case 2:
	  if (tmp > '1')
	    goto bad_char;
	  break;
	case 8:
	  if (tmp > '7')
	    goto bad_char;
	  break;
	case 10:
	  if (tmp > '9')
	    goto bad_char;
	  break;
	case 16:
	  if (tmp > 'F')
	    goto bad_char;
	  if (tmp > '9' && tmp < 'A')
	    goto bad_char;
	  break;
	default:
	  abort ();
	}
      tmp -= '0';
      if (tmp > 9)
	tmp -= 7;
      if (mul_double (val_lo, val_hi, base, 0, &val_lo, &val_hi))
	overflow++;
      add_double (val_lo, val_hi, tmp, 0, &val_lo, &val_hi);
      if (val_hi < 0)
	overflow++;
      valid_chars++;
    }
 bad_char:
  obstack_free (&temporary_obstack, intchars);
  if (!valid_chars)
    {
      if (pass == 2)
	error ("invalid number format `%s'", oldp);
      return 0;
    }
  val = build_int_2 (val_lo, val_hi);
  /* We set the type to long long (or long long unsigned) so that
     constant fold of literals is less likely to overflow.  */
  if (int_fits_type_p (val, long_long_integer_type_node))
    type = long_long_integer_type_node;
  else
    {
      if (! int_fits_type_p (val, long_long_unsigned_type_node))
	overflow++;
      type = long_long_unsigned_type_node;
    }
  TREE_TYPE (val) = type;
  CH_DERIVED_FLAG (val) = 1;
  
  if (overflow)
    error ("integer literal too big");

  return val;
}

/* Convert a bitstring literal on the temporary_obstack to
   a bitstring CONSTRUCTOR.  Free the literal from the obstack. */

static tree
convert_bitstring (p)
     char *p;
{
#ifdef YYDEBUG
  extern int yydebug;
#endif
  int bl = 0, valid_chars = 0, bits_per_char = 0, c, k;
  tree initlist = NULL_TREE;
  tree val;
  
  /* Move p to stack so we can re-use temporary_obstack for result. */
  char *oldp = (char*) alloca (strlen (p) + 1);
  if (oldp == 0) fatal ("stack space exhausted");
  strcpy (oldp, p);
  obstack_free (&temporary_obstack, p);
  p = oldp;
  
  switch (*p)
    {
    case 'h':
    case 'H':
      bits_per_char = 4;
      break;
    case 'o':
    case 'O':
      bits_per_char = 3;
      break;
    case 'b':
    case 'B':
      bits_per_char = 1;
      break;
    }
  p += 2;

  while (*p)
    {
      c = *p++;
      if (c == '_' || c == '\'')
	continue;
      if (c >= 'a')
	c -= ' ';
      c -= '0';
      if (c > 9)
	c -= 7;
      valid_chars++;
      
      for (k = BYTES_BIG_ENDIAN ? bits_per_char - 1 : 0;
	   BYTES_BIG_ENDIAN ? k >= 0 : k < bits_per_char;
	   bl++, BYTES_BIG_ENDIAN ? k-- : k++)
	{
	  if (c & (1 << k))
	    initlist = tree_cons (NULL_TREE, build_int_2 (bl, 0), initlist);
        }
    }
#if 0
  /* as long as BOOLS(0) is valid it must tbe possible to
     specify an empty bitstring */
  if (!valid_chars)
    {
      if (pass == 2)
	error ("invalid number format `%s'", oldp);
      return 0;
    }
#endif
  val = build (CONSTRUCTOR,
	       build_bitstring_type (size_int (bl)),
	       NULL_TREE, nreverse (initlist));
  TREE_CONSTANT (val) = 1;
  CH_DERIVED_FLAG (val) = 1;
  return val;
}

/* Check if two filenames name the same file.
   This is done by stat'ing both files and comparing their inodes.

   Note: we have to take care of seize_path_list. Therefore do it the same
   way as in yywrap. FIXME: This probably can be done better. */

static int
same_file (filename1, filename2)
     const char *filename1;
     const char *filename2;
{
  struct stat s[2];
  const char *fn_input[2];
  int         i, stat_status;
  
  if (grant_only_flag)
    /* do nothing in this case */
    return 0;

  /* if filenames are equal -- return 1, cause there is no need
     to search in the include list in this case */
  if (strcmp (filename1, filename2) == 0)
    return 1;
  
  fn_input[0] = filename1;
  fn_input[1] = filename2;

  for (i = 0; i < 2; i++)
    {
      stat_status = stat (fn_input[i], &s[i]);
      if (stat_status < 0 &&
	  strchr (fn_input[i], '/') == 0)
        {
	  STRING_LIST *plp;
	  char        *path;
	  
	  for (plp = seize_path_list; plp != 0; plp = plp->next)
	    {
	      path = (char *)xmalloc (strlen (fn_input[i]) +
				      strlen (plp->str) + 2);
	      sprintf (path, "%s/%s", plp->str, fn_input[i]);
	      stat_status = stat (path, &s[i]);
	      free (path);
	      if (stat_status >= 0)
	        break;
  	    }
        }
      if (stat_status < 0)
        pfatal_with_name (fn_input[i]);
  }
  return s[0].st_ino == s[1].st_ino && s[0].st_dev == s[1].st_dev;
}

/*
 * Note that simply appending included file names to a list in this
 * way completely eliminates the need for nested files, and the
 * associated book-keeping, since the EOF processing in the lexer
 * will simply process the files one at a time, in the order that the
 * USE_SEIZE_FILE directives were scanned.
 */
static void
handle_use_seizefile_directive (restricted)
    int restricted;
{
  tree seen;
  int   len;
  int   c = skip_whitespace ();
  char *use_seizefile_str = readstring (c, &len);

  if (pass > 1)
    return;

  if (c != '\'' && c != '\"')
    {
      error ("USE_SEIZE_FILE directive must be followed by string");
      return;
    }

  use_seizefile_name = get_identifier (use_seizefile_str);
  CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name) = restricted;
  
  if (!grant_only_flag)
    {
      /* If file foo.ch contains a <> use_seize_file "bar.grt" <>,
	 and file bar.ch contains a <> use_seize_file "foo.grt" <>,
	 then if we're compiling foo.ch, we will indirectly be
	 asked to seize foo.grt.  Don't. */
      extern char *grant_file_name;
      if (strcmp (use_seizefile_str, grant_file_name) == 0)
	return;

      /* Check if the file is already on the list. */
      for (seen = files_to_seize; seen != NULL_TREE; seen = TREE_CHAIN (seen))
	if (same_file (IDENTIFIER_POINTER (TREE_VALUE (seen)),
		       use_seizefile_str))
	  return;  /* Previously seen; nothing to do. */
    }

  /* Haven't been asked to seize this file yet, so add
     its name to the list. */
  {
    tree pl = perm_tree_cons (0, use_seizefile_name, NULL_TREE);
    if (files_to_seize == NULL_TREE)
      files_to_seize = pl;
    else
      TREE_CHAIN (last_file_to_seize) = pl;
    if (next_file_to_seize == NULL_TREE)
      next_file_to_seize = pl;
    last_file_to_seize = pl;
  }
}


/*
 * get input, convert to lower case for comparison
 */
static int
getlc (file)
     FILE *file;
{
  register int c;

  c = getc (file);  
  if (ignore_case)
    c = TOLOWER (c);
  return c;
}

#if defined HANDLE_PRAGMA
/* Local versions of these macros, that can be passed as function pointers.  */
static int
pragma_getc ()
{
  return getc (finput);
}

static void
pragma_ungetc (arg)
     int arg;
{
  ungetc (arg, finput);
}
#endif /* HANDLE_PRAGMA */

#ifdef HANDLE_GENERIC_PRAGMAS
/* Handle a generic #pragma directive.
   BUFFER contains the text we read after `#pragma'.  Processes the entire input
   line and return non-zero iff the pragma was successfully processed.  */

static int
handle_generic_pragma (buffer)
     char * buffer;
{
  register int c;

  for (;;)
    {
      char * buff;
      
      handle_pragma_token (buffer, NULL);

      c = getc (finput);

      while (c == ' ' || c == '\t')
	c = getc (finput);
      ungetc (c, finput);
      
      if (c == '\n' || c == EOF)
	return handle_pragma_token (NULL, NULL);

      /* Read the next word of the pragma into the buffer.  */
      buff = buffer;
      do
	{
	  * buff ++ = c;
	  c = getc (finput);
	}
      while (c != EOF && isascii (c) && ! ISSPACE (c) && c != '\n'
	     && buff < buffer + 128); /* XXX shared knowledge about size of buffer.  */
      
      ungetc (c, finput);
      
      * -- buff = 0;
    }
}
#endif /* HANDLE_GENERIC_PRAGMAS */

/* At the beginning of a line, increment the line number and process
   any #-directive on this line.  If the line is a #-directive, read
   the entire line and return a newline.  Otherwise, return the line's
   first non-whitespace character.

   (Each language front end has a check_newline() function that is called
   from lang_init() for that language.  One of the things this function
   must do is read the first line of the input file, and if it is a #line
   directive, extract the filename from it and use it to initialize
   main_input_filename.  Proper generation of debugging information in
   the normal "front end calls cpp then calls cc1XXXX environment" depends
   upon this being done.) */

int
check_newline ()
{
  register int c;

  lineno++;

  /* Read first nonwhite char on the line.  */

  c = getc (finput);

  while (c == ' ' || c == '\t')
    c = getc (finput);

  if (c != '#' || inside_c_comment)
    {
      /* If not #, return it so caller will use it.  */
      return c;
    }

  /* Read first nonwhite char after the `#'.  */

  c = getc (finput);
  while (c == ' ' || c == '\t')
    c = getc (finput);

  /* If a letter follows, then if the word here is `line', skip
     it and ignore it; otherwise, ignore the line, with an error
     if the word isn't `pragma', `ident', `define', or `undef'.  */

  if (ignore_case)
    c = TOLOWER (c);

  if (c >= 'a' && c <= 'z')
    {
      if (c == 'p')
	{
	  if (getlc (finput) == 'r'
	      && getlc (finput) == 'a'
	      && getlc (finput) == 'g'
	      && getlc (finput) == 'm'
	      && getlc (finput) == 'a'
	      && (c = getlc (finput), ISSPACE (c)))
	    {
#ifdef HANDLE_PRAGMA
	      static char buffer [128];
	      char * buff = buffer;

	      /* Read the pragma name into a buffer.  */
	      while (c = getlc (finput), ISSPACE (c))
		continue;
	      
	      do
		{
		  * buff ++ = c;
		  c = getlc (finput);
		}
	      while (c != EOF && ! ISSPACE (c) && c != '\n'
		     && buff < buffer + 128);

	      pragma_ungetc (c);
		
	      * -- buff = 0;
	      
	      if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc, buffer))
		goto skipline;
#endif /* HANDLE_PRAGMA */
	      
#ifdef HANDLE_GENERIC_PRAGMAS
	      if (handle_generic_pragma (buffer))
		goto skipline;
#endif /* HANDLE_GENERIC_PRAGMAS */
	      
	      goto skipline;
	    }
	}

      else if (c == 'd')
	{
	  if (getlc (finput) == 'e'
	      && getlc (finput) == 'f'
	      && getlc (finput) == 'i'
	      && getlc (finput) == 'n'
	      && getlc (finput) == 'e'
	      && (c = getlc (finput), ISSPACE (c)))
	    {
#if 0 /*def DWARF_DEBUGGING_INFO*/
	      if (c != '\n'
		  && (debug_info_level == DINFO_LEVEL_VERBOSE)
		  && (write_symbols == DWARF_DEBUG))
	        dwarfout_define (lineno, get_directive_line (finput));
#endif /* DWARF_DEBUGGING_INFO */
	      goto skipline;
	    }
	}
      else if (c == 'u')
	{
	  if (getlc (finput) == 'n'
	      && getlc (finput) == 'd'
	      && getlc (finput) == 'e'
	      && getlc (finput) == 'f'
	      && (c = getlc (finput), ISSPACE (c)))
	    {
#if 0 /*def DWARF_DEBUGGING_INFO*/
	      if (c != '\n'
		  && (debug_info_level == DINFO_LEVEL_VERBOSE)
		  && (write_symbols == DWARF_DEBUG))
	        dwarfout_undef (lineno, get_directive_line (finput));
#endif /* DWARF_DEBUGGING_INFO */
	      goto skipline;
	    }
	}
      else if (c == 'l')
	{
	  if (getlc (finput) == 'i'
	      && getlc (finput) == 'n'
	      && getlc (finput) == 'e'
	      && ((c = getlc (finput)) == ' ' || c == '\t'))
	    goto linenum;
	}
#if 0
      else if (c == 'i')
	{
	  if (getlc (finput) == 'd'
	      && getlc (finput) == 'e'
	      && getlc (finput) == 'n'
	      && getlc (finput) == 't'
	      && ((c = getlc (finput)) == ' ' || c == '\t'))
	    {
	      /* #ident.  The pedantic warning is now in cccp.c.  */

	      /* Here we have just seen `#ident '.
		 A string constant should follow.  */

	      while (c == ' ' || c == '\t')
		c = getlc (finput);

	      /* If no argument, ignore the line.  */
	      if (c == '\n')
		return c;

	      ungetc (c, finput);
	      token = yylex ();
	      if (token != STRING
		  || TREE_CODE (yylval.ttype) != STRING_CST)
		{
		  error ("invalid #ident");
		  goto skipline;
		}

	      if (!flag_no_ident)
		{
#ifdef ASM_OUTPUT_IDENT
		  extern FILE *asm_out_file;
		  ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype));
#endif
		}

	      /* Skip the rest of this line.  */
	      goto skipline;
	    }
	}
#endif

      error ("undefined or invalid # directive");
      goto skipline;
    }

linenum:
  /* Here we have either `#line' or `# <nonletter>'.
     In either case, it should be a line number; a digit should follow.  */

  while (c == ' ' || c == '\t')
    c = getlc (finput);

  /* If the # is the only nonwhite char on the line,
     just ignore it.  Check the new newline.  */
  if (c == '\n')
    return c;

  /* Something follows the #; read a token.  */

  if (ISDIGIT(c))
    {
      int old_lineno = lineno;
      int used_up = 0;
      int l = 0;
      extern struct obstack permanent_obstack;

      do
	{
	  l = l * 10 + (c - '0'); /* FIXME Not portable */
	  c = getlc(finput);
	} while (ISDIGIT(c));
      /* subtract one, because it is the following line that
	 gets the specified number */

      l--;

      /* Is this the last nonwhite stuff on the line?  */
      c = getlc (finput);
      while (c == ' ' || c == '\t')
	c = getlc (finput);
      if (c == '\n')
	{
	  /* No more: store the line number and check following line.  */
	  lineno = l;
	  return c;
	}

      /* More follows: it must be a string constant (filename).  */

      /* Read the string constant, but don't treat \ as special.  */
      ignore_escape_flag = 1;
      ignore_escape_flag = 0;

      if (c != '\"')
	{
	  error ("invalid #line");
	  goto skipline;
	}

      for (;;)
	{
	  c = getc (finput);
	  if (c == EOF || c == '\n')
	    {
	      error ("invalid #line");
	      return c;
	    }
	  if (c == '\"')
	    {
	      obstack_1grow(&permanent_obstack, 0);
	      input_filename = obstack_finish (&permanent_obstack);
	      break;
	    }
	  obstack_1grow(&permanent_obstack, c);
	}

      lineno = l;

      /* Each change of file name
	 reinitializes whether we are now in a system header.  */
      in_system_header = 0;

      if (main_input_filename == 0)
	main_input_filename = input_filename;

      /* Is this the last nonwhite stuff on the line?  */
      c = getlc (finput);
      while (c == ' ' || c == '\t')
	c = getlc (finput);
      if (c == '\n')
	return c;

      used_up = 0;

      /* `1' after file name means entering new file.
	 `2' after file name means just left a file.  */

      if (ISDIGIT (c))
	{
	  if (c == '1')
	    {
	      /* Pushing to a new file.  */
	      struct file_stack *p
		= (struct file_stack *) xmalloc (sizeof (struct file_stack));
	      input_file_stack->line = old_lineno;
	      p->next = input_file_stack;
	      p->name = input_filename;
	      input_file_stack = p;
	      input_file_stack_tick++;
#ifdef DWARF_DEBUGGING_INFO
	      if (debug_info_level == DINFO_LEVEL_VERBOSE
		  && write_symbols == DWARF_DEBUG)
		dwarfout_start_new_source_file (input_filename);
#endif /* DWARF_DEBUGGING_INFO */

	      used_up = 1;
	    }
	  else if (c == '2')
	    {
	      /* Popping out of a file.  */
	      if (input_file_stack->next)
		{
		  struct file_stack *p = input_file_stack;
		  input_file_stack = p->next;
		  free (p);
		  input_file_stack_tick++;
#ifdef DWARF_DEBUGGING_INFO
		  if (debug_info_level == DINFO_LEVEL_VERBOSE
		      && write_symbols == DWARF_DEBUG)
		    dwarfout_resume_previous_source_file (input_file_stack->line);
#endif /* DWARF_DEBUGGING_INFO */
		}
	      else
		error ("#-lines for entering and leaving files don't match");

	      used_up = 1;
	    }
	}

      /* If we have handled a `1' or a `2',
	 see if there is another number to read.  */
      if (used_up)
	{
	  /* Is this the last nonwhite stuff on the line?  */
	  c = getlc (finput);
	  while (c == ' ' || c == '\t')
	    c = getlc (finput);
	  if (c == '\n')
	    return c;
	  used_up = 0;
	}

      /* `3' after file name means this is a system header file.  */

      if (c == '3')
	in_system_header = 1;
    }
  else
    error ("invalid #-line");

  /* skip the rest of this line.  */
 skipline:
  while (c != '\n' && c != EOF)
    c = getc (finput);
  return c;
}


tree
get_chill_filename ()
{
  return (build_chill_string (
            strlen (input_filename) + 1,  /* +1 to get a zero terminated string */
	      input_filename));
}

tree
get_chill_linenumber ()
{
  return build_int_2 ((HOST_WIDE_INT)lineno, 0);
}


/* Assuming '/' and '*' have been read, skip until we've
   read the terminating '*' and '/'. */

static void
skip_c_comment ()
{
  int c = input();
  int start_line = lineno;

  inside_c_comment++;
  for (;;)
    if (c == EOF)
      {
	error_with_file_and_line (input_filename, start_line,
				  "unterminated comment");
	break;
      }
    else if (c != '*')
      c = input();
    else if ((c = input ()) == '/')
      break;
  inside_c_comment--;
}


/* Assuming "--" has been read, skip until '\n'. */

static void
skip_line_comment ()
{
  for (;;)
    {
      int c = input ();

      if (c == EOF)
	return;
      if (c == '\n')
	break;
    }
  unput ('\n');
}


static int
skip_whitespace ()
{
  for (;;)
    {
      int c = input ();

      if (c == EOF)
	return c;
      if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v')
	continue;
      if (c == '/')
	{
	  c = input ();
	  if (c == '*')
	    {
	      skip_c_comment ();
	      continue;
	    }
	  else
	    {
	      unput (c);
	      return '/';
	    }
	}
      if (c == '-')
	{
	  c = input ();
	  if (c == '-')
	    {
	      skip_line_comment ();
	      continue;
	    }
	  else
	    {
	      unput (c);
	      return '-';
	    }
	}
      return c;
    }
}

/*
 * avoid recursive calls to yylex to parse the ' = digits' or
 * ' = SYNvalue' which are supposed to follow certain compiler
 * directives.  Read the input stream, and return the value parsed.
 */
         /* FIXME: overflow check in here */
         /* FIXME: check for EOF around here */
static tree
equal_number ()
{
  int      c, result;
  char    *tokenbuf;
  char    *cursor;
  tree     retval = integer_zero_node;
  
  c = skip_whitespace();
  if ((char)c != '=')
    {
      if (pass == 2)
	error ("missing `=' in compiler directive");
      return integer_zero_node;
    }
  c = skip_whitespace();

  /* collect token into tokenbuf for later analysis */
  while (TRUE)
    {
      if (ISSPACE (c) || c == '<')
	break;
      obstack_1grow (&temporary_obstack, c);
      c = input ();
    }
  unput (c);             /* put uninteresting char back */
  obstack_1grow (&temporary_obstack, '\0');        /* terminate token */
  tokenbuf = obstack_finish (&temporary_obstack);
  maybe_downcase (tokenbuf);

  if (*tokenbuf == '-')
    /* will fail in the next test */
    result = BITSTRING;
  else if (maybe_number (tokenbuf))
    {
      if (pass == 1)
	return integer_zero_node;
      push_obstacks_nochange ();
      end_temporary_allocation ();
      yylval.ttype = convert_integer (tokenbuf);
      tokenbuf = 0;  /* Was freed by convert_integer. */
      result = yylval.ttype ? NUMBER : 0;
      pop_obstacks ();
    }
  else
    result = 0;
  
  if (result  == NUMBER)
    {
      retval = yylval.ttype;
    }
  else if (result == BITSTRING)
    {
      if (pass == 1)
        error ("invalid value follows `=' in compiler directive");
      goto finish;
    }
  else /* not a number */
    {
      cursor = tokenbuf;
      c = *cursor;
      if (!ISALPHA (c) && c != '_')
	{
	  if (pass == 1)
	    error ("invalid value follows `=' in compiler directive");
	  goto finish;
	}

      for (cursor = &tokenbuf[1]; *cursor != '\0'; cursor++)
	if (ISALPHA ((unsigned char) *cursor) || *cursor == '_' ||
	    ISDIGIT (*cursor))
	  continue;
	else
	  {
	    if (pass == 1)
	      error ("invalid `%c' character in name", *cursor);
	    goto finish;
	  }
      if (pass == 1)
	goto finish;
      else
	{
	  tree value = lookup_name (get_identifier (tokenbuf));
	  if (value == NULL_TREE
	      || TREE_CODE (value) != CONST_DECL
	      || TREE_CODE (DECL_INITIAL (value)) != INTEGER_CST)
	    {
	      if (pass == 2)
		error ("`%s' not integer constant synonym ",
		       tokenbuf);
	      goto finish;
	    }
	  obstack_free (&temporary_obstack, tokenbuf);
	  tokenbuf = 0;
	  push_obstacks_nochange ();
	  end_temporary_allocation ();
	  retval = convert (chill_taskingcode_type_node, DECL_INITIAL (value));
	  pop_obstacks ();
	}
    }

  /* check the value */
  if (TREE_CODE (retval) != INTEGER_CST)
    {
      if (pass == 2)
	error ("invalid value follows `=' in compiler directive");
    }
  else if (TREE_INT_CST_HIGH (retval) != 0 ||
	   TREE_INT_CST_LOW (retval) > TREE_INT_CST_LOW (TYPE_MAX_VALUE (chill_unsigned_type_node)))
    {
      if (pass == 2)
	error ("value out of range in compiler directive");
    }
 finish:
  if (tokenbuf)
    obstack_free (&temporary_obstack, tokenbuf);
  return retval;
}

/*
 * add a possible grant-file path to the list
 */
void
register_seize_path (path)
     const char *path;
{
  int          pathlen = strlen (path);
  char        *new_path = (char *)xmalloc (pathlen + 1);
  STRING_LIST *pl     = (STRING_LIST *)xmalloc (sizeof (STRING_LIST));
    
  /* strip off trailing slash if any */
  if (path[pathlen - 1] == '/')
    pathlen--;

  memcpy (new_path, path, pathlen);
  pl->str  = new_path;
  pl->next = seize_path_list;
  seize_path_list = pl;
}


/* Used by decode_decl to indicate that a <> use_seize_file NAME <>
   directive has been written to the grantfile. */

void
mark_use_seizefile_written (name)
     tree name;
{
  tree node;

  for (node = files_to_seize;  node != NULL_TREE; node = TREE_CHAIN (node))
    if (TREE_VALUE (node) == name)
      {
	TREE_PURPOSE (node) = integer_one_node;
	break;
      }
}


static int
yywrap ()
{
  extern char *chill_real_input_filename;

  close_input_file (input_filename);

  use_seizefile_name = NULL_TREE;

  if (next_file_to_seize && !grant_only_flag)
    {
      FILE *grt_in = NULL;
      char *seizefile_name_chars
	= IDENTIFIER_POINTER (TREE_VALUE (next_file_to_seize));

      /* find a seize file, open it.  If it's not at the path the
       * user gave us, and that path contains no slashes, look on
       * the seize_file paths, specified by the '-I' options.
       */     
      grt_in = fopen (seizefile_name_chars, "r");
      if (grt_in == NULL 
	  && strchr (seizefile_name_chars, '/') == NULL)
	{
	  STRING_LIST *plp;
	  char      *path;

	  for (plp = seize_path_list; plp != NULL; plp = plp->next)
	    {
	      path = (char *)xmalloc (strlen (seizefile_name_chars)
				      + strlen (plp->str) + 2);

	      sprintf (path, "%s/%s", plp->str, seizefile_name_chars);
	      grt_in = fopen (path, "r");
	      if (grt_in == NULL)
		free (path);
	      else
		{
		  seizefile_name_chars = path;
		  break;
		}
	    }
	}

      if (grt_in == NULL)
	pfatal_with_name (seizefile_name_chars);

      finput = grt_in;
      input_filename = seizefile_name_chars;

      lineno = 0;
      current_seizefile_name = TREE_VALUE (next_file_to_seize);

      next_file_to_seize = TREE_CHAIN (next_file_to_seize);

      saw_eof = 0;
      return 0;
    }

  if (pass == 1)
    {
      next_file_to_seize = files_to_seize;
      current_seizefile_name = NULL_TREE;

      if (strcmp (main_input_filename, "stdin"))
	finput = fopen (chill_real_input_filename, "r");
      else
	finput = stdin;
      if (finput == NULL)
	{
	  error ("can't reopen %s", chill_real_input_filename);
	  return 1;
	}
      input_filename = main_input_filename;
      ch_lex_init ();
      lineno = 0;
      /* Read a line directive if there is one.  */
      ungetc (check_newline (), finput);
      starting_pass_2 = 1;
      saw_eof = 0;
      if (module_number == 0)
	warning ("no modules seen");
      return 0;
    }
  return 1;
}
OpenPOWER on IntegriCloud