| 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, Statement; | 7 import '../js/js.dart' as js show Expression, Statement; |
| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 Method(this.element, this.name, this.code); | 340 Method(this.element, this.name, this.code); |
| 341 } | 341 } |
| 342 | 342 |
| 343 /// A method that corresponds to a method in the original Dart program. | 343 /// A method that corresponds to a method in the original Dart program. |
| 344 class DartMethod extends Method { | 344 class DartMethod extends Method { |
| 345 final bool needsTearOff; | 345 final bool needsTearOff; |
| 346 final String tearOffName; | 346 final String tearOffName; |
| 347 final List<ParameterStubMethod> parameterStubs; | 347 final List<ParameterStubMethod> parameterStubs; |
| 348 final bool canBeApplied; | 348 final bool canBeApplied; |
| 349 final bool canBeReflected; | 349 final bool canBeReflected; |
| 350 final DartType type; | 350 |
| 351 // Is non-null if [needsTearOff] or [canBeReflected]. |
| 352 // |
| 353 // If the type is encoded in the metadata table this field contains an index |
| 354 // into the table. Otherwise the type contains type variables in which case |
| 355 // this field holds a function computing the function signature. |
| 356 final js.Expression functionType; |
| 351 | 357 |
| 352 // Signature information for this method. This is only required and stored | 358 // Signature information for this method. This is only required and stored |
| 353 // here if the method [canBeApplied] or [canBeReflected] | 359 // here if the method [canBeApplied] or [canBeReflected] |
| 354 final int requiredParameterCount; | 360 final int requiredParameterCount; |
| 355 final /* Map | List */ optionalParameterDefaultValues; | 361 final /* Map | List */ optionalParameterDefaultValues; |
| 356 | 362 |
| 357 // If this method can be torn off, contains the name of the corresponding | 363 // If this method can be torn off, contains the name of the corresponding |
| 358 // call method. For example, for the member `foo$1$name` it would be | 364 // call method. For example, for the member `foo$1$name` it would be |
| 359 // `call$1$name` (in unminified mode). | 365 // `call$1$name` (in unminified mode). |
| 360 final String callName; | 366 final String callName; |
| 361 | 367 |
| 362 DartMethod(Element element, String name, js.Expression code, | 368 DartMethod(Element element, String name, js.Expression code, |
| 363 this.parameterStubs, this.callName, this.type, | 369 this.parameterStubs, this.callName, |
| 364 {this.needsTearOff, this.tearOffName, this.canBeApplied, | 370 {this.needsTearOff, this.tearOffName, this.canBeApplied, |
| 365 this.canBeReflected, this.requiredParameterCount, | 371 this.canBeReflected, this.requiredParameterCount, |
| 366 this.optionalParameterDefaultValues}) | 372 this.optionalParameterDefaultValues, this.functionType}) |
| 367 : super(element, name, code) { | 373 : super(element, name, code) { |
| 368 assert(needsTearOff != null); | 374 assert(needsTearOff != null); |
| 369 assert(!needsTearOff || tearOffName != null); | 375 assert(!needsTearOff || tearOffName != null); |
| 370 assert(canBeApplied != null); | 376 assert(canBeApplied != null); |
| 371 assert(canBeReflected != null); | 377 assert(canBeReflected != null); |
| 372 assert((!canBeReflected && !canBeApplied) || | 378 assert((!canBeReflected && !canBeApplied) || |
| 373 (requiredParameterCount != null && | 379 (requiredParameterCount != null && |
| 374 optionalParameterDefaultValues != null)); | 380 optionalParameterDefaultValues != null)); |
| 375 } | 381 } |
| 376 } | 382 } |
| 377 | 383 |
| 378 class InstanceMethod extends DartMethod { | 384 class InstanceMethod extends DartMethod { |
| 379 /// An alternative name for this method. This is used to model calls to | 385 /// An alternative name for this method. This is used to model calls to |
| 380 /// a method via `super`. If [aliasName] is non-null, the emitter has to | 386 /// a method via `super`. If [aliasName] is non-null, the emitter has to |
| 381 /// ensure that this method is registered on the prototype under both [name] | 387 /// ensure that this method is registered on the prototype under both [name] |
| 382 /// and [aliasName]. | 388 /// and [aliasName]. |
| 383 final String aliasName; | 389 final String aliasName; |
| 384 final bool isClosure; | 390 final bool isClosure; |
| 385 | 391 |
| 386 | 392 |
| 387 InstanceMethod(Element element, String name, js.Expression code, | 393 InstanceMethod(Element element, String name, js.Expression code, |
| 388 List<ParameterStubMethod> parameterStubs, | 394 List<ParameterStubMethod> parameterStubs, |
| 389 String callName, DartType type, | 395 String callName, |
| 390 {bool needsTearOff, | 396 {bool needsTearOff, |
| 391 String tearOffName, | 397 String tearOffName, |
| 392 this.aliasName, | 398 this.aliasName, |
| 393 bool canBeApplied, | 399 bool canBeApplied, |
| 394 bool canBeReflected, | 400 bool canBeReflected, |
| 395 int requiredParameterCount, | 401 int requiredParameterCount, |
| 396 /* List | Map */ optionalParameterDefaultValues, | 402 /* List | Map */ optionalParameterDefaultValues, |
| 397 this.isClosure}) | 403 this.isClosure, |
| 398 : super(element, name, code, parameterStubs, callName, type, | 404 js.Expression functionType}) |
| 405 : super(element, name, code, parameterStubs, callName, |
| 399 needsTearOff: needsTearOff, | 406 needsTearOff: needsTearOff, |
| 400 tearOffName: tearOffName, | 407 tearOffName: tearOffName, |
| 401 canBeApplied: canBeApplied, | 408 canBeApplied: canBeApplied, |
| 402 canBeReflected: canBeReflected, | 409 canBeReflected: canBeReflected, |
| 403 requiredParameterCount: requiredParameterCount, | 410 requiredParameterCount: requiredParameterCount, |
| 404 optionalParameterDefaultValues: optionalParameterDefaultValues) { | 411 optionalParameterDefaultValues: optionalParameterDefaultValues, |
| 412 functionType: functionType) { |
| 405 assert(isClosure != null); | 413 assert(isClosure != null); |
| 406 } | 414 } |
| 407 } | 415 } |
| 408 | 416 |
| 409 /// A method that is generated by the backend and has not direct correspondence | 417 /// A method that is generated by the backend and has not direct correspondence |
| 410 /// to a method in the original Dart program. Examples are getter and setter | 418 /// to a method in the original Dart program. Examples are getter and setter |
| 411 /// stubs and stubs to dispatch calls to methods with optional parameters. | 419 /// stubs and stubs to dispatch calls to methods with optional parameters. |
| 412 class StubMethod extends Method { | 420 class StubMethod extends Method { |
| 413 StubMethod(String name, js.Expression code, | 421 StubMethod(String name, js.Expression code, |
| 414 {Element element}) | 422 {Element element}) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 438 | 446 |
| 439 abstract class StaticMethod implements Method { | 447 abstract class StaticMethod implements Method { |
| 440 Holder get holder; | 448 Holder get holder; |
| 441 } | 449 } |
| 442 | 450 |
| 443 class StaticDartMethod extends DartMethod implements StaticMethod { | 451 class StaticDartMethod extends DartMethod implements StaticMethod { |
| 444 final Holder holder; | 452 final Holder holder; |
| 445 | 453 |
| 446 StaticDartMethod(Element element, String name, this.holder, | 454 StaticDartMethod(Element element, String name, this.holder, |
| 447 js.Expression code, List<ParameterStubMethod> parameterStubs, | 455 js.Expression code, List<ParameterStubMethod> parameterStubs, |
| 448 String callName, DartType type, | 456 String callName, |
| 449 {bool needsTearOff, String tearOffName, bool canBeApplied, | 457 {bool needsTearOff, String tearOffName, bool canBeApplied, |
| 450 bool canBeReflected, int requiredParameterCount, | 458 bool canBeReflected, int requiredParameterCount, |
| 451 /* List | Map */ optionalParameterDefaultValues}) | 459 /* List | Map */ optionalParameterDefaultValues, |
| 452 : super(element, name, code, parameterStubs, callName, type, | 460 js.Expression functionType}) |
| 461 : super(element, name, code, parameterStubs, callName, |
| 453 needsTearOff: needsTearOff, | 462 needsTearOff: needsTearOff, |
| 454 tearOffName : tearOffName, | 463 tearOffName : tearOffName, |
| 455 canBeApplied : canBeApplied, | 464 canBeApplied : canBeApplied, |
| 456 canBeReflected : canBeReflected, | 465 canBeReflected : canBeReflected, |
| 457 requiredParameterCount: requiredParameterCount, | 466 requiredParameterCount: requiredParameterCount, |
| 458 optionalParameterDefaultValues: optionalParameterDefaultValues); | 467 optionalParameterDefaultValues: optionalParameterDefaultValues, |
| 468 functionType: functionType); |
| 459 } | 469 } |
| 460 | 470 |
| 461 class StaticStubMethod extends StubMethod implements StaticMethod { | 471 class StaticStubMethod extends StubMethod implements StaticMethod { |
| 462 Holder holder; | 472 Holder holder; |
| 463 StaticStubMethod(String name, this.holder, js.Expression code) | 473 StaticStubMethod(String name, this.holder, js.Expression code) |
| 464 : super(name, code); | 474 : super(name, code); |
| 465 } | 475 } |
| OLD | NEW |