Merge pull request #194 from alliedmodders/keyword-this

Define 'this' as a keyword.
This commit is contained in:
David Anderson 2014-11-09 13:09:22 -08:00
commit 801b7ec9e2
24 changed files with 55 additions and 19 deletions

View File

@ -434,6 +434,7 @@ enum TokenKind {
tSWITCH,
tTAGOF,
tTHEN,
tTHIS,
tTYPEDEF,
tUNION,
tVOID,

View File

@ -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++;

View File

@ -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",

View File

@ -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)<sizeof lastsymbol);
strcpy(lastsymbol,st);
} /* if */
}
if (tok==tSYMBOL && !findconst(st,NULL)) {
/* first look for a local variable */
if ((sym=findloc(st))!=0) {

View File

@ -209,6 +209,7 @@ static const char *errmsg[] = {
/*163*/ "indeterminate array size in \"sizeof\" expression (symbol \"%s\")\n",
/*164*/ "allocated array type '%s' doesn't match original type '%s'\n",
/*165*/ "cannot create dynamic arrays in static scope - did you mean to create a fixed-length array with brackets after the variable name?\n",
/*166*/ "cannot use 'this' outside of a methodmap method or property\n",
#else
"\315e\306\227\266k\217:\235\277bu\201fo\220\204\223\012",
"\202l\224\250s\205g\346\356e\233\201(\243\315\214\267\202) \253 f\255low ea\305 \042c\353e\042\012",

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this[]);
native CloseHandle(Handle:handle[]);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -0,0 +1,12 @@
methodmap Egg
{
public void illegal(Egg x) {
this = x;
}
};
public main()
{
Egg egg;
egg.illegal(egg);
}

View File

@ -0,0 +1 @@
(4) : error 022: must be lvalue (non-constant)

View File

@ -1,4 +1,4 @@
native Q(X:this, a);
native Q(X:handle, a);
methodmap X {
public ~X() = Q;

View File

@ -1,4 +1,4 @@
Q(X:this)
Q(X:handle)
{
}

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle(HandleEgg:this);
native CloseHandle(HandleEgg:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle({Handle, Egg}:this);
native CloseHandle({Handle, Egg}:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -0,0 +1,3 @@
public OnPluginStart() {
return this;
}

View File

@ -0,0 +1 @@
(2) : error 166: cannot use 'this' outside of a methodmap method or property

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
};

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
enum Handle {
INVALID_HANDLE = 0,

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;

View File

@ -1,5 +1,5 @@
native CloneHandle(Handle:this);
native CloseHandle(Handle:this);
native CloneHandle(Handle:handle);
native CloseHandle(Handle:handle);
methodmap Handle {
public Clone() = CloneHandle;

View File

@ -1,4 +1,4 @@
native CloseHandle(Handle:this);
native CloseHandle(Handle:handle);
methodmap Handle {
public Close() = CloseHandle;