| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Top level generator object for writing code and keeping track of | 6 * Top level generator object for writing code and keeping track of |
| 7 * dependencies. | 7 * dependencies. |
| 8 * | 8 * |
| 9 * Should have two compilation models, but only one implemented so far. | 9 * Should have two compilation models, but only one implemented so far. |
| 10 * | 10 * |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 body = world.objectType.varStubs[checkName].body; | 221 body = world.objectType.varStubs[checkName].body; |
| 222 } else if (onType.name == 'StringImplementation' || | 222 } else if (onType.name == 'StringImplementation' || |
| 223 onType.name == 'NumImplementation') { | 223 onType.name == 'NumImplementation') { |
| 224 body = 'return ${onType.nativeType.name}(this)'; | 224 body = 'return ${onType.nativeType.name}(this)'; |
| 225 } | 225 } |
| 226 writer.writeln(_prototypeOf(onType, checkName) + ' = function(){$body};'); | 226 writer.writeln(_prototypeOf(onType, checkName) + ' = function(){$body};'); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 writeType(Type type) { | 230 writeType(Type type) { |
| 231 if (type.isWritten) return; |
| 232 |
| 233 type.isWritten = true; |
| 234 // Ensure parent has been written before the child. Important ordering for |
| 235 // IE when we're using $inherits, since we don't have __proto__ available. |
| 236 if (type.parent != null && !type.isNative) { |
| 237 writeType(type.parent); |
| 238 } |
| 239 |
| 231 // TODO(jimhug): Workaround for problems with reified generic Array. | 240 // TODO(jimhug): Workaround for problems with reified generic Array. |
| 232 if (type.name != null && type is ConcreteType && | 241 if (type.name != null && type is ConcreteType && |
| 233 type.library == world.coreimpl && | 242 type.library == world.coreimpl && |
| 234 type.name.startsWith('ListFactory')) { | 243 type.name.startsWith('ListFactory')) { |
| 235 writer.writeln('${type.jsname} = ${type.genericType.jsname};'); | 244 writer.writeln('${type.jsname} = ${type.genericType.jsname};'); |
| 236 return; | 245 return; |
| 237 } | 246 } |
| 238 | 247 |
| 239 var typeName = type.jsname != null ? type.jsname : 'top level'; | 248 var typeName = type.jsname != null ? type.jsname : 'top level'; |
| 240 writer.comment('// ********** Code for ${typeName} **************'); | 249 writer.comment('// ********** Code for ${typeName} **************'); |
| 241 if (type.isNative && !type.isTop) { | 250 if (type.isNative && !type.isTop) { |
| 242 var nativeName = type.definition.nativeType.name; | 251 var nativeName = type.definition.nativeType.name; |
| 243 if (nativeName == '') { | 252 if (nativeName == '') { |
| 244 writer.writeln('function ${type.jsname}() {}'); | 253 writer.writeln('function ${type.jsname}() {}'); |
| 245 } else if (type.jsname != nativeName) { | 254 } else if (type.jsname != nativeName) { |
| 246 writer.writeln('${type.jsname} = ${nativeName};'); | 255 writer.writeln('${type.jsname} = ${nativeName};'); |
| 247 } | 256 } |
| 248 } | 257 } |
| 249 | 258 |
| 259 // We need the $inherits function to be declared before factory constructors |
| 260 // so that inheritance ($inherits) will work correctly in IE. |
| 261 if (!type.isTop) { |
| 262 if (type is ConcreteType) { |
| 263 ConcreteType c = type; |
| 264 corejs.ensureInheritsHelper(); |
| 265 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});'); |
| 266 |
| 267 // Mixin members from concrete specializations of base types too. |
| 268 // TODO(jmesserly): emit this sooner instead of at the end. |
| 269 // But it needs to come after we've emitted both types. |
| 270 // TODO(jmesserly): HACK: using _parent instead of parent so we don't |
| 271 // try to inherit things that we didn't actually use. |
| 272 for (var p = c._parent; p is ConcreteType; p = p._parent) { |
| 273 _ensureInheritMembersHelper(); |
| 274 _mixins.writeln('\$inheritsMembers(${c.jsname}, ${p.jsname});'); |
| 275 } |
| 276 } else if (!type.isNative) { |
| 277 if (type.parent != null && !type.parent.isObject) { |
| 278 corejs.ensureInheritsHelper(); |
| 279 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});'); |
| 280 } |
| 281 } |
| 282 } |
| 283 |
| 250 if (type.isTop) { | 284 if (type.isTop) { |
| 251 // no preludes for top type | 285 // no preludes for top type |
| 252 } else if (type.constructors.length == 0) { | 286 } else if (type.constructors.length == 0) { |
| 253 if (!type.isNative) { | 287 if (!type.isNative) { |
| 254 // TODO(jimhug): More guards to guarantee staticness | 288 // TODO(jimhug): More guards to guarantee staticness |
| 255 writer.writeln('function ${type.jsname}() {}'); | 289 writer.writeln('function ${type.jsname}() {}'); |
| 256 } | 290 } |
| 257 } else { | 291 } else { |
| 258 Member standardConstructor = type.constructors['']; | 292 Member standardConstructor = type.constructors['']; |
| 259 if (standardConstructor == null || | 293 if (standardConstructor == null || |
| 260 standardConstructor.generator == null) { | 294 standardConstructor.generator == null) { |
| 261 if (!type.isNative) { | 295 if (!type.isNative) { |
| 262 writer.writeln('function ${type.jsname}() {}'); | 296 writer.writeln('function ${type.jsname}() {}'); |
| 263 } | 297 } |
| 264 } else { | 298 } else { |
| 265 standardConstructor.generator.writeDefinition(writer, null); | 299 standardConstructor.generator.writeDefinition(writer, null); |
| 266 } | 300 } |
| 267 | 301 |
| 268 for (var c in type.constructors.getValues()) { | 302 for (var c in type.constructors.getValues()) { |
| 269 if (c.generator != null && c != standardConstructor) { | 303 if (c.generator != null && c != standardConstructor) { |
| 270 c.generator.writeDefinition(writer, null); | 304 c.generator.writeDefinition(writer, null); |
| 271 } | 305 } |
| 272 } | 306 } |
| 273 } | 307 } |
| 274 | 308 |
| 275 if (!type.isTop) { | |
| 276 if (type is ConcreteType) { | |
| 277 ConcreteType c = type; | |
| 278 corejs.ensureInheritsHelper(); | |
| 279 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});'); | |
| 280 | |
| 281 // Mixin members from concrete specializations of base types too. | |
| 282 // TODO(jmesserly): emit this sooner instead of at the end. | |
| 283 // But it needs to come after we've emitted both types. | |
| 284 // TODO(jmesserly): HACK: using _parent instead of parent so we don't | |
| 285 // try to inherit things that we didn't actually use. | |
| 286 for (var p = c._parent; p is ConcreteType; p = p._parent) { | |
| 287 _ensureInheritMembersHelper(); | |
| 288 _mixins.writeln('\$inheritsMembers(${c.jsname}, ${p.jsname});'); | |
| 289 } | |
| 290 } else if (!type.isNative) { | |
| 291 if (type.parent != null && !type.parent.isObject) { | |
| 292 corejs.ensureInheritsHelper(); | |
| 293 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});'); | |
| 294 } | |
| 295 } | |
| 296 } | |
| 297 | |
| 298 // Concrete types (like List<String>) will have this already defined on | 309 // Concrete types (like List<String>) will have this already defined on |
| 299 // their prototype from the generic type (like List) | 310 // their prototype from the generic type (like List) |
| 300 if (type is! ConcreteType) { | 311 if (type is! ConcreteType) { |
| 301 _maybeIsTest(type, type); | 312 _maybeIsTest(type, type); |
| 302 } | 313 } |
| 303 if (type.genericType._concreteTypes != null) { | 314 if (type.genericType._concreteTypes != null) { |
| 304 for (var ct in _orderValues(type.genericType._concreteTypes)) { | 315 for (var ct in _orderValues(type.genericType._concreteTypes)) { |
| 305 _maybeIsTest(type, ct); | 316 _maybeIsTest(type, ct); |
| 306 } | 317 } |
| 307 } | 318 } |
| (...skipping 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2487 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); | 2498 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2488 } | 2499 } |
| 2489 for (int i = bareCount; i < length; i++) { | 2500 for (int i = bareCount; i < length; i++) { |
| 2490 var name = getName(i); | 2501 var name = getName(i); |
| 2491 if (name == null) name = '\$$i'; | 2502 if (name == null) name = '\$$i'; |
| 2492 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2503 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2493 } | 2504 } |
| 2494 return new Arguments(nodes, result); | 2505 return new Arguments(nodes, result); |
| 2495 } | 2506 } |
| 2496 } | 2507 } |
| OLD | NEW |