Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart

Issue 10961074: Separate type for dynamic in mirrors.dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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('dart:io'); 7 #import('dart:io');
8 #import('dart:uri'); 8 #import('dart:uri');
9 9
10 #import('../../../../../lib/compiler/compiler.dart', prefix: 'diagnostics'); 10 #import('../../../../../lib/compiler/compiler.dart', prefix: 'diagnostics');
11 #import('../../../../../lib/compiler/implementation/elements/elements.dart'); 11 #import('../../../../../lib/compiler/implementation/elements/elements.dart');
12 #import('../../../../../lib/compiler/implementation/apiimpl.dart', prefix: 'api' ); 12 #import('../../../../../lib/compiler/implementation/apiimpl.dart', prefix: 'api' );
13 #import('../../../../../lib/compiler/implementation/scanner/scannerlib.dart'); 13 #import('../../../../../lib/compiler/implementation/scanner/scannerlib.dart');
14 #import('../../../../../lib/compiler/implementation/ssa/ssa.dart');
14 #import('../../../../../lib/compiler/implementation/leg.dart'); 15 #import('../../../../../lib/compiler/implementation/leg.dart');
15 #import('../../../../../lib/compiler/implementation/filenames.dart'); 16 #import('../../../../../lib/compiler/implementation/filenames.dart');
16 #import('../../../../../lib/compiler/implementation/source_file.dart'); 17 #import('../../../../../lib/compiler/implementation/source_file.dart');
17 #import('../../../../../lib/compiler/implementation/tree/tree.dart'); 18 #import('../../../../../lib/compiler/implementation/tree/tree.dart');
18 #import('../../../../../lib/compiler/implementation/util/util.dart'); 19 #import('../../../../../lib/compiler/implementation/util/util.dart');
19 #import('../../../../../lib/compiler/implementation/util/uri_extras.dart'); 20 #import('../../../../../lib/compiler/implementation/util/uri_extras.dart');
20 #import('../../../../../lib/compiler/implementation/dart2js.dart'); 21 #import('../../../../../lib/compiler/implementation/dart2js.dart');
21 22
22 // TODO(rnystrom): Use "package:" URL (#4968). 23 // TODO(rnystrom): Use "package:" URL (#4968).
23 #import('../../mirrors.dart'); 24 #import('../../mirrors.dart');
(...skipping 28 matching lines...) Expand all
52 } 53 }
53 54
54 Dart2JsTypeMirror _convertTypeToTypeMirror( 55 Dart2JsTypeMirror _convertTypeToTypeMirror(
55 Dart2JsMirrorSystem system, 56 Dart2JsMirrorSystem system,
56 DartType type, 57 DartType type,
57 InterfaceType defaultType, 58 InterfaceType defaultType,
58 [FunctionSignature functionSignature]) { 59 [FunctionSignature functionSignature]) {
59 if (type === null) { 60 if (type === null) {
60 return new Dart2JsInterfaceTypeMirror(system, defaultType); 61 return new Dart2JsInterfaceTypeMirror(system, defaultType);
61 } else if (type is InterfaceType) { 62 } else if (type is InterfaceType) {
62 return new Dart2JsInterfaceTypeMirror(system, type); 63 if (type === system.compiler.types.dynamicType) {
64 return new Dart2JsDynamicMirror(system, type);
65 } else {
66 return new Dart2JsInterfaceTypeMirror(system, type);
67 }
63 } else if (type is TypeVariableType) { 68 } else if (type is TypeVariableType) {
64 return new Dart2JsTypeVariableMirror(system, type); 69 return new Dart2JsTypeVariableMirror(system, type);
65 } else if (type is FunctionType) { 70 } else if (type is FunctionType) {
66 return new Dart2JsFunctionTypeMirror(system, type, functionSignature); 71 return new Dart2JsFunctionTypeMirror(system, type, functionSignature);
67 } else if (type is VoidType) { 72 } else if (type is VoidType) {
68 return new Dart2JsVoidMirror(system, type); 73 return new Dart2JsVoidMirror(system, type);
69 } else if (type is TypedefType) { 74 } else if (type is TypedefType) {
70 return new Dart2JsTypedefMirror(system, type); 75 return new Dart2JsTypedefMirror(system, type);
71 } 76 }
72 throw new IllegalArgumentException("Unexpected interface type $type"); 77 throw new IllegalArgumentException("Unexpected interface type $type");
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 final Dart2JsLibraryMirror library; 673 final Dart2JsLibraryMirror library;
669 Map<String, Dart2JsMemberMirror> _members; 674 Map<String, Dart2JsMemberMirror> _members;
670 List<TypeVariableMirror> _typeVariables; 675 List<TypeVariableMirror> _typeVariables;
671 676
672 Dart2JsInterfaceMirror(Dart2JsMirrorSystem system, ClassElement _class) 677 Dart2JsInterfaceMirror(Dart2JsMirrorSystem system, ClassElement _class)
673 : this.library = system.getLibrary(_class.getLibrary()), 678 : this.library = system.getLibrary(_class.getLibrary()),
674 super(system, _class); 679 super(system, _class);
675 680
676 ClassElement get _class => _element; 681 ClassElement get _class => _element;
677 682
678
679 Dart2JsInterfaceMirror.fromLibrary(Dart2JsLibraryMirror library, 683 Dart2JsInterfaceMirror.fromLibrary(Dart2JsLibraryMirror library,
680 ClassElement _class) 684 ClassElement _class)
681 : this.library = library, 685 : this.library = library,
682 super(library.system, _class); 686 super(library.system, _class);
683 687
684 String get canonicalName => simpleName; 688 String get canonicalName => simpleName;
685 689
686 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; 690 String get qualifiedName => '${library.qualifiedName}.${simpleName}';
687 691
688 Location get location { 692 Location get location {
(...skipping 19 matching lines...) Expand all
708 } 712 }
709 } 713 }
710 714
711 Map<Object, MemberMirror> get declaredMembers { 715 Map<Object, MemberMirror> get declaredMembers {
712 _ensureMembers(); 716 _ensureMembers();
713 return new ImmutableMapWrapper<Object, MemberMirror>(_members); 717 return new ImmutableMapWrapper<Object, MemberMirror>(_members);
714 } 718 }
715 719
716 bool get isObject => _class == system.compiler.objectClass; 720 bool get isObject => _class == system.compiler.objectClass;
717 721
718 bool get isDynamic => _class == system.compiler.dynamicClass; 722 bool get isDynamic => false;
719 723
720 bool get isVoid => false; 724 bool get isVoid => false;
721 725
722 bool get isTypeVariable => false; 726 bool get isTypeVariable => false;
723 727
724 bool get isTypedef => false; 728 bool get isTypedef => false;
725 729
726 bool get isFunction => false; 730 bool get isFunction => false;
727 731
728 InterfaceMirror get declaration => this; 732 InterfaceMirror get declaration => this;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 if (node !== null) { 834 if (node !== null) {
831 var script = _typedef.element.getCompilationUnit().script; 835 var script = _typedef.element.getCompilationUnit().script;
832 var span = system.compiler.spanFromNode(node, script.uri); 836 var span = system.compiler.spanFromNode(node, script.uri);
833 return new Dart2JsLocation(script, span); 837 return new Dart2JsLocation(script, span);
834 } 838 }
835 return super.location; 839 return super.location;
836 } 840 }
837 841
838 LibraryMirror get library => _library; 842 LibraryMirror get library => _library;
839 843
840 bool get isObject => false;
841
842 bool get isDynamic => false;
843
844 bool get isVoid => false;
845
846 bool get isTypeVariable => false;
847
848 bool get isTypedef => true; 844 bool get isTypedef => true;
849 845
850 bool get isFunction => false;
851
852 List<TypeMirror> get typeArguments { 846 List<TypeMirror> get typeArguments {
853 throw new UnsupportedOperationException( 847 throw new UnsupportedOperationException(
854 'Declarations do not have type arguments'); 848 'Declarations do not have type arguments');
855 } 849 }
856 850
857 List<TypeVariableMirror> get typeVariables { 851 List<TypeVariableMirror> get typeVariables {
858 if (_typeVariables == null) { 852 if (_typeVariables == null) {
859 _typeVariables = <TypeVariableMirror>[]; 853 _typeVariables = <TypeVariableMirror>[];
860 for (TypeVariableType typeVariable in _typedef.typeArguments) { 854 for (TypeVariableType typeVariable in _typedef.typeArguments) {
861 _typeVariables.add( 855 _typeVariables.add(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 _declarer = new Dart2JsTypedefMirror(system, 921 _declarer = new Dart2JsTypedefMirror(system,
928 _typeVariableType.element.enclosingElement.computeType( 922 _typeVariableType.element.enclosingElement.computeType(
929 system.compiler)); 923 system.compiler));
930 } 924 }
931 } 925 }
932 return _declarer; 926 return _declarer;
933 } 927 }
934 928
935 LibraryMirror get library => declarer.library; 929 LibraryMirror get library => declarer.library;
936 930
937 bool get isObject => false;
938
939 bool get isDynamic => false;
940
941 bool get isVoid => false;
942
943 bool get isTypeVariable => true; 931 bool get isTypeVariable => true;
944 932
945 bool get isTypedef => false;
946
947 bool get isFunction => false;
948
949 TypeMirror get bound => _convertTypeToTypeMirror( 933 TypeMirror get bound => _convertTypeToTypeMirror(
950 system, 934 system,
951 _typeVariableType.element.bound, 935 _typeVariableType.element.bound,
952 system.compiler.objectClass.computeType(system.compiler)); 936 system.compiler.objectClass.computeType(system.compiler));
953 937
954 bool operator ==(Object other) { 938 bool operator ==(Object other) {
955 if (this === other) { 939 if (this === other) {
956 return true; 940 return true;
957 } 941 }
958 if (other is! TypeVariableMirror) { 942 if (other is! TypeVariableMirror) {
(...skipping 25 matching lines...) Expand all
984 Location get location { 968 Location get location {
985 var script = _type.element.getCompilationUnit().script; 969 var script = _type.element.getCompilationUnit().script;
986 return new Dart2JsLocation(script, 970 return new Dart2JsLocation(script,
987 system.compiler.spanFromElement(_type.element)); 971 system.compiler.spanFromElement(_type.element));
988 } 972 }
989 973
990 LibraryMirror get library { 974 LibraryMirror get library {
991 return system.getLibrary(_type.element.getLibrary()); 975 return system.getLibrary(_type.element.getLibrary());
992 } 976 }
993 977
978 bool get isObject => false;
979
980 bool get isVoid => false;
981
982 bool get isDynamic => false;
983
984 bool get isTypeVariable => false;
985
986 bool get isTypedef => false;
987
988 bool get isFunction => false;
989
994 String toString() => _type.element.toString(); 990 String toString() => _type.element.toString();
995 } 991 }
996 992
997 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror 993 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror
998 implements InterfaceMirror { 994 implements InterfaceMirror {
999 List<TypeMirror> _typeArguments; 995 List<TypeMirror> _typeArguments;
1000 996
1001 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, 997 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system,
1002 InterfaceType interfaceType) 998 InterfaceType interfaceType)
1003 : super(system, interfaceType); 999 : super(system, interfaceType);
1004 1000
1005 InterfaceType get _interfaceType => _type; 1001 InterfaceType get _interfaceType => _type;
1006 1002
1007 String get qualifiedName => declaration.qualifiedName; 1003 String get qualifiedName => declaration.qualifiedName;
1008 1004
1009 // TODO(johnniwinther): Substitute type arguments for type variables. 1005 // TODO(johnniwinther): Substitute type arguments for type variables.
1010 Map<Object, MemberMirror> get declaredMembers => declaration.declaredMembers; 1006 Map<Object, MemberMirror> get declaredMembers => declaration.declaredMembers;
1011 1007
1012 bool get isObject => system.compiler.objectClass == _type.element; 1008 bool get isObject => system.compiler.objectClass == _type.element;
1013 1009
1014 bool get isDynamic => system.compiler.dynamicClass == _type.element; 1010 bool get isDynamic => system.compiler.dynamicClass == _type.element;
1015 1011
1016 bool get isTypeVariable => false;
1017
1018 bool get isVoid => false;
1019
1020 bool get isTypedef => false;
1021
1022 bool get isFunction => false;
1023
1024 InterfaceMirror get declaration 1012 InterfaceMirror get declaration
1025 => new Dart2JsInterfaceMirror(system, _type.element); 1013 => new Dart2JsInterfaceMirror(system, _type.element);
1026 1014
1027 // TODO(johnniwinther): Substitute type arguments for type variables. 1015 // TODO(johnniwinther): Substitute type arguments for type variables.
1028 InterfaceMirror get superclass => declaration.superclass; 1016 InterfaceMirror get superclass => declaration.superclass;
1029 1017
1030 // TODO(johnniwinther): Substitute type arguments for type variables. 1018 // TODO(johnniwinther): Substitute type arguments for type variables.
1031 Map<Object, InterfaceMirror> get interfaces => declaration.interfaces; 1019 Map<Object, InterfaceMirror> get interfaces => declaration.interfaces;
1032 1020
1033 bool get isClass => declaration.isClass; 1021 bool get isClass => declaration.isClass;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 var map = new Map<String, MemberMirror>.from( 1095 var map = new Map<String, MemberMirror>.from(
1108 declaration.declaredMembers); 1096 declaration.declaredMembers);
1109 var name = method.qualifiedName; 1097 var name = method.qualifiedName;
1110 map[name] = method; 1098 map[name] = method;
1111 Function func = null; 1099 Function func = null;
1112 return new ImmutableMapWrapper<Object, MemberMirror>(map); 1100 return new ImmutableMapWrapper<Object, MemberMirror>(map);
1113 } 1101 }
1114 return declaration.declaredMembers; 1102 return declaration.declaredMembers;
1115 } 1103 }
1116 1104
1117 bool get isObject => system.compiler.objectClass == _type.element;
1118
1119 bool get isDynamic => system.compiler.dynamicClass == _type.element;
1120
1121 bool get isVoid => false;
1122
1123 bool get isTypeVariable => false;
1124
1125 bool get isTypedef => false;
1126
1127 bool get isFunction => true; 1105 bool get isFunction => true;
1128 1106
1129 MethodMirror get callMethod => _convertElementMethodToMethodMirror( 1107 MethodMirror get callMethod => _convertElementMethodToMethodMirror(
1130 system.getLibrary(_functionType.element.getLibrary()), 1108 system.getLibrary(_functionType.element.getLibrary()),
1131 _functionType.element); 1109 _functionType.element);
1132 1110
1133 InterfaceMirror get declaration 1111 InterfaceMirror get declaration
1134 => new Dart2JsInterfaceMirror(system, system.compiler.functionClass); 1112 => new Dart2JsInterfaceMirror(system, system.compiler.functionClass);
1135 1113
1136 // TODO(johnniwinther): Substitute type arguments for type variables. 1114 // TODO(johnniwinther): Substitute type arguments for type variables.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 /** 1160 /**
1183 * The void type has no location. 1161 * The void type has no location.
1184 */ 1162 */
1185 Location get location => null; 1163 Location get location => null;
1186 1164
1187 /** 1165 /**
1188 * The void type has no library. 1166 * The void type has no library.
1189 */ 1167 */
1190 LibraryMirror get library => null; 1168 LibraryMirror get library => null;
1191 1169
1192 bool get isObject => false;
1193
1194 bool get isVoid => true; 1170 bool get isVoid => true;
1195 1171
1196 bool get isDynamic => false;
1197
1198 bool get isTypeVariable => false;
1199
1200 bool get isTypedef => false;
1201
1202 bool get isFunction => false;
1203
1204 bool operator ==(Object other) { 1172 bool operator ==(Object other) {
1205 if (this === other) { 1173 if (this === other) {
1174 return true;
1175 }
1176 if (other is! TypeMirror) {
1177 return false;
1178 }
1179 return other.isVoid;
1180 }
1181 }
1182
1183
1184 class Dart2JsDynamicMirror extends Dart2JsTypeElementMirror {
1185 Dart2JsDynamicMirror(Dart2JsMirrorSystem system, InterfaceType voidType)
1186 : super(system, voidType);
1187
1188 InterfaceType get _dynamicType => _type;
1189
1190 String get qualifiedName => simpleName;
1191
1192 /**
1193 * The dynamic type has no location.
1194 */
1195 Location get location => null;
1196
1197 /**
1198 * The dynamic type has no library.
1199 */
1200 LibraryMirror get library => null;
1201
1202 bool get isDynamic => true;
1203
1204 bool operator ==(Object other) {
1205 if (this === other) {
1206 return true; 1206 return true;
1207 } 1207 }
1208 if (other is! TypeMirror) { 1208 if (other is! TypeMirror) {
1209 return false; 1209 return false;
1210 } 1210 }
1211 return other.isVoid; 1211 return other.isDynamic;
1212 } 1212 }
1213 } 1213 }
1214 1214
1215 //------------------------------------------------------------------------------ 1215 //------------------------------------------------------------------------------
1216 // Member mirrors implementation. 1216 // Member mirrors implementation.
1217 //------------------------------------------------------------------------------ 1217 //------------------------------------------------------------------------------
1218 1218
1219 class Dart2JsMethodMirror extends Dart2JsElementMirror 1219 class Dart2JsMethodMirror extends Dart2JsElementMirror
1220 implements Dart2JsMemberMirror, MethodMirror { 1220 implements Dart2JsMemberMirror, MethodMirror {
1221 final Dart2JsObjectMirror _objectMirror; 1221 final Dart2JsObjectMirror _objectMirror;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 if (node !== null) { 1391 if (node !== null) {
1392 var span = system.compiler.spanFromNode(node, script.uri); 1392 var span = system.compiler.spanFromNode(node, script.uri);
1393 return new Dart2JsLocation(script, span); 1393 return new Dart2JsLocation(script, span);
1394 } else { 1394 } else {
1395 var span = system.compiler.spanFromElement(_variable); 1395 var span = system.compiler.spanFromElement(_variable);
1396 return new Dart2JsLocation(script, span); 1396 return new Dart2JsLocation(script, span);
1397 } 1397 }
1398 } 1398 }
1399 } 1399 }
1400 1400
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698