Chromium Code Reviews| 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. | |
|
Jennifer Messerly
2011/12/08 18:43:52
might want to add a note that this is for the $inh
| |
| 236 if (type.parent != null && !type.isNative) | |
|
Jennifer Messerly
2011/12/08 18:43:52
style nit: add { } around the body unless the enti
| |
| 237 writeType(type.parent); | |
| 238 | |
| 231 // TODO(jimhug): Workaround for problems with reified generic Array. | 239 // TODO(jimhug): Workaround for problems with reified generic Array. |
| 232 if (type.name != null && type is ConcreteType && | 240 if (type.name != null && type is ConcreteType && |
| 233 type.library == world.coreimpl && | 241 type.library == world.coreimpl && |
| 234 type.name.startsWith('ListFactory')) { | 242 type.name.startsWith('ListFactory')) { |
| 235 writer.writeln('${type.jsname} = ${type.genericType.jsname};'); | 243 writer.writeln('${type.jsname} = ${type.genericType.jsname};'); |
| 236 return; | 244 return; |
| 237 } | 245 } |
| 238 | 246 |
| 239 var typeName = type.jsname != null ? type.jsname : 'top level'; | 247 var typeName = type.jsname != null ? type.jsname : 'top level'; |
| 240 writer.comment('// ********** Code for ${typeName} **************'); | 248 writer.comment('// ********** Code for ${typeName} **************'); |
| 241 if (type.isNative && !type.isTop) { | 249 if (type.isNative && !type.isTop) { |
| 242 var nativeName = type.definition.nativeType.name; | 250 var nativeName = type.definition.nativeType.name; |
| 243 if (nativeName == '') { | 251 if (nativeName == '') { |
| 244 writer.writeln('function ${type.jsname}() {}'); | 252 writer.writeln('function ${type.jsname}() {}'); |
| 245 } else if (type.jsname != nativeName) { | 253 } else if (type.jsname != nativeName) { |
| 246 writer.writeln('${type.jsname} = ${nativeName};'); | 254 writer.writeln('${type.jsname} = ${nativeName};'); |
| 247 } | 255 } |
| 248 } | 256 } |
| 249 | 257 |
| 258 if (!type.isTop) { | |
|
Jennifer Messerly
2011/12/08 18:43:52
maybe add a note here that $inherits needs to come
| |
| 259 if (type is ConcreteType) { | |
| 260 ConcreteType c = type; | |
| 261 corejs.ensureInheritsHelper(); | |
| 262 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});'); | |
| 263 | |
| 264 // Mixin members from concrete specializations of base types too. | |
| 265 // TODO(jmesserly): emit this sooner instead of at the end. | |
| 266 // But it needs to come after we've emitted both types. | |
| 267 // TODO(jmesserly): HACK: using _parent instead of parent so we don't | |
| 268 // try to inherit things that we didn't actually use. | |
| 269 for (var p = c._parent; p is ConcreteType; p = p._parent) { | |
| 270 _ensureInheritMembersHelper(); | |
| 271 _mixins.writeln('\$inheritsMembers(${c.jsname}, ${p.jsname});'); | |
| 272 } | |
| 273 } else if (!type.isNative) { | |
| 274 if (type.parent != null && !type.parent.isObject) { | |
| 275 corejs.ensureInheritsHelper(); | |
| 276 writer.writeln('\$inherits(${type.jsname}, ${type.parent.jsname});'); | |
| 277 } | |
| 278 } | |
| 279 } | |
| 280 | |
| 250 if (type.isTop) { | 281 if (type.isTop) { |
| 251 // no preludes for top type | 282 // no preludes for top type |
| 252 } else if (type.constructors.length == 0) { | 283 } else if (type.constructors.length == 0) { |
| 253 if (!type.isNative) { | 284 if (!type.isNative) { |
| 254 // TODO(jimhug): More guards to guarantee staticness | 285 // TODO(jimhug): More guards to guarantee staticness |
| 255 writer.writeln('function ${type.jsname}() {}'); | 286 writer.writeln('function ${type.jsname}() {}'); |
| 256 } | 287 } |
| 257 } else { | 288 } else { |
| 258 Member standardConstructor = type.constructors['']; | 289 Member standardConstructor = type.constructors['']; |
| 259 if (standardConstructor == null || | 290 if (standardConstructor == null || |
| 260 standardConstructor.generator == null) { | 291 standardConstructor.generator == null) { |
| 261 if (!type.isNative) { | 292 if (!type.isNative) { |
| 262 writer.writeln('function ${type.jsname}() {}'); | 293 writer.writeln('function ${type.jsname}() {}'); |
| 263 } | 294 } |
| 264 } else { | 295 } else { |
| 265 standardConstructor.generator.writeDefinition(writer, null); | 296 standardConstructor.generator.writeDefinition(writer, null); |
| 266 } | 297 } |
| 267 | 298 |
| 268 for (var c in type.constructors.getValues()) { | 299 for (var c in type.constructors.getValues()) { |
| 269 if (c.generator != null && c != standardConstructor) { | 300 if (c.generator != null && c != standardConstructor) { |
| 270 c.generator.writeDefinition(writer, null); | 301 c.generator.writeDefinition(writer, null); |
| 271 } | 302 } |
| 272 } | 303 } |
| 273 } | 304 } |
| 274 | 305 |
| 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 | 306 // Concrete types (like List<String>) will have this already defined on |
| 299 // their prototype from the generic type (like List) | 307 // their prototype from the generic type (like List) |
| 300 if (type is! ConcreteType) { | 308 if (type is! ConcreteType) { |
| 301 _maybeIsTest(type, type); | 309 _maybeIsTest(type, type); |
| 302 } | 310 } |
| 303 if (type.genericType._concreteTypes != null) { | 311 if (type.genericType._concreteTypes != null) { |
| 304 for (var ct in _orderValues(type.genericType._concreteTypes)) { | 312 for (var ct in _orderValues(type.genericType._concreteTypes)) { |
| 305 _maybeIsTest(type, ct); | 313 _maybeIsTest(type, ct); |
| 306 } | 314 } |
| 307 } | 315 } |
| (...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2473 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); | 2481 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2474 } | 2482 } |
| 2475 for (int i = bareCount; i < length; i++) { | 2483 for (int i = bareCount; i < length; i++) { |
| 2476 var name = getName(i); | 2484 var name = getName(i); |
| 2477 if (name == null) name = '\$$i'; | 2485 if (name == null) name = '\$$i'; |
| 2478 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2486 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2479 } | 2487 } |
| 2480 return new Arguments(nodes, result); | 2488 return new Arguments(nodes, result); |
| 2481 } | 2489 } |
| 2482 } | 2490 } |
| OLD | NEW |