diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 1c02741f..9e200699 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -434,6 +434,7 @@ enum TokenKind { tSWITCH, tTAGOF, tTHEN, + tTHIS, tTYPEDEF, tUNION, tVOID, diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index 796226ff..edeb8daf 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -3702,7 +3702,6 @@ int check_this_tag(methodmap_t *map, symbol *target) 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) { @@ -5576,6 +5575,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) argptr->tags = (int *)malloc(sizeof(int)); argptr->tags[0] = *thistag; argptr->numtags = 1; + argptr->usage = uCONST; } else { argptr = &sym->dim.arglist[0]; } @@ -5591,6 +5591,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag) argptr->idxtag, 0 ); + sym->usage |= uCONST; markusage(sym, uREAD); argcnt++; diff --git a/sourcepawn/compiler/sc2.cpp b/sourcepawn/compiler/sc2.cpp index d02a082a..c0119e24 100644 --- a/sourcepawn/compiler/sc2.cpp +++ b/sourcepawn/compiler/sc2.cpp @@ -1973,7 +1973,7 @@ const char *sc_tokens[] = { "public", "return", "sizeof", "sleep", "static", "stock", "struct", "switch", - "tagof", "*then", "typedef", + "tagof", "*then", "this", "typedef", "union", "void", "while", diff --git a/sourcepawn/compiler/sc3.cpp b/sourcepawn/compiler/sc3.cpp index 1a067b6b..5fe2878c 100644 --- a/sourcepawn/compiler/sc3.cpp +++ b/sourcepawn/compiler/sc3.cpp @@ -2304,12 +2304,28 @@ static int primary(value *lval) clear_value(lval); /* clear lval */ tok=lex(&val,&st); + + if (tok == tTHIS) { + strcpy(lastsymbol, "this"); + if ((sym = findloc("this")) == NULL) { + error(166); /* 'this' outside method body */ + ldconst(0, sPRI); + return FALSE; + } + + assert(sym->ident == iVARIABLE); + lval->sym = sym; + lval->ident = sym->ident; + lval->tag = sym->tag; + return TRUE; + } + if (tok==tSYMBOL) { /* lastsymbol is char[sNAMEMAX+1], lex() should have truncated any symbol * to sNAMEMAX significant characters */ assert(strlen(st)