95
95
96
96
#include <string.h> /* to declare strxxx() functions */
97
97
#include <ctype.h> /* to define isxxx() macros */
98
- #include <setjmp.h>
99
98
100
99
#include "parse.h" /* always include */
101
100
#include "read.h" /* to define file readLineFromInputFile() */
104
103
#include "debug.h" /* for Assert */
105
104
#include "xtag.h"
106
105
107
- typedef enum eAdaException
108
- {
109
- EXCEPTION_NONE ,
110
- EXCEPTION_EOF
111
- } adaException ;
112
106
113
- static adaException exception ;
107
+ static bool eof_reached ;
114
108
115
109
typedef enum eAdaParseMode
116
110
{
@@ -301,13 +295,6 @@ static const char *AdaKeywords[] =
301
295
"with"
302
296
};
303
297
304
- /* a jump buffer for fail-safe error prevention */
305
- static jmp_buf eofError ;
306
-
307
- /* a simple var to keep track of how many times we hit EOF... If we hit it
308
- * say, about 1000 times, we will print an error, jump to the end of the
309
- * program, and store what tags we have */
310
- static int eofCount ;
311
298
312
299
/* variables for managing the input string, position as well as input line
313
300
* number and position */
@@ -624,17 +611,8 @@ static void readNewLine (void)
624
611
if (line == NULL )
625
612
{
626
613
lineLen = 0 ;
627
- exception = EXCEPTION_EOF ;
628
- eofCount ++ ;
629
-
630
- if (eofCount >= 1000 )
631
- {
632
- longjmp (eofError , exception );
633
- }
634
- else
635
- {
636
- return ;
637
- }
614
+ eof_reached = true;
615
+ return ;
638
616
}
639
617
640
618
lineLen = strlen (line );
@@ -649,7 +627,7 @@ static void readNewLine (void)
649
627
static void movePos (int amount )
650
628
{
651
629
pos += amount ;
652
- if (exception != EXCEPTION_EOF && pos >= lineLen )
630
+ if (! eof_reached && pos >= lineLen )
653
631
{
654
632
readNewLine ();
655
633
}
@@ -709,10 +687,10 @@ static bool adaCmp (const char *match)
709
687
{
710
688
bool status = false;
711
689
712
- /* first check to see if line is empty, if it is, throw an exception */
690
+ /* first check to see if line is empty */
713
691
if (line == NULL )
714
692
{
715
- exception = EXCEPTION_EOF ;
693
+ eof_reached = true ;
716
694
return status ;
717
695
}
718
696
@@ -735,10 +713,10 @@ static bool adaKeywordCmp (adaKeyword keyword)
735
713
{
736
714
bool status = false;
737
715
738
- /* first check to see if line is empty, if it is, throw an exception */
716
+ /* first check to see if line is empty, if it is */
739
717
if (line == NULL )
740
718
{
741
- exception = EXCEPTION_EOF ;
719
+ eof_reached = true ;
742
720
return status ;
743
721
}
744
722
@@ -762,7 +740,7 @@ static void skipUntilWhiteSpace (void)
762
740
* check to be true immediately */
763
741
skipComments ();
764
742
765
- while (exception != EXCEPTION_EOF && !isspace (line [pos ]))
743
+ while (! eof_reached && !isspace (line [pos ]))
766
744
{
767
745
/* don't use movePos () because if we read in a new line with this function
768
746
* we need to stop */
@@ -778,7 +756,7 @@ static void skipUntilWhiteSpace (void)
778
756
if (line == NULL )
779
757
{
780
758
lineLen = 0 ;
781
- exception = EXCEPTION_EOF ;
759
+ eof_reached = true ;
782
760
return ;
783
761
}
784
762
@@ -798,7 +776,7 @@ static void skipWhiteSpace (void)
798
776
* check to fail immediately */
799
777
skipComments ();
800
778
801
- while (exception != EXCEPTION_EOF && isspace (line [pos ]))
779
+ while (! eof_reached && isspace (line [pos ]))
802
780
{
803
781
movePos (1 );
804
782
@@ -809,7 +787,7 @@ static void skipWhiteSpace (void)
809
787
810
788
static void skipComments (void )
811
789
{
812
- while (exception != EXCEPTION_EOF && isAdaComment (line , pos , lineLen ))
790
+ while (! eof_reached && isAdaComment (line , pos , lineLen ))
813
791
{
814
792
readNewLine ();
815
793
}
@@ -819,18 +797,18 @@ static void skipComments (void)
819
797
* Return false if no string literal (nor char literal) is found. */
820
798
static bool skipStringLiteral (void )
821
799
{
822
- if (exception != EXCEPTION_EOF && isAdaStringLiteral (line , pos , lineLen ))
800
+ if (! eof_reached && isAdaStringLiteral (line , pos , lineLen ))
823
801
{
824
802
do {
825
803
movePos (1 );
826
- } while (exception != EXCEPTION_EOF && !isAdaStringLiteral (line , pos , lineLen ));
804
+ } while (! eof_reached && !isAdaStringLiteral (line , pos , lineLen ));
827
805
828
806
/* Go to the next char of " */
829
807
movePos (1 );
830
808
831
809
return true;
832
810
}
833
- else if (exception != EXCEPTION_EOF && isAdaCharLiteral (line , pos , lineLen ))
811
+ else if (! eof_reached && isAdaCharLiteral (line , pos , lineLen ))
834
812
{
835
813
movePos (3 );
836
814
return true;
@@ -855,7 +833,7 @@ static void skipPast (const char *past)
855
833
skipCommentsAndStringLiteral ();
856
834
857
835
/* now look for the keyword */
858
- while (exception != EXCEPTION_EOF && !adaCmp (past ))
836
+ while (! eof_reached && !adaCmp (past ))
859
837
{
860
838
movePos (1 );
861
839
@@ -871,7 +849,7 @@ static void skipPastKeyword (adaKeyword keyword)
871
849
skipComments ();
872
850
873
851
/* now look for the keyword */
874
- while (exception != EXCEPTION_EOF && !adaKeywordCmp (keyword ))
852
+ while (! eof_reached && !adaKeywordCmp (keyword ))
875
853
{
876
854
movePos (1 );
877
855
@@ -888,7 +866,7 @@ static void skipPastWord (void)
888
866
889
867
/* now increment until we hit a non-word character... Specifically,
890
868
* whitespace, '(', ')', ':', and ';' */
891
- while (exception != EXCEPTION_EOF && !isspace (line [pos ]) &&
869
+ while (! eof_reached && !isspace (line [pos ]) &&
892
870
line [pos ] != '(' && line [pos ] != ')' && line [pos ] != ':' &&
893
871
line [pos ] != ';' )
894
872
{
@@ -906,7 +884,7 @@ static void skipPastWord (void)
906
884
if (line == NULL )
907
885
{
908
886
lineLen = 0 ;
909
- exception = EXCEPTION_EOF ;
887
+ eof_reached = true ;
910
888
return ;
911
889
}
912
890
@@ -927,7 +905,7 @@ static void skipPastLambda (skipCompFn cmpfn, void *data)
927
905
skipCommentsAndStringLiteral ();
928
906
929
907
/* now call the predicate */
930
- while (exception != EXCEPTION_EOF && !cmpfn (data ))
908
+ while (! eof_reached && !cmpfn (data ))
931
909
{
932
910
movePos (1 );
933
911
@@ -1019,9 +997,9 @@ static adaTokenInfo *adaParseBlock (adaTokenInfo *parent, adaKind kind)
1019
997
skipWhiteSpace ();
1020
998
1021
999
/* task and protected types are allowed to have discriminants */
1022
- if (exception != EXCEPTION_EOF && line [pos ] == '(' )
1000
+ if (! eof_reached && line [pos ] == '(' )
1023
1001
{
1024
- while (exception != EXCEPTION_EOF && line [pos ] != ')' )
1002
+ while (! eof_reached && line [pos ] != ')' )
1025
1003
{
1026
1004
movePos (1 );
1027
1005
adaParseVariables (token , ADA_KIND_AUTOMATIC_VARIABLE );
@@ -1088,7 +1066,7 @@ static adaTokenInfo *adaParseBlock (adaTokenInfo *parent, adaKind kind)
1088
1066
skipUntilWhiteSpace ();
1089
1067
}
1090
1068
1091
- if (exception == EXCEPTION_EOF )
1069
+ if (eof_reached )
1092
1070
{
1093
1071
freeAdaToken (& parent -> children , token );
1094
1072
token = NULL ;
@@ -1123,9 +1101,9 @@ static adaTokenInfo *adaParseSubprogram (adaTokenInfo *parent, adaKind kind)
1123
1101
skipWhiteSpace ();
1124
1102
1125
1103
/* if we find a '(' grab any parameters */
1126
- if (exception != EXCEPTION_EOF && line [pos ] == '(' && token != NULL )
1104
+ if (! eof_reached && line [pos ] == '(' && token != NULL )
1127
1105
{
1128
- while (exception != EXCEPTION_EOF && line [pos ] != ')' )
1106
+ while (! eof_reached && line [pos ] != ')' )
1129
1107
{
1130
1108
movePos (1 );
1131
1109
tmpToken = adaParseVariables (token , ADA_KIND_AUTOMATIC_VARIABLE );
@@ -1141,9 +1119,9 @@ static adaTokenInfo *adaParseSubprogram (adaTokenInfo *parent, adaKind kind)
1141
1119
* pair */
1142
1120
skipWhiteSpace ();
1143
1121
1144
- if (exception != EXCEPTION_EOF && line [pos ] == '(' )
1122
+ if (! eof_reached && line [pos ] == '(' )
1145
1123
{
1146
- while (exception != EXCEPTION_EOF && line [pos ] != ')' )
1124
+ while (! eof_reached && line [pos ] != ')' )
1147
1125
{
1148
1126
movePos (1 );
1149
1127
adaParseVariables (token , ADA_KIND_AUTOMATIC_VARIABLE );
@@ -1156,7 +1134,7 @@ static adaTokenInfo *adaParseSubprogram (adaTokenInfo *parent, adaKind kind)
1156
1134
/* loop infinitely until we hit a "is", "do" or ";", this will skip over
1157
1135
* the returns keyword, returned-type for functions as well as any one of a
1158
1136
* myriad of keyword qualifiers */
1159
- while (exception != EXCEPTION_EOF && token != NULL )
1137
+ while (! eof_reached && token != NULL )
1160
1138
{
1161
1139
skipWhiteSpace ();
1162
1140
@@ -1235,11 +1213,11 @@ static adaTokenInfo *adaParseType (adaTokenInfo *parent, adaKind kind)
1235
1213
movePos (i );
1236
1214
skipWhiteSpace ();
1237
1215
1238
- if (exception != EXCEPTION_EOF && line [pos ] == '(' )
1216
+ if (! eof_reached && line [pos ] == '(' )
1239
1217
{
1240
1218
/* in this case there is a discriminant to this type, gather the
1241
1219
* variables */
1242
- while (exception != EXCEPTION_EOF && line [pos ] != ')' )
1220
+ while (! eof_reached && line [pos ] != ')' )
1243
1221
{
1244
1222
movePos (1 );
1245
1223
adaParseVariables (token , ADA_KIND_AUTOMATIC_VARIABLE );
@@ -1254,7 +1232,7 @@ static adaTokenInfo *adaParseType (adaTokenInfo *parent, adaKind kind)
1254
1232
{
1255
1233
skipWhiteSpace ();
1256
1234
/* check to see if this may be a record or an enumeration */
1257
- if (exception != EXCEPTION_EOF && line [pos ] == '(' )
1235
+ if (! eof_reached && line [pos ] == '(' )
1258
1236
{
1259
1237
movePos (1 );
1260
1238
adaParseVariables (token , ADA_KIND_ENUM_LITERAL );
@@ -1292,7 +1270,7 @@ static adaTokenInfo *adaParseType (adaTokenInfo *parent, adaKind kind)
1292
1270
{
1293
1271
/* A and B */
1294
1272
/* until we hit "end record" we need to gather type variables */
1295
- while (exception != EXCEPTION_EOF )
1273
+ while (! eof_reached )
1296
1274
{
1297
1275
skipWhiteSpace ();
1298
1276
@@ -1373,7 +1351,7 @@ static adaTokenInfo *adaParseVariables (adaTokenInfo *parent, adaKind kind)
1373
1351
* bufLen match */
1374
1352
buf [bufLen ] = '\0' ;
1375
1353
1376
- while (exception != EXCEPTION_EOF )
1354
+ while (! eof_reached )
1377
1355
{
1378
1356
/* make sure that we don't count anything in a comment as being valid to
1379
1357
* parse */
@@ -1454,7 +1432,7 @@ static adaTokenInfo *adaParseVariables (adaTokenInfo *parent, adaKind kind)
1454
1432
1455
1433
/* if we just incremented beyond the length of the current buffer, we need
1456
1434
* to read in a new line */
1457
- if (exception != EXCEPTION_EOF && bufPos >= bufLen )
1435
+ if (! eof_reached && bufPos >= bufLen )
1458
1436
{
1459
1437
readNewLine ();
1460
1438
@@ -1592,14 +1570,14 @@ static adaTokenInfo *adaParse (adaParseMode mode, adaTokenInfo *parent)
1592
1570
initAdaTokenList (& genericParamsRoot .children );
1593
1571
1594
1572
/* if we hit the end of the file, line will be NULL and our skip and match
1595
- * functions will hit this jump buffer with EXCEPTION_EOF */
1596
- while (exception == EXCEPTION_NONE )
1573
+ * functions will hit this jump buffer with eof_reached */
1574
+ while (! eof_reached )
1597
1575
{
1598
1576
/* find the next place to start */
1599
1577
skipWhiteSpace ();
1600
1578
1601
1579
/* check some universal things to check for first */
1602
- if (exception == EXCEPTION_EOF )
1580
+ if (eof_reached )
1603
1581
{
1604
1582
break ;
1605
1583
}
@@ -1655,7 +1633,7 @@ static adaTokenInfo *adaParse (adaParseMode mode, adaTokenInfo *parent)
1655
1633
skipWhiteSpace ();
1656
1634
1657
1635
/* skip over the "(" until we hit the tag */
1658
- if (exception != EXCEPTION_EOF && line [pos ] == '(' )
1636
+ if (! eof_reached && line [pos ] == '(' )
1659
1637
{
1660
1638
movePos (1 );
1661
1639
skipWhiteSpace ();
@@ -1782,9 +1760,9 @@ static adaTokenInfo *adaParse (adaParseMode mode, adaTokenInfo *parent)
1782
1760
movePos (i );
1783
1761
1784
1762
/* now gather the parameters to this subprogram */
1785
- if (exception != EXCEPTION_EOF && line [pos ] == '(' )
1763
+ if (! eof_reached && line [pos ] == '(' )
1786
1764
{
1787
- while (exception != EXCEPTION_EOF && line [pos ] != ')' )
1765
+ while (! eof_reached && line [pos ] != ')' )
1788
1766
{
1789
1767
movePos (1 );
1790
1768
adaParseVariables (genericParamsRoot .children .tail ,
@@ -2366,11 +2344,10 @@ static void findAdaTags (void)
2366
2344
adaTokenInfo * tmp ;
2367
2345
2368
2346
/* init all global data now */
2369
- exception = EXCEPTION_NONE ;
2347
+ eof_reached = false ;
2370
2348
line = NULL ;
2371
2349
pos = 0 ;
2372
2350
matchLineNum = 0 ;
2373
- eofCount = 0 ;
2374
2351
2375
2352
/* cannot just set matchFilePos to 0 because the fpos_t is not a simple
2376
2353
* integer on all systems. */
@@ -2386,12 +2363,11 @@ static void findAdaTags (void)
2386
2363
2387
2364
/* read in the first line */
2388
2365
readNewLine ();
2389
- if (exception == EXCEPTION_EOF )
2366
+ if (eof_reached )
2390
2367
goto out ;
2391
2368
2392
2369
/* tokenize entire file */
2393
- exception = setjmp (eofError );
2394
- while (exception != EXCEPTION_EOF && adaParse (ADA_ROOT , & root ) != NULL );
2370
+ while (!eof_reached && adaParse (ADA_ROOT , & root ) != NULL );
2395
2371
2396
2372
/* store tags */
2397
2373
tmp = root .children .head ;
0 commit comments