From 354022888fd403c5eacc6052b3cc1f778dbab067 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 22 Jun 2014 13:21:46 -0700 Subject: [PATCH 1/2] Add support for fully inline functions in methodmaps. --- sourcepawn/compiler/sc.h | 1 + sourcepawn/compiler/sc1.c | 100 +++-- sourcepawn/compiler/sc2.c | 15 +- sourcepawn/compiler/sc5.scp | 357 +++++++++--------- .../tests/fail-method-name-too-long.sp | 7 + .../tests/fail-method-name-too-long.txt | 1 + .../compiler/tests/ok-inline-methods.sp | 13 + 7 files changed, 285 insertions(+), 209 deletions(-) create mode 100644 sourcepawn/compiler/tests/fail-method-name-too-long.sp create mode 100644 sourcepawn/compiler/tests/fail-method-name-too-long.txt create mode 100644 sourcepawn/compiler/tests/ok-inline-methods.sp diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 48859abc..8502b633 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -235,6 +235,7 @@ typedef struct s_symbol { #define sGLOBAL 0 /* global variable/constant class (no states) */ #define sLOCAL 1 /* local variable/constant */ #define sSTATIC 2 /* global life, local scope */ +#define sPROXY 3 /* only find proxies */ #define sSTATEVAR 3 /* criterion to find variables (sSTATEVAR implies a global variable) */ diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 9a941739..415e8fbc 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -117,7 +117,7 @@ static cell init(int ident,int *tag,int *errorfound); static int getstates(const char *funcname); static void attachstatelist(symbol *sym, int state_id); static symbol *funcstub(int fnative, const funcstub_setup_t *setup); -static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stock); +static int newfunc(const funcstub_setup_t *setup,int fpublic,int fstatic,int stock,symbol **symp); static int declargs(symbol *sym, int chkshadow, const int *thistag); static void doarg(char *name,int ident,int offset,int tags[],int numtags, int fpublic,int fconst,int chkshadow,arginfo *arg); @@ -1562,13 +1562,20 @@ static void parse(void) case tLABEL: case tSYMBOL: case tOPERATOR: + { + funcstub_setup_t setup; + memset(&setup, 0, sizeof(setup)); + setup.return_tag = -1; + setup.this_tag = -1; + lexpush(); - if (!newfunc(NULL,-1,FALSE,FALSE,FALSE)) { + if (!newfunc(&setup,FALSE,FALSE,FALSE,NULL)) { error(10); /* illegal function or declaration */ lexclr(TRUE); /* drop the rest of the line */ litidx=0; /* drop the literal queue too */ } /* if */ break; + } case tNATIVE: funcstub(TRUE, NULL); /* create a dummy function */ break; @@ -1784,19 +1791,30 @@ static void declfuncvar(int fpublic,int fstatic,int fstock,int fconst) return; } /* if */ if (tok==tOPERATOR) { + funcstub_setup_t setup; + memset(&setup, 0, sizeof(setup)); + setup.return_tag = tag; + setup.this_tag = -1; lexpush(); /* push "operator" keyword back (for later analysis) */ - if (!newfunc(NULL,tag,fpublic,fstatic,fstock)) { + if (!newfunc(&setup,fpublic,fstatic,fstock,NULL)) { error(10); /* illegal function or declaration */ lexclr(TRUE); /* drop the rest of the line */ litidx=0; /* drop the literal queue too */ } /* if */ } else { + funcstub_setup_t setup; + memset(&setup, 0, sizeof(setup)); + setup.return_tag = tag; + setup.this_tag = -1; + setup.name = name; + /* so tok is tSYMBOL */ assert(strlen(str)<=sNAMEMAX); strcpy(name,str); + /* only variables can be "const" or both "public" and "stock" */ - invalidfunc= fconst || (fpublic && fstock); - if (invalidfunc || !newfunc(name,tag,fpublic,fstatic,fstock)) { + invalidfunc = fconst || (fpublic && fstock); + if (invalidfunc || !newfunc(&setup,fpublic,fstatic,fstock,NULL)) { /* if not a function, try a global variable */ if (pstruct) { declstructvar(name,fpublic,pstruct); @@ -3337,8 +3355,6 @@ int parse_decl(declinfo_t *decl, const token_t *first, int flags) void define_constructor(methodmap_t *map, methodmap_method_t *method) { symbol *sym = findglb(map->name, sGLOBAL); - if (sym && sym->ident == iPROXY && sym->parent == method->target) - return; if (sym) { const char *type = ""; @@ -3383,20 +3399,31 @@ static int match_method_bind() } if (!matchtoken(')')) { - for (int i = 0; i < 2; i++) - lexpush(); + lexpush(); return FALSE; } if (!matchtoken('=')) { - for (int i = 0; i < 3; i++) - lexpush(); + lexpush(); + lexpush(); return FALSE; } return TRUE; } +// If a name is too long, error and truncate. +void check_name_length(char *original) +{ + if (strlen(original) > sNAMEMAX) { + char buffer[METHOD_NAMEMAX + 1]; + strcpy(buffer, original); + buffer[sNAMEMAX] = '\0'; + error(123, original, buffer); + original[sNAMEMAX] = '\0'; + } +} + methodmap_method_t *parse_method(methodmap_t *map) { int is_ctor = 0; @@ -3496,11 +3523,12 @@ methodmap_method_t *parse_method(methodmap_t *map) // Make sure the final name has "~" in it. strcpy(ident.name, "~"); strcat(ident.name, map->name); + check_name_length(ident.name); } else if (is_ctor) { if (strcmp(ident.name, map->name) != 0) error(114, "constructor", spectype, map->name); } - + symbol *target = NULL; if (is_bind) { // Find an existing symbol. @@ -3519,7 +3547,7 @@ methodmap_method_t *parse_method(methodmap_t *map) setup.return_tag = decl.tag; if (is_ctor) - setup.this_tag = 0; + setup.this_tag = -1; else setup.this_tag = map->tag; @@ -3528,10 +3556,20 @@ methodmap_method_t *parse_method(methodmap_t *map) strcpy(fullname, map->name); strcat(fullname, "."); strcat(fullname, ident.name); + check_name_length(fullname); + setup.name = fullname; - if (is_native) + if (is_native) { target = funcstub(TRUE, &setup); + } else { + if (!newfunc(&setup, FALSE, FALSE, TRUE, &target)) + return NULL; + if (!target || (target->usage & uFORWARD)) { + error(10); + return NULL; + } + } } if (!target) @@ -4572,7 +4610,7 @@ static symbol *funcstub(int fnative, const funcstub_setup_t *setup) int tok,tag,fpublic; char *str; cell val,size; - char symbolname[METHOD_NAMEMAX+1]; + char symbolname[sNAMEMAX+1]; int idxtag[sDIMEN_MAX]; int dim[sDIMEN_MAX]; int numdim; @@ -4729,7 +4767,7 @@ static symbol *funcstub(int fnative, const funcstub_setup_t *setup) * glb_declared (altered) * sc_alignnext (altered) */ -static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stock) +static int newfunc(const funcstub_setup_t *setup,int fpublic,int fstatic,int stock,symbol **symp) { symbol *sym; int argcnt,tok,tag,funcline; @@ -4749,12 +4787,18 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc assert(loctab.next==NULL); /* local symbol table should be empty */ filenum=fcurrent; /* save file number at the start of the declaration */ - if (firstname!=NULL) { - assert(strlen(firstname)<=sNAMEMAX); - strcpy(symbolname,firstname); /* save symbol name */ - tag=firsttag; + if (symp) + *symp = NULL; + + if (setup->name) { + assert(strlen(setup->name) <= METHOD_NAMEMAX); + strcpy(symbolname, setup->name); /* save symbol name */ + tag = setup->return_tag; } else { - tag= (firsttag>=0) ? firsttag : pc_addtag(NULL); + if (setup->return_tag != -1) + tag = setup->return_tag; + else + tag = pc_addtag(NULL); tok=lex(&val,&str); assert(!fpublic); if (tok==tNATIVE || (tok==tPUBLIC && stock)) @@ -4813,7 +4857,7 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc error(235,symbolname); #endif /* declare all arguments */ - argcnt=declargs(sym, TRUE, NULL); + argcnt=declargs(sym, TRUE, &setup->this_tag); opererror=!operatoradjust(opertok,sym,symbolname,tag); if (strcmp(symbolname,uMAINFUNC)==0 || strcmp(symbolname,uENTRYFUNC)==0) { if (argcnt>0) @@ -4882,6 +4926,10 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc if (matchtoken('{')) { lexpush(); } else { + // We require '{' for new methods. + if (setup->this_tag != -1) + needtoken('{'); + /* Insert a separator so that comments following the statement will not * be attached to this function; they should be attached to the next * function. This is not a problem for functions having a compound block, @@ -4932,6 +4980,8 @@ static int newfunc(char *firstname,int firsttag,int fpublic,int fstatic,int stoc code_idx=cidx; glb_declared=glbdecl; } /* if */ + if (symp) + *symp = sym; return TRUE; } @@ -5014,7 +5064,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) fconst=FALSE; fpublic = (sym->usage & (uPUBLIC|uSTOCK))!=0; - if (thistag) { + if (thistag && *thistag != -1) { // Allocate space for a new argument, then terminate. sym->dim.arglist = (arginfo *)realloc(sym->dim.arglist, (argcnt + 2) * sizeof(arginfo)); memset(&sym->dim.arglist[argcnt + 1], 0, sizeof(arginfo)); @@ -5026,6 +5076,10 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) argptr->tags = malloc(sizeof(int)); argptr->tags[0] = *thistag; argptr->numtags = 1; + + addvariable2(argptr->name, (argcnt+3)*sizeof(cell), argptr->ident, sLOCAL, argptr->tags[0], + argptr->dim, argptr->numdim, argptr->idxtag, 0); + argcnt++; } diff --git a/sourcepawn/compiler/sc2.c b/sourcepawn/compiler/sc2.c index f40589d2..32f56226 100644 --- a/sourcepawn/compiler/sc2.c +++ b/sourcepawn/compiler/sc2.c @@ -2229,7 +2229,6 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym) SC_FUNC void lexpush(void) { assert(sTokenBuffer->depth < MAX_TOKEN_DEPTH); - assert(sTokenBuffer->depth < 1); sTokenBuffer->depth++; if (sTokenBuffer->cursor == 0) sTokenBuffer->cursor = MAX_TOKEN_DEPTH - 1; @@ -2675,13 +2674,9 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_ continue; } - if (delete_functions || (sym->target->usage & uNATIVE) != 0) { - RemoveFromHashTable(sp_Globals, sym); - iter->next = sym->next; - free_symbol(sym); - } else { - iter = sym; - } + RemoveFromHashTable(sp_Globals, sym); + iter->next = sym->next; + free_symbol(sym); } } @@ -3104,7 +3099,9 @@ SC_FUNC int expecttoken(int id, token_t *tok) { int rval = needtoken(id); if (rval) { - tok->id = tokeninfo(&tok->val, &tok->str); + tok->val = current_token()->value; + tok->id = current_token()->id; + tok->str = current_token()->str; return rval; } return FALSE; diff --git a/sourcepawn/compiler/sc5.scp b/sourcepawn/compiler/sc5.scp index 9a6de437..e43909b1 100644 --- a/sourcepawn/compiler/sc5.scp +++ b/sourcepawn/compiler/sc5.scp @@ -31,14 +31,14 @@ SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned ch #define SCPACK_TABLE errstr_table /*-*SCPACK start of pair table, do not change or remove this line */ unsigned char errstr_table [][2] = { - {101,32}, {116,32}, {111,110}, {115,32}, {105,110}, {97,114}, {100,32}, {116,105}, {37,115}, {101,114}, {101,110}, {97,108}, {110,111}, {135,130}, {34,136}, {142,34}, - {114,101}, {117,110}, {111,114}, {97,110}, {121,32}, {115,116}, {100,101}, {115,105}, {97,116}, {140,129}, {32,143}, {109,98}, {109,138}, {41,10}, {101,134}, {116,104}, - {141,32}, {98,108}, {117,115}, {145,99}, {102,163}, {114,97}, {111,108}, {146,32}, {115,121}, {118,139}, {97,32}, {168,155}, {171,166}, {103,32}, {101,120}, {137,32}, - {103,117}, {176,156}, {133,165}, {133,177}, {105,131}, {102,132}, {105,134}, {115,151}, {97,161}, {99,104}, {164,160}, {169,182}, {101,100}, {111,102}, {162,129}, {115,10}, - {132,187}, {109,190}, {104,97}, {101,131}, {172,154}, {109,97}, {99,130}, {118,133}, {189,32}, {105,184}, {199,201}, {116,97}, {109,101}, {116,111}, {98,128}, {112,144}, - {99,147}, {178,148}, {44,32}, {150,181}, {133,97}, {179,129}, {208,153}, {130,32}, {99,116}, {118,128}, {101,10}, {149,152}, {102,105}, {117,108}, {97,115}, {154,10}, - {109,152}, {196,157}, {110,32}, {40,225}, {100,105}, {99,111}, {202,128}, {198,149}, {34,32}, {139,32}, {119,105}, {99,108}, {151,122}, {108,128}, {136,10}, {147,32}, - {132,173}, {194,217}, {98,101}, {111,112}, {116,121}, {37,131}, {164,141}, {102,146}, {132,32}, {140,32}, {203,173}, {224,185}, {193,206}, {58,223}, {100,111} + {101,32}, {116,32}, {111,110}, {115,32}, {105,110}, {100,32}, {97,114}, {116,105}, {37,115}, {101,114}, {101,110}, {97,108}, {110,111}, {135,130}, {34,136}, {142,34}, + {114,101}, {117,110}, {111,114}, {97,110}, {121,32}, {115,105}, {97,116}, {115,116}, {100,101}, {140,129}, {32,143}, {109,98}, {101,133}, {109,138}, {41,10}, {116,104}, + {141,32}, {145,99}, {98,108}, {117,115}, {102,161}, {114,97}, {111,108}, {146,32}, {115,121}, {118,139}, {97,32}, {168,155}, {171,166}, {101,120}, {103,32}, {137,32}, + {103,117}, {105,131}, {115,149}, {176,157}, {134,165}, {134,179}, {105,133}, {102,132}, {97,162}, {99,104}, {164,160}, {169,182}, {101,100}, {111,102}, {163,129}, {115,10}, + {132,187}, {109,190}, {104,97}, {116,111}, {101,131}, {172,154}, {109,97}, {98,128}, {99,130}, {118,134}, {112,144}, {44,32}, {189,32}, {105,184}, {201,205}, {116,97}, + {109,101}, {99,147}, {180,148}, {152,183}, {134,97}, {117,108}, {99,116}, {181,129}, {209,153}, {130,32}, {102,105}, {118,128}, {154,10}, {101,10}, {151,150}, {97,115}, + {128,143}, {109,150}, {197,158}, {110,32}, {40,226}, {100,105}, {99,111}, {200,151}, {34,32}, {139,32}, {119,105}, {99,108}, {149,122}, {116,121}, {108,128}, {136,10}, + {147,32}, {132,174}, {194,219}, {98,101}, {111,112}, {237,112}, {37,131}, {164,141}, {102,146}, {111,32}, {132,32}, {140,32}, {207,174}, {202,178}, {225,185} }; /*-*SCPACK end of pair table, do not change or remove this line */ @@ -166,128 +166,131 @@ static char *errmsg[] = { /*120*/ "methodmap and class signatures must use new-style declarations\n", /*121*/ "this syntax is not yet supported\n", /*122*/ "expected type expression\n", +/*123*/ "fully-qualified name \"%s\" is too long, would be truncated to \"%s\"\n", #else - "\256pe\330\236\315k\212:\232\322bu\201fo\221\206\217\012", - "\202l\224\252s\204g\355\333e\234\201(\247\256\317\267\202) \320 f\246low ea\271 \042c\336e\042\012", - "\226\353\324\240\310\252loc\351\346\301appe\205 \370\252\345mpo\221\206\241ock\012", - "\366\232 \264\231imple\234t\274\012", - "\272\305\224\231\361\263t\277", - "\374a\267gn\236\315 \357\262y\012", - "\363\211\230\247\326\316\220\323\274\012", - "\374\252\347\223\201\256\317\267\202; \336sum\236z\211o\012", - "\300\321\354\200(nega\207ve\322z\211o \247ou\201\310bo\221ds\235", - "\300\272\247\226\353\324\215\012", - "\300out\227d\200\366\277", - "\300\272c\213l\322\231\252\273add\220s\277", - "\371\212tr\224po\204\201(\371pu\241ic \366s\235", - "\300\333e\234t; \231\370s\352t\271\012", - "\042\226fa\335t\350c\336\200\374\237\200l\336\201c\336\200\370s\352t\271 \333e\234t\012", - "m\335\207p\355\226fa\335t\203\370\042s\352t\271\042\012", - "\221\323\236\304\012", - "\204i\207\213iza\240d\230\252\256ce\274\203\226\353\205\236\354\332", - "\231\252la\362l\375", - "\300\254 nam\200\217\012", - "\254 \213\220ad\224\323\274\375", - "\374l\251u\200(n\202-\347\223t\235", - "\321a\267gn\234\201\374\227mp\355a\267gn\234t\012", - "\042b\220ak\350\247\042\306t\204ue\350\264ou\201\310\306t\256t\012", - "\272head\360\344ff\211\203from pro\315\364p\332", - "\371\373\360\042#if...\042\012", - "\300\271\324\330\257\347\223t\012", - "\300subscrip\201(\231\357\321\247\315o m\223\224subscripts)\375", - "\300\256\317\267\202\322\336sum\236z\211o\012", - "\345mpo\221\206\333e\234\201\231\353os\236a\201\237\200\212\206\310\334\355(\225\205t\236a\201l\204\200%d\235", - "\221k\214w\342\344\220c\207v\332", - "\321\204\226x ou\201\310bo\221d\203(\346\217\235", - "\321\374\204\226x\236(\346\217\235", - "\325\376\303\231\361\252\226fa\335\201\251u\200(\325%d\235", - "\325\364p\200mis\373 (\325%d\235", - "empt\224\333e\234t\012", - "\300\225r\360(po\267\241\224n\202-t\211m\204\230\236\225r\204g\235", - "\256t\245 \271\324\330\211\203\327l\204\332", - "\347\223\201\254 \302\203\371\354\332", - "duplic\230\200\042c\336e\350la\362l (\251u\200%d\235", - "\300ellip\227s\322\321\354\200\264\231k\214wn\012", - "\300\345\233\204a\240\310\353\336\203speci\334\211\277", - "\271\324\330\257\347\223\201\256ce\274\203r\223g\200f\247pack\236\225r\204g\012", - "po\227\215\351p\324\314t\211\203\301\317c\274\200\213l nam\236p\324\314t\211\277", - "\315o m\223\224\272\263t\277", - "\221k\214w\342\321\354\200(\346\217\235", - "\321\354\303\376 \231\373\322\247\226\225\204a\240\321\264\315o sm\213l\012", - "\321(\203\376 \231\373\012", - "\300l\204\200\306t\204ua\215\012", - "\300r\223g\332", - "\300subscript\322\242\200\042[ ]\350\363\211\230\222\203\327\305j\247\344\234\227\202\277", - "m\335\207-\344\234\227\202\351\262y\203\374f\335l\224\204i\207\213iz\274\012", - "\256ce\274\360\305ximum nu\233\257\310\344\234\227\202\277", - "\221\373\236\353os\360b\245c\200(\042}\042\235", - "\225\205\201\310\272bod\224\352\237ou\201\272head\211\012", - "\262ys\322loc\351\312\303\223\206\272\263t\203\326\316pu\241ic (\346\217\235", - "\221\265ish\236\256\317\267\327\362\367\200\345mpil\257\344\220c\207v\332", - "duplic\230\200\263t; sam\200\325\264p\336s\236t\352c\332", - "\272\325\305\224\231\361\252\226fa\335\201\251u\200(\346\217\235", - "m\335\207p\355\042#else\350\344\220c\207v\303\362twe\212 \042#if ... #\212\344f\042\012", - "\042#elseif\350\344\220c\207\331f\246low\203\357\042#else\350\344\220c\207v\332", - "nu\233\257\310\363\211\223d\203\376\303\231\334\201\237\200\363\211\230\222\012", - "\272\220s\335\201\372\310\363\211\230\222\232 \374\217\012", - "\326\271\223g\200\317\323\236\363\211\230\222\277", - "\272\325\305\224\202l\224\361\252s\204g\355\372(\325%d\235", - "\272\325\305\224\231\316\252\220f\211\212c\200\325\247\357\321(\325\217\235", - "\346\326\316bo\237 \252\220f\211\212c\200\223\206\357\321(\346\217\235", - "\300\245\215\351nu\233\257\317ci\227\327\370#p\245g\305\012", - "\245\215\351nu\233\257\367\305\201\213\220ad\224\323\274\012", + "\255pe\326\234\303k\212:\232\313bu\201fo\221\205\217\012", + "\202l\224\252s\204g\356\336e\235\201(\247\255\375\202) \321 f\246low ea\271 \042c\337e\042\012", + "\230\353\324\240\314\252loc\351\316\200\301appe\206 \372\252\346mpo\221\205\242ock\012", + "\367\232 \261\231imple\235t\274\012", + "\272\306\224\231\362\265t\277", + "\301\307a\262gn\234\303 \360\264y\012", + "\364\211\226\247\330\307\220\323\274\012", + "\301\307\252\347\223\201\255\375\202; \337sum\234z\211o\012", + "\300\322\354\200(nega\207ve\313z\211\371\247ou\201\314bo\221ds\236", + "\300\272\247\230\353\324\215\012", + "\300out\225d\200\367\277", + "\300\272c\213l\313\231\252\273add\220s\277", + "\373\212tr\224po\204\201(\373pu\242ic \367s\236", + "\300\336e\235t; \231\372s\352t\271\012", + "\042\230fa\325t\350c\337\200\301\307\237\200l\337\201c\337\200\372s\352t\271 \336e\235t\012", + "m\325\207p\356\230fa\325t\203\372\042s\352t\271\042\012", + "\221\323\234\305\012", + "\204i\207\213iza\240d\226\252\255ce\274\203\230\353\206\234\354\335", + "\231\252la\363l:\334", + "\300\254 nam\340\012", + "\254 \213\220ad\224\323\274:\334", + "\301\307l\251u\200(n\202-\347\223t\236", + "\322a\262gn\235\201\301\307\225mp\356a\262gn\235t\012", + "\042b\220ak\350\247\042\310t\204ue\350\261ou\201\314\310t\255t\012", + "\272head\361\345ff\211\203from pro\303\365\335", + "\373\376\361\042#if...\042\012", + "\300\271\324\326\257\347\223t\012", + "\300subscrip\201(\231\360\322\247\303\371m\223\224subscripts):\334", + "\300\255\375\202\313\337sum\234z\211o\012", + "\346mpo\221\205\336e\235\201\231\353os\234a\201\237\200\212\205\314\332\356(\227\206t\234a\201l\204\200%d\236", + "\221k\214w\343\345\220c\207v\335", + "\322\204\230x ou\201\314bo\221d\203(\316\340\236", + "\322\301\307\204\230x\234(\316\340\236", + "\327do\304\231\362\252\230fa\325\201\251u\200(\327%d\236", + "\327\365\200mis\376 (\327%d\236", + "empt\224\336e\235t\012", + "\300\227r\361(po\262\242\224n\202-t\211m\204\226\234\227r\204g\236", + "\255t\245 \271\324\326\211\203\331l\204\335", + "\347\223\201\254 \302\203\373\354\335", + "duplic\226\200\042c\337e\350la\363l (\251u\200%d\236", + "\300ellip\225s\313\322\354\200\261\231k\214wn\012", + "\300\346\233\204a\240\314\353\337\203speci\332\211\277", + "\271\324\326\257\347\223\201\255ce\274\203r\223g\200f\247pack\234\227r\204g\012", + "po\225\215\351p\324\320t\211\203\301\312c\274\200\213l nam\234p\324\320t\211\277", + "\303\371m\223\224\272\265t\277", + "\221k\214w\343\322\354\200(\316\340\236", + "\322\354\304d\371\231\376\313\247\230\227\204a\240\322\261\303\371sm\213l\012", + "\322(\203d\371\231\376\012", + "\300l\204\200\310t\204ua\215\012", + "\300r\223g\335", + "\300subscript\313\243\200\042[ ]\350\364\211\226\222\203\331\306j\247\345\235\225\202\277", + "m\325\207-\345\235\225\202\351\264y\203\301\307f\325l\224\204i\207\213iz\274\012", + "\255ce\274\361\306ximum nu\233\257\314\345\235\225\202\277", + "\221\376\234\353os\361b\245c\200(\042}\042\236", + "\227\206\201\314\272bod\224\352\237ou\201\272head\211\012", + "\264ys\313loc\351\316\304\223\205\272\265t\203\330\307pu\242ic (\316\340\236", + "\221\267ish\234\255\375\331\363\370\200\346mpil\257\345\220c\207v\335", + "duplic\226\200\265t; sam\200\327\261p\337s\234t\352c\335", + "\272\327\306\224\231\362\252\230fa\325\201\251u\200(\316\340\236", + "m\325\207p\356\042#else\350\345\220c\207v\304\363twe\212 \042#if ... #\212\345f\042\012", + "\042#elseif\350\345\220c\207\333f\246low\203\360\042#else\350\345\220c\207v\335", + "nu\233\257\314\364\211\223d\203do\304\231\332\201\237\200\364\211\226\222\012", + "\272\220s\325\201\374\314\364\211\226\222\232 \301\307\217\012", + "\330\271\223g\200\312\323\234\364\211\226\222\277", + "\272\327\306\224\202l\224\362\252s\204g\356\374(\327%d\236", + "\272\327\306\224\231\307\252\220f\211\212c\200\327\247\360\322(\327\217\236", + "\316\200\330\307bo\237 \252\220f\211\212c\200\223\205\360\322(\316\340\236", + "\300\245\215\351nu\233\257\312ci\225\331\372#p\245g\306\012", + "\245\215\351nu\233\257\370\306\201\213\220ad\224\323\274\012", "\245\215\351nu\233\257supp\222\201wa\203\231\212\270\274\012", - "\242\211-\323\236\363\211\230\247\374\226\353\205\236\362\367\200\242\200(\366\232\235", - "\042\354e\275\350\363\211\230\247\264\300\327\042\366\350\254\277", - "\272\325\374\357\321(\325\217\235", - "#\323\200p\230t\211\342\301\225\205\201\352\237 \357\213p\302\362\207c \271\324\330\211\012", - "\204pu\201l\204\200\315o l\202\255(aft\257subs\207tu\215s\235", - "\250n\313x \211r\247\370\237\200\256\317\267\202\322\247\300\272c\213l\012", - "m\213\367m\236UTF-8 \212\345d\204g\322\247c\222rupt\236\334le: \356", - "\272\242\303bo\237 \042\220turn\350\223\206\042\220tur\342<\251ue>\042\012", - "\204\306\227\225\212\201\220tur\342\364p\303(\321& n\202-\262y\235", - "\221k\214w\342\254\322\247\231\252\347\223\201\254 \343", - "\326\313k\200\252\372a\203\252\226fa\335\201\251u\200f\247\357\204\226x\236\321p\324\314t\257\343", - "\242\211-\323\236\363\211\230\222\203\223\206na\207\331\366\203\305\224\231\361\333e\277", - "\252\272\247\346\305\224\202l\224\362l\202\255\315 \252s\204g\355au\315\340\327\343", - "\333\200\306fli\330: \202\200\310\237\200\333\303\264\213\220ad\224a\267gn\236\315 a\214\237\257imple\234\313\240\343", - "\371\333\303\205\200\323\236f\247\304\012", - "\221k\214w\342au\315\340\202\337", - "\221k\214w\342\333\200\217 f\247au\315\340\202\337", - "pu\241ic \312\303\223\206loc\351\312\303\305\224\231\361\333\303\343", - "\333\200\312\303\305\224\231\316\204i\207\213iz\236\343", - "pu\241ic \366\203\305\224\231\220tur\342\262y\203\343", - "a\233i\260ou\203\347\223t; \372ov\211rid\200\264\220qui\220\206\343", - "nu\233\257\310\263t\203\376\303\231\373 \323i\215\012", - "\256pe\330\236\372nam\200id\212\207\334\211\012", - "\272\212um\211a\240\220qui\220\203\221iqu\200\313g\012", - "\326\361\220qui\220\206p\324\314t\211\203aft\257\363\215\351p\324\314t\211\277", - "\345\335\206\231\265\206\314\233\211\232 \370\225ruc\201\217\012", - "\304 \376\303\231\361\252\373\360\364p\332", - "\364p\200\217 sho\335\206\316\217 \370new-\225y\355\226\353\324\215\277", - "\365sho\335\206\231\361\357\256plici\201\220tur\342\364p\332", - "\272pro\315\364p\303\376 \231\373\012", - "specif\224ei\237\257\213l \344\234\227\202\203\247\202l\224\237\200l\336\201\344\234\227\202\012", - "\326\265\206\365\356", - "\365wa\203\213\220ad\224\323\236\327\237\264\356", - "\326\265\206\223\224\314\237od\203f\247\356", - "\326\265\206\314\237o\206\210.\356", - "\326c\213l \314\237od\203\327\357\262y\012", - "\326c\213l \314\237od\203\327\252\366\012", - "\314\237o\206\301\361\252\334rs\201\325\345mpa\207\241\200\352\237 \237\200\365\364p\200(\210\235", - "\365nam\200\301\225\205\201\352\237 \357upp\211c\336\200lett\211\012", - "\365\302\203\213\220ad\224\362\212 \323\236(\317vio\242l\224se\212 a\203\210\235", - "\256pe\330\236id\212\207\334\257- d\266you \367ge\201\252\364pe?\012", - "\347ru\330\247\272\301\220tur\342\372\356", - "\326\323\200\347ru\330\247\367\232; \213\220ad\224\256i\225\203a\203\252\356", - "miss\360\364pe\322\247\365\301\361\237\200sam\200nam\200a\203\365\217\012", - "\326\242\200\226lete\322\365\365\302\203\371\226\225ru\330\222\012", - "\371\314\237od\305p \247\353\336\203wa\203fo\221\206f\247\356", - "\371\226\225ru\330\247wa\203fo\221\206f\247\365\356", - "\226\225ru\330\222\203\374na\207\331\366\277", - "\226\225ru\330\222\203\326\361\256t\245 \263t\277", - "\314\237od\305p \223\206\353\336\203\227gn\230u\220\203\301\242\200new-\225y\355\226\353\324\215\277", - "\237\264\250n\313x \264\231ye\201supp\222t\274\012" + "\243\211-\323\234\364\211\226\247\301\307\230\353\206\234\363\370\200\243\200(\367\232\236", + "\042\354e\275\350\364\211\226\247\261\300\331\042\367\350\254\277", + "\272\327\301\307\360\322(\327\217\236", + "#\323\200p\226t\211\343\301\227\206\201\352\237 \360\213p\302\363\207c \271\324\326\211\012", + "\204pu\201l\204\200\303\371l\202\256(aft\257subs\207tu\215s\236", + "\250n\317x \211r\247\372\237\200\255\375\202\313\247\300\272c\213l\012", + "m\213\370m\234UTF-8 \212\346d\204g\313\247c\222rupt\234\332le: \357", + "\272\243\304bo\237 \042\220turn\350\223\205\042\220tur\343<\251ue>\042\012", + "\204\310\225\227\212\201\220tur\343\365\304(\322& n\202-\264y\236", + "\221k\214w\343\254\313\247\231\252\347\223\201\254 \344", + "\330\317k\200\252\374a\203\252\230fa\325\201\251u\200f\247\360\204\230x\234\322p\324\320t\257\344", + "\243\211-\323\234\364\211\226\222\203\223\205na\207\333\367\203\306\224\231\362\336e\277", + "\252\272\247\316\200\306\224\202l\224\363l\202\256\303 \252s\204g\356au\303\341\331\344", + "\336\200\310fli\326: \202\200\314\237\200\336\304\261\213\220ad\224a\262gn\234\303 a\214\237\257imple\235\317\240\344", + "\373\336\304\206\200\323\234f\247\305\012", + "\221k\214w\343au\303\341\202\334", + "\221k\214w\343\336\340 f\247au\303\341\202\334", + "pu\242ic \316\304\223\205loc\351\316\304\306\224\231\362\336\304\344", + "\336\200\316\304\306\224\231\307\204i\207\213iz\234\344", + "pu\242ic \367\203\306\224\231\220tur\343\264y\203\344", + "a\233i\260ou\203\347\223t; \374ov\211rid\200\261\220qui\220\205\344", + "nu\233\257\314\265t\203do\304\231\376 \323i\215\012", + "\255pe\326\234\374nam\200id\212\207\332\211\012", + "\272\212um\211a\240\220qui\220\203\221iqu\200\317g\012", + "\330\362\220qui\220\205p\324\320t\211\203aft\257\364\215\351p\324\320t\211\277", + "\346\325\205\231\267\205\320\233\211\232 \372\227ruc\201\217\012", + "\305 do\304\231\362\252\376\361\365\335", + "\365\340 sho\325\205\307\217 \372new-\227y\356\230\353\324\215\277", + "\366sho\325\205\231\362\360\255plici\201\220tur\343\365\335", + "\272pro\303\365\304d\371\231\376\012", + "specif\224ei\237\257\213l \345\235\225\202\203\247\202l\224\237\200l\337\201\345\235\225\202\012", + "\330\267\205\366\357", + "\366wa\203\213\220ad\224\323\234\331\237\261\357", + "\330\267\205\223\224\320\237od\203f\247\357", + "\330\267\205\320\237o\205\210.\357", + "\330c\213l \320\237od\203\331\360\264y\012", + "\330c\213l \320\237od\203\331\252\367\012", + "\320\237o\205\301\362\252\332rs\201\327\346mpa\207\242\200\352\237 \237\200\366\365\200(\210\236", + "\366nam\200\301\227\206\201\352\237 \360upp\211c\337\200lett\211\012", + "\366\302\203\213\220ad\224\363\212 \323\234(\312vio\243l\224se\212 a\203\210\236", + "\255pe\326\234id\212\207\332\257- d\266you \370ge\201\252\365e?\012", + "\347ru\326\247\272\301\220tur\343\374\357", + "\330\323\200\347ru\326\247\370\232; \213\220ad\224\255i\227\203a\203\252\357", + "miss\361\365e\313\247\366\301\362\237\200sam\200nam\200a\203\366\217\012", + "\330\243\200\230lete\313\366\366\302\203\373\230\227ru\326\222\012", + "\373\320\237od\306p \247\353\337\203wa\203fo\221\205f\247\357", + "\373\230\227ru\326\247wa\203fo\221\205f\247\366\357", + "\230\227ru\326\222\203\301\307na\207\333\367\277", + "\230\227ru\326\222\203\330\362\255t\245 \265t\277", + "\320\237od\306p \223\205\353\337\203\225gn\226u\220\203\301\243\200new-\227y\356\230\353\324\215\277", + "\237\261\250n\317x \261\231ye\201supp\222t\274\012", + "\255pe\326\234\365\200\255\375\202\012", + "f\325ly-qu\213i\332\234nam\340 \261\303\371l\202g\313wo\325\205\307tr\241\226\234\303\334" #endif }; @@ -312,18 +315,18 @@ static char *fatalmsg[] = { /*170*/ "assertion failed: %s\n", /*171*/ "user error: %s\n", #else - "\326\220a\206from \334le\375", - "\326writ\200\315 \334le\375", - "t\270\200ov\211flow\375", - "\204suf\334ci\212\201\314m\222y\012", - "\300\336se\233l\257\204\225ruc\215\337", - "num\211ic ov\211flow\322\256ce\274\360capaci\364\012", - "\345mpil\236scrip\201\256ce\274\203\237\200\305ximum \314m\222\224\354\200(%l\206bytes\235", - "\315o m\223\224\211r\247\314ssag\303\327\202\200l\204\332", - "\345\226pag\200\305pp\360\334\355\231fo\221d\012", - "\300p\230h\375", - "\336s\211\240fail\274: \356", - "\242\257\211r\222: \356" + "\330\220a\205from \332le:\334", + "\330writ\200\303 \332le:\334", + "t\270\200ov\211flow:\334", + "\204suf\332ci\212\201\320m\222y\012", + "\300\337se\233l\257\204\227ruc\215\334", + "num\211ic ov\211flow\313\255ce\274\361capaci\355\012", + "\346mpil\234scrip\201\255ce\274\203\237\200\306ximum \320m\222\224\354\200(%l\205bytes\236", + "\303\371m\223\224\211r\247\320ssag\304\331\202\200l\204\335", + "\346\230pag\200\306pp\361\332\356\231fo\221d\012", + "\300p\226h:\334", + "\337s\211\240fail\274: \357", + "\243\257\211r\222: \357" #endif }; @@ -367,43 +370,43 @@ static char *warnmsg[] = { /*235*/ "public function lacks forward declaration (symbol \"%s\")\n", /*236*/ "unknown parameter in substitution (incorrect #define pattern)\n" #else - "\304 \264tr\243\230\236\315 %\206\271\324\330\211\277", - "\220\323i\240\310\347\223t/\305cro \343", - "nu\233\257\310\263t\203\376\303\231\373 \323i\215\012", - "\254 \264nev\257\242\274\375", - "\254 \264a\267gn\236\252\251u\200\237a\201\264nev\257\242\274\375", - "\220d\221d\223\201\345\226: \347\223\201\256\317\267\327\264z\211o\012", - "\220d\221d\223\201te\225: \347\223\201\256\317\267\327\264n\202-z\211o\012", - "\221k\214w\342#p\245g\305\012", - "\272\352\237 \372\220s\335\201\242\236\362\367\200\323i\215\322\367c\360\220p\205s\332", - "\366\232 sho\335\206\220tur\342\252\251u\332", - "po\267\241\200\242\200\310\254 \362\367\200\204i\207\213iza\215\375", - "po\267\241\224\221\204t\212\226\206a\267gn\234t\012", - "po\267\241\224\221\204t\212\226\206bit\352s\200\363\211a\215\012", - "\372mis\373\012", - "po\267\241\224\252\042\347\350\321\325wa\203\204t\212\226d\375", - "\256\317\267\327\302\203\371effe\330\012", - "ne\225\236\345m\234t\012", - "loos\200\204d\212\313\215\012", - "\246\206\225y\355pro\315\364p\303\242\236\352\237 \363\215\351semic\246umn\277", - "loc\351\346\217 s\302\376w\203\252\346a\201\252\317c\274\360level\012", - "\256\317\267\327\352\237 \372ov\211rid\200\301appe\205 \362twe\212 p\205\212\237ese\277", - "la\362l nam\200\217 s\302\376w\203\372na\314\012", - "nu\233\257\310\344git\203\256ce\274\203\245\215\351nu\233\257\317ci\227\202\012", - "\220d\221d\223\201\042\354e\275\042: \325\354\200\264\213way\2031 \343", - "\204\226t\211m\204\230\200\321\354\200\370\042\354e\275\350\256\317\267\327\343", - "\221\220a\271\270\200\345\226\012", - "\252\346\264a\267gn\236\315 itself \343", - "m\222\200\204i\207\213iz\211\203\237\357\212um \334eld\277", - "l\212g\237 \310\204i\207\213iz\257\256ce\274\203\354\200\310\237\200\212um \334eld\012", - "\204\226x \372mis\373 \343", - "\371imple\234\313\240f\247\333\200\217 \370\366\232\322\371f\213l-back\012", - "\333\200speci\334ca\240\327\367w\205\206\226\353\324\240\264ig\214\220d\012", - "outpu\201\334\355\264writt\212\322bu\201\352\237 \345mpac\201\212\345d\360\344s\270\274\012", - "\333\200\346\217 s\302\376w\203\252glob\351\312\332", - "\304 \264m\205k\236a\203\226\317c\230\274: \356", - "pu\241ic \272lack\203\367w\205\206\226\353\324\240\343", - "\221k\214w\342p\324\314t\257\370subs\207tu\240(\204c\222\220c\201#\323\200p\230t\211n\235" + "\305 \261tr\241\226\234\303 %\205\271\324\326\211\277", + "\220\323i\240\314\347\223t/\306cr\371\344", + "nu\233\257\314\265t\203do\304\231\376 \323i\215\012", + "\254 \261nev\257\243\274:\334", + "\254 \261a\262gn\234\252\251u\200\237a\201\261nev\257\243\274:\334", + "\220d\221d\223\201\346\230: \347\223\201\255\375\331\261z\211o\012", + "\220d\221d\223\201te\227: \347\223\201\255\375\331\261n\202-z\211o\012", + "\221k\214w\343#p\245g\306\012", + "\272\352\237 \374\220s\325\201\243\234\363\370\200\323i\215\313\370c\361\220p\206s\335", + "\367\232 sho\325\205\220tur\343\252\251u\335", + "po\262\242\200\243\200\314\254 \363\370\200\204i\207\213iza\215:\334", + "po\262\242\224\221\204t\212\230\205a\262gn\235t\012", + "po\262\242\224\221\204t\212\230\205bit\352s\200\364\211a\215\012", + "\374mis\376\012", + "po\262\242\224\252\042\347\350\322\327wa\203\204t\212\230d:\334", + "\255\375\331\302\203\373effe\326\012", + "ne\227\234\346m\235t\012", + "loos\200\204d\212\317\215\012", + "\246\205\227y\356pro\303\365\304\243\234\352\237 \364\215\351semic\246umn\277", + "loc\351\316\340 s\302dow\203\252\316\200a\201\252\312c\274\361level\012", + "\255\375\331\352\237 \374ov\211rid\200\301appe\206 \363twe\212 p\206\212\237ese\277", + "la\363l nam\340 s\302dow\203\374na\320\012", + "nu\233\257\314\345git\203\255ce\274\203\245\215\351nu\233\257\312ci\225\202\012", + "\220d\221d\223\201\042\354e\275\042: \327\354\200\261\213way\2031 \344", + "\204\230t\211m\204\226\200\322\354\200\372\042\354e\275\350\255\375\331\344", + "\221\220a\271\270\200\346\230\012", + "\252\316\200\261a\262gn\234\303 itself \344", + "m\222\200\204i\207\213iz\211\203\237\360\212um \332eld\277", + "l\212g\237 \314\204i\207\213iz\257\255ce\274\203\354\200\314\237\200\212um \332eld\012", + "\204\230x \374mis\376 \344", + "\373imple\235\317\240f\247\336\340 \372\367\232\313\373f\213l-back\012", + "\336\200speci\332ca\240\331\370w\206\205\230\353\324\240\261ig\214\220d\012", + "outpu\201\332\356\261writt\212\313bu\201\352\237 \346mpac\201\212\346d\361\345s\270\274\012", + "\336\200\316\340 s\302dow\203\252glob\351\316\335", + "\305 \261m\206k\234a\203\230\312c\226\274: \357", + "pu\242ic \272lack\203\370w\206\205\230\353\324\240\344", + "\221k\214w\343p\324\320t\257\372subs\207tu\240(\204c\222\220c\201#\323\200p\226t\211n\236" #endif }; diff --git a/sourcepawn/compiler/tests/fail-method-name-too-long.sp b/sourcepawn/compiler/tests/fail-method-name-too-long.sp new file mode 100644 index 00000000..55e07fac --- /dev/null +++ b/sourcepawn/compiler/tests/fail-method-name-too-long.sp @@ -0,0 +1,7 @@ +methodmap ThisNameIsReallyLongWowItsVeryLong { + public ThisNameIsReallyLongWowItsVeryLong() { + } +} + +public main() { +} diff --git a/sourcepawn/compiler/tests/fail-method-name-too-long.txt b/sourcepawn/compiler/tests/fail-method-name-too-long.txt new file mode 100644 index 00000000..b6856a3e --- /dev/null +++ b/sourcepawn/compiler/tests/fail-method-name-too-long.txt @@ -0,0 +1 @@ +fully-qualified name "ThisNameIsReallyLongWowItsVeryLong.ThisNameIsReallyLongWowItsVeryLong" is too long, would be truncated to "ThisNameIsReallyLongWowItsVeryLong.ThisNameIsReallyLongWowItsVe" diff --git a/sourcepawn/compiler/tests/ok-inline-methods.sp b/sourcepawn/compiler/tests/ok-inline-methods.sp new file mode 100644 index 00000000..bdc12ba2 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-inline-methods.sp @@ -0,0 +1,13 @@ +methodmap Crab { + public Crab(n) { + return Crab:n; + } + public int Value() { + return _:this; + } +}; + +public main() { + new Crab:crab = Crab(5); + return crab.Value(); +} From b6eb3b041bf074d142d991455ceeed76b669d5e0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 22 Jun 2014 13:28:35 -0700 Subject: [PATCH 2/2] Fix bug in requiring braces for new methods. --- sourcepawn/compiler/sc.h | 1 - sourcepawn/compiler/sc1.c | 4 +++- sourcepawn/compiler/tests/fail-method-requires-brace.sp | 8 ++++++++ sourcepawn/compiler/tests/fail-method-requires-brace.txt | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 sourcepawn/compiler/tests/fail-method-requires-brace.sp create mode 100644 sourcepawn/compiler/tests/fail-method-requires-brace.txt diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 8502b633..48859abc 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -235,7 +235,6 @@ typedef struct s_symbol { #define sGLOBAL 0 /* global variable/constant class (no states) */ #define sLOCAL 1 /* local variable/constant */ #define sSTATIC 2 /* global life, local scope */ -#define sPROXY 3 /* only find proxies */ #define sSTATEVAR 3 /* criterion to find variables (sSTATEVAR implies a global variable) */ diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 415e8fbc..3b6efe69 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -82,6 +82,7 @@ typedef struct funcstub_setup_s { const char *name; int return_tag; int this_tag; + int is_new; } funcstub_setup_t; static void resetglobals(void); @@ -3559,6 +3560,7 @@ methodmap_method_t *parse_method(methodmap_t *map) check_name_length(fullname); setup.name = fullname; + setup.is_new = TRUE; if (is_native) { target = funcstub(TRUE, &setup); @@ -4927,7 +4929,7 @@ static int newfunc(const funcstub_setup_t *setup,int fpublic,int fstatic,int sto lexpush(); } else { // We require '{' for new methods. - if (setup->this_tag != -1) + if (setup->is_new) needtoken('{'); /* Insert a separator so that comments following the statement will not diff --git a/sourcepawn/compiler/tests/fail-method-requires-brace.sp b/sourcepawn/compiler/tests/fail-method-requires-brace.sp new file mode 100644 index 00000000..c5f05f8e --- /dev/null +++ b/sourcepawn/compiler/tests/fail-method-requires-brace.sp @@ -0,0 +1,8 @@ +methodmap Crab { + public Crab() return Crab:5; +}; + +public main() { + new Crab:crab = Crab(); + return _:crab; +} diff --git a/sourcepawn/compiler/tests/fail-method-requires-brace.txt b/sourcepawn/compiler/tests/fail-method-requires-brace.txt new file mode 100644 index 00000000..986fc3b9 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-method-requires-brace.txt @@ -0,0 +1 @@ +expected token: "{", but found "return"