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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 Type type, | 54 Type type, |
55 InterfaceType defaultType, | 55 InterfaceType defaultType, |
56 [FunctionSignature functionSignature]) { | 56 [FunctionSignature functionSignature]) { |
57 if (type === null) { | 57 if (type === null) { |
58 return new Dart2JsInterfaceTypeMirror(system, defaultType); | 58 return new Dart2JsInterfaceTypeMirror(system, defaultType); |
59 } else if (type is InterfaceType) { | 59 } else if (type is InterfaceType) { |
60 return new Dart2JsInterfaceTypeMirror(system, type); | 60 return new Dart2JsInterfaceTypeMirror(system, type); |
61 } else if (type is TypeVariableType) { | 61 } else if (type is TypeVariableType) { |
62 return new Dart2JsTypeVariableMirror(system, type); | 62 return new Dart2JsTypeVariableMirror(system, type); |
63 } else if (type is FunctionType) { | 63 } else if (type is FunctionType) { |
64 if (type.element is TypedefElement) { | 64 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); |
65 return new Dart2JsTypedefMirror(system, type.element); | |
66 } else { | |
67 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); | |
68 } | |
69 } else if (type is VoidType) { | 65 } else if (type is VoidType) { |
70 return new Dart2JsVoidMirror(system, type); | 66 return new Dart2JsVoidMirror(system, type); |
| 67 } else if (type is TypedefType) { |
| 68 return new Dart2JsTypedefMirror(system, type); |
71 } | 69 } |
72 throw new IllegalArgumentException("Unexpected interface type $type"); | 70 throw new IllegalArgumentException("Unexpected interface type $type"); |
73 } | 71 } |
74 | 72 |
75 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( | 73 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( |
76 Dart2JsObjectMirror library, Element element) { | 74 Dart2JsObjectMirror library, Element element) { |
77 if (element is SynthesizedConstructorElement) { | 75 if (element is SynthesizedConstructorElement) { |
78 return const <Dart2JsMemberMirror>[]; | 76 return const <Dart2JsMemberMirror>[]; |
79 } else if (element is VariableElement) { | 77 } else if (element is VariableElement) { |
80 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; | 78 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 void _ensureTypes() { | 494 void _ensureTypes() { |
497 if (_types == null) { | 495 if (_types == null) { |
498 _types = <InterfaceMirror>{}; | 496 _types = <InterfaceMirror>{}; |
499 _library.forEachExport((Element e) { | 497 _library.forEachExport((Element e) { |
500 if (e.getLibrary() == _library) { | 498 if (e.getLibrary() == _library) { |
501 if (e.isClass()) { | 499 if (e.isClass()) { |
502 e.ensureResolved(system.compiler); | 500 e.ensureResolved(system.compiler); |
503 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); | 501 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); |
504 _types[type.canonicalName] = type; | 502 _types[type.canonicalName] = type; |
505 } else if (e.isTypedef()) { | 503 } else if (e.isTypedef()) { |
506 var type = new Dart2JsTypedefMirror.fromLibrary(this, e); | 504 var type = new Dart2JsTypedefMirror.fromLibrary(this, |
| 505 e.computeType(system.compiler)); |
507 _types[type.canonicalName] = type; | 506 _types[type.canonicalName] = type; |
508 } | 507 } |
509 } | 508 } |
510 }); | 509 }); |
511 } | 510 } |
512 } | 511 } |
513 | 512 |
514 void _ensureMembers() { | 513 void _ensureMembers() { |
515 if (_members == null) { | 514 if (_members == null) { |
516 _members = <MemberMirror>{}; | 515 _members = <MemberMirror>{}; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 if (library != other.library) { | 785 if (library != other.library) { |
787 return false; | 786 return false; |
788 } | 787 } |
789 if (isDeclaration !== other.isDeclaration) { | 788 if (isDeclaration !== other.isDeclaration) { |
790 return false; | 789 return false; |
791 } | 790 } |
792 return qualifiedName == other.qualifiedName; | 791 return qualifiedName == other.qualifiedName; |
793 } | 792 } |
794 } | 793 } |
795 | 794 |
796 class Dart2JsTypedefMirror extends Dart2JsElementMirror | 795 class Dart2JsTypedefMirror extends Dart2JsTypeElementMirror |
797 implements Dart2JsTypeMirror, TypedefMirror { | 796 implements Dart2JsTypeMirror, TypedefMirror { |
798 final Dart2JsLibraryMirror _library; | 797 final Dart2JsLibraryMirror _library; |
799 List<TypeVariableMirror> _typeVariables; | 798 List<TypeVariableMirror> _typeVariables; |
800 TypeMirror _definition; | 799 TypeMirror _definition; |
801 | 800 |
802 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefElement _typedef) | 801 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefType _typedef) |
803 : this._library = system.getLibrary(_typedef.getLibrary()), | 802 : this._library = system.getLibrary(_typedef.element.getLibrary()), |
804 super(system, _typedef); | 803 super(system, _typedef); |
805 | 804 |
806 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, | 805 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, |
807 TypedefElement _typedef) | 806 TypedefType _typedef) |
808 : this._library = library, | 807 : this._library = library, |
809 super(library.system, _typedef); | 808 super(library.system, _typedef); |
810 | 809 |
811 TypedefElement get _typedef() => _element; | 810 TypedefType get _typedef() => _type; |
812 | 811 |
813 String get canonicalName() => simpleName; | 812 String get canonicalName() => simpleName; |
814 | 813 |
815 String get qualifiedName() => '${library.qualifiedName}.${simpleName}'; | 814 String get qualifiedName() => '${library.qualifiedName}.${simpleName}'; |
816 | 815 |
817 Location get location() { | 816 Location get location() { |
818 var node = _typedef.parseNode(_diagnosticListener); | 817 var node = _typedef.element.parseNode(_diagnosticListener); |
819 if (node !== null) { | 818 if (node !== null) { |
820 var script = _typedef.getCompilationUnit().script; | 819 var script = _typedef.element.getCompilationUnit().script; |
821 var span = system.compiler.spanFromNode(node, script.uri); | 820 var span = system.compiler.spanFromNode(node, script.uri); |
822 return new Dart2JsLocation(script, span); | 821 return new Dart2JsLocation(script, span); |
823 } | 822 } |
824 return super.location; | 823 return super.location; |
825 } | 824 } |
826 | 825 |
827 LibraryMirror get library() => _library; | 826 LibraryMirror get library() => _library; |
828 | 827 |
829 bool get isObject() => false; | 828 bool get isObject() => false; |
830 | 829 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 | 896 |
898 String get qualifiedName() => '${declarer.qualifiedName}.${simpleName}'; | 897 String get qualifiedName() => '${declarer.qualifiedName}.${simpleName}'; |
899 | 898 |
900 InterfaceMirror get declarer() { | 899 InterfaceMirror get declarer() { |
901 if (_declarer === null) { | 900 if (_declarer === null) { |
902 if (_typeVariableType.element.enclosingElement.isClass()) { | 901 if (_typeVariableType.element.enclosingElement.isClass()) { |
903 _declarer = new Dart2JsInterfaceMirror(system, | 902 _declarer = new Dart2JsInterfaceMirror(system, |
904 _typeVariableType.element.enclosingElement); | 903 _typeVariableType.element.enclosingElement); |
905 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { | 904 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { |
906 _declarer = new Dart2JsTypedefMirror(system, | 905 _declarer = new Dart2JsTypedefMirror(system, |
907 _typeVariableType.element.enclosingElement); | 906 _typeVariableType.element.enclosingElement.computeType( |
| 907 system.compiler)); |
908 } | 908 } |
909 } | 909 } |
910 return _declarer; | 910 return _declarer; |
911 } | 911 } |
912 | 912 |
913 LibraryMirror get library() => declarer.library; | 913 LibraryMirror get library() => declarer.library; |
914 | 914 |
915 bool get isObject() => false; | 915 bool get isObject() => false; |
916 | 916 |
917 bool get isDynamic() => false; | 917 bool get isDynamic() => false; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 if (node !== null) { | 1360 if (node !== null) { |
1361 var span = system.compiler.spanFromNode(node, script.uri); | 1361 var span = system.compiler.spanFromNode(node, script.uri); |
1362 return new Dart2JsLocation(script, span); | 1362 return new Dart2JsLocation(script, span); |
1363 } else { | 1363 } else { |
1364 var span = system.compiler.spanFromElement(_variable); | 1364 var span = system.compiler.spanFromElement(_variable); |
1365 return new Dart2JsLocation(script, span); | 1365 return new Dart2JsLocation(script, span); |
1366 } | 1366 } |
1367 } | 1367 } |
1368 } | 1368 } |
1369 | 1369 |
OLD | NEW |