diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 48859abc..b16bddfb 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -309,8 +309,9 @@ typedef struct { } token_t; // The method name buffer is larger since we can include our parent class's -// name, a "." to separate it, and a "~" for constructors. -#define METHOD_NAMEMAX sNAMEMAX * 2 + 2 +// name, a "." to separate it, a "~" for constructors, or a ".get/.set" for +// accessors. +#define METHOD_NAMEMAX sNAMEMAX * 2 + 6 typedef struct { token_t tok; diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 3b6efe69..47066c11 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -3341,6 +3341,26 @@ int parse_typeexpr(declinfo_t *decl, const token_t *first, int flags) return TRUE; } +// Consumes a line, returns FALSE if EOF hit. +static int consume_line() +{ + int val; + char *str; + + // First check for EOF. + if (lex(&val, &str) == 0) + return FALSE; + lexpush(); + + while (!matchtoken(tTERM)) { + // Check for EOF. + if (lex(&val, &str) == 0) + return FALSE; + } + + return TRUE; +} + // Parse a new-style declaration. If the name was already fetched (because we // didn't have enough lookahead), it can be given ahead of time. int parse_decl(declinfo_t *decl, const token_t *first, int flags) @@ -3425,6 +3445,181 @@ void check_name_length(char *original) } } +symbol *parse_inline_function(methodmap_t *map, const declinfo_t *decl, const char *name, int is_native, int is_ctor, int is_dtor) +{ + funcstub_setup_t setup; + if (is_dtor) + setup.return_tag = -1; + else if (is_ctor) + setup.return_tag = map->tag; + else + setup.return_tag = decl->tag; + + if (is_ctor) + setup.this_tag = -1; + else + setup.this_tag = map->tag; + + // Build a new symbol. Construct a temporary name including the class. + char fullname[METHOD_NAMEMAX + 1]; + strcpy(fullname, map->name); + strcat(fullname, "."); + strcat(fullname, name); + check_name_length(fullname); + + setup.name = fullname; + setup.is_new = TRUE; + + symbol *target = NULL; + 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; + } + } + return target; +} + +int check_this_tag(methodmap_t *map, symbol *target) +{ + // Check the implicit this parameter. Currently we only allow scalars. As + // to not encourage enum-structs, we will not allow those either. + const arginfo *first_arg = &target->dim.arglist[0]; + if (first_arg->ident == 0 || + first_arg->ident != iVARIABLE || + (first_arg->usage & uCONST) || + first_arg->hasdefault || + first_arg->numtags != 1) + { + return FALSE; + } + + // Ensure the methodmap tag is compatible with |this|. + int ok = FALSE; + for (methodmap_t *mapptr = map; mapptr; mapptr = mapptr->parent) { + if (first_arg->tags[0] == mapptr->tag) { + ok = TRUE; + break; + } + } + return ok; +} + +int parse_property_accessor(const declinfo_t *decl, methodmap_t *map, methodmap_method_t *method) +{ + token_t tok; + token_ident_t ident; + int is_native = FALSE; + + needtoken(tPUBLIC); + if (!matchsymbol(&ident)) { + if (!matchtoken(tNATIVE)) { + error(125); + return FALSE; + } + is_native = TRUE; + if (!needsymbol(&ident)) + return FALSE; + } + + int getter = TRUE; + + if (strcmp(ident.name, "get") != 0) { + error(125); + return FALSE; + } + + symbol *target = NULL; + + token_ident_t bindsource; + int is_bind = match_method_bind(); + if (is_bind) { + if (!needsymbol(&bindsource)) + return FALSE; + } + + if (is_bind) { + // Find an existing symbol. + target = findglb(bindsource.name, sGLOBAL); + if (!target) + error(17, bindsource.name); + else if (target->ident != iFUNCTN) + error(10); + } else { + char tmpname[METHOD_NAMEMAX + 1]; + strcpy(tmpname, method->name); + strcat(tmpname, ".get"); + target = parse_inline_function(map, decl, tmpname, is_native, FALSE, FALSE); + } + + if (!target) + return FALSE; + + if (method->getter) { + error(126, "getter", method->name); + return FALSE; + } + + if (getter) { + method->getter = target; + + // Cannot have extra arguments. + if (target->dim.arglist[0].ident && target->dim.arglist[1].ident) + error(127); + } + + // Must return the same tag as the property. + if (decl->tag != target->tag) { + const char *kind = getter ? "getter" : "setter"; + error(128, "getter", map->name, decl->type); + } + + if (!check_this_tag(map, target)) { + error(108, layout_spec_name(map->spec), map->name); + return FALSE; + } + + needtoken(tTERM); + return TRUE; +} + +methodmap_method_t *parse_property(methodmap_t *map) +{ + declinfo_t decl; + if (!parse_decl(&decl, NULL, DECLFLAG_ONLY_NEW_TYPES)) + return NULL; + + token_ident_t ident; + if (!needsymbol(&ident)) + return NULL; + + methodmap_method_t *method = (methodmap_method_t *)calloc(1, sizeof(methodmap_method_t)); + strcpy(method->name, ident.name); + method->target = NULL; + method->getter = NULL; + method->setter = NULL; + + if (!matchtoken(tTERM)) { + if (!needtoken('{')) + return method; + + while (!matchtoken('}')) { + if (!parse_property_accessor(&decl, map,method)) { + if (!consume_line()) + return NULL; + } + } + + needtoken(tTERM); + } + + return method; +} + methodmap_method_t *parse_method(methodmap_t *map) { int is_ctor = 0; @@ -3441,8 +3636,6 @@ methodmap_method_t *parse_method(methodmap_t *map) token_ident_t bindsource; strcpy(bindsource.name, ""); - needtoken(tPUBLIC); - token_t tok; declinfo_t decl; if (matchtoken('~')) { @@ -3539,39 +3732,7 @@ methodmap_method_t *parse_method(methodmap_t *map) else if (target->ident != iFUNCTN) error(10); } else { - funcstub_setup_t setup; - if (is_dtor) - setup.return_tag = -1; - else if (is_ctor) - setup.return_tag = map->tag; - else - setup.return_tag = decl.tag; - - if (is_ctor) - setup.this_tag = -1; - else - setup.this_tag = map->tag; - - // Build a new symbol. Construct a temporary name including the class. - char fullname[METHOD_NAMEMAX + 1]; - strcpy(fullname, map->name); - strcat(fullname, "."); - strcat(fullname, ident.name); - check_name_length(fullname); - - setup.name = fullname; - setup.is_new = TRUE; - - 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; - } - } + target = parse_inline_function(map, &decl, ident.name, is_native, is_ctor, is_dtor); } if (!target) @@ -3604,17 +3765,11 @@ methodmap_method_t *parse_method(methodmap_t *map) error(112, map->name); } - // Check that a method with this name doesn't already exist. - for (size_t i = 0; i < map->nummethods; i++) { - if (strcmp(map->methods[i]->name, ident.name) == 0) { - error(103, ident.name, spectype); - return NULL; - } - } - methodmap_method_t *method = (methodmap_method_t *)calloc(1, sizeof(methodmap_method_t)); strcpy(method->name, ident.name); method->target = target; + method->getter = NULL; + method->setter = NULL; // If the symbol is a constructor, we bypass the initial argument checks. if (is_ctor) { @@ -3622,56 +3777,17 @@ methodmap_method_t *parse_method(methodmap_t *map) return method; } - // Check the implicit this parameter. Currently we only allow scalars. As - // to not encourage enum-structs, we will not allow those either. - const arginfo *first_arg = &target->dim.arglist[0]; - if (first_arg->ident == 0 || - first_arg->ident != iVARIABLE || - (first_arg->usage & uCONST) || - first_arg->hasdefault || - first_arg->numtags != 1) - { - free(method); + if (!check_this_tag(map, target)) { error(108, spectype, map->name); - return NULL; + return method; } - // Ensure the methodmap tag is compatible with |this|. - int ok = 0; - for (methodmap_t *mapptr = map; mapptr; mapptr = mapptr->parent) { - if (first_arg->tags[0] == mapptr->tag) { - ok = 1; - break; - } - } - if (!ok) - error(108, spectype, map->name); - if (is_dtor) map->dtor = method; return method; } -static int consume_line() -{ - int val; - char *str; - - // First check for EOF. - if (lex(&val, &str) == 0) - return FALSE; - lexpush(); - - while (!matchtoken(tTERM)) { - // Check for EOF. - if (lex(&val, &str) == 0) - return FALSE; - } - - return TRUE; -} - /** * domethodmap - declare a method map for OO-ish syntax. * @@ -3718,10 +3834,30 @@ static void domethodmap(LayoutSpec spec) needtoken('{'); while (!matchtoken('}')) { - methodmap_method_t *method; + token_t tok; methodmap_method_t **methods; + methodmap_method_t *method = NULL; - if ((method = parse_method(map)) == NULL) { + if (lextok(&tok) == tPUBLIC) { + method = parse_method(map); + } else if (tok.id == tSYMBOL && strcmp(tok.str, "property") == 0) { + method = parse_property(map); + } else { + error(124); + } + + if (method) { + // Check that a method with this name doesn't already exist. + for (size_t i = 0; i < map->nummethods; i++) { + if (strcmp(map->methods[i]->name, method->name) == 0) { + error(103, method->name, spectype); + method = NULL; + break; + } + } + } + + if (!method) { if (!consume_line()) return; continue; @@ -3794,7 +3930,7 @@ static void dodelete() // For some reason, we don't get a sysreq.n once this passes through the // peephole optimizer. I can't tell why. -dvander // - // push pri + // push.pri // push.c 1 // sysreq.c N 1 // stack 8 @@ -3803,7 +3939,7 @@ static void dodelete() { pushval(1); ffcall(map->dtor->target, NULL, 1); - map->dtor->target->usage |= uREAD; + markusage(map->dtor->target, uREAD); } markexpr(sEXPR,NULL,0); } @@ -5079,8 +5215,18 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) 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); + symbol *sym = addvariable2( + argptr->name, + (argcnt+3)*sizeof(cell), + argptr->ident, + sLOCAL, + argptr->tags[0], + argptr->dim, + argptr->numdim, + argptr->idxtag, + 0 + ); + markusage(sym, uREAD); argcnt++; } diff --git a/sourcepawn/compiler/sc3.c b/sourcepawn/compiler/sc3.c index 8f54d5a1..c2b8714b 100644 --- a/sourcepawn/compiler/sc3.c +++ b/sourcepawn/compiler/sc3.c @@ -1786,6 +1786,28 @@ static int hier2(value *lval) } /* switch */ } +static void invoke_getter(methodmap_t *map, methodmap_method_t *method, svalue *thisval) +{ + if (thisval->lvalue) + rvalue(&thisval->val); + + // push.pri + // push.c 1 + // sysreq.c N 1 + // stack 8 + pushreg(sPRI); + markexpr(sPARM, NULL, 0); + { + pushval(1); + ffcall(method->getter, NULL, 1); + markusage(method->getter, uREAD); + } + markexpr(sEXPR, NULL, 0); + + // We can't tell whether gets are effectful, but they really shouldn't be. + sideeffect = TRUE; +} + /* hier1 * * The highest hierarchy level: it looks for pointer and array indices @@ -1975,7 +1997,7 @@ restart: lval1->constval=0; } /* if */ - // If there's a call coming up, keep parsing. + // If there's a call/fetch coming up, keep parsing. if (matchtoken('.')) { lexpush(); goto restart; @@ -2018,7 +2040,19 @@ restart: tokeninfo(&lexval, &lexstr); if ((method = methodmap_find_method(map, lexstr)) == NULL) error(105, map->name, lexstr); - if (method) { + + if (method && method->getter) { + invoke_getter(map, method, &thisval); + clear_value(lval1); + lval1->ident = iEXPRESSION; + lval1->tag = method->getter->tag; + lvalue = FALSE; + goto restart; + } + + if (!method || !method->target) { + error(105, map->name, lexstr); + } else { implicitthis = &thisval; sym = method->target; } diff --git a/sourcepawn/compiler/sc5.scp b/sourcepawn/compiler/sc5.scp index e43909b1..b8c5f70b 100644 --- a/sourcepawn/compiler/sc5.scp +++ b/sourcepawn/compiler/sc5.scp @@ -32,13 +32,13 @@ SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned ch /*-*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}, {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} + {111,114}, {114,101}, {117,110}, {97,110}, {121,32}, {115,116}, {115,105}, {97,116}, {100,101}, {140,129}, {101,133}, {32,143}, {117,109}, {41,10}, {116,104}, {144,32}, + {98,108}, {117,115}, {141,32}, {146,99}, {114,97}, {98,111}, {102,163}, {101,120}, {115,121}, {118,139}, {97,32}, {109,165}, {168,171}, {172,108}, {103,32}, {156,138}, + {137,32}, {103,175}, {134,177}, {105,131}, {115,150}, {134,164}, {105,133}, {102,132}, {115,10}, {97,160}, {99,104}, {161,129}, {166,162}, {169,182}, {109,187}, {104,97}, + {101,100}, {111,102}, {116,111}, {132,189}, {112,101}, {99,116}, {173,155}, {44,32}, {109,97}, {109,101}, {98,128}, {99,130}, {118,134}, {112,145}, {99,147}, {193,32}, + {105,185}, {204,208}, {116,97}, {109,138}, {181,148}, {206,153}, {152,183}, {134,97}, {117,108}, {118,128}, {101,131}, {178,129}, {130,32}, {102,105}, {111,112}, {116,121}, + {37,131}, {155,10}, {149,151}, {110,32}, {99,111}, {97,115}, {222,137}, {128,143}, {109,151}, {198,157}, {34,32}, {100,105}, {40,233}, {203,149}, {139,32}, {191,217}, + {119,105}, {99,108}, {150,122}, {108,128}, {136,10}, {101,10}, {147,32}, {132,174}, {98,101}, {158,128}, {97,131}, {166,141}, {102,144}, {111,32}, {132,32} }; /*-*SCPACK end of pair table, do not change or remove this line */ @@ -148,7 +148,7 @@ static char *errmsg[] = { /*102*/ "cannot find %s %s\n", /*103*/ "%s was already defined on this %s\n", /*104*/ "cannot find any methods for %s\n", -/*105*/ "cannot find method %s.%s\n", +/*105*/ "cannot find method or property %s.%s\n", /*106*/ "cannot call methods on an array\n", /*107*/ "cannot call methods on a function\n", /*108*/ "method must have a first argument compatible with the %s type (%s)\n", @@ -163,134 +163,144 @@ static char *errmsg[] = { /*117*/ "no destructor was found for %s %s\n", /*118*/ "destructors must be native functions\n", /*119*/ "destructors cannot have extra arguments\n", -/*120*/ "methodmap and class signatures must use new-style declarations\n", +/*120*/ "methodmap and class signatures must use new-style type 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", +/*124*/ "unexpected token, expected method or property\n", +/*125*/ "expected \"native\" or \"get\"\n", +/*126*/ "%s for %s already exists\n", +/*127*/ "property getters cannot accept extra arguments\n", +/*128*/ "%s must have the same return type as property %s (%s)\n", #else - "\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", - "\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" + "\247\304\305\232\302k\212:\233\307bu\201fo\222\205\217\012", + "\202l\224\252s\204g\363\342e\323\201(\237\247\315\264\202) \316 follow ea\272 \042c\345e\042\012", + "\230\361\327\242\317\252loc\356\321\200\276ap\304\206 \376\252\344mpo\222\205\240ock\012", + "\373\233 \263\231imple\323t\300\012", + "\274\310\224\231\357\262t\270", + "\276\312a\264gn\232\302 \366\265y\012", + "\346\227\237\325\312\221\326\300\012", + "\276\312\252\355\223\201\247\315\264\202; \345s\234\232z\211o\012", + "\303\324\362\200(nega\207ve\307z\211\375\237ou\201\317\245\222ds\235", + "\303\274\237\230\361\327\215\012", + "\303out\226d\200\373\270", + "\303\274c\213l\307\231\252\275add\221s\270", + "\214 \212tr\224po\204\201(\214 pu\240ic \373s\235", + "\303\342e\323t; \231\376s\360t\272\012", + "\042\230fa\330t\352c\345\200\276\312\371l\345\201c\345\200\376s\360t\272 \342e\323t\012", + "m\330\207p\363\230fa\330t\203\376\042s\360t\272\042\012", + "\222\326\232\306\012", + "\204i\207\213iza\242d\227\252\247ce\300\203\230\361\206\232\362\365", + "\231\252la\370l:\341", + "\303\255 nam\347\012", + "\255 \213\221ad\224\326\300:\341", + "\276\312l\251u\200(n\202-\355\223t\235", + "\324a\264gn\323\201\276\312\226mp\363a\264gn\323t\012", + "\042b\221ak\352\237\042\313t\204ue\352\263ou\201\317\313t\247t\012", + "\274head\367\353ff\211\203from pro\302\337\304\012", + "\214 \350\272\367\042#if...\042\012", + "\303\272\327\305\260\355\223t\012", + "\303subscrip\201(\231\366\324\237\302\375m\223\224subscripts):\341", + "\303\247\315\264\202\307\345s\234\232z\211o\012", + "\344mpo\222\205\342e\323\201\231\361os\232a\201\371\212\205\317\335\363(\225\206t\232a\201l\204\200%d\235", + "\222k\214w\343\353\221c\207v\365", + "\324\204\230x ou\201\317\245\222d\203(\321\347\235", + "\324\276\312\204\230x\232(\321\347\235", + "\333do\332\231\357\252\230fa\330\201\251u\200(\333%d\235", + "\333\337p\200mis\350\272 (\333%d\235", + "empt\224\342e\323t\012", + "\303\225r\367(po\264\240\224n\202-t\211m\204\227\232\225r\204g\235", + "\247t\244 \272\327\305\211\203\334l\204\365", + "\355\223\201\255 \277\203\214 \362\365", + "duplic\227\200\042c\345e\352la\370l (\251u\200%d\235", + "\303ellip\226s\307\324\362\200\263\231k\214wn\012", + "\303\344mb\204a\242\317\361\345\203s\304ci\335\211\270", + "\272\327\305\260\355\223\201\247ce\300\203r\223g\200f\237pack\232\225r\204g\012", + "po\226\215\356p\327\311t\211\203\276\315c\300\200\213l nam\232p\327\311t\211\270", + "\302\375m\223\224\274\262t\270", + "\222k\214w\343\324\362\200(\321\347\235", + "\324\362\332d\375\231\350\272\307\237\230\225\204a\242\324\263\302\375sm\213l\012", + "\324(\203d\375\231\350\272\012", + "\303l\204\200\313t\204ua\215\012", + "\303r\223g\365", + "\303subscript\307\241\200\042[ ]\352\346\227\220\203\334\310j\237\353\323\226\202\270", + "m\330\207-\353\323\226\202\356\265y\203\276\312f\330l\224\204i\207\213iz\300\012", + "\247ce\300\367\310xim\234 n\234b\260\317\353\323\226\202\270", + "\222\350\272\232\361os\367b\244c\200(\042}\042\235", + "\225\206\201\317\274\245d\224\360\236ou\201\274head\211\012", + "\265ys\307loc\356\321\332\223\205\274\262t\203\325\312pu\240ic (\321\347\235", + "\222\267ish\232\247\315\264\334\370\374\200\344mpil\260\353\221c\207v\365", + "duplic\227\200\262t; sam\200\333\263p\345s\232t\360c\365", + "\274\333\310\224\231\357\252\230fa\330\201\251u\200(\321\347\235", + "m\330\207p\363\042#else\352\353\221c\207v\332\370twe\212 \042#if ... #\212\353f\042\012", + "\042#elseif\352\353\221c\207\331follow\203\366\042#else\352\353\221c\207v\365", + "n\234b\260\317\346\223d\203do\332\231\335\201\371\346\227\220\012", + "\274\221s\330\201\322\256\317\346\227\220\233 \276\312\217\012", + "\325\272\223g\200\315\326\232\346\227\220\270", + "\274\333\310\224\202l\224\357\252s\204g\363\322\256(\333%d\235", + "\274\333\310\224\231\312\252\221f\211\212c\200\333\237\366\324(\333\217\235", + "\321\200\325\312\245\236 \252\221f\211\212c\200\223\205\366\324(\321\347\235", + "\303\244\215\356n\234b\260\315ci\226\334\376#p\244g\310\012", + "\244\215\356n\234b\260\374\310\201\213\221ad\224\326\300\012", + "\244\215\356n\234b\260supp\220\201w\372\231\212\271\300\012", + "\241\211-\326\232\346\227\237\276\312\230\361\206\232\370\374\200\241\200(\373\233\235", + "\042\362e\301\352\346\227\237\263\303\334\042\373\352\255\270", + "\274\333\276\312\366\324(\333\217\235", + "#\326\200p\227t\211\343\276\225\206\201\360\236 \366\213p\277\370\207c \272\327\305\211\012", + "\204pu\201l\204\200\302\375l\202\256(aft\260subs\207tu\215s\235", + "\250n\322x \211r\237\376\371\247\315\264\202\307\237\303\274c\213l\012", + "m\213\374m\232UTF-8 \212\344d\204g\307\237c\220rupt\232\335le: \364", + "\274\241\332\245\236 \042\221turn\352\223\205\042\221tur\343<\251ue>\042\012", + "\204\313\226\225\212\201\221tur\343\337\304\203(\324& n\202-\265y\235", + "\222k\214w\343\255\307\237\231\252\355\223\201\255 \354", + "\325\322k\200\252\322\256\372\252\230fa\330\201\251u\200f\237\366\204\230x\232\324p\327\311t\260\354", + "\241\211-\326\232\346\227\220\203\223\205na\207\331\373\203\310\224\231\357\342e\270", + "\252\274\237\321\200\310\224\202l\224\370l\202\256\302 \252s\204g\363au\302\350\334\354", + "\342\200\313fli\305: \202\200\317\371\342\332\263\213\221ad\224a\264gn\232\302 a\214\236\260imple\323\322\242\354", + "\214 \342\332\206\200\326\232f\237\306\012", + "\222k\214w\343au\302\350\202\341", + "\222k\214w\343\342\347 f\237au\302\350\202\341", + "pu\240ic \321\332\223\205loc\356\321\332\310\224\231\357\342\332\354", + "\342\200\321\332\310\224\231\312\204i\207\213iz\232\354", + "pu\240ic \373\203\310\224\231\221tur\343\265y\203\354", + "ambiguou\203\355\223t; \322\256ov\211rid\200\263\221qui\221\205\354", + "n\234b\260\317\262t\203do\332\231\350\272 \326i\215\012", + "\247\304\305\232\322\256nam\200id\212\207\335\211\012", + "\274\212\234\211a\242\221qui\221\203\222iqu\200\322g\012", + "\325\357\221qui\221\205p\327\311t\211\203aft\260\336\215\356p\327\311t\211\270", + "\344\330\205\231\267\205\311mb\211\233 \376\225ruc\201\217\012", + "\306 do\332\231\357\252\350\272\367\337\304\012", + "\337p\347 sho\330\205\312\217 \376new-\225y\363\230\361\327\215\270", + "\340sho\330\205\231\357\366\247plici\201\221tur\343\337\304\012", + "\274pro\302\337\304\203d\375\231\350\272\012", + "s\304cif\224ei\236\260\213l \353\323\226\202\203\237\202l\224\371l\345\201\353\323\226\202\012", + "\325\267\205\340\364", + "\340w\372\213\221ad\224\326\232\334\236\263\364", + "\325\267\205\223\224\311\236od\203f\237\364", + "\325\267\205\311\236o\205\237pr\346t\224\210.\364", + "\325c\213l \311\236od\203\334\366\265y\012", + "\325c\213l \311\236od\203\334\252\373\012", + "\311\236o\205\276\357\252\335rs\201\333\344mpa\207\240\200\360\236 \371\340\337p\200(\210\235", + "\340nam\200\276\225\206\201\360\236 \366upp\211c\345\200lett\211\012", + "\340\277\203\213\221ad\224\370\212 \326\232(\315vio\241l\224se\212 \372\210\235", + "\247\304\305\232id\212\207\335\260- d\266you \374ge\201\252\337\304?\012", + "\355ru\305\237\274\276\221tur\343\322\256\364", + "\325\326\200\355ru\305\237\374\233; \213\221ad\224\247i\225\203\372\252\364", + "miss\367\337\304\307\237\340\276\357\371sam\200nam\200\372\340\217\012", + "\325\241\200\230lete\307\340\340\277\203\214 \230\225ru\305\220\012", + "\214 \311\236od\310p \237\361\345\203w\372fo\222\205f\237\364", + "\214 \230\225ru\305\237w\372fo\222\205f\237\340\364", + "\230\225ru\305\220\203\276\312na\207\331\373\270", + "\230\225ru\305\220\203\325\357\247t\244 \262t\270", + "\311\236od\310p \223\205\361\345\203\226gn\227u\221\203\276\241\200new-\225y\363\337p\200\230\361\327\215\270", + "\236\263\250n\322x \263\231ye\201supp\220t\300\012", + "\247\304\305\232\337p\200\247\315\264\202\012", + "f\330ly-qu\213i\335\232nam\347 \263\302\375l\202g\307wo\330\205\312tr\243\227\232\302\341", + "\222\247\304\305\232\302k\212\307\247\304\305\232\311\236o\205\237pr\346\337\012", + "\247\304\305\232\042na\207ve\352\237\042get\042\012", + "\340f\237\340\213\221ad\224\247i\225\270", + "pr\346t\224gett\211\203\325accep\201\247t\244 \262t\270", + "\340\276\357\371sam\200\221tur\343\337p\200\372pr\346t\224\340(\210\235" #endif }; @@ -315,18 +325,18 @@ static char *fatalmsg[] = { /*170*/ "assertion failed: %s\n", /*171*/ "user error: %s\n", #else - "\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" + "\325\221a\205from \335le:\341", + "\325writ\200\302 \335le:\341", + "t\271\200ov\211flow:\341", + "\204suf\335ci\212\201\311m\220y\012", + "\303\345sem\240\260\204\225ruc\215\341", + "n\234\211ic ov\211flow\307\247ce\300\367capaci\337\012", + "\344mpil\232scrip\201\247ce\300\203\371\310xim\234 \311m\220\224\362\200(%l\205bytes\235", + "\302\375m\223\224\211r\237\311ssag\332\334\202\200l\204\365", + "\344\230pag\200\310pp\367\335\363\231fo\222d\012", + "\303p\227h:\341", + "\345s\211\242fail\300: \364", + "\241\260\211r\220: \364" #endif }; @@ -370,43 +380,43 @@ static char *warnmsg[] = { /*235*/ "public function lacks forward declaration (symbol \"%s\")\n", /*236*/ "unknown parameter in substitution (incorrect #define pattern)\n" #else - "\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" + "\306 \263tr\243\227\232\302 %\205\272\327\305\211\270", + "\221\326i\242\317\355\223t/\310cr\375\354", + "n\234b\260\317\262t\203do\332\231\350\272 \326i\215\012", + "\255 \263nev\260\241\300:\341", + "\255 \263a\264gn\232\252\251u\200\236a\201\263nev\260\241\300:\341", + "\221d\222d\223\201\344\230: \355\223\201\247\315\264\334\263z\211o\012", + "\221d\222d\223\201te\225: \355\223\201\247\315\264\334\263n\202-z\211o\012", + "\222k\214w\343#p\244g\310\012", + "\274\360\236 \322\256\221s\330\201\241\232\370\374\200\326i\215\307\374c\367\221p\206s\365", + "\373\233 sho\330\205\221tur\343\252\251u\365", + "po\264\240\200\241\200\317\255 \370\374\200\204i\207\213iza\215:\341", + "po\264\240\224\222\204t\212\230\205a\264gn\323t\012", + "po\264\240\224\222\204t\212\230\205bit\360s\200\346a\215\012", + "\322\256mis\350\272\012", + "po\264\240\224\252\042\355\352\324\333w\372\204t\212\230d:\341", + "\247\315\264\334\277\203\214 effe\305\012", + "ne\225\232\344m\323t\012", + "loos\200\204d\212\322\215\012", + "ol\205\225y\363pro\302\337\304\203\241\232\360\236 \336\215\356semi\344l\234n\270", + "loc\356\321\347 s\277dow\203\252\321\200a\201\252\315c\300\367level\012", + "\247\315\264\334\360\236 \322\256ov\211rid\200\276ap\304\206 \370twe\212 p\206\212\236ese\270", + "la\370l nam\347 s\277dow\203\322\256na\311\012", + "n\234b\260\317\353git\203\247ce\300\203\244\215\356n\234b\260\315ci\226\202\012", + "\221d\222d\223\201\042\362e\301\042: \333\362\200\263\213way\2031 \354", + "\204\230t\211m\204\227\200\324\362\200\376\042\362e\301\352\247\315\264\334\354", + "\222\221a\272\271\200\344\230\012", + "\252\321\200\263a\264gn\232\302 itself \354", + "m\220\200\204i\207\213iz\211\203\236\366\212\234 \335eld\270", + "l\212g\236 \317\204i\207\213iz\260\247ce\300\203\362\200\317\371\212\234 \335eld\012", + "\204\230x \322\256mis\350\272 \354", + "\214 imple\323\322\242f\237\342\347 \376\373\233\307\214 f\213l-back\012", + "\342\200s\304ci\335ca\242\334\374w\206\205\230\361\327\242\263ig\214\221d\012", + "outpu\201\335\363\263writt\212\307bu\201\360\236 \344mpac\201\212\344d\367\353s\271\300\012", + "\342\200\321\347 s\277dow\203\252glob\356\321\365", + "\306 \263m\206k\232\372\230\315c\227\300: \364", + "pu\240ic \274lack\203\374w\206\205\230\361\327\242\354", + "\222k\214w\343p\327\311t\260\376subs\207tu\242(\204c\220\221c\201#\326\200p\227t\211n\235" #endif }; diff --git a/sourcepawn/compiler/sctracker.h b/sourcepawn/compiler/sctracker.h index 3e8ef711..72901aec 100644 --- a/sourcepawn/compiler/sctracker.h +++ b/sourcepawn/compiler/sctracker.h @@ -83,6 +83,8 @@ typedef struct methodmap_method_s { char name[METHOD_NAMEMAX + 1]; symbol *target; + symbol *getter; + symbol *setter; } methodmap_method_t; typedef struct methodmap_s diff --git a/sourcepawn/compiler/tests/fail-duplicate-getter.sp b/sourcepawn/compiler/tests/fail-duplicate-getter.sp new file mode 100644 index 00000000..0cdfd6a0 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-duplicate-getter.sp @@ -0,0 +1,9 @@ +methodmap Crab { + property int Crab { + public native get(); + public native get(); + } +} + +public main() { +} diff --git a/sourcepawn/compiler/tests/fail-duplicate-getter.txt b/sourcepawn/compiler/tests/fail-duplicate-getter.txt new file mode 100644 index 00000000..c2b4feee --- /dev/null +++ b/sourcepawn/compiler/tests/fail-duplicate-getter.txt @@ -0,0 +1 @@ +getter for Crab already exists diff --git a/sourcepawn/compiler/tests/fail-duplicate-methods.sp b/sourcepawn/compiler/tests/fail-duplicate-methods.sp index 52f54937..071d9d7a 100644 --- a/sourcepawn/compiler/tests/fail-duplicate-methods.sp +++ b/sourcepawn/compiler/tests/fail-duplicate-methods.sp @@ -1,7 +1,7 @@ -native X:Crab(); +native X:Crab(X:x); methodmap X { - public X() = Crab; - public X() = Crab; + public X2() = Crab; + public X2() = Crab; } public main() { diff --git a/sourcepawn/compiler/tests/fail-duplicate-methods.txt b/sourcepawn/compiler/tests/fail-duplicate-methods.txt index 31daf0de..f56c4be2 100644 --- a/sourcepawn/compiler/tests/fail-duplicate-methods.txt +++ b/sourcepawn/compiler/tests/fail-duplicate-methods.txt @@ -1 +1 @@ -X was already defined on this methodmap +X2 was already defined on this methodmap diff --git a/sourcepawn/compiler/tests/fail-duplicate-property.sp b/sourcepawn/compiler/tests/fail-duplicate-property.sp new file mode 100644 index 00000000..25a42aaa --- /dev/null +++ b/sourcepawn/compiler/tests/fail-duplicate-property.sp @@ -0,0 +1,7 @@ +methodmap Crab { + property int Crab; + property int Crab; +} + +public main() { +} diff --git a/sourcepawn/compiler/tests/fail-duplicate-property.txt b/sourcepawn/compiler/tests/fail-duplicate-property.txt new file mode 100644 index 00000000..8e4bf6a9 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-duplicate-property.txt @@ -0,0 +1 @@ +Crab was already defined on this methodmap diff --git a/sourcepawn/compiler/tests/fail-old-decl-new-types.txt b/sourcepawn/compiler/tests/fail-old-decl-new-types.txt index d6d17b6a..371fe020 100644 --- a/sourcepawn/compiler/tests/fail-old-decl-new-types.txt +++ b/sourcepawn/compiler/tests/fail-old-decl-new-types.txt @@ -1,3 +1,3 @@ type "Float" should be "float" in new-style declarations type "String" should be "char" in new-style declarations -methodmap and class signatures must use new-style declarations +methodmap and class signatures must use new-style type declarations diff --git a/sourcepawn/compiler/tests/fail-property-bad-return-type.sp b/sourcepawn/compiler/tests/fail-property-bad-return-type.sp new file mode 100644 index 00000000..9bbf7cfe --- /dev/null +++ b/sourcepawn/compiler/tests/fail-property-bad-return-type.sp @@ -0,0 +1,12 @@ +native GetCrab(Crab:crab); + +methodmap Crab { + property float Blah { + public get() = GetCrab; + } +} + +public main() { + new Crab:crab = Crab:5; + new x = crab.Blah; +} diff --git a/sourcepawn/compiler/tests/fail-property-bad-return-type.txt b/sourcepawn/compiler/tests/fail-property-bad-return-type.txt new file mode 100644 index 00000000..d9f58f58 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-property-bad-return-type.txt @@ -0,0 +1 @@ +getter must have the same return type as property Crab (float) diff --git a/sourcepawn/compiler/tests/fail-property-bad-return-value.txt b/sourcepawn/compiler/tests/fail-property-bad-return-value.txt new file mode 100644 index 00000000..80e10d93 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-property-bad-return-value.txt @@ -0,0 +1 @@ +(4) : warning 213: tag mismatch diff --git a/sourcepawn/compiler/tests/fail-property-bad-this-type.sp b/sourcepawn/compiler/tests/fail-property-bad-this-type.sp new file mode 100644 index 00000000..8567e7fc --- /dev/null +++ b/sourcepawn/compiler/tests/fail-property-bad-this-type.sp @@ -0,0 +1,12 @@ +native Float:GetCrab(); + +methodmap Crab { + property float Blah { + public get() = GetCrab(); + } +} + +public main() { + new Crab:crab = Crab:5; + new x = crab.Blah; +} diff --git a/sourcepawn/compiler/tests/fail-property-bad-this-type.txt b/sourcepawn/compiler/tests/fail-property-bad-this-type.txt new file mode 100644 index 00000000..e23c2488 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-property-bad-this-type.txt @@ -0,0 +1 @@ +method must have a first argument compatible with the methodmap type (Crab) diff --git a/sourcepawn/compiler/tests/ok-properties.sp b/sourcepawn/compiler/tests/ok-properties.sp new file mode 100644 index 00000000..80db5e16 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-properties.sp @@ -0,0 +1,29 @@ +native Float:GetCrabWhat(Crab:crab); + +methodmap Crab { + public Crab(n) { + return Crab:n; + } + property Crab Yams { + public get() { + return Crab:5; + } + } + property int Blah { + public native get(); + } + property float What { + public get() = GetCrabWhat; + } +} + +print(n) { + return n +} + +public main() { + new Crab:crab = Crab(10); + print(_:crab.Yams.Yams.Yams) + print(crab.Blah); + print(_:crab.What); +} diff --git a/sourcepawn/compiler/tests/runtests.py b/sourcepawn/compiler/tests/runtests.py index 981fdd6f..0c03b064 100644 --- a/sourcepawn/compiler/tests/runtests.py +++ b/sourcepawn/compiler/tests/runtests.py @@ -39,6 +39,7 @@ def run_tests(args): elif not compiled and kind != 'fail': status = 'fail' + fails = [] if status == 'ok' and kind != 'pass': lines = [] with open(os.path.join(testdir, test + '.txt')) as fp: @@ -46,18 +47,21 @@ def run_tests(args): lines.append(line.strip()) for line in lines: if line not in stdout: - sys.stderr.write('Expected to find text in stdout: >>>\n') - sys.stderr.write(text) - sys.stderr.write('<<<\n') - status = 'fail' + fails += [ + 'Expected to find text in stdout: >>>\n', + line, + '<<<\n', + ] break - if status == 'fail': + if status == 'fail' or len(fails): print('Test {0} ... FAIL'.format(test)) failed = True sys.stderr.write('FAILED! Dumping stdout/stderr:\n') sys.stderr.write(stdout) sys.stderr.write(stderr) + for line in fails: + sys.stderr.write(line) else: print('Test {0} ... OK'.format(test))