| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.new_js_emitter.model; | 5 library dart2js.new_js_emitter.model; |
| 6 | 6 |
| 7 import '../js/js.dart' as js show Expression; | 7 import '../js/js.dart' as js show Expression; |
| 8 import '../constants/values.dart' show ConstantValue; | 8 import '../constants/values.dart' show ConstantValue; |
| 9 | 9 |
| 10 import '../deferred_load.dart' show OutputUnit; | 10 import '../deferred_load.dart' show OutputUnit; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 Method(this.element, this.name, this.code); | 327 Method(this.element, this.name, this.code); |
| 328 } | 328 } |
| 329 | 329 |
| 330 /** | 330 /** |
| 331 * A method that corresponds to a method in the original Dart program. | 331 * A method that corresponds to a method in the original Dart program. |
| 332 */ | 332 */ |
| 333 class DartMethod extends Method { | 333 class DartMethod extends Method { |
| 334 final bool needsTearOff; | 334 final bool needsTearOff; |
| 335 final String tearOffName; | 335 final String tearOffName; |
| 336 // TODO(herhut): Directly store stubs instead/ | 336 final List<ParameterStubMethod> parameterStubs; |
| 337 final bool needsStubs; | |
| 338 // TODO(herhut): Directly store aliases instead. | 337 // TODO(herhut): Directly store aliases instead. |
| 339 final bool canBeApplied; | 338 final bool canBeApplied; |
| 340 final bool canBeReflected; | 339 final bool canBeReflected; |
| 341 | 340 |
| 342 DartMethod(Element element, String name, js.Expression code, | 341 DartMethod(Element element, String name, js.Expression code, |
| 343 {this.needsTearOff, this.tearOffName, this.needsStubs, this.canBeApplied, | 342 {this.needsTearOff, this.tearOffName, this.parameterStubs, |
| 344 this.canBeReflected}) | 343 this.canBeApplied, this.canBeReflected}) |
| 345 : super(element, name, code) { | 344 : super(element, name, code) { |
| 346 assert(needsTearOff != null); | 345 assert(needsTearOff != null); |
| 347 assert(!needsTearOff || tearOffName != null); | 346 assert(!needsTearOff || tearOffName != null); |
| 348 assert(canBeApplied != null); | 347 assert(canBeApplied != null); |
| 348 assert(parameterStubs != null); |
| 349 assert(canBeReflected != null); | 349 assert(canBeReflected != null); |
| 350 assert(needsStubs != null); | |
| 351 } | 350 } |
| 352 } | 351 } |
| 353 | 352 |
| 354 class InstanceMethod extends DartMethod { | 353 class InstanceMethod extends DartMethod { |
| 355 // TODO(herhut): Directly store aliases instead. | 354 // TODO(herhut): Directly store aliases instead. |
| 356 final bool hasSuperAlias; | 355 final bool hasSuperAlias; |
| 357 final bool isClosure; | 356 final bool isClosure; |
| 358 | 357 |
| 359 InstanceMethod(element, name, code, | 358 InstanceMethod(element, name, code, |
| 360 {bool needsTearOff, | 359 {bool needsTearOff, |
| 361 String tearOffName, | 360 String tearOffName, |
| 362 this.hasSuperAlias, | 361 this.hasSuperAlias, |
| 363 bool canBeApplied, | 362 bool canBeApplied, |
| 364 bool canBeReflected, | 363 bool canBeReflected, |
| 365 this.isClosure, | 364 this.isClosure, |
| 366 bool needsStubs}) | 365 List<ParameterStubMethod> parameterStubs}) |
| 367 : super(element, name, code, | 366 : super(element, name, code, |
| 368 needsTearOff: needsTearOff, | 367 needsTearOff: needsTearOff, |
| 369 tearOffName: tearOffName, | 368 tearOffName: tearOffName, |
| 370 canBeApplied: canBeApplied, | 369 canBeApplied: canBeApplied, |
| 371 canBeReflected: canBeReflected, | 370 canBeReflected: canBeReflected, |
| 372 needsStubs: needsStubs) { | 371 parameterStubs: parameterStubs) { |
| 373 assert(hasSuperAlias != null); | 372 assert(hasSuperAlias != null); |
| 374 assert(isClosure != null); | 373 assert(isClosure != null); |
| 375 } | 374 } |
| 376 } | 375 } |
| 377 | 376 |
| 378 /** | 377 /** |
| 379 * A method that is generated by the backend and has not direct correspondence | 378 * A method that is generated by the backend and has not direct correspondence |
| 380 * to a method in the original Dart program. Examples are getter and setter | 379 * to a method in the original Dart program. Examples are getter and setter |
| 381 * stubs and stubs to dispatch calls to methods with optional parameters. | 380 * stubs and stubs to dispatch calls to methods with optional parameters. |
| 382 */ | 381 */ |
| 383 class StubMethod extends Method { | 382 class StubMethod extends Method { |
| 384 StubMethod(String name, js.Expression code, | 383 StubMethod(String name, js.Expression code, |
| 385 {Element element}) | 384 {Element element}) |
| 386 : super(element, name, code); | 385 : super(element, name, code); |
| 387 } | 386 } |
| 388 | 387 |
| 388 /** |
| 389 * A method that is generated for the different versions of method calls of |
| 390 * methods with named parameters, |
| 391 * |
| 392 * For example for a method foo(a, b, {c, d}) that is called as foo(1, 2, c: 3) |
| 393 * we have the stub foo$3$c(a, b, c) => foo$4$c$d(a, b, c, null); |
| 394 */ |
| 395 class ParameterStubMethod extends StubMethod { |
| 396 final Selector selector; |
| 397 ParameterStubMethod(String name, js.Expression code, this.selector, |
| 398 {Element element}) |
| 399 : super(name, code, element: element); |
| 400 } |
| 401 |
| 389 abstract class StaticMethod implements Method { | 402 abstract class StaticMethod implements Method { |
| 390 Holder get holder; | 403 Holder get holder; |
| 391 } | 404 } |
| 392 | 405 |
| 393 class StaticDartMethod extends DartMethod implements StaticMethod { | 406 class StaticDartMethod extends DartMethod implements StaticMethod { |
| 394 final Holder holder; | 407 final Holder holder; |
| 395 | |
| 396 StaticDartMethod(Element element, String name, this.holder, | 408 StaticDartMethod(Element element, String name, this.holder, |
| 397 js.Expression code, | 409 js.Expression code, |
| 398 {bool needsTearOff, String tearOffName, bool canBeApplied, | 410 {bool needsTearOff, String tearOffName, bool canBeApplied, |
| 399 bool canBeReflected, bool needsStubs}) | 411 bool canBeReflected, List<StubMethod> parameterStubs}) |
| 400 : super(element, name, code, | 412 : super(element, name, code, |
| 401 needsTearOff: needsTearOff, | 413 needsTearOff: needsTearOff, |
| 402 tearOffName : tearOffName, | 414 tearOffName : tearOffName, |
| 403 canBeApplied : canBeApplied, | 415 canBeApplied : canBeApplied, |
| 404 canBeReflected : canBeReflected, | 416 canBeReflected : canBeReflected, |
| 405 needsStubs : needsStubs); | 417 parameterStubs : parameterStubs); |
| 406 } | 418 } |
| 407 | 419 |
| 408 class StaticStubMethod extends StubMethod implements StaticMethod { | 420 class StaticStubMethod extends StubMethod implements StaticMethod { |
| 409 Holder holder; | 421 Holder holder; |
| 410 StaticStubMethod(String name, this.holder, js.Expression code) | 422 StaticStubMethod(String name, this.holder, js.Expression code) |
| 411 : super(name, code); | 423 : super(name, code); |
| 412 } | 424 } |
| OLD | NEW |