Browse Source

added __this__ support

Nicolas Cannasse 14 years ago
parent
commit
d0f733946a

+ 1 - 0
doc/CHANGES.txt

@@ -25,6 +25,7 @@
 	all : optimized variable tracking/renaming
 	all : optimized macro engine (speed x2)
 	all : added -D macrotimes support
+	all : added untyped __this__ support (prepare for 'this' spec. change)
 
 2011-01-30: 2.07
 	all : fixed completion support with --remap

+ 1 - 1
std/Date.hx

@@ -148,7 +148,7 @@ extern class Date
 			}
 		};
 		d.prototype[#if as3 "toStringHX" #else "toString" #end] = function() {
-			var date : Date = this;
+			var date : Date = __this__;
 			var m = date.getMonth() + 1;
 			var d = date.getDate();
 			var h = date.getHours();

+ 4 - 4
std/List.hx

@@ -153,14 +153,14 @@ class List<T> {
 		return cast {
 			h : h,
 			hasNext : function() {
-				return untyped (this.h != null);
+				return untyped (__this__.h != null);
 			},
 			next : function() {
 				untyped {
-					if( this.h == null )
+					if( __this__.h == null )
 						return null;
-					var x = this.h[0];
-					this.h = this.h[1];
+					var x = __this__.h[0];
+					__this__.h = __this__.h[1];
 					return x;
 				}
 			}

+ 20 - 20
std/cpp/_std/Xml.hx

@@ -54,34 +54,34 @@ enum XmlType {
 			cur : x,
 			xml : function(name,att) {
 				var x : Dynamic = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.Element;
 				x._nodeName = new String(name);
 				x._attributes = att;
 				x._children = new Array();
 				untyped {
 					var i = 0;
-					this.cur.addChild(x);
-					this.cur = x;
+					__this__.cur.addChild(x);
+					__this__.cur = x;
 				}
 			},
 			cdata : function(text) {
 				var x = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.CData;
 				x._nodeValue = new String(text);
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			pcdata : function(text) {
 				var x = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.PCData;
 				x._nodeValue = new String(text);
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			comment : function(text:String) {
 				var x = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				if( untyped text.cca(0) == 63 ) {
 					x.nodeType = Xml.Prolog;
 					text = new String(text);
@@ -91,17 +91,17 @@ enum XmlType {
 					text = new String(text);
 				}
 				x._nodeValue = text;
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			doctype : function(text) {
 				var x = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.DocType;
 				x._nodeValue = (new String(text)).substr(1);
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			done : function() {
-				untyped this.cur = this.cur._parent;
+				untyped __this__.cur = __this__.cur._parent;
 			}
 		};
 		untyped _parse(str,parser);
@@ -245,24 +245,24 @@ enum XmlType {
 		return untyped {
 			cur: 0,
 			hasNext : function() {
-				var k:Int = this.cur;
+				var k:Int = __this__.cur;
 				var l = children.length;
 				while( k < l ) {
 					if( children[k].nodeType == Xml.Element )
 						break;
 					k += 1;
 				}
-				this.cur = k;
+				__this__.cur = k;
 				return k < l;
 			},
 			next : function() {
-				var k = this.cur;
+				var k = __this__.cur;
 				var l = children.length;
 				while( k < l ) {
 					var n = children[k];
 					k += 1;
 					if( n.nodeType == Xml.Element ) {
-						this.cur = k;
+						__this__.cur = k;
 						return n;
 					}
 				}
@@ -278,7 +278,7 @@ enum XmlType {
 		return untyped {
 			cur: 0,
 			hasNext : function() {
-				var k = this.cur;
+				var k = __this__.cur;
 				var l = children.length;
 				while( k < l ) {
 					var n = children[k];
@@ -286,17 +286,17 @@ enum XmlType {
 						break;
 					k++;
 				}
-				this.cur = k;
+				__this__.cur = k;
 				return k < l;
 			},
 			next : function() {
-				var k = this.cur;
+				var k = __this__.cur;
 				var l = children.length;
 				while( k < l ) {
 					var n = children[k];
 					k++;
 					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						this.cur = k;
+						__this__.cur = k;
 						return n;
 					}
 				}

+ 8 - 8
std/flash/Boot.hx

@@ -224,14 +224,14 @@ class Boot {
 			g.haxeInitDone = true;
 			Array.prototype["copy"] = Array.prototype["slice"];
 			Array.prototype["insert"] = function(i,x) {
-				this["splice"](i,0,x);
+				__this__["splice"](i,0,x);
 			};
 			Array.prototype["remove"] = function(obj) {
 				var i = 0;
-				var l = this["length"];
+				var l = __this__["length"];
 				while( i < l ) {
-					if( this[i] == obj ) {
-						this["splice"](i,1);
+					if( __this__[i] == obj ) {
+						__this__["splice"](i,1);
 						return true;
 					}
 					i++;
@@ -241,12 +241,12 @@ class Boot {
 			Array.prototype["iterator"] = function() {
 				return {
 					cur : 0,
-					arr : this,
+					arr : __this__,
 					hasNext : function() {
-						return this.cur < this.arr["length"];
+						return __this__.cur < __this__.arr["length"];
 					},
 					next : function() {
-						return this.arr[this.cur++];
+						return __this__.arr[__this__.cur++];
 					}
 				}
 			};
@@ -254,7 +254,7 @@ class Boot {
 			var cca = String.prototype["charCodeAt"];
 			String.prototype["cca"] = cca;
 			String.prototype["charCodeAt"] = function(i) {
-				var x = this["cca"](i);
+				var x = __this__["cca"](i);
 				if( x <= 0 ) // fast NaN
 					return null;
 				return x;

+ 2 - 2
std/flash/_std/Hash.hx

@@ -58,8 +58,8 @@
 		return untyped {
 			ref : h,
 			it : __keys__(h)["iterator"](),
-			hasNext : function() { return this.it[__unprotect__("hasNext")](); },
-			next : function() { var i = this.it[__unprotect__("next")](); return this.ref[i]; }
+			hasNext : function() { return __this__.it[__unprotect__("hasNext")](); },
+			next : function() { var i = __this__.it[__unprotect__("next")](); return __this__.ref[i]; }
 		};
 	}
 

+ 2 - 2
std/flash/_std/IntHash.hx

@@ -60,8 +60,8 @@
 		return untyped {
 			ref : h,
 			it : keys(),
-			hasNext : function() { return this.it[__unprotect__("hasNext")](); },
-			next : function() { var i = this.it[__unprotect__("next")](); return this.ref[i]; }
+			hasNext : function() { return __this__.it[__unprotect__("hasNext")](); },
+			next : function() { var i = __this__.it[__unprotect__("next")](); return __this__.ref[i]; }
 		};
 	}
 

+ 2 - 2
std/flash/_std/Reflect.hx

@@ -26,7 +26,7 @@
 @:core_api class Reflect {
 
 	public inline static function hasField( o : Dynamic, field : String ) : Bool untyped {
-		return this["hasOwnProperty"]["call"](o,field);
+		return __this__["hasOwnProperty"]["call"](o,field);
 	}
 
 	public inline static function field( o : Dynamic, field : String ) : Dynamic untyped {
@@ -72,7 +72,7 @@
 	}
 
 	public static function deleteField( o : Dynamic, f : String ) : Bool untyped {
-		if( this["hasOwnProperty"]["call"](o,f) != true ) return false;
+		if( __this__["hasOwnProperty"]["call"](o,f) != true ) return false;
 		__delete__(o,f);
 		return true;
 	}

+ 13 - 13
std/flash/_std/Xml.hx

@@ -167,11 +167,11 @@ enum XmlType {
 		return untyped {
 			cur: this.__x[untyped "firstChild"],
 			hasNext : function(){
-				return this.cur != null;
+				return __this__.cur != null;
 			},
 			next : function(){
-				var r = convert(this.cur);
-				this.cur = this.cur["nextSibling"];
+				var r = convert(__this__.cur);
+				__this__.cur = __this__.cur["nextSibling"];
 				return r;
 			}
 		}
@@ -183,21 +183,21 @@ enum XmlType {
 		return untyped {
 			cur: this.__x[untyped "firstChild"],
 			hasNext : function() {
-				var r = this.cur;
+				var r = __this__.cur;
 				while( r != null && r["nodeType"] != 1 )
 					r = r["nextSibling"];
-				this.cur = r;
+				__this__.cur = r;
 				return r != null;
 			},
 			next : function(){
-				var r = this.cur;
+				var r = __this__.cur;
 				while( r != null && r["nodeType"] != 1 )
 					r = r["nextSibling"];
 				if( r == null ) {
-					this.cur = null;
+					__this__.cur = null;
 					return null;
 				}
-				this.cur = r["nextSibling"];
+				__this__.cur = r["nextSibling"];
 				return convert(r);
 			}
 		}
@@ -209,21 +209,21 @@ enum XmlType {
 		return untyped {
 			cur: this.__x[untyped "firstChild"],
 			hasNext : function() {
-				var r = this.cur;
+				var r = __this__.cur;
 				while( r != null && (r["nodeType"] != 1 || r["nodeName"] != name) )
 					r = r["nextSibling"];
-				this.cur = r;
+				__this__.cur = r;
 				return r != null;
 			},
 			next : function(){
-				var r = this.cur;
+				var r = __this__.cur;
 				while( r != null && (r["nodeType"] != 1 || r["nodeName"] != name) )
 					r = r["nextSibling"];
 				if( r == null ) {
-					this.cur = null;
+					__this__.cur = null;
 					return null;
 				}
-				this.cur = r["nextSibling"];
+				__this__.cur = r["nextSibling"];
 				return convert(r);
 			}
 		}

+ 6 - 6
std/flash9/Boot.hx

@@ -196,20 +196,20 @@ class Boot extends flash.display.MovieClip {
 	static function __init__() untyped {
 		var aproto = Array.prototype;
 		aproto.copy = function() {
-			return this.slice();
+			return __this__.slice();
 		};
 		aproto.insert = function(i,x) {
-			this.splice(i,0,x);
+			__this__.splice(i,0,x);
 		};
 		aproto.remove = function(obj) {
-			var idx = this.indexOf(obj);
+			var idx = __this__.indexOf(obj);
 			if( idx == -1 ) return false;
-			this.splice(idx,1);
+			__this__.splice(idx,1);
 			return true;
 		}
 		aproto.iterator = function() {
 			var cur = 0;
-			var arr : Array<Dynamic> = this;
+			var arr : Array<Dynamic> = __this__;
 			return {
 				hasNext : function() {
 					return cur < arr.length;
@@ -224,7 +224,7 @@ class Boot extends flash.display.MovieClip {
 		aproto.setPropertyIsEnumerable("remove", false);
 		aproto.setPropertyIsEnumerable("iterator", false);
 		String.prototype.charCodeAt = function(i) : Null<Int> {
-			var s : String = this;
+			var s : String = __this__;
 			var x : Float = s.cca(i);
 			if( __global__["isNaN"](x) )
 				return null;

+ 2 - 2
std/flash9/_std/Hash.hx

@@ -58,8 +58,8 @@
 		return untyped {
 			ref : h,
 			it : __keys__(h).iterator(),
-			hasNext : function() { return this.it.hasNext(); },
-			next : function() { var i : Dynamic = this.it.next(); return this.ref[i]; }
+			hasNext : function() { return __this__.it.hasNext(); },
+			next : function() { var i : Dynamic = __this__.it.next(); return __this__.ref[i]; }
 		};
 	}
 

+ 2 - 2
std/flash9/_std/IntHash.hx

@@ -57,8 +57,8 @@
 		return untyped {
 			ref : h,
 			it : keys(),
-			hasNext : function() { return this.it.hasNext(); },
-			next : function() { var i = this.it.next(); return this.ref[i]; }
+			hasNext : function() { return __this__.it.hasNext(); },
+			next : function() { var i = __this__.it.next(); return __this__.ref[i]; }
 		};
 	}
 

+ 14 - 14
std/js/Boot.hx

@@ -203,19 +203,19 @@ class Boot {
 #end
 			Array.prototype.copy = Array.prototype.slice;
 			Array.prototype.insert = function(i,x) {
-				this.splice(i,0,x);
+				__this__.splice(i,0,x);
 			};
 			Array.prototype.remove = if( Array.prototype.indexOf ) function(obj) {
-				var idx = this.indexOf(obj);
+				var idx = __this__.indexOf(obj);
 				if( idx == -1 ) return false;
-				this.splice(idx,1);
+				__this__.splice(idx,1);
 				return true;
 			} else function(obj) {
 				var i = 0;
-				var l = this.length;
+				var l = __this__.length;
 				while( i < l ) {
-					if( this[i] == obj ) {
-						this.splice(i,1);
+					if( __this__[i] == obj ) {
+						__this__.splice(i,1);
 						return true;
 					}
 					i++;
@@ -225,19 +225,19 @@ class Boot {
 			Array.prototype.iterator = function() {
 				return {
 					cur : 0,
-					arr : this,
+					arr : __this__,
 					hasNext : function() {
-						return this.cur < this.arr.length;
+						return __this__.cur < __this__.arr.length;
 					},
 					next : function() {
-						return this.arr[this.cur++];
+						return __this__.arr[__this__.cur++];
 					}
 				}
 			};
 			if( String.prototype.cca == null )
 				String.prototype.cca = String.prototype.charCodeAt;
 			String.prototype.charCodeAt = function(i) {
-				var x = this.cca(i);
+				var x = __this__.cca(i);
 				if( x != x ) // fast isNaN
 					return null;
 				return x;
@@ -245,14 +245,14 @@ class Boot {
 			var oldsub = String.prototype.substr;
 			String.prototype.substr = function(pos,len){
 				if( pos != null && pos != 0 && len != null && len < 0 ) return "";
-				if( len == null ) len = this.length;
+				if( len == null ) len = __this__.length;
 				if( pos < 0 ){
-					pos = this.length + pos;
+					pos = __this__.length + pos;
 					if( pos < 0 ) pos = 0;
 				}else if( len < 0 ){
-					len = this.length + len - pos;
+					len = __this__.length + len - pos;
 				}
-				return oldsub.apply(this,[pos,len]);
+				return oldsub.apply(__this__,[pos,len]);
 			};
 			__js__("$closure = js.Boot.__closure");
 		}

+ 2 - 2
std/js/_std/Hash.hx

@@ -72,8 +72,8 @@
 		return untyped {
 			ref : h,
 			it : keys(),
-			hasNext : function() { return this.it.hasNext(); },
-			next : function() { var i = this.it.next(); return this.ref["$"+i]; }
+			hasNext : function() { return __this__.it.hasNext(); },
+			next : function() { var i = __this__.it.next(); return __this__.ref["$"+i]; }
 		};
 	}
 

+ 2 - 2
std/js/_std/IntHash.hx

@@ -63,8 +63,8 @@
 		return untyped {
 			ref : h,
 			it : keys(),
-			hasNext : function() { return this.it.hasNext(); },
-			next : function() { var i = this.it.next(); return this.ref[i]; }
+			hasNext : function() { return __this__.it.hasNext(); },
+			next : function() { var i = __this__.it.next(); return __this__.ref[i]; }
 		};
 	}
 

+ 18 - 18
std/js/_std/Xml.hx

@@ -279,10 +279,10 @@ enum XmlType {
 			cur: 0,
 			x: this._children,
 			hasNext : function(){
-				return this.cur < this.x.length;
+				return __this__.cur < __this__.x.length;
 			},
 			next : function(){
-				return this.x[this.cur++];
+				return __this__.x[__this__.cur++];
 			}
 		}
 	}
@@ -293,24 +293,24 @@ enum XmlType {
 			cur: 0,
 			x: this._children,
 			hasNext : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					if( this.x[k].nodeType == Xml.Element )
+					if( __this__.x[k].nodeType == Xml.Element )
 						break;
 					k += 1;
 				}
-				this.cur = k;
+				__this__.cur = k;
 				return k < l;
 			},
 			next : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					var n = this.x[k];
+					var n = __this__.x[k];
 					k += 1;
 					if( n.nodeType == Xml.Element ) {
-						this.cur = k;
+						__this__.cur = k;
 						return n;
 					}
 				}
@@ -325,25 +325,25 @@ enum XmlType {
 			cur: 0,
 			x: this._children,
 			hasNext : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					var n = this.x[k];
+					var n = __this__.x[k];
 					if( n.nodeType == Xml.Element && n._nodeName == name )
 						break;
 					k++;
 				}
-				this.cur = k;
+				__this__.cur = k;
 				return k < l;
 			},
 			next : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					var n = this.x[k];
+					var n = __this__.x[k];
 					k++;
 					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						this.cur = k;
+						__this__.cur = k;
 						return n;
 					}
 				}

+ 3 - 3
std/neko/_std/Array.hx

@@ -60,11 +60,11 @@
 			a : this,
 			p : 0,
 			hasNext : function() {
-				return this.p < this.a.length;
+				return __this__.p < __this__.a.length;
 			},
 			next : function() {
-				var i = this.a.__a[this.p];
-				this.p += 1;
+				var i = __this__.a.__a[__this__.p];
+				__this__.p += 1;
 				return i;
 			}
 		};

+ 30 - 30
std/neko/_std/Xml.hx

@@ -60,7 +60,7 @@ enum XmlType {
 			cur : x,
 			xml : function(name,att) {
 				var x : Dynamic = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.Element;
 				x._nodeName = new String(name);
 				x._attributes = att;
@@ -73,27 +73,27 @@ enum XmlType {
 						__dollar__objset(att,f[i], new String(__dollar__objget(att,f[i]))) ;
 						i++;
 					}
-					this.cur.addChild(x);
-					this.cur = x;
+					__this__.cur.addChild(x);
+					__this__.cur = x;
 				}
 			},
 			cdata : function(text) {
 				var x : Dynamic = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.CData;
 				x._nodeValue = new String(text);
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			pcdata : function(text) {
 				var x : Dynamic = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.PCData;
 				x._nodeValue = new String(text);
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			comment : function(text) {
 				var x : Dynamic = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				if( untyped __dollar__sget(text,0) == 63 ) {
 					x.nodeType = Xml.Prolog;
 					text = new String(text);
@@ -103,17 +103,17 @@ enum XmlType {
 					text = new String(text);
 				}
 				x._nodeValue = text;
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			doctype : function(text) {
 				var x : Dynamic = new Xml();
-				x._parent = untyped this.cur;
+				x._parent = untyped __this__.cur;
 				x.nodeType = Xml.DocType;
 				x._nodeValue = new String(text).substr(1);
-				untyped this.cur.addChild(x);
+				untyped __this__.cur.addChild(x);
 			},
 			done : function() {
-				untyped this.cur = this.cur._parent;
+				untyped __this__.cur = __this__.cur._parent;
 			}
 		};
 		untyped _parse(str.__s,parser);
@@ -238,10 +238,10 @@ enum XmlType {
 			cur: 0,
 			x: this._children,
 			hasNext : function(){
-				return this.cur < this.x.length;
+				return __this__.cur < __this__.x.length;
 			},
 			next : function(){
-				return this.x[this.cur++];
+				return __this__.x[__this__.cur++];
 			}
 		}
 	}
@@ -254,24 +254,24 @@ enum XmlType {
 			cur: 0,
 			x: this._children,
 			hasNext : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					if( this.x[k].nodeType == Xml.Element )
+					if( __this__.x[k].nodeType == Xml.Element )
 						break;
 					k += 1;
 				}
-				this.cur = k;
+				__this__.cur = k;
 				return k < l;
 			},
 			next : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					var n = this.x[k];
+					var n = __this__.x[k];
 					k += 1;
 					if( n.nodeType == Xml.Element ) {
-						this.cur = k;
+						__this__.cur = k;
 						return n;
 					}
 				}
@@ -287,25 +287,25 @@ enum XmlType {
 			cur: 0,
 			x: this._children,
 			hasNext : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					var n = this.x[k];
+					var n = __this__.x[k];
 					if( n.nodeType == Xml.Element && n._nodeName == name )
 						break;
 					k++;
 				}
-				this.cur = k;
+				__this__.cur = k;
 				return k < l;
 			},
 			next : function() {
-				var k = this.cur;
-				var l = this.x.length;
+				var k = __this__.cur;
+				var l = __this__.x.length;
 				while( k < l ) {
-					var n = this.x[k];
+					var n = __this__.x[k];
 					k++;
 					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						this.cur = k;
+						__this__.cur = k;
 						return n;
 					}
 				}

+ 2 - 2
std/neko/db/MacroManager.hx

@@ -422,7 +422,7 @@ class MacroManager<T : Object> {
 		if( manager == null || manager.table_keys == null ) throw ("Invalid manager for relation "+table_name+":"+r.prop);
 		if( manager.table_keys.length != 1 ) throw ("Relation " + r.prop + "(" + r.key + ") on a multiple key table");
 		Reflect.setField(class_proto.prototype,"get_"+r.prop,function() {
-			var othis = untyped this;
+			var othis = untyped __this__;
 			var f = Reflect.field(othis,hprop);
 			if( f != null )
 				return f;
@@ -439,7 +439,7 @@ class MacroManager<T : Object> {
 			return f;
 		});
 		Reflect.setField(class_proto.prototype,"set_"+r.prop,function(f) {
-			var othis = untyped this;
+			var othis = untyped __this__;
 			Reflect.setField(othis,hprop,f);
 			Reflect.setField(othis,hkey,Reflect.field(f,manager.table_keys[0]));
 			return f;

+ 2 - 2
std/neko/db/Manager.hx

@@ -467,7 +467,7 @@ class Manager<T : Object> {
 		if( manager == null || manager.table_keys == null ) throw ("Invalid manager for relation "+table_name+":"+r.prop);
 		if( manager.table_keys.length != 1 ) throw ("Relation "+r.prop+"("+r.key+") on a multiple key table");
 		Reflect.setField(class_proto.prototype,"get_"+r.prop,function() {
-			var othis = untyped this;
+			var othis = untyped __this__;
 			var f = Reflect.field(othis,hprop);
 			if( f != null )
 				return f;
@@ -482,7 +482,7 @@ class Manager<T : Object> {
 			return f;
 		});
 		Reflect.setField(class_proto.prototype,"set_"+r.prop,function(f) {
-			var othis = untyped this;
+			var othis = untyped __this__;
 			Reflect.setField(othis,hprop,f);
 			Reflect.setField(othis,hkey,Reflect.field(f,manager.table_keys[0]));
 			return f;

+ 2 - 2
std/neko/db/Types.hx

@@ -58,10 +58,10 @@ extern class SFlags<T> {
 		return (cast this) & (1 << Type.enumIndex(v)) != 0;
 	}
 	public inline function set( v : T ) : Void {
-		untyped this |= 1 << Type.enumIndex(v);
+		untyped __this__ |= 1 << Type.enumIndex(v);
 	}
 	public inline function unset( v : T ) : Void {
-		untyped this &= 0xFFFFFFF - (1 << Type.enumIndex(v));
+		untyped __this__ &= 0xFFFFFFF - (1 << Type.enumIndex(v));
 	}
 	public inline static function ofInt<T>( i : Int ) : SFlags<T> {
 		return cast i;

+ 9 - 6
typer.ml

@@ -458,8 +458,8 @@ let type_ident ctx i is_type p mode =
 		else
 			AKNo i
 	| "this" ->
-		if not ctx.untyped && ctx.in_static then error "Cannot access this from a static function" p;
-		if mode = MGet || ctx.untyped then
+		if ctx.in_static then display_error ctx "Cannot access this from a static function" p;
+		if mode = MGet then
 			AKExpr (mk (TConst TThis) ctx.tthis p)
 		else
 			AKNo i
@@ -530,10 +530,13 @@ let type_ident ctx i is_type p mode =
 		let e = (try type_type ctx ([],i) p with Error (Module_not_found ([],name),_) when name = i -> raise Not_found) in
 		AKExpr e
 	with Not_found ->
-		if ctx.untyped then
-			let t = mk_mono() in
-			AKExpr (mk (TLocal (alloc_var i t)) t p)
-		else begin
+		if ctx.untyped then begin
+			if i = "__this__" then
+				AKExpr (mk (TConst TThis) ctx.tthis p)
+			else
+				let t = mk_mono() in
+				AKExpr (mk (TLocal (alloc_var i t)) t p)
+		end else begin
 			if ctx.in_static && PMap.mem i ctx.curclass.cl_fields then error ("Cannot access " ^ i ^ " in static function") p;
 			raise (Error (Unknown_ident i,p))
 		end