@@ -8548,16 +8548,13 @@ SC_FUNC void pragma_nodestruct(symbol *sym)
8548
8548
*/
8549
8549
SC_FUNC cell do_static_check (int use_warning )
8550
8550
{
8551
- int already_staging ,didalloc ,optmsg ;
8551
+ int already_staging ,already_recording ,optmsg ;
8552
8552
int ident ,index ;
8553
- int bck_litidx ;
8554
- int exprstartfline ,exprendfline ;
8553
+ int bck_litidx ,recstartpos ;
8555
8554
cell cidx ,val ;
8556
8555
char * str ;
8557
- const unsigned char * exprstart ,* exprend ;
8558
8556
8559
- str = NULL ;
8560
- didalloc = optmsg = FALSE;
8557
+ optmsg = FALSE;
8561
8558
index = 0 ;
8562
8559
cidx = 0 ;
8563
8560
@@ -8567,53 +8564,34 @@ SC_FUNC cell do_static_check(int use_warning)
8567
8564
stgset (TRUE); /* start stage-buffering */
8568
8565
errorset (sEXPRMARK ,0 );
8569
8566
} /* if */
8570
- exprstart = lptr ;
8571
- exprstartfline = fline ;
8567
+ already_recording = pc_isrecording ;
8568
+ if (!already_recording ) {
8569
+ recstart ();
8570
+ recstartpos = 0 ;
8571
+ } else {
8572
+ recstop (); /* trim out the part of the current line that hasn't been read by lex() yet */
8573
+ recstartpos = strlen (pc_recstr );
8574
+ recstart (); /* restart recording */
8575
+ } /* if */
8572
8576
ident = expression (& val ,NULL ,NULL ,FALSE);
8577
+ if (!already_recording || val == 0 )
8578
+ recstop ();
8579
+ str = & pc_recstr [recstartpos ];
8580
+ if (recstartpos != 0 && pc_recstr [recstartpos ]== ' ' )
8581
+ str ++ ; /* skip leading whitespace */
8573
8582
if (ident != iCONSTEXPR )
8574
8583
error (8 ); /* must be constant expression */
8575
- exprend = lptr ;
8576
- exprendfline = fline ;
8577
8584
stgdel (index ,cidx ); /* scratch generated code */
8578
8585
if (!already_staging ) {
8579
8586
errorset (sEXPRRELEASE ,0 );
8580
8587
stgset (FALSE); /* stop stage-buffering */
8581
8588
} /* if */
8582
8589
8583
- /* don't bother allocating space and copying the message
8584
- * if the expression is true */
8585
- if (val == 0 ) {
8586
- if (exprstartfline == exprendfline ) {
8587
- /* skip leading whitespaces */
8588
- while (* exprstart == ' ' )
8589
- exprstart ++ ;
8590
- /* strip the trailing ',' or ')'. as well as the whitespaces */
8591
- exprend -- ;
8592
- if (* exprend == ')' || * exprend == ',' ) {
8593
- while (* (exprend - 1 )== ' ' )
8594
- exprend -- ;
8595
- } /* if */
8596
- /* copy the expression string */
8597
- str = malloc ((exprend - exprstart + 1 )* sizeof (char ));
8598
- if (str == NULL )
8599
- error (103 ); /* insufficient memory */
8600
- memcpy (str ,exprstart ,exprend - exprstart );
8601
- str [exprend - exprstart ]= '\0' ;
8602
- didalloc = TRUE;
8603
- } else {
8604
- /* Currently there's no reliable way to capture multiline expressions,
8605
- * as the lexer would only keep the contents of the line the expression
8606
- * ends at, so try to print "-epression-" instead. Not the prefect
8607
- * solution, but at least it's better than not printing anything. */
8608
- str = "-expression-" ;
8609
- } /* if */
8610
- } /* if */
8611
-
8612
8590
/* read the optional message */
8613
8591
if (matchtoken (',' )) {
8614
- if (didalloc ) {
8615
- free (str );
8616
- didalloc = FALSE ;
8592
+ if (! already_recording ) {
8593
+ free (pc_recstr );
8594
+ pc_recstr = NULL ;
8617
8595
} /* if */
8618
8596
optmsg = TRUE;
8619
8597
str = parsestringparam (val != 0 ,& bck_litidx );
@@ -8623,12 +8601,15 @@ SC_FUNC cell do_static_check(int use_warning)
8623
8601
int errnum = use_warning ? 249 /* check failed */
8624
8602
: 110 ; /* assertion failed */
8625
8603
error (errnum ,(str != NULL ) ? str : "" );
8626
- if (didalloc )
8627
- free (str );
8628
- else if (optmsg && str != NULL )
8604
+ if (optmsg )
8629
8605
litidx = bck_litidx ; /* remove the string from the literal queue */
8606
+ if (already_recording )
8607
+ recstart (); /* restart recording */
8608
+ } /* if */
8609
+ if (!optmsg && !already_recording ) {
8610
+ free (pc_recstr );
8611
+ pc_recstr = NULL ;
8630
8612
} /* if */
8631
-
8632
8613
needtoken (')' );
8633
8614
return !!val ;
8634
8615
}
0 commit comments