| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 new MethodGenerator(meth, enclosingMethod).run(); | 212 new MethodGenerator(meth, enclosingMethod).run(); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 String _prototypeOf(Type type, String name) { | 216 String _prototypeOf(Type type, String name) { |
| 217 if (type.isSingletonNative) { | 217 if (type.isSingletonNative) { |
| 218 // e.g. window.console.log$1 | 218 // e.g. window.console.log$1 |
| 219 return '${type.jsname}.$name'; | 219 return '${type.jsname}.$name'; |
| 220 } else if (type.isHiddenNativeType) { | 220 } else if (type.isHiddenNativeType) { |
| 221 corejs.ensureDynamicProto(); | 221 corejs.ensureDynamicProto(); |
| 222 return '\$dynamic("$name").${type.jsname}'; | 222 return '\$dynamic("$name").${type.definition.nativeType.name}'; |
| 223 } else { | 223 } else { |
| 224 return '${type.jsname}.prototype.$name'; | 224 return '${type.jsname}.prototype.$name'; |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 _maybeIsTest(Type onType, Type checkType) { | 228 _maybeIsTest(Type onType, Type checkType) { |
| 229 bool isSubtype = onType.isSubtypeOf(checkType); | 229 bool isSubtype = onType.isSubtypeOf(checkType); |
| 230 if (checkType.isTested) { | 230 if (checkType.isTested) { |
| 231 // TODO(jmesserly): cache these functions? they just return true or false. | 231 // TODO(jmesserly): cache these functions? they just return true or false. |
| 232 writer.writeln(_prototypeOf(onType, 'is\$${checkType.jsname}') | 232 writer.writeln(_prototypeOf(onType, 'is\$${checkType.jsname}') |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 return; | 267 return; |
| 268 } | 268 } |
| 269 | 269 |
| 270 var typeName = type.jsname != null ? type.jsname : 'top level'; | 270 var typeName = type.jsname != null ? type.jsname : 'top level'; |
| 271 writer.comment('// ********** Code for ${typeName} **************'); | 271 writer.comment('// ********** Code for ${typeName} **************'); |
| 272 if (type.isNative && !type.isTop) { | 272 if (type.isNative && !type.isTop) { |
| 273 var nativeName = type.definition.nativeType.name; | 273 var nativeName = type.definition.nativeType.name; |
| 274 if (nativeName == '') { | 274 if (nativeName == '') { |
| 275 writer.writeln('function ${type.jsname}() {}'); | 275 writer.writeln('function ${type.jsname}() {}'); |
| 276 } else if (type.jsname != nativeName) { | 276 } else if (type.jsname != nativeName) { |
| 277 writer.writeln('${type.jsname} = ${nativeName};'); | 277 if (type.isHiddenNativeType) { |
| 278 // This is a holder for static methods. |
| 279 // TODO(sra): Generate only if used. |
| 280 writer.writeln('function ${type.jsname}() {}'); |
| 281 } else { |
| 282 writer.writeln('${type.jsname} = ${nativeName};'); |
| 283 } |
| 278 } | 284 } |
| 279 } | 285 } |
| 280 | 286 |
| 281 // We need the $inherits function to be declared before factory constructors | 287 // We need the $inherits function to be declared before factory constructors |
| 282 // so that inheritance ($inherits) will work correctly in IE. | 288 // so that inheritance ($inherits) will work correctly in IE. |
| 283 if (!type.isTop) { | 289 if (!type.isTop) { |
| 284 if (type is ConcreteType) { | 290 if (type is ConcreteType) { |
| 285 ConcreteType c = type; | 291 ConcreteType c = type; |
| 286 corejs.ensureInheritsHelper(); | 292 corejs.ensureInheritsHelper(); |
| 287 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});'); | 293 writer.writeln('\$inherits(${c.jsname}, ${c.genericType.jsname});'); |
| (...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2545 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); | 2551 result.add(new Value(world.varType, '\$$i', null, /*needsTemp:*/false)); |
| 2546 } | 2552 } |
| 2547 for (int i = bareCount; i < length; i++) { | 2553 for (int i = bareCount; i < length; i++) { |
| 2548 var name = getName(i); | 2554 var name = getName(i); |
| 2549 if (name == null) name = '\$$i'; | 2555 if (name == null) name = '\$$i'; |
| 2550 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); | 2556 result.add(new Value(world.varType, name, null, /*needsTemp:*/false)); |
| 2551 } | 2557 } |
| 2552 return new Arguments(nodes, result); | 2558 return new Arguments(nodes, result); |
| 2553 } | 2559 } |
| 2554 } | 2560 } |
| OLD | NEW |