mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-21 19:51:27 +00:00
Lemon update 2015-10-29 13:48:15 on branch trunk
- Fix uses of ctype functions (ex: isspace()) on signed characters in test programs and in some obscure extensions. No changes to the core. (user: drh)
This commit is contained in:
parent
daa68a0c88
commit
5286a7fef3
1 changed files with 45 additions and 37 deletions
|
@ -17,6 +17,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define ISSPACE(X) isspace((unsigned char)(X))
|
||||
#define ISDIGIT(X) isdigit((unsigned char)(X))
|
||||
#define ISALNUM(X) isalnum((unsigned char)(X))
|
||||
#define ISALPHA(X) isalpha((unsigned char)(X))
|
||||
#define ISUPPER(X) isupper((unsigned char)(X))
|
||||
#define ISLOWER(X) islower((unsigned char)(X))
|
||||
|
||||
|
||||
#ifndef __WIN32__
|
||||
# if defined(_WIN32) || defined(WIN32)
|
||||
# define __WIN32__
|
||||
|
@ -1494,7 +1502,7 @@ int main(int argc, char **argv)
|
|||
while( lem.symbols[i-1]->type==MULTITERMINAL ){ i--; }
|
||||
assert( strcmp(lem.symbols[i-1]->name,"{default}")==0 );
|
||||
lem.nsymbol = i - 1;
|
||||
for(i=1; isupper(lem.symbols[i]->name[0]); i++);
|
||||
for(i=1; ISUPPER(lem.symbols[i]->name[0]); i++);
|
||||
lem.nterminal = i;
|
||||
|
||||
/* Generate a reprint of the grammar, if requested on the command line */
|
||||
|
@ -2028,7 +2036,7 @@ static void parseonetoken(struct pstate *psp)
|
|||
case WAITING_FOR_DECL_OR_RULE:
|
||||
if( x[0]=='%' ){
|
||||
psp->state = WAITING_FOR_DECL_KEYWORD;
|
||||
}else if( islower(x[0]) ){
|
||||
}else if( ISLOWER(x[0]) ){
|
||||
psp->lhs = Symbol_new(x);
|
||||
psp->nrhs = 0;
|
||||
psp->lhsalias = 0;
|
||||
|
@ -2058,7 +2066,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case PRECEDENCE_MARK_1:
|
||||
if( !isupper(x[0]) ){
|
||||
if( !ISUPPER(x[0]) ){
|
||||
ErrorMsg(psp->filename,psp->tokenlineno,
|
||||
"The precedence symbol must be a terminal.");
|
||||
psp->errorcnt++;
|
||||
|
@ -2098,7 +2106,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case LHS_ALIAS_1:
|
||||
if( isalpha(x[0]) ){
|
||||
if( ISALPHA(x[0]) ){
|
||||
psp->lhsalias = x;
|
||||
psp->state = LHS_ALIAS_2;
|
||||
}else{
|
||||
|
@ -2167,7 +2175,7 @@ to follow the previous rule.");
|
|||
psp->prevrule = rp;
|
||||
}
|
||||
psp->state = WAITING_FOR_DECL_OR_RULE;
|
||||
}else if( isalpha(x[0]) ){
|
||||
}else if( ISALPHA(x[0]) ){
|
||||
if( psp->nrhs>=MAXRHS ){
|
||||
ErrorMsg(psp->filename,psp->tokenlineno,
|
||||
"Too many symbols on RHS of rule beginning at \"%s\".",
|
||||
|
@ -2195,7 +2203,7 @@ to follow the previous rule.");
|
|||
msp->subsym = (struct symbol **) realloc(msp->subsym,
|
||||
sizeof(struct symbol*)*msp->nsubsym);
|
||||
msp->subsym[msp->nsubsym-1] = Symbol_new(&x[1]);
|
||||
if( islower(x[1]) || islower(msp->subsym[0]->name[0]) ){
|
||||
if( ISLOWER(x[1]) || ISLOWER(msp->subsym[0]->name[0]) ){
|
||||
ErrorMsg(psp->filename,psp->tokenlineno,
|
||||
"Cannot form a compound containing a non-terminal");
|
||||
psp->errorcnt++;
|
||||
|
@ -2210,7 +2218,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case RHS_ALIAS_1:
|
||||
if( isalpha(x[0]) ){
|
||||
if( ISALPHA(x[0]) ){
|
||||
psp->alias[psp->nrhs-1] = x;
|
||||
psp->state = RHS_ALIAS_2;
|
||||
}else{
|
||||
|
@ -2232,7 +2240,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case WAITING_FOR_DECL_KEYWORD:
|
||||
if( isalpha(x[0]) ){
|
||||
if( ISALPHA(x[0]) ){
|
||||
psp->declkeyword = x;
|
||||
psp->declargslot = 0;
|
||||
psp->decllinenoslot = 0;
|
||||
|
@ -2312,7 +2320,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case WAITING_FOR_DESTRUCTOR_SYMBOL:
|
||||
if( !isalpha(x[0]) ){
|
||||
if( !ISALPHA(x[0]) ){
|
||||
ErrorMsg(psp->filename,psp->tokenlineno,
|
||||
"Symbol name missing after %%destructor keyword");
|
||||
psp->errorcnt++;
|
||||
|
@ -2326,7 +2334,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case WAITING_FOR_DATATYPE_SYMBOL:
|
||||
if( !isalpha(x[0]) ){
|
||||
if( !ISALPHA(x[0]) ){
|
||||
ErrorMsg(psp->filename,psp->tokenlineno,
|
||||
"Symbol name missing after %%type keyword");
|
||||
psp->errorcnt++;
|
||||
|
@ -2351,7 +2359,7 @@ to follow the previous rule.");
|
|||
case WAITING_FOR_PRECEDENCE_SYMBOL:
|
||||
if( x[0]=='.' ){
|
||||
psp->state = WAITING_FOR_DECL_OR_RULE;
|
||||
}else if( isupper(x[0]) ){
|
||||
}else if( ISUPPER(x[0]) ){
|
||||
struct symbol *sp;
|
||||
sp = Symbol_new(x);
|
||||
if( sp->prec>=0 ){
|
||||
|
@ -2369,7 +2377,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case WAITING_FOR_DECL_ARG:
|
||||
if( x[0]=='{' || x[0]=='\"' || isalnum(x[0]) ){
|
||||
if( x[0]=='{' || x[0]=='\"' || ISALNUM(x[0]) ){
|
||||
const char *zOld, *zNew;
|
||||
char *zBuf, *z;
|
||||
int nOld, n, nLine, nNew, nBack;
|
||||
|
@ -2430,7 +2438,7 @@ to follow the previous rule.");
|
|||
case WAITING_FOR_FALLBACK_ID:
|
||||
if( x[0]=='.' ){
|
||||
psp->state = WAITING_FOR_DECL_OR_RULE;
|
||||
}else if( !isupper(x[0]) ){
|
||||
}else if( !ISUPPER(x[0]) ){
|
||||
ErrorMsg(psp->filename, psp->tokenlineno,
|
||||
"%%fallback argument \"%s\" should be a token", x);
|
||||
psp->errorcnt++;
|
||||
|
@ -2451,7 +2459,7 @@ to follow the previous rule.");
|
|||
case WAITING_FOR_WILDCARD_ID:
|
||||
if( x[0]=='.' ){
|
||||
psp->state = WAITING_FOR_DECL_OR_RULE;
|
||||
}else if( !isupper(x[0]) ){
|
||||
}else if( !ISUPPER(x[0]) ){
|
||||
ErrorMsg(psp->filename, psp->tokenlineno,
|
||||
"%%wildcard argument \"%s\" should be a token", x);
|
||||
psp->errorcnt++;
|
||||
|
@ -2467,7 +2475,7 @@ to follow the previous rule.");
|
|||
}
|
||||
break;
|
||||
case WAITING_FOR_CLASS_ID:
|
||||
if( !islower(x[0]) ){
|
||||
if( !ISLOWER(x[0]) ){
|
||||
ErrorMsg(psp->filename, psp->tokenlineno,
|
||||
"%%token_class must be followed by an identifier: ", x);
|
||||
psp->errorcnt++;
|
||||
|
@ -2486,12 +2494,12 @@ to follow the previous rule.");
|
|||
case WAITING_FOR_CLASS_TOKEN:
|
||||
if( x[0]=='.' ){
|
||||
psp->state = WAITING_FOR_DECL_OR_RULE;
|
||||
}else if( isupper(x[0]) || ((x[0]=='|' || x[0]=='/') && isupper(x[1])) ){
|
||||
}else if( ISUPPER(x[0]) || ((x[0]=='|' || x[0]=='/') && ISUPPER(x[1])) ){
|
||||
struct symbol *msp = psp->tkclass;
|
||||
msp->nsubsym++;
|
||||
msp->subsym = (struct symbol **) realloc(msp->subsym,
|
||||
sizeof(struct symbol*)*msp->nsubsym);
|
||||
if( !isupper(x[0]) ) x++;
|
||||
if( !ISUPPER(x[0]) ) x++;
|
||||
msp->subsym[msp->nsubsym-1] = Symbol_new(x);
|
||||
}else{
|
||||
ErrorMsg(psp->filename, psp->tokenlineno,
|
||||
|
@ -2524,7 +2532,7 @@ static void preprocess_input(char *z){
|
|||
for(i=0; z[i]; i++){
|
||||
if( z[i]=='\n' ) lineno++;
|
||||
if( z[i]!='%' || (i>0 && z[i-1]!='\n') ) continue;
|
||||
if( strncmp(&z[i],"%endif",6)==0 && isspace(z[i+6]) ){
|
||||
if( strncmp(&z[i],"%endif",6)==0 && ISSPACE(z[i+6]) ){
|
||||
if( exclude ){
|
||||
exclude--;
|
||||
if( exclude==0 ){
|
||||
|
@ -2532,13 +2540,13 @@ static void preprocess_input(char *z){
|
|||
}
|
||||
}
|
||||
for(j=i; z[j] && z[j]!='\n'; j++) z[j] = ' ';
|
||||
}else if( (strncmp(&z[i],"%ifdef",6)==0 && isspace(z[i+6]))
|
||||
|| (strncmp(&z[i],"%ifndef",7)==0 && isspace(z[i+7])) ){
|
||||
}else if( (strncmp(&z[i],"%ifdef",6)==0 && ISSPACE(z[i+6]))
|
||||
|| (strncmp(&z[i],"%ifndef",7)==0 && ISSPACE(z[i+7])) ){
|
||||
if( exclude ){
|
||||
exclude++;
|
||||
}else{
|
||||
for(j=i+7; isspace(z[j]); j++){}
|
||||
for(n=0; z[j+n] && !isspace(z[j+n]); n++){}
|
||||
for(j=i+7; ISSPACE(z[j]); j++){}
|
||||
for(n=0; z[j+n] && !ISSPACE(z[j+n]); n++){}
|
||||
exclude = 1;
|
||||
for(k=0; k<nDefine; k++){
|
||||
if( strncmp(azDefine[k],&z[j],n)==0 && lemonStrlen(azDefine[k])==n ){
|
||||
|
@ -2636,7 +2644,7 @@ void Parse(struct lemon *gp)
|
|||
lineno = 1;
|
||||
for(cp=filebuf; (c= *cp)!=0; ){
|
||||
if( c=='\n' ) lineno++; /* Keep track of the line number */
|
||||
if( isspace(c) ){ cp++; continue; } /* Skip all white space */
|
||||
if( ISSPACE(c) ){ cp++; continue; } /* Skip all white space */
|
||||
if( c=='/' && cp[1]=='/' ){ /* Skip C++ style comments */
|
||||
cp+=2;
|
||||
while( (c= *cp)!=0 && c!='\n' ) cp++;
|
||||
|
@ -2706,15 +2714,15 @@ void Parse(struct lemon *gp)
|
|||
}else{
|
||||
nextcp = cp+1;
|
||||
}
|
||||
}else if( isalnum(c) ){ /* Identifiers */
|
||||
while( (c= *cp)!=0 && (isalnum(c) || c=='_') ) cp++;
|
||||
}else if( ISALNUM(c) ){ /* Identifiers */
|
||||
while( (c= *cp)!=0 && (ISALNUM(c) || c=='_') ) cp++;
|
||||
nextcp = cp;
|
||||
}else if( c==':' && cp[1]==':' && cp[2]=='=' ){ /* The operator "::=" */
|
||||
cp += 3;
|
||||
nextcp = cp;
|
||||
}else if( (c=='/' || c=='|') && isalpha(cp[1]) ){
|
||||
}else if( (c=='/' || c=='|') && ISALPHA(cp[1]) ){
|
||||
cp += 2;
|
||||
while( (c = *cp)!=0 && (isalnum(c) || c=='_') ) cp++;
|
||||
while( (c = *cp)!=0 && (ISALNUM(c) || c=='_') ) cp++;
|
||||
nextcp = cp;
|
||||
}else{ /* All other (one character) operators */
|
||||
cp++;
|
||||
|
@ -3169,7 +3177,7 @@ PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno)
|
|||
if( name ){
|
||||
for(i=0; line[i]; i++){
|
||||
if( line[i]=='P' && strncmp(&line[i],"Parse",5)==0
|
||||
&& (i==0 || !isalpha(line[i-1]))
|
||||
&& (i==0 || !ISALPHA(line[i-1]))
|
||||
){
|
||||
if( i>iStart ) fprintf(out,"%.*s",i-iStart,&line[iStart]);
|
||||
fprintf(out,"%s",name);
|
||||
|
@ -3413,9 +3421,9 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){
|
|||
|
||||
/* This const cast is wrong but harmless, if we're careful. */
|
||||
for(cp=(char *)rp->code; *cp; cp++){
|
||||
if( isalpha(*cp) && (cp==rp->code || (!isalnum(cp[-1]) && cp[-1]!='_')) ){
|
||||
if( ISALPHA(*cp) && (cp==rp->code || (!ISALNUM(cp[-1]) && cp[-1]!='_')) ){
|
||||
char saved;
|
||||
for(xp= &cp[1]; isalnum(*xp) || *xp=='_'; xp++);
|
||||
for(xp= &cp[1]; ISALNUM(*xp) || *xp=='_'; xp++);
|
||||
saved = *xp;
|
||||
*xp = 0;
|
||||
if( rp->lhsalias && strcmp(cp,rp->lhsalias)==0 ){
|
||||
|
@ -3579,9 +3587,9 @@ void print_stack_union(
|
|||
cp = sp->datatype;
|
||||
if( cp==0 ) cp = lemp->vartype;
|
||||
j = 0;
|
||||
while( isspace(*cp) ) cp++;
|
||||
while( ISSPACE(*cp) ) cp++;
|
||||
while( *cp ) stddt[j++] = *cp++;
|
||||
while( j>0 && isspace(stddt[j-1]) ) j--;
|
||||
while( j>0 && ISSPACE(stddt[j-1]) ) j--;
|
||||
stddt[j] = 0;
|
||||
if( lemp->tokentype && strcmp(stddt, lemp->tokentype)==0 ){
|
||||
sp->dtnum = 0;
|
||||
|
@ -3792,8 +3800,8 @@ void ReportTable(
|
|||
if( lemp->arg && lemp->arg[0] ){
|
||||
size_t i;
|
||||
i = lemonStrlen(lemp->arg);
|
||||
while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
|
||||
while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
|
||||
while( i>=1 && ISSPACE(lemp->arg[i-1]) ) i--;
|
||||
while( i>=1 && (ISALNUM(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
|
||||
fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++;
|
||||
fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++;
|
||||
fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n",
|
||||
|
@ -4603,7 +4611,7 @@ struct symbol *Symbol_new(const char *x)
|
|||
sp = (struct symbol *)calloc(1, sizeof(struct symbol) );
|
||||
MemoryCheck(sp);
|
||||
sp->name = Strsafe(x);
|
||||
sp->type = isupper(*x) ? TERMINAL : NONTERMINAL;
|
||||
sp->type = ISUPPER(*x) ? TERMINAL : NONTERMINAL;
|
||||
sp->rule = 0;
|
||||
sp->fallback = 0;
|
||||
sp->prec = -1;
|
||||
|
|
Loading…
Reference in a new issue