Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('mirrors.dart2js'); | 5 #library('mirrors.dart2js'); |
| 6 | 6 |
| 7 #import('../../compiler/compiler.dart', prefix: 'diagnostics'); | 7 #import('../../compiler/compiler.dart', prefix: 'diagnostics'); |
| 8 #import('../../compiler/implementation/elements/elements.dart'); | 8 #import('../../compiler/implementation/elements/elements.dart'); |
| 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); | 9 #import('../../compiler/implementation/apiimpl.dart', prefix: 'api'); |
| 10 #import('../../compiler/implementation/scanner/scannerlib.dart'); | 10 #import('../../compiler/implementation/scanner/scannerlib.dart'); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 return name.startsWith('_'); | 29 return name.startsWith('_'); |
| 30 } | 30 } |
| 31 | 31 |
| 32 List<ParameterMirror> _parametersFromFunctionSignature( | 32 List<ParameterMirror> _parametersFromFunctionSignature( |
| 33 Dart2JsMirrorSystem system, | 33 Dart2JsMirrorSystem system, |
| 34 Dart2JsMethodMirror method, | 34 Dart2JsMethodMirror method, |
| 35 FunctionSignature signature) { | 35 FunctionSignature signature) { |
| 36 var parameters = <ParameterMirror>[]; | 36 var parameters = <ParameterMirror>[]; |
| 37 Link<Element> link = signature.requiredParameters; | 37 Link<Element> link = signature.requiredParameters; |
| 38 while (!link.isEmpty()) { | 38 while (!link.isEmpty()) { |
| 39 parameters.add(new Dart2JsParameterMirror(system, method, | 39 parameters.add(_convertVariableElementToParameterMirror( |
| 40 link.head, false)); | 40 system, method, link.head, false)); |
| 41 link = link.tail; | 41 link = link.tail; |
| 42 } | 42 } |
| 43 link = signature.optionalParameters; | 43 link = signature.optionalParameters; |
| 44 while (!link.isEmpty()) { | 44 while (!link.isEmpty()) { |
| 45 parameters.add(new Dart2JsParameterMirror(system, method, | 45 parameters.add(_convertVariableElementToParameterMirror( |
| 46 link.head, true)); | 46 system, method, link.head, true)); |
|
floitsch
2012/07/17 18:53:04
indent by 4.
Johnni Winther
2012/07/18 13:32:50
Done.
| |
| 47 link = link.tail; | 47 link = link.tail; |
| 48 } | 48 } |
| 49 return parameters; | 49 return parameters; |
| 50 } | 50 } |
| 51 | 51 |
| 52 Dart2JsParameterMirror _convertVariableElementToParameterMirror( | |
|
floitsch
2012/07/17 18:53:04
alternatively you could make the unnamed Dart2JsPa
Johnni Winther
2012/07/18 13:32:50
Done.
| |
| 53 Dart2JsMirrorSystem system, | |
| 54 MethodMirror method, | |
| 55 VariableElement element, | |
| 56 bool isOptional) { | |
| 57 if (element is FieldParameterElement) { | |
| 58 return new Dart2JsFieldParameterMirror(system, method, element, isOptional); | |
| 59 } | |
| 60 return new Dart2JsParameterMirror(system, method, element, isOptional); | |
| 61 } | |
| 62 | |
| 63 | |
| 52 Dart2JsTypeMirror _convertTypeToTypeMirror( | 64 Dart2JsTypeMirror _convertTypeToTypeMirror( |
| 53 Dart2JsMirrorSystem system, | 65 Dart2JsMirrorSystem system, |
| 54 Type type, | 66 Type type, |
| 55 InterfaceType defaultType, | 67 InterfaceType defaultType, |
| 56 [FunctionSignature functionSignature]) { | 68 [FunctionSignature functionSignature]) { |
| 57 if (type === null) { | 69 if (type === null) { |
| 58 return new Dart2JsInterfaceTypeMirror(system, defaultType); | 70 return new Dart2JsInterfaceTypeMirror(system, defaultType); |
| 59 } else if (type is InterfaceType) { | 71 } else if (type is InterfaceType) { |
| 60 return new Dart2JsInterfaceTypeMirror(system, type); | 72 return new Dart2JsInterfaceTypeMirror(system, type); |
| 61 } else if (type is TypeVariableType) { | 73 } else if (type is TypeVariableType) { |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 VariableElement element, | 582 VariableElement element, |
| 571 this._isOptional) | 583 this._isOptional) |
| 572 : super(system, element); | 584 : super(system, element); |
| 573 | 585 |
| 574 VariableElement get _variableElement() => _element; | 586 VariableElement get _variableElement() => _element; |
| 575 | 587 |
| 576 String get canonicalName() => simpleName(); | 588 String get canonicalName() => simpleName(); |
| 577 | 589 |
| 578 String qualifiedName() => '${_method.qualifiedName()}#${simpleName()}'; | 590 String qualifiedName() => '${_method.qualifiedName()}#${simpleName()}'; |
| 579 | 591 |
| 580 // TODO(johnniwinther): Provide | |
| 581 // [:_variableElement.variables.functionSignature:] instead of [:null:]. | |
| 582 TypeMirror type() => _convertTypeToTypeMirror(system, | 592 TypeMirror type() => _convertTypeToTypeMirror(system, |
| 583 _variableElement.computeType(system.compiler), | 593 _variableElement.computeType(system.compiler), |
| 584 system.compiler.dynamicClass.computeType(system.compiler), | 594 system.compiler.dynamicClass.computeType(system.compiler), |
| 585 null); | 595 _variableElement.variables.functionSignature); |
| 586 | 596 |
| 587 String defaultValue() => null; // TODO(johnniwinther): How to compute this? | 597 String defaultValue() { |
| 588 | 598 if (hasDefaultValue()) { |
| 589 bool hasDefaultValue() => false; // TODO(johnniwinther): How to compute this? | 599 SendSet expression = _variableElement.cachedNode.asSendSet(); |
| 600 return expression.arguments.head.unparse(); | |
| 601 } | |
| 602 return null; | |
| 603 } | |
| 604 bool hasDefaultValue() { | |
| 605 return _variableElement.cachedNode !== null && | |
| 606 _variableElement.cachedNode is SendSet; | |
| 607 } | |
| 590 | 608 |
| 591 bool isOptional() => _isOptional; | 609 bool isOptional() => _isOptional; |
| 610 | |
| 611 bool isInitializingFormal() => false; | |
| 612 | |
| 613 FieldMirror initializedField() => null; | |
| 614 } | |
| 615 | |
| 616 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror { | |
| 617 | |
| 618 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system, | |
| 619 MethodMirror method, | |
| 620 FieldParameterElement element, | |
| 621 bool isOptional) | |
| 622 : super(system, method, element, isOptional); | |
| 623 | |
| 624 FieldParameterElement get _fieldParameterElement() => _element; | |
| 625 | |
| 626 TypeMirror type() { | |
| 627 if (_fieldParameterElement.variables.cachedNode.type !== null) { | |
| 628 return super.type(); | |
| 629 } | |
| 630 return _convertTypeToTypeMirror(system, | |
| 631 _fieldParameterElement.fieldElement.computeType(system.compiler), | |
| 632 system.compiler.dynamicClass.computeType(system.compiler), | |
| 633 _variableElement.variables.functionSignature); | |
| 634 } | |
| 635 | |
| 636 bool isInitializingFormal() => true; | |
| 637 | |
| 638 FieldMirror initializedField() => new Dart2JsFieldMirror( | |
| 639 _method.surroundingDeclaration(), _fieldParameterElement.fieldElement); | |
| 592 } | 640 } |
| 593 | 641 |
| 594 //------------------------------------------------------------------------------ | 642 //------------------------------------------------------------------------------ |
| 595 // Declarations | 643 // Declarations |
| 596 //------------------------------------------------------------------------------ | 644 //------------------------------------------------------------------------------ |
| 597 class Dart2JsInterfaceMirror extends Dart2JsObjectMirror | 645 class Dart2JsInterfaceMirror extends Dart2JsObjectMirror |
| 598 implements Dart2JsTypeMirror, InterfaceMirror { | 646 implements Dart2JsTypeMirror, InterfaceMirror { |
| 599 final Dart2JsLibraryMirror _library; | 647 final Dart2JsLibraryMirror _library; |
| 600 Map<String, Dart2JsMemberMirror> _members; | 648 Map<String, Dart2JsMemberMirror> _members; |
| 601 List<TypeVariableMirror> _typeVariables; | 649 List<TypeVariableMirror> _typeVariables; |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1311 if (node !== null) { | 1359 if (node !== null) { |
| 1312 var span = system.compiler.spanFromNode(node, script.uri); | 1360 var span = system.compiler.spanFromNode(node, script.uri); |
| 1313 return new Dart2JsLocation(script, span); | 1361 return new Dart2JsLocation(script, span); |
| 1314 } else { | 1362 } else { |
| 1315 var span = system.compiler.spanFromElement(_variable); | 1363 var span = system.compiler.spanFromElement(_variable); |
| 1316 return new Dart2JsLocation(script, span); | 1364 return new Dart2JsLocation(script, span); |
| 1317 } | 1365 } |
| 1318 } | 1366 } |
| 1319 } | 1367 } |
| 1320 | 1368 |
| OLD | NEW |