From 23a2d861401ac03c8aea17316b9c7c51e13d55cc Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 25 Jan 2007 01:53:02 +0000 Subject: [PATCH] added new functag keyword for fast funcenums --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40343 --- sourcepawn/compiler/sc.h | 71 ++++++++++++++++++++------------------- sourcepawn/compiler/sc1.c | 36 ++++++++++++++------ sourcepawn/compiler/sc2.c | 2 +- sourcepawn/compiler/sc3.c | 4 +-- 4 files changed, 64 insertions(+), 49 deletions(-) diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index d89b282f..d314f0f6 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -288,7 +288,7 @@ typedef struct s_stringpair { */ #define tFIRST 256 /* value of first multi-character operator */ #define tMIDDLE 280 /* value of last multi-character operator */ -#define tLAST 332 /* value of last multi-character match-able token */ +#define tLAST 333 /* value of last multi-character match-able token */ /* multi-character operators */ #define taMULT 256 /* *= */ #define taDIV 257 /* /= */ @@ -334,41 +334,42 @@ typedef struct s_stringpair { #define tFOR 296 #define tFORWARD 297 #define tFUNCENUM 298 -#define tGOTO 299 -#define tIF 300 -#define tNATIVE 301 -#define tNEW 302 -#define tDECL 303 -#define tOPERATOR 304 -#define tPUBLIC 305 -#define tRETURN 306 -#define tSIZEOF 307 -#define tSLEEP 308 -#define tSTATE 309 -#define tSTATIC 310 -#define tSTOCK 311 -#define tSTRUCT 312 -#define tSWITCH 313 -#define tTAGOF 314 -#define tTHEN 315 -#define tWHILE 316 +#define tFUNCTAG 299 +#define tGOTO 300 +#define tIF 301 +#define tNATIVE 302 +#define tNEW 303 +#define tDECL 304 +#define tOPERATOR 305 +#define tPUBLIC 306 +#define tRETURN 307 +#define tSIZEOF 308 +#define tSLEEP 309 +#define tSTATE 310 +#define tSTATIC 311 +#define tSTOCK 312 +#define tSTRUCT 313 +#define tSWITCH 314 +#define tTAGOF 315 +#define tTHEN 316 +#define tWHILE 317 /* compiler directives */ -#define tpASSERT 317 /* #assert */ -#define tpDEFINE 318 -#define tpELSE 319 /* #else */ -#define tpELSEIF 320 /* #elseif */ -#define tpEMIT 321 -#define tpENDIF 322 -#define tpENDINPUT 323 -#define tpENDSCRPT 324 -#define tpERROR 325 -#define tpFILE 326 -#define tpIF 327 /* #if */ -#define tINCLUDE 328 -#define tpLINE 329 -#define tpPRAGMA 330 -#define tpTRYINCLUDE 331 -#define tpUNDEF 332 +#define tpASSERT 318 /* #assert */ +#define tpDEFINE 319 +#define tpELSE 320 /* #else */ +#define tpELSEIF 321 /* #elseif */ +#define tpEMIT 322 +#define tpENDIF 323 +#define tpENDINPUT 324 +#define tpENDSCRPT 325 +#define tpERROR 326 +#define tpFILE 327 +#define tpIF 328 /* #if */ +#define tINCLUDE 329 +#define tpLINE 330 +#define tpPRAGMA 331 +#define tpTRYINCLUDE 332 +#define tpUNDEF 333 /* semicolon is a special case, because it can be optional */ #define tTERM 333 /* semicolon or newline */ #define tENDEXPR 334 /* forced end of expression */ diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 784c6138..b80f3baf 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -133,7 +133,7 @@ static void doswitch(void); static void dogoto(void); static void dolabel(void); static void doreturn(void); -static void dofuncenum(void); +static void dofuncenum(int listmode); static void dobreak(void); static void docont(void); static void dosleep(void); @@ -1418,7 +1418,10 @@ static void parse(void) decl_enum(sGLOBAL); break; case tFUNCENUM: - dofuncenum(); + dofuncenum(TRUE); + break; + case tFUNCTAG: + dofuncenum(FALSE); break; case tSTRUCT: declstruct(); @@ -2970,7 +2973,7 @@ static void declstruct(void) /** * dofuncenum - declare function enumerations */ -static void dofuncenum(void) +static void dofuncenum(int listmode) { cell val; char *str,*ptr; @@ -3005,11 +3008,14 @@ static void dofuncenum(void) fenum = funcenums_add(tagname); - needtoken('{'); + if (listmode) + { + needtoken('{'); + } do { functag_t func; - if (matchtoken('}')) + if (listmode && matchtoken('}')) { /* Quick exit */ lexpush(); @@ -3018,13 +3024,13 @@ static void dofuncenum(void) memset(&func, 0, sizeof(func)); func.ret_tag = pc_addtag(NULL); /* Get the return tag */ l = lex(&val, &str); - if (l == tFORWARD) + if (l == tSTOCK) { - func.type = uFORWARD; + func.type = uSTOCK; } else if (l == tPUBLIC) { func.type = uPUBLIC; } else { - error(1, "-forward,public-", str); + error(1, "-stock,public-", str); } needtoken('('); do @@ -3145,8 +3151,15 @@ static void dofuncenum(void) } } functags_add(fenum, &func); + if (!listmode) + { + break; + } } while (matchtoken(',')); - needtoken('}'); + if (listmode) + { + needtoken('}'); + } matchtoken(';'); /* eat an optional semicolon. nom nom nom */ errorset(sRESET, 0); } @@ -4130,7 +4143,7 @@ static int declargs(symbol *sym,int chkshadow) ident=iVARIABLE; numtags=0; fconst=FALSE; - fpublic= (sym->usage & uPUBLIC)!=0; + fpublic= (sym->usage & (uPUBLIC|uSTOCK))!=0; /* the '(' parantheses has already been parsed */ if (!matchtoken(')')){ do { /* there are arguments; process them */ @@ -4188,7 +4201,8 @@ static int declargs(symbol *sym,int chkshadow) * So the offset of each argument is "(argcnt+3) * sizeof(cell)". */ doarg(name,ident,(argcnt+3)*sizeof(cell),tags,numtags,fpublic,fconst,chkshadow,&arg); - if (fpublic && arg.hasdefault) + /* :TODO: fix this so stocks that are func pointers can't have default arguments? */ + if ((sym->usage & uPUBLIC) && arg.hasdefault) error(59,name); /* arguments of a public function may not have a default value */ if ((sym->usage & uPROTOTYPED)==0) { /* redimension the argument list, add the entry */ diff --git a/sourcepawn/compiler/sc2.c b/sourcepawn/compiler/sc2.c index 77365892..536a3e8a 100644 --- a/sourcepawn/compiler/sc2.c +++ b/sourcepawn/compiler/sc2.c @@ -1878,7 +1878,7 @@ char *sc_tokens[] = { "||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--", "...", "..", "::", "assert", "*begin", "break", "case", "cellsof", "chars", "const", "continue", "default", - "defined", "do", "else", "*end", "enum", "exit", "for", "forward", "funcenum", "goto", + "defined", "do", "else", "*end", "enum", "exit", "for", "forward", "funcenum", "functag", "goto", "if", "native", "new", "decl", "operator", "public", "return", "sizeof", "sleep", "state", "static", "stock", "struct", "switch", "tagof", "*then", "while", "#assert", "#define", "#else", "#elseif", "#emit", "#endif", "#endinput", diff --git a/sourcepawn/compiler/sc3.c b/sourcepawn/compiler/sc3.c index f7fde4c9..74a879bc 100644 --- a/sourcepawn/compiler/sc3.c +++ b/sourcepawn/compiler/sc3.c @@ -359,7 +359,7 @@ SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce) { usage = uPUBLIC; } else if (v->name[5] = '!') { - usage = uFORWARD; + usage = uSTOCK; } index = atoi(&v->name[6]); @@ -379,7 +379,7 @@ SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce) } } } - } else if (usage == uFORWARD) { + } else if (usage == uSTOCK) { for (sym=glbtab.next; sym!=NULL; sym=sym->next) { if (sym->ident==iFUNCTN && (sym->vclass == sGLOBAL)) {