Use the newly implemented token recording mechanism to record expressions checked in __static_assert
and __static_check
This commit is contained in:
parent
8970ad281e
commit
3d02bfa428
@ -8548,16 +8548,13 @@ SC_FUNC void pragma_nodestruct(symbol *sym)
|
|||||||
*/
|
*/
|
||||||
SC_FUNC cell do_static_check(int use_warning)
|
SC_FUNC cell do_static_check(int use_warning)
|
||||||
{
|
{
|
||||||
int already_staging,didalloc,optmsg;
|
int already_staging,already_recording,optmsg;
|
||||||
int ident,index;
|
int ident,index;
|
||||||
int bck_litidx;
|
int bck_litidx,recstartpos;
|
||||||
int exprstartfline,exprendfline;
|
|
||||||
cell cidx,val;
|
cell cidx,val;
|
||||||
char *str;
|
char *str;
|
||||||
const unsigned char *exprstart,*exprend;
|
|
||||||
|
|
||||||
str=NULL;
|
optmsg=FALSE;
|
||||||
didalloc=optmsg=FALSE;
|
|
||||||
index=0;
|
index=0;
|
||||||
cidx=0;
|
cidx=0;
|
||||||
|
|
||||||
@ -8567,53 +8564,34 @@ SC_FUNC cell do_static_check(int use_warning)
|
|||||||
stgset(TRUE); /* start stage-buffering */
|
stgset(TRUE); /* start stage-buffering */
|
||||||
errorset(sEXPRMARK,0);
|
errorset(sEXPRMARK,0);
|
||||||
} /* if */
|
} /* if */
|
||||||
exprstart=lptr;
|
already_recording=pc_isrecording;
|
||||||
exprstartfline=fline;
|
if (!already_recording) {
|
||||||
|
recstart();
|
||||||
|
recstartpos=0;
|
||||||
|
} else {
|
||||||
|
recstop(); /* trim out the part of the current line that hasn't been read by lex() yet */
|
||||||
|
recstartpos=strlen(pc_recstr);
|
||||||
|
recstart(); /* restart recording */
|
||||||
|
} /* if */
|
||||||
ident=expression(&val,NULL,NULL,FALSE);
|
ident=expression(&val,NULL,NULL,FALSE);
|
||||||
|
if (!already_recording || val==0)
|
||||||
|
recstop();
|
||||||
|
str=&pc_recstr[recstartpos];
|
||||||
|
if (recstartpos!=0 && pc_recstr[recstartpos]==' ')
|
||||||
|
str++; /* skip leading whitespace */
|
||||||
if (ident!=iCONSTEXPR)
|
if (ident!=iCONSTEXPR)
|
||||||
error(8); /* must be constant expression */
|
error(8); /* must be constant expression */
|
||||||
exprend=lptr;
|
|
||||||
exprendfline=fline;
|
|
||||||
stgdel(index,cidx); /* scratch generated code */
|
stgdel(index,cidx); /* scratch generated code */
|
||||||
if (!already_staging) {
|
if (!already_staging) {
|
||||||
errorset(sEXPRRELEASE,0);
|
errorset(sEXPRRELEASE,0);
|
||||||
stgset(FALSE); /* stop stage-buffering */
|
stgset(FALSE); /* stop stage-buffering */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* don't bother allocating space and copying the message
|
|
||||||
* if the expression is true */
|
|
||||||
if (val==0) {
|
|
||||||
if (exprstartfline==exprendfline) {
|
|
||||||
/* skip leading whitespaces */
|
|
||||||
while (*exprstart==' ')
|
|
||||||
exprstart++;
|
|
||||||
/* strip the trailing ',' or ')'. as well as the whitespaces */
|
|
||||||
exprend--;
|
|
||||||
if (*exprend==')' || *exprend==',') {
|
|
||||||
while (*(exprend-1)==' ')
|
|
||||||
exprend--;
|
|
||||||
} /* if */
|
|
||||||
/* copy the expression string */
|
|
||||||
str=malloc((exprend-exprstart+1)*sizeof(char));
|
|
||||||
if (str==NULL)
|
|
||||||
error(103); /* insufficient memory */
|
|
||||||
memcpy(str,exprstart,exprend-exprstart);
|
|
||||||
str[exprend-exprstart]='\0';
|
|
||||||
didalloc=TRUE;
|
|
||||||
} else {
|
|
||||||
/* Currently there's no reliable way to capture multiline expressions,
|
|
||||||
* as the lexer would only keep the contents of the line the expression
|
|
||||||
* ends at, so try to print "-epression-" instead. Not the prefect
|
|
||||||
* solution, but at least it's better than not printing anything. */
|
|
||||||
str="-expression-";
|
|
||||||
} /* if */
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
/* read the optional message */
|
/* read the optional message */
|
||||||
if (matchtoken(',')) {
|
if (matchtoken(',')) {
|
||||||
if (didalloc) {
|
if (!already_recording) {
|
||||||
free(str);
|
free(pc_recstr);
|
||||||
didalloc=FALSE;
|
pc_recstr=NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
optmsg=TRUE;
|
optmsg=TRUE;
|
||||||
str=parsestringparam(val!=0,&bck_litidx);
|
str=parsestringparam(val!=0,&bck_litidx);
|
||||||
@ -8623,12 +8601,15 @@ SC_FUNC cell do_static_check(int use_warning)
|
|||||||
int errnum=use_warning ? 249 /* check failed */
|
int errnum=use_warning ? 249 /* check failed */
|
||||||
: 110; /* assertion failed */
|
: 110; /* assertion failed */
|
||||||
error(errnum,(str!=NULL) ? str : "");
|
error(errnum,(str!=NULL) ? str : "");
|
||||||
if (didalloc)
|
if (optmsg)
|
||||||
free(str);
|
|
||||||
else if (optmsg && str!=NULL)
|
|
||||||
litidx=bck_litidx; /* remove the string from the literal queue */
|
litidx=bck_litidx; /* remove the string from the literal queue */
|
||||||
|
if (already_recording)
|
||||||
|
recstart(); /* restart recording */
|
||||||
|
} /* if */
|
||||||
|
if (!optmsg && !already_recording) {
|
||||||
|
free(pc_recstr);
|
||||||
|
pc_recstr=NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
needtoken(')');
|
needtoken(')');
|
||||||
return !!val;
|
return !!val;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user