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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 64033002: Version 0.8.10.8 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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
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:async'; 7 import 'dart:async';
8 8
9 import '../../compiler.dart' as api; 9 import '../../compiler.dart' as api;
10 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 * Returns the element to be used to determine the begin token of this 286 * Returns the element to be used to determine the begin token of this
287 * declaration and the metadata associated with this declaration. 287 * declaration and the metadata associated with this declaration.
288 * 288 *
289 * This indirection is needed to use the [VariableListElement] as the location 289 * This indirection is needed to use the [VariableListElement] as the location
290 * for type and metadata information on a [VariableElement]. 290 * for type and metadata information on a [VariableElement].
291 */ 291 */
292 Element get _beginElement => _element; 292 Element get _beginElement => _element;
293 293
294 String get simpleName => _element.name; 294 String get simpleName => _element.name;
295 295
296 bool get isNameSynthetic => false;
297
296 /** 298 /**
297 * Computes the first token for this declaration using the begin token of the 299 * Computes the first token for this declaration using the begin token of the
298 * element node or element position as indicator. 300 * element node or element position as indicator.
299 */ 301 */
300 Token getBeginToken() { 302 Token getBeginToken() {
301 // TODO(johnniwinther): Avoid calling [parseNode]. 303 // TODO(johnniwinther): Avoid calling [parseNode].
302 Node node = _beginElement.parseNode(mirrors.compiler); 304 Node node = _beginElement.parseNode(mirrors.compiler);
303 if (node == null) { 305 if (node == null) {
304 return _beginElement.position(); 306 return _beginElement.position();
305 } 307 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 532
531 LibraryMirror library() => this; 533 LibraryMirror library() => this;
532 534
533 /** 535 /**
534 * Returns the library name (for libraries with a library tag) or the script 536 * Returns the library name (for libraries with a library tag) or the script
535 * file name (for scripts without a library tag). The latter case is used to 537 * file name (for scripts without a library tag). The latter case is used to
536 * provide a 'library name' for scripts, to use for instance in dartdoc. 538 * provide a 'library name' for scripts, to use for instance in dartdoc.
537 */ 539 */
538 String get simpleName { 540 String get simpleName {
539 if (_library.libraryTag != null) { 541 if (_library.libraryTag != null) {
540 // TODO(ahe): Remove StringNode check when old syntax is removed. 542 return _library.libraryTag.name.toString();
541 StringNode name = _library.libraryTag.name.asStringNode();
542 if (name != null) {
543 return name.dartString.slowToString();
544 } else {
545 return _library.libraryTag.name.toString();
546 }
547 } else { 543 } else {
548 // Use the file name as script name. 544 // Use the file name as script name.
549 String path = _library.canonicalUri.path; 545 String path = _library.canonicalUri.path;
550 return path.substring(path.lastIndexOf('/') + 1); 546 return path.substring(path.lastIndexOf('/') + 1);
551 } 547 }
552 } 548 }
553 549
554 String get qualifiedName => simpleName; 550 String get qualifiedName => simpleName;
555 551
556 void _ensureClasses() { 552 void _ensureClasses() {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 836
841 ClassMirror get originalDeclaration => this; 837 ClassMirror get originalDeclaration => this;
842 838
843 ClassMirror get superclass { 839 ClassMirror get superclass {
844 if (_class.supertype != null) { 840 if (_class.supertype != null) {
845 return new Dart2JsInterfaceTypeMirror(mirrors, _class.supertype); 841 return new Dart2JsInterfaceTypeMirror(mirrors, _class.supertype);
846 } 842 }
847 return null; 843 return null;
848 } 844 }
849 845
846 ClassMirror get mixin {
847 if (_class.isMixinApplication) {
848 MixinApplicationElement mixinApplication = _class;
849 return new Dart2JsInterfaceTypeMirror(mirrors,
850 mixinApplication.mixinType);
851 }
852 return this;
853 }
854
855 bool get isNameSynthetic {
856 if (_class.isMixinApplication) {
857 MixinApplicationElement mixinApplication = _class;
858 return mixinApplication.isUnnamedMixinApplication;
859 }
860 return false;
861 }
862
850 List<ClassMirror> get superinterfaces { 863 List<ClassMirror> get superinterfaces {
851 var list = <ClassMirror>[]; 864 var list = <ClassMirror>[];
852 Link<DartType> link = _class.interfaces; 865 Link<DartType> link = _class.interfaces;
853 while (!link.isEmpty) { 866 while (!link.isEmpty) {
854 var type = _convertTypeToTypeMirror(mirrors, link.head, 867 var type = _convertTypeToTypeMirror(mirrors, link.head,
855 mirrors.compiler.types.dynamicType); 868 mirrors.compiler.types.dynamicType);
856 list.add(type); 869 list.add(type);
857 link = link.tail; 870 link = link.tail;
858 } 871 }
859 return list; 872 return list;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 return _definition; 964 return _definition;
952 } 965 }
953 966
954 ClassMirror get originalDeclaration => this; 967 ClassMirror get originalDeclaration => this;
955 968
956 // TODO(johnniwinther): How should a typedef respond to these? 969 // TODO(johnniwinther): How should a typedef respond to these?
957 ClassMirror get superclass => null; 970 ClassMirror get superclass => null;
958 971
959 List<ClassMirror> get superinterfaces => const <ClassMirror>[]; 972 List<ClassMirror> get superinterfaces => const <ClassMirror>[];
960 973
974 // TODO(johnniwinther): Refactor [TypedefMirror] to not extend [ClassMirror]
975 // and remove this.
976 ClassMirror get mixin => this;
977
961 bool get isClass => false; 978 bool get isClass => false;
962 979
963 bool get isOriginalDeclaration => true; 980 bool get isOriginalDeclaration => true;
964 981
965 bool get isAbstract => false; 982 bool get isAbstract => false;
966 } 983 }
967 984
968 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror 985 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror
969 implements TypeVariableMirror { 986 implements TypeVariableMirror {
970 final TypeVariableType _typeVariableType; 987 final TypeVariableType _typeVariableType;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror 1087 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror
1071 implements ClassMirror { 1088 implements ClassMirror {
1072 List<TypeMirror> _typeArguments; 1089 List<TypeMirror> _typeArguments;
1073 1090
1074 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, 1091 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system,
1075 InterfaceType interfaceType) 1092 InterfaceType interfaceType)
1076 : super(system, interfaceType); 1093 : super(system, interfaceType);
1077 1094
1078 InterfaceType get _interfaceType => _type; 1095 InterfaceType get _interfaceType => _type;
1079 1096
1097 bool get isNameSynthetic => originalDeclaration.isNameSynthetic;
1098
1080 String get qualifiedName => originalDeclaration.qualifiedName; 1099 String get qualifiedName => originalDeclaration.qualifiedName;
1081 1100
1082 // TODO(johnniwinther): Substitute type arguments for type variables. 1101 // TODO(johnniwinther): Substitute type arguments for type variables.
1083 Map<String, MemberMirror> get members => originalDeclaration.members; 1102 Map<String, MemberMirror> get members => originalDeclaration.members;
1084 1103
1085 bool get isObject => mirrors.compiler.objectClass == _type.element; 1104 bool get isObject => mirrors.compiler.objectClass == _type.element;
1086 1105
1087 // TODO(johnniwinther): How to show malformed types? 1106 // TODO(johnniwinther): How to show malformed types?
1088 bool get isDynamic => _type.isDynamic; 1107 bool get isDynamic => _type.isDynamic;
1089 1108
1090 ClassMirror get originalDeclaration 1109 ClassMirror get originalDeclaration
1091 => new Dart2JsClassMirror(mirrors, _type.element); 1110 => new Dart2JsClassMirror(mirrors, _type.element);
1092 1111
1093 // TODO(johnniwinther): Substitute type arguments for type variables. 1112 // TODO(johnniwinther): Substitute type arguments for type variables.
1094 ClassMirror get superclass => originalDeclaration.superclass; 1113 ClassMirror get superclass => originalDeclaration.superclass;
1095 1114
1096 // TODO(johnniwinther): Substitute type arguments for type variables. 1115 // TODO(johnniwinther): Substitute type arguments for type variables.
1097 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces; 1116 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces;
1098 1117
1118 // TODO(johnniwinther): Substitute type arguments for type variables.
1119 ClassMirror get mixin {
1120 if (originalDeclaration.mixin == originalDeclaration) {
1121 return this;
1122 }
1123 return originalDeclaration.mixin;
1124 }
1125
1099 bool get isClass => originalDeclaration.isClass; 1126 bool get isClass => originalDeclaration.isClass;
1100 1127
1101 bool get isAbstract => originalDeclaration.isAbstract; 1128 bool get isAbstract => originalDeclaration.isAbstract;
1102 1129
1103 bool get isPrivate => originalDeclaration.isPrivate; 1130 bool get isPrivate => originalDeclaration.isPrivate;
1104 1131
1105 bool get isOriginalDeclaration => false; 1132 bool get isOriginalDeclaration => false;
1106 1133
1107 List<TypeMirror> get typeArguments { 1134 List<TypeMirror> get typeArguments {
1108 if (_typeArguments == null) { 1135 if (_typeArguments == null) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1190 }
1164 } 1191 }
1165 1192
1166 1193
1167 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror 1194 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror
1168 implements FunctionTypeMirror { 1195 implements FunctionTypeMirror {
1169 final FunctionSignature _functionSignature; 1196 final FunctionSignature _functionSignature;
1170 List<ParameterMirror> _parameters; 1197 List<ParameterMirror> _parameters;
1171 1198
1172 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, 1199 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system,
1173 FunctionType functionType, this._functionSignature) 1200 FunctionType functionType, this._functionSignature)
1174 : super(system, functionType) { 1201 : super(system, functionType) {
1175 assert (_functionSignature != null); 1202 assert (_functionSignature != null);
1176 } 1203 }
1177 1204
1178 FunctionType get _functionType => _type; 1205 FunctionType get _functionType => _type;
1179 1206
1180 // TODO(johnniwinther): Is this the qualified name of a function type? 1207 // TODO(johnniwinther): Is this the qualified name of a function type?
1181 String get qualifiedName => originalDeclaration.qualifiedName; 1208 String get qualifiedName => originalDeclaration.qualifiedName;
1182 1209
1183 // TODO(johnniwinther): Substitute type arguments for type variables. 1210 // TODO(johnniwinther): Substitute type arguments for type variables.
(...skipping 18 matching lines...) Expand all
1202 1229
1203 ClassMirror get originalDeclaration 1230 ClassMirror get originalDeclaration
1204 => new Dart2JsClassMirror(mirrors, mirrors.compiler.functionClass); 1231 => new Dart2JsClassMirror(mirrors, mirrors.compiler.functionClass);
1205 1232
1206 // TODO(johnniwinther): Substitute type arguments for type variables. 1233 // TODO(johnniwinther): Substitute type arguments for type variables.
1207 ClassMirror get superclass => originalDeclaration.superclass; 1234 ClassMirror get superclass => originalDeclaration.superclass;
1208 1235
1209 // TODO(johnniwinther): Substitute type arguments for type variables. 1236 // TODO(johnniwinther): Substitute type arguments for type variables.
1210 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces; 1237 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces;
1211 1238
1239 ClassMirror get mixin => this;
1240
1212 bool get isClass => originalDeclaration.isClass; 1241 bool get isClass => originalDeclaration.isClass;
1213 1242
1214 bool get isPrivate => originalDeclaration.isPrivate; 1243 bool get isPrivate => originalDeclaration.isPrivate;
1215 1244
1216 bool get isOriginalDeclaration => false; 1245 bool get isOriginalDeclaration => false;
1217 1246
1218 bool get isAbstract => false; 1247 bool get isAbstract => false;
1219 1248
1220 List<TypeMirror> get typeArguments => const <TypeMirror>[]; 1249 List<TypeMirror> get typeArguments => const <TypeMirror>[];
1221 1250
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 * 1778 *
1750 * All API in this class is experimental. 1779 * All API in this class is experimental.
1751 */ 1780 */
1752 class BackDoor { 1781 class BackDoor {
1753 /// Return the compilation units comprising [library]. 1782 /// Return the compilation units comprising [library].
1754 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { 1783 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) {
1755 return library._library.compilationUnits.toList().map( 1784 return library._library.compilationUnits.toList().map(
1756 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); 1785 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList();
1757 } 1786 }
1758 } 1787 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698