@@ -122,8 +122,8 @@ static void destructsymbols(symbol *root,int level);
122
122
static constvalue * find_constval_byval (constvalue_root * table ,cell val );
123
123
static symbol * fetchlab (char * name );
124
124
static void statement (int * lastindent ,int allow_decl );
125
- static void compound (int stmt_sameline , int starttok );
126
- static int test (int label ,int parens ,int invert );
125
+ static void compound (int stmt_sameline );
126
+ static int test (int label ,int needparens ,int invert );
127
127
static int doexpr (int comma ,int chkeffect ,int allowarray ,int mark_endexpr ,
128
128
int * tag ,symbol * * symptr ,int chkfuncresult ,cell * val );
129
129
static void doassert (void );
@@ -205,12 +205,6 @@ typedef struct {
205
205
OPCODE_PROC func ;
206
206
} EMIT_OPCODE ;
207
207
208
- enum {
209
- TEST_PLAIN , /* no parentheses */
210
- TEST_THEN , /* '(' <expr> ')' or <expr> 'then' */
211
- TEST_DO , /* '(' <expr> ')' or <expr> 'do' */
212
- TEST_OPT , /* '(' <expr> ')' or <expr> */
213
- };
214
208
static int lastst = 0 ; /* last executed statement type */
215
209
static int endlessloop = 0 ; /* nesting level of endless loop */
216
210
static int rettype = 0 ; /* the type that a "return" expression should have */
@@ -5709,10 +5703,9 @@ static void statement(int *lastindent,int allow_decl)
5709
5703
} /* if */
5710
5704
break ;
5711
5705
case '{' :
5712
- case tBEGIN :
5713
5706
save = fline ;
5714
5707
if (!matchtoken ('}' )) /* {} is the empty statement */
5715
- compound (save == fline , tok );
5708
+ compound (save == fline );
5716
5709
/* lastst (for "last statement") does not change */
5717
5710
break ;
5718
5711
case ';' :
@@ -5810,24 +5803,23 @@ static void statement(int *lastindent,int allow_decl)
5810
5803
} /* switch */
5811
5804
}
5812
5805
5813
- static void compound (int stmt_sameline , int starttok )
5806
+ static void compound (int stmt_sameline )
5814
5807
{
5815
5808
int indent = -1 ;
5816
5809
cell save_decl = declared ;
5817
5810
int count_stmt = 0 ;
5818
5811
int block_start = fline ; /* save line where the compound block started */
5819
- int endtok ;
5820
5812
5821
5813
/* if there is more text on this line, we should adjust the statement indent */
5822
5814
if (stmt_sameline ) {
5823
5815
int i ;
5824
5816
const unsigned char * p = lptr ;
5825
5817
/* go back to the opening brace */
5826
- while (* p != starttok ) {
5818
+ while (* p != '{' ) {
5827
5819
assert (p > pline );
5828
5820
p -- ;
5829
5821
} /* while */
5830
- assert (* p == starttok ); /* it should be found */
5822
+ assert (* p == '{' ); /* it should be found */
5831
5823
/* go forward, skipping white-space */
5832
5824
p ++ ;
5833
5825
while (* p <=' ' && * p != '\0' )
@@ -5841,9 +5833,8 @@ static void compound(int stmt_sameline,int starttok)
5841
5833
stmtindent ++ ;
5842
5834
} /* if */
5843
5835
5844
- endtok = (starttok == '{' ) ? '}' : tEND ;
5845
5836
pc_nestlevel += 1 ; /* increase compound statement level */
5846
- while (matchtoken (endtok )== 0 ){ /* repeat until compound statement is closed */
5837
+ while (matchtoken ('}' )== 0 ) { /* repeat until compound statement is closed */
5847
5838
if (!freading ){
5848
5839
error (30 ,block_start ); /* compound block not closed at end of file */
5849
5840
break ;
@@ -5966,12 +5957,12 @@ SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr)
5966
5957
*
5967
5958
* Global references: sc_intest (altered, but restored upon termination)
5968
5959
*/
5969
- static int test (int label ,int parens ,int invert )
5960
+ static int test (int label ,int needparens ,int invert )
5970
5961
{
5971
5962
int index ,tok ;
5972
5963
cell cidx ;
5973
5964
int ident ,tag ;
5974
- int endtok ;
5965
+ int foundparen ;
5975
5966
short save_intest ;
5976
5967
cell constval ;
5977
5968
symbol * sym ;
@@ -5988,15 +5979,9 @@ static int test(int label,int parens,int invert)
5988
5979
5989
5980
save_intest = sc_intest ;
5990
5981
sc_intest = TRUE;
5991
- endtok = 0 ;
5992
- if (parens != TEST_PLAIN ) {
5993
- if (matchtoken ('(' ))
5994
- endtok = ')' ;
5995
- else if (parens == TEST_THEN )
5996
- endtok = tTHEN ;
5997
- else if (parens == TEST_DO )
5998
- endtok = tDO ;
5999
- } /* if */
5982
+ foundparen = FALSE;
5983
+ if (needparens )
5984
+ foundparen = needtoken ('(' );
6000
5985
do {
6001
5986
stgget (& index ,& cidx ); /* mark position (of last expression) in
6002
5987
* code generator */
@@ -6009,8 +5994,12 @@ static int test(int label,int parens,int invert)
6009
5994
markexpr (sEXPR ,NULL ,0 );
6010
5995
} /* if */
6011
5996
} while (tok ); /* do */
6012
- if (endtok != 0 )
6013
- needtoken (endtok );
5997
+ if (needparens ) {
5998
+ if (foundparen )
5999
+ needtoken (')' );
6000
+ else
6001
+ matchtoken (')' );
6002
+ } /* if */
6014
6003
if (ident == iARRAY || ident == iREFARRAY ) {
6015
6004
char * ptr = (sym != NULL ) ? sym -> name : "-unknown-" ;
6016
6005
error (33 ,ptr ); /* array must be indexed */
@@ -6060,7 +6049,7 @@ static int doif(void)
6060
6049
lastst = 0 ; /* reset the last statement */
6061
6050
ifindent = stmtindent ; /* save the indent of the "if" instruction */
6062
6051
flab1 = getlabel (); /* get label number for false branch */
6063
- test (flab1 ,TEST_THEN ,FALSE); /* get expression, branch to flab1 if false */
6052
+ test (flab1 ,TRUE ,FALSE); /* get expression, branch to flab1 if false */
6064
6053
statement (NULL ,FALSE); /* if true, do a statement */
6065
6054
if (!matchtoken (tELSE )) { /* if...else ? */
6066
6055
setlabel (flab1 ); /* no, simple if..., print false label */
@@ -6115,7 +6104,7 @@ static int dowhile(void)
6115
6104
* so any assignments made inside the loop control expression
6116
6105
* could be cleaned up later */
6117
6106
pc_loopcond = tWHILE ;
6118
- endlessloop = test (wq [wqEXIT ],TEST_DO ,FALSE);/* branch to wq[wqEXIT] if false */
6107
+ endlessloop = test (wq [wqEXIT ],TRUE ,FALSE); /* branch to wq[wqEXIT] if false */
6119
6108
pc_loopcond = 0 ;
6120
6109
pc_nestlevel -- ;
6121
6110
statement (NULL ,FALSE); /* if so, do a statement */
@@ -6157,7 +6146,7 @@ static int dodo(void)
6157
6146
* so any assignments made inside the loop control expression
6158
6147
* could be cleaned up later */
6159
6148
pc_loopcond = tDO ;
6160
- endlessloop = test (wq [wqEXIT ],TEST_OPT ,FALSE);
6149
+ endlessloop = test (wq [wqEXIT ],TRUE ,FALSE);
6161
6150
pc_loopcond = 0 ;
6162
6151
pc_nestlevel -- ;
6163
6152
clearassignments (pc_nestlevel + 1 );
@@ -6178,7 +6167,7 @@ static int dofor(void)
6178
6167
int wq [wqSIZE ],skiplab ;
6179
6168
cell save_decl ;
6180
6169
int save_nestlevel ,save_endlessloop ,save_numloopvars ;
6181
- int index , endtok ;
6170
+ int index ;
6182
6171
int * ptr ;
6183
6172
int loopline = fline ;
6184
6173
symstate * loopvars = NULL ;
@@ -6191,7 +6180,7 @@ static int dofor(void)
6191
6180
6192
6181
addwhile (wq );
6193
6182
skiplab = getlabel ();
6194
- endtok = matchtoken ('(' ) ? ')' : tDO ;
6183
+ needtoken ('(' );
6195
6184
pc_nestlevel ++ ; /* temporarily increase the "compound statement" nesting level,
6196
6185
* so any assignments made inside the loop initialization, control
6197
6186
* expression and increment blocks could be cleaned up later */
@@ -6236,14 +6225,14 @@ static int dofor(void)
6236
6225
endlessloop = 1 ;
6237
6226
} else {
6238
6227
pc_loopcond = tFOR ;
6239
- endlessloop = test (wq [wqEXIT ],TEST_PLAIN ,FALSE);/* expression 2 (jump to wq[wqEXIT] if false) */
6228
+ endlessloop = test (wq [wqEXIT ],FALSE ,FALSE); /* expression 2 (jump to wq[wqEXIT] if false) */
6240
6229
pc_loopcond = 0 ;
6241
6230
needtoken (';' );
6242
6231
} /* if */
6243
6232
stgmark ((char )(sEXPRSTART + 1 )); /* mark start of 3th expression in stage */
6244
- if (!matchtoken (endtok )) {
6233
+ if (!matchtoken (')' )) {
6245
6234
doexpr (TRUE,TRUE,TRUE,TRUE,NULL ,NULL ,FALSE,NULL ); /* expression 3 */
6246
- needtoken (endtok );
6235
+ needtoken (')' );
6247
6236
} /* if */
6248
6237
stgmark (sENDREORDER ); /* mark end of reversed evaluation */
6249
6238
stgout (index );
@@ -6290,7 +6279,7 @@ static int doswitch(void)
6290
6279
{
6291
6280
int lbl_table ,lbl_exit ,lbl_case ;
6292
6281
int swdefault ,casecount ;
6293
- int tok , endtok ;
6282
+ int tok ;
6294
6283
int swtag ,csetag ;
6295
6284
int allterminal ;
6296
6285
int enumsymcount ;
@@ -6304,11 +6293,11 @@ static int doswitch(void)
6304
6293
char labelname [sNAMEMAX + 1 ];
6305
6294
symstate * assignments = NULL ;
6306
6295
6307
- endtok = matchtoken ('(' ) ? ')' : tDO ;
6296
+ needtoken ('(' );
6308
6297
ident = doexpr (TRUE,FALSE,FALSE,FALSE,& swtag ,NULL ,TRUE,NULL ); /* evaluate switch expression */
6309
6298
if (ident == iCONSTEXPR )
6310
6299
error (243 ); /* redundant code: switch control expression is constant */
6311
- needtoken (endtok );
6300
+ needtoken (')' );
6312
6301
/* generate the code for the switch statement, the label is the address
6313
6302
* of the case table (to be generated later).
6314
6303
*/
@@ -6327,12 +6316,7 @@ static int doswitch(void)
6327
6316
enumsym = NULL ;
6328
6317
} /* if */
6329
6318
6330
- if (matchtoken (tBEGIN )) {
6331
- endtok = tEND ;
6332
- } else {
6333
- endtok = '}' ;
6334
- needtoken ('{' );
6335
- } /* if */
6319
+ needtoken ('{' );
6336
6320
lbl_exit = getlabel (); /* get label number for jumping out of switch */
6337
6321
swdefault = FALSE;
6338
6322
allterminal = TRUE; /* assume that all cases end with terminal statements */
@@ -6437,13 +6421,13 @@ static int doswitch(void)
6437
6421
allterminal &= isterminal (lastst );
6438
6422
break ;
6439
6423
default :
6440
- if (tok != endtok ) {
6424
+ if (tok != '}' ) {
6441
6425
error (2 );
6442
6426
indent_nowarn = TRUE; /* disable this check */
6443
- tok = endtok ; /* break out of the loop after an error */
6427
+ tok = '}' ; /* break out of the loop after an error */
6444
6428
} /* if */
6445
6429
} /* switch */
6446
- } while (tok != endtok );
6430
+ } while (tok != '}' );
6447
6431
restoreassignments (pc_nestlevel + 1 ,assignments );
6448
6432
6449
6433
if (enumsym != NULL && swdefault == FALSE && enumsym -> x .tags .unique - enumsymcount <=2 ) {
@@ -6528,7 +6512,7 @@ static void doassert(void)
6528
6512
6529
6513
if ((sc_debug & sCHKBOUNDS )!= 0 ) {
6530
6514
flab1 = getlabel (); /* get label number for "OK" branch */
6531
- test (flab1 ,TEST_PLAIN ,TRUE);/* get expression and branch to flab1 if true */
6515
+ test (flab1 ,FALSE ,TRUE); /* get expression and branch to flab1 if true */
6532
6516
insert_dbgline (fline ); /* make sure we can find the correct line number */
6533
6517
ffabort (xASSERTION );
6534
6518
setlabel (flab1 );
@@ -8324,7 +8308,7 @@ static void dostate(void)
8324
8308
if (matchtoken ('(' )) {
8325
8309
flabel = getlabel (); /* get label number for "false" branch */
8326
8310
pc_docexpr = TRUE; /* attach expression as a documentation string */
8327
- test (flabel ,TEST_PLAIN ,FALSE);/* get expression, branch to flabel if false */
8311
+ test (flabel ,FALSE ,FALSE); /* get expression, branch to flabel if false */
8328
8312
pc_docexpr = FALSE;
8329
8313
needtoken (')' );
8330
8314
} else {
0 commit comments