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

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

Issue 57983002: Add mixin support to source mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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 ClassMirror get mixin => this;
karlklose 2013/11/05 10:34:18 Add a TODO about removing this?
Johnni Winther 2013/11/05 11:20:47 Done.
975
961 bool get isClass => false; 976 bool get isClass => false;
962 977
963 bool get isOriginalDeclaration => true; 978 bool get isOriginalDeclaration => true;
964 979
965 bool get isAbstract => false; 980 bool get isAbstract => false;
966 } 981 }
967 982
968 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror 983 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror
969 implements TypeVariableMirror { 984 implements TypeVariableMirror {
970 final TypeVariableType _typeVariableType; 985 final TypeVariableType _typeVariableType;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror 1085 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror
1071 implements ClassMirror { 1086 implements ClassMirror {
1072 List<TypeMirror> _typeArguments; 1087 List<TypeMirror> _typeArguments;
1073 1088
1074 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, 1089 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system,
1075 InterfaceType interfaceType) 1090 InterfaceType interfaceType)
1076 : super(system, interfaceType); 1091 : super(system, interfaceType);
1077 1092
1078 InterfaceType get _interfaceType => _type; 1093 InterfaceType get _interfaceType => _type;
1079 1094
1095 bool get isNameSynthetic => originalDeclaration.isNameSynthetic;
1096
1080 String get qualifiedName => originalDeclaration.qualifiedName; 1097 String get qualifiedName => originalDeclaration.qualifiedName;
1081 1098
1082 // TODO(johnniwinther): Substitute type arguments for type variables. 1099 // TODO(johnniwinther): Substitute type arguments for type variables.
1083 Map<String, MemberMirror> get members => originalDeclaration.members; 1100 Map<String, MemberMirror> get members => originalDeclaration.members;
1084 1101
1085 bool get isObject => mirrors.compiler.objectClass == _type.element; 1102 bool get isObject => mirrors.compiler.objectClass == _type.element;
1086 1103
1087 // TODO(johnniwinther): How to show malformed types? 1104 // TODO(johnniwinther): How to show malformed types?
1088 bool get isDynamic => _type.isDynamic; 1105 bool get isDynamic => _type.isDynamic;
1089 1106
1090 ClassMirror get originalDeclaration 1107 ClassMirror get originalDeclaration
1091 => new Dart2JsClassMirror(mirrors, _type.element); 1108 => new Dart2JsClassMirror(mirrors, _type.element);
1092 1109
1093 // TODO(johnniwinther): Substitute type arguments for type variables. 1110 // TODO(johnniwinther): Substitute type arguments for type variables.
1094 ClassMirror get superclass => originalDeclaration.superclass; 1111 ClassMirror get superclass => originalDeclaration.superclass;
1095 1112
1096 // TODO(johnniwinther): Substitute type arguments for type variables. 1113 // TODO(johnniwinther): Substitute type arguments for type variables.
1097 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces; 1114 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces;
1098 1115
1116 // TODO(johnniwinther): Substitute type arguments for type variables.
1117 ClassMirror get mixin {
1118 if (originalDeclaration.mixin == originalDeclaration) {
1119 return this;
1120 }
1121 return originalDeclaration.mixin;
1122 }
1123
1099 bool get isClass => originalDeclaration.isClass; 1124 bool get isClass => originalDeclaration.isClass;
1100 1125
1101 bool get isAbstract => originalDeclaration.isAbstract; 1126 bool get isAbstract => originalDeclaration.isAbstract;
1102 1127
1103 bool get isPrivate => originalDeclaration.isPrivate; 1128 bool get isPrivate => originalDeclaration.isPrivate;
1104 1129
1105 bool get isOriginalDeclaration => false; 1130 bool get isOriginalDeclaration => false;
1106 1131
1107 List<TypeMirror> get typeArguments { 1132 List<TypeMirror> get typeArguments {
1108 if (_typeArguments == null) { 1133 if (_typeArguments == null) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1188 }
1164 } 1189 }
1165 1190
1166 1191
1167 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror 1192 class Dart2JsFunctionTypeMirror extends Dart2JsTypeElementMirror
1168 implements FunctionTypeMirror { 1193 implements FunctionTypeMirror {
1169 final FunctionSignature _functionSignature; 1194 final FunctionSignature _functionSignature;
1170 List<ParameterMirror> _parameters; 1195 List<ParameterMirror> _parameters;
1171 1196
1172 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, 1197 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system,
1173 FunctionType functionType, this._functionSignature) 1198 FunctionType functionType, this._functionSignature)
1174 : super(system, functionType) { 1199 : super(system, functionType) {
1175 assert (_functionSignature != null); 1200 assert (_functionSignature != null);
1176 } 1201 }
1177 1202
1178 FunctionType get _functionType => _type; 1203 FunctionType get _functionType => _type;
1179 1204
1180 // TODO(johnniwinther): Is this the qualified name of a function type? 1205 // TODO(johnniwinther): Is this the qualified name of a function type?
1181 String get qualifiedName => originalDeclaration.qualifiedName; 1206 String get qualifiedName => originalDeclaration.qualifiedName;
1182 1207
1183 // TODO(johnniwinther): Substitute type arguments for type variables. 1208 // TODO(johnniwinther): Substitute type arguments for type variables.
(...skipping 18 matching lines...) Expand all
1202 1227
1203 ClassMirror get originalDeclaration 1228 ClassMirror get originalDeclaration
1204 => new Dart2JsClassMirror(mirrors, mirrors.compiler.functionClass); 1229 => new Dart2JsClassMirror(mirrors, mirrors.compiler.functionClass);
1205 1230
1206 // TODO(johnniwinther): Substitute type arguments for type variables. 1231 // TODO(johnniwinther): Substitute type arguments for type variables.
1207 ClassMirror get superclass => originalDeclaration.superclass; 1232 ClassMirror get superclass => originalDeclaration.superclass;
1208 1233
1209 // TODO(johnniwinther): Substitute type arguments for type variables. 1234 // TODO(johnniwinther): Substitute type arguments for type variables.
1210 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces; 1235 List<ClassMirror> get superinterfaces => originalDeclaration.superinterfaces;
1211 1236
1237 ClassMirror get mixin => this;
1238
1212 bool get isClass => originalDeclaration.isClass; 1239 bool get isClass => originalDeclaration.isClass;
1213 1240
1214 bool get isPrivate => originalDeclaration.isPrivate; 1241 bool get isPrivate => originalDeclaration.isPrivate;
1215 1242
1216 bool get isOriginalDeclaration => false; 1243 bool get isOriginalDeclaration => false;
1217 1244
1218 bool get isAbstract => false; 1245 bool get isAbstract => false;
1219 1246
1220 List<TypeMirror> get typeArguments => const <TypeMirror>[]; 1247 List<TypeMirror> get typeArguments => const <TypeMirror>[];
1221 1248
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 * 1776 *
1750 * All API in this class is experimental. 1777 * All API in this class is experimental.
1751 */ 1778 */
1752 class BackDoor { 1779 class BackDoor {
1753 /// Return the compilation units comprising [library]. 1780 /// Return the compilation units comprising [library].
1754 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { 1781 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) {
1755 return library._library.compilationUnits.toList().map( 1782 return library._library.compilationUnits.toList().map(
1756 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); 1783 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList();
1757 } 1784 }
1758 } 1785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698