Chromium Code Reviews| Index: compiler/lib/implementation/rtt.js |
| diff --git a/compiler/lib/implementation/rtt.js b/compiler/lib/implementation/rtt.js |
| index 83179d3dfa46193a18563e04bcd62f1eaa1ee3dc..32f06e4ce1be3d056ea2c0f400eba005bff7edab 100644 |
| --- a/compiler/lib/implementation/rtt.js |
| +++ b/compiler/lib/implementation/rtt.js |
| @@ -10,16 +10,20 @@ |
| * @param {string} classkey |
| * @param {string=} typekey |
| * @param {Array.<RTT>=} typeargs |
| + * @param {RTT} returnType |
| + * @param {bool} functionType |
| */ |
| -function RTT(classkey, typekey, typeargs) { |
| +function RTT(classkey, typekey, typeargs, returnType, functionType) { |
| this.classKey = classkey; |
| this.typeKey = typekey ? typekey : classkey; |
| this.typeArgs = typeargs; |
| + this.returnType = returnType; // key for the return type |
| this.implementedTypes = {}; |
| + this.functionType = functionType; |
| // Add self |
| this.implementedTypes[classkey] = this; |
| // Add Object |
| - if (classkey != $cls('Object')) { |
| + if (!functionType && classkey != $cls('Object')) { |
| this.implementedTypes[$cls('Object')] = RTT.objectType; |
| } |
| } |
| @@ -39,6 +43,7 @@ RTT.prototype.toString = function() { return this.typeKey; } |
| */ |
| RTT.prototype.implementedBy = function(value){ |
| return (value == null) ? RTT.nullInstanceOf(this) : |
| + this.functionType ? this.implementedByTypeFunc(value) : |
| this.implementedByType(RTT.getTypeInfo(value)); |
| }; |
| @@ -76,6 +81,43 @@ RTT.prototype.implementedByType = function(otherType) { |
| }; |
| /** |
| + * @param {!RTT} other |
| + * @return {boolean} Whether this type is implement by other |
| + */ |
| +RTT.prototype.implementedByTypeFunc = function(otherType) { |
| + if (otherType === this || otherType === RTT.dynamicType) { |
| + return true; |
| + } |
| + var found = true; |
| + var props = Object.getOwnPropertyNames(otherType.implementedTypes); |
| + for (var i = 0 ; i < props.length; i++) { |
| + found = true; |
| + var mapped = otherType.implementedTypes[props[i]]; |
| + if (mapped.returnType && this.returnType) { |
| + if (!this.returnType.implementedByType(mapped.returnType)) { |
| + continue; |
| + } |
| + } else if (mapped.returnType || this.returnType) { |
| + continue; //handles mixed undef/defined. undef/undef falls through |
| + } |
| + if (mapped.typeArgs && this.typeArgs) { |
| + for(var i = this.typeArgs.length - 1; i >= 0; i--) { |
|
zundel
2011/11/08 15:28:42
you are re-using 'i' here, its already used as an
codefu
2011/11/14 19:33:40
Done.
|
| + if (!this.typeArgs[i].implementedByType(mapped.typeArgs[i])) { |
| + found = false; |
| + break; // fall through and search the next property |
|
zundel
2011/11/08 15:28:42
So, one of the type args doesn't match. From what
codefu
2011/11/14 19:33:40
I've changed this around a little in the new patch
|
| + } |
| + } |
| + } else if (mapped.typeArgs || this.typeArgs) { |
| + continue; //handles mixed undef/defined. undef/undef falls through |
| + } |
| + if ( found == true ) { |
| + return true; |
| + } |
| + } |
| + return false; |
| +}; |
| + |
| +/** |
| * @return {string} the class name associated with this type |
| */ |
| RTT.prototype.getClassName = function() { |
| @@ -115,19 +157,21 @@ RTT.getNativeTypeInfo = function(value) { |
| * @param {string} name |
| * @param {function(RTT,Array.<RTT>)=} implementsSupplier |
| * @param {Array.<RTT>=} typeArgs |
| + * @param {<RTT>=} returnType (if defined) |
| + * @param {bool} type is a function |
| * @return {RTT} The RTT information object |
| */ |
| -RTT.create = function(name, implementsSupplier, typeArgs) { |
| +RTT.create = function(name, implementsSupplier, typeArgs, returnType, funtionType) { |
| if (name == $cls("Object")) return RTT.objectType; |
| - var typekey = RTT.getTypeKey(name, typeArgs); |
| + var typekey = RTT.getTypeKey(name, typeArgs, returnType); |
| var rtt = $mapLookup(RTT.types, typekey); |
| if (rtt) { |
| return rtt; |
| } |
| var classkey = RTT.getTypeKey(name); |
| - rtt = new RTT(classkey, typekey, typeArgs); |
| + rtt = new RTT(classkey, typekey, typeArgs, returnType, funtionType); |
| RTT.types[typekey] = rtt; |
| - if (implementsSupplier) { |
| + if (!funtionType && implementsSupplier) { |
| implementsSupplier(rtt, typeArgs); |
| } |
| return rtt; |
| @@ -136,13 +180,17 @@ RTT.create = function(name, implementsSupplier, typeArgs) { |
| /** |
| * @param {string} classkey |
| * @param {Array.<(RTT|string)>=} typeargs |
| + * @param {string} returntype |
| * @return {string} |
| */ |
| -RTT.getTypeKey = function(classkey, typeargs) { |
| +RTT.getTypeKey = function(classkey, typeargs, returntype) { |
| var key = classkey; |
| if (typeargs) { |
| key += "<" + typeargs.join(",") + ">"; |
| } |
| + if (returntype) { |
| + key += "-><" + returntype + ">"; |
| + } |
| return key; |
| }; |