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