Merge branch 'feature_enum_static' of https://github.com/VVWVV/pawn into VVWVV-feature_enum_static

This commit is contained in:
Zeex 2017-01-29 02:35:29 +06:00
commit 2dd0e8c6af
2 changed files with 32 additions and 15 deletions

View File

@ -89,7 +89,7 @@ static void declglb(char *firstname,int firsttag,int fpublic,int fstatic,
int stock,int fconst); int stock,int fconst);
static int declloc(int fstatic); static int declloc(int fstatic);
static void decl_const(int table); static void decl_const(int table);
static void decl_enum(int table); static void decl_enum(int table,int fstatic);
static cell needsub(int *tag,constvalue **enumroot); static cell needsub(int *tag,constvalue **enumroot);
static void initials(int ident,int tag,cell *size,int dim[],int numdim, static void initials(int ident,int tag,cell *size,int dim[],int numdim,
constvalue *enumroot); constvalue *enumroot);
@ -1601,6 +1601,9 @@ static void parse(void)
declglb(NULL,0,fpublic,fstatic,fstock,fconst); declglb(NULL,0,fpublic,fstatic,fstock,fconst);
break; break;
case tSTATIC: case tSTATIC:
if (matchtoken(tENUM)) {
decl_enum(sGLOBAL,TRUE);
} else {
/* This can be a static function or a static global variable; we know /* This can be a static function or a static global variable; we know
* which of the two as soon as we have parsed up to the point where an * which of the two as soon as we have parsed up to the point where an
* opening paranthesis of a function would be expected. To back out after * opening paranthesis of a function would be expected. To back out after
@ -1611,12 +1614,13 @@ static void parse(void)
assert(!fpublic); assert(!fpublic);
declfuncvar(fpublic,fstatic,fstock,fconst); declfuncvar(fpublic,fstatic,fstock,fconst);
} /* if */ } /* if */
} /* if */
break; break;
case tCONST: case tCONST:
decl_const(sGLOBAL); decl_const(sGLOBAL);
break; break;
case tENUM: case tENUM:
decl_enum(sGLOBAL); decl_enum(sGLOBAL,matchtoken(tSTATIC));
break; break;
case tPUBLIC: case tPUBLIC:
/* This can be a public function or a public variable; see the comment /* This can be a public function or a public variable; see the comment
@ -2769,7 +2773,7 @@ static void decl_const(int vclass)
/* decl_enum - declare enumerated constants /* decl_enum - declare enumerated constants
* *
*/ */
static void decl_enum(int vclass) static void decl_enum(int vclass,int fstatic)
{ {
char enumname[sNAMEMAX+1],constname[sNAMEMAX+1]; char enumname[sNAMEMAX+1],constname[sNAMEMAX+1];
cell val,value,size; cell val,value,size;
@ -2778,6 +2782,11 @@ static void decl_enum(int vclass)
cell increment,multiplier; cell increment,multiplier;
constvalue *enumroot; constvalue *enumroot;
symbol *enumsym; symbol *enumsym;
short filenum;
filenum=fcurrent;
if (fstatic && vclass==sLOCAL)
error(92);
/* get an explicit tag, if any (we need to remember whether an explicit /* get an explicit tag, if any (we need to remember whether an explicit
* tag was passed, even if that explicit tag was "_:", so we cannot call * tag was passed, even if that explicit tag was "_:", so we cannot call
@ -2821,8 +2830,11 @@ static void decl_enum(int vclass)
if (strlen(enumname)>0) { if (strlen(enumname)>0) {
/* already create the root symbol, so the fields can have it as their "parent" */ /* already create the root symbol, so the fields can have it as their "parent" */
enumsym=add_constant(enumname,0,vclass,tag); enumsym=add_constant(enumname,0,vclass,tag);
if (enumsym!=NULL) if (enumsym!=NULL) {
enumsym->usage |= uENUMROOT; enumsym->usage |= uENUMROOT;
if (fstatic)
enumsym->fnumber=filenum;
}
/* start a new list for the element names */ /* start a new list for the element names */
if ((enumroot=(constvalue*)malloc(sizeof(constvalue)))==NULL) if ((enumroot=(constvalue*)malloc(sizeof(constvalue)))==NULL)
error(103); /* insufficient memory (fatal error) */ error(103); /* insufficient memory (fatal error) */
@ -2869,6 +2881,10 @@ static void decl_enum(int vclass)
sym->dim.array.length=size; sym->dim.array.length=size;
sym->dim.array.level=0; sym->dim.array.level=0;
sym->parent=enumsym; sym->parent=enumsym;
if (fstatic)
sym->fnumber=filenum;
/* add the constant to a separate list as well */ /* add the constant to a separate list as well */
if (enumroot!=NULL) { if (enumroot!=NULL) {
sym->usage |= uENUMFIELD; sym->usage |= uENUMFIELD;
@ -5052,7 +5068,7 @@ static void statement(int *lastindent,int allow_decl)
decl_const(sLOCAL); decl_const(sLOCAL);
break; break;
case tENUM: case tENUM:
decl_enum(sLOCAL); decl_enum(sLOCAL,FALSE);
break; break;
default: /* non-empty expression */ default: /* non-empty expression */
sc_allowproccall=optproccall; sc_allowproccall=optproccall;

View File

@ -128,7 +128,8 @@ static char *errmsg[] = {
/*088*/ "public variables and local variables may not have states (symbol \"%s\")\n", /*088*/ "public variables and local variables may not have states (symbol \"%s\")\n",
/*089*/ "state variables may not be initialized (symbol \"%s\")\n", /*089*/ "state variables may not be initialized (symbol \"%s\")\n",
/*090*/ "public functions may not return arrays (symbol \"%s\")\n", /*090*/ "public functions may not return arrays (symbol \"%s\")\n",
/*091*/ "ambiguous constant; tag override is required (symbol \"%s\")\n" /*091*/ "ambiguous constant; tag override is required (symbol \"%s\")\n",
/*092*/ "static enums may not be declared in a compound block\n"
}; };
static char *fatalmsg[] = { static char *fatalmsg[] = {