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

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_mirrors.dart

Issue 981143003: dart2js: split out types from metadata. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart._js_mirrors; 5 library dart._js_mirrors;
6 6
7 import 'dart:_js_embedded_names' show 7 import 'dart:_js_embedded_names' show
8 JsGetName, 8 JsGetName,
9 ALL_CLASSES, 9 ALL_CLASSES,
10 LAZIES, 10 LAZIES,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 Primitives, 48 Primitives,
49 ReflectionInfo, 49 ReflectionInfo,
50 RuntimeError, 50 RuntimeError,
51 TearOffClosure, 51 TearOffClosure,
52 TypeVariable, 52 TypeVariable,
53 UnimplementedNoSuchMethodError, 53 UnimplementedNoSuchMethodError,
54 createRuntimeType, 54 createRuntimeType,
55 createUnmangledInvocationMirror, 55 createUnmangledInvocationMirror,
56 getMangledTypeName, 56 getMangledTypeName,
57 getMetadata, 57 getMetadata,
58 getType,
58 getRuntimeType, 59 getRuntimeType,
59 runtimeTypeToString, 60 runtimeTypeToString,
60 setRuntimeTypeInfo, 61 setRuntimeTypeInfo,
61 throwInvalidReflectionError, 62 throwInvalidReflectionError,
62 TypeImpl, 63 TypeImpl,
63 deferredLoadHook; 64 deferredLoadHook;
64 65
65 import 'dart:_interceptors' show 66 import 'dart:_interceptors' show
66 Interceptor, 67 Interceptor,
67 JSArray, 68 JSArray,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 281 }
281 282
282 String get _prettyName => 'TypeVariableMirror'; 283 String get _prettyName => 'TypeVariableMirror';
283 284
284 bool get isTopLevel => false; 285 bool get isTopLevel => false;
285 bool get isStatic => false; 286 bool get isStatic => false;
286 287
287 TypeMirror get upperBound { 288 TypeMirror get upperBound {
288 if (_cachedUpperBound != null) return _cachedUpperBound; 289 if (_cachedUpperBound != null) return _cachedUpperBound;
289 return _cachedUpperBound = typeMirrorFromRuntimeTypeRepresentation( 290 return _cachedUpperBound = typeMirrorFromRuntimeTypeRepresentation(
290 owner, getMetadata(_typeVariable.bound)); 291 owner, getType(_typeVariable.bound));
291 } 292 }
292 293
293 bool isSubtypeOf(TypeMirror other) => throw new UnimplementedError(); 294 bool isSubtypeOf(TypeMirror other) => throw new UnimplementedError();
294 bool isAssignableTo(TypeMirror other) => throw new UnimplementedError(); 295 bool isAssignableTo(TypeMirror other) => throw new UnimplementedError();
295 296
296 _asRuntimeType() => _metadataIndex; 297 _asRuntimeType() => _metadataIndex;
297 } 298 }
298 299
299 class JsTypeMirror extends JsDeclarationMirror implements TypeMirror { 300 class JsTypeMirror extends JsDeclarationMirror implements TypeMirror {
300 JsTypeMirror(Symbol simpleName) 301 JsTypeMirror(Symbol simpleName)
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // Typedefs are represented as normal classes with two special properties: 643 // Typedefs are represented as normal classes with two special properties:
643 // TYPEDEF_PREDICATE_PROPERTY_NAME and TYPEDEF_TYPE_PROPERTY_NAME. 644 // TYPEDEF_PREDICATE_PROPERTY_NAME and TYPEDEF_TYPE_PROPERTY_NAME.
644 // For example: 645 // For example:
645 // MyTypedef: { 646 // MyTypedef: {
646 // "^": "Object;", 647 // "^": "Object;",
647 // $typedefType: 58, 648 // $typedefType: 58,
648 // $$isTypedef: true 649 // $$isTypedef: true
649 // } 650 // }
650 // The typedefType is the index into the metadata table. 651 // The typedefType is the index into the metadata table.
651 int index = JS('int', '#[#]', descriptor, TYPEDEF_TYPE_PROPERTY_NAME); 652 int index = JS('int', '#[#]', descriptor, TYPEDEF_TYPE_PROPERTY_NAME);
652 mirror = new JsTypedefMirror(symbol, mangledName, getMetadata(index)); 653 mirror = new JsTypedefMirror(symbol, mangledName, getType(index));
653 } else { 654 } else {
654 fields = JS('', '#[#]', descriptor, 655 fields = JS('', '#[#]', descriptor,
655 JS_GET_NAME(JsGetName.CLASS_DESCRIPTOR_PROPERTY)); 656 JS_GET_NAME(JsGetName.CLASS_DESCRIPTOR_PROPERTY));
656 if (fields is List) { 657 if (fields is List) {
657 fieldsMetadata = fields.getRange(1, fields.length).toList(); 658 fieldsMetadata = fields.getRange(1, fields.length).toList();
658 fields = fields[0]; 659 fields = fields[0];
659 } 660 }
660 if (fields is! String) { 661 if (fields is! String) {
661 // TODO(ahe): This is CSP mode. Find a way to determine the 662 // TODO(ahe): This is CSP mode. Find a way to determine the
662 // fields of this class. 663 // fields of this class.
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 1504
1504 List<InstanceMirror> get metadata => _class.metadata; 1505 List<InstanceMirror> get metadata => _class.metadata;
1505 1506
1506 ClassMirror get superclass { 1507 ClassMirror get superclass {
1507 if (_superclass != null) return _superclass; 1508 if (_superclass != null) return _superclass;
1508 1509
1509 var typeInformationContainer = JS_EMBEDDED_GLOBAL('', TYPE_INFORMATION); 1510 var typeInformationContainer = JS_EMBEDDED_GLOBAL('', TYPE_INFORMATION);
1510 List<int> typeInformation = 1511 List<int> typeInformation =
1511 JS('List|Null', '#[#]', typeInformationContainer, _class._mangledName); 1512 JS('List|Null', '#[#]', typeInformationContainer, _class._mangledName);
1512 assert(typeInformation != null); 1513 assert(typeInformation != null);
1513 var type = getMetadata(typeInformation[0]); 1514 var type = getType(typeInformation[0]);
1514 return _superclass = typeMirrorFromRuntimeTypeRepresentation(this, type); 1515 return _superclass = typeMirrorFromRuntimeTypeRepresentation(this, type);
1515 } 1516 }
1516 1517
1517 InstanceMirror invoke(Symbol memberName, 1518 InstanceMirror invoke(Symbol memberName,
1518 List positionalArguments, 1519 List positionalArguments,
1519 [Map<Symbol,dynamic> namedArguments]) { 1520 [Map<Symbol,dynamic> namedArguments]) {
1520 return _class.invoke(memberName, positionalArguments, namedArguments); 1521 return _class.invoke(memberName, positionalArguments, namedArguments);
1521 } 1522 }
1522 1523
1523 bool get isOriginalDeclaration => false; 1524 bool get isOriginalDeclaration => false;
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 return _cachedMetadata = 1980 return _cachedMetadata =
1980 new UnmodifiableListView<InstanceMirror>(_metadata.map(reflect)); 1981 new UnmodifiableListView<InstanceMirror>(_metadata.map(reflect));
1981 } 1982 }
1982 1983
1983 ClassMirror get superclass { 1984 ClassMirror get superclass {
1984 if (_superclass == null) { 1985 if (_superclass == null) {
1985 var typeInformationContainer = JS_EMBEDDED_GLOBAL('', TYPE_INFORMATION); 1986 var typeInformationContainer = JS_EMBEDDED_GLOBAL('', TYPE_INFORMATION);
1986 List<int> typeInformation = 1987 List<int> typeInformation =
1987 JS('List|Null', '#[#]', typeInformationContainer, _mangledName); 1988 JS('List|Null', '#[#]', typeInformationContainer, _mangledName);
1988 if (typeInformation != null) { 1989 if (typeInformation != null) {
1989 var type = getMetadata(typeInformation[0]); 1990 var type = getType(typeInformation[0]);
1990 _superclass = typeMirrorFromRuntimeTypeRepresentation(this, type); 1991 _superclass = typeMirrorFromRuntimeTypeRepresentation(this, type);
1991 } else { 1992 } else {
1992 var superclassName = _fieldsDescriptor.split(';')[0]; 1993 var superclassName = _fieldsDescriptor.split(';')[0];
1993 // TODO(zarah): Remove special handing of mixins. 1994 // TODO(zarah): Remove special handing of mixins.
1994 var mixins = superclassName.split('+'); 1995 var mixins = superclassName.split('+');
1995 if (mixins.length > 1) { 1996 if (mixins.length > 1) {
1996 if (mixins.length != 2) { 1997 if (mixins.length != 2) {
1997 throw new RuntimeError('Strange mixin: $_fieldsDescriptor'); 1998 throw new RuntimeError('Strange mixin: $_fieldsDescriptor');
1998 } 1999 }
1999 _superclass = reflectClassByMangledName(mixins[0]); 2000 _superclass = reflectClassByMangledName(mixins[0]);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 2038
2038 ClassMirror get originalDeclaration => this; 2039 ClassMirror get originalDeclaration => this;
2039 2040
2040 List<ClassMirror> _getSuperinterfacesWithOwner(DeclarationMirror owner) { 2041 List<ClassMirror> _getSuperinterfacesWithOwner(DeclarationMirror owner) {
2041 var typeInformationContainer = JS_EMBEDDED_GLOBAL('', TYPE_INFORMATION); 2042 var typeInformationContainer = JS_EMBEDDED_GLOBAL('', TYPE_INFORMATION);
2042 List<int> typeInformation = 2043 List<int> typeInformation =
2043 JS('List|Null', '#[#]', typeInformationContainer, _mangledName); 2044 JS('List|Null', '#[#]', typeInformationContainer, _mangledName);
2044 List<ClassMirror> result = const <ClassMirror>[]; 2045 List<ClassMirror> result = const <ClassMirror>[];
2045 if (typeInformation != null) { 2046 if (typeInformation != null) {
2046 ClassMirror lookupType(int i) { 2047 ClassMirror lookupType(int i) {
2047 var type = getMetadata(i); 2048 var type = getType(i);
2048 return typeMirrorFromRuntimeTypeRepresentation(owner, type); 2049 return typeMirrorFromRuntimeTypeRepresentation(owner, type);
2049 } 2050 }
2050 2051
2051 //We skip the first since it is the supertype. 2052 //We skip the first since it is the supertype.
2052 result = typeInformation.skip(1).map(lookupType).toList(); 2053 result = typeInformation.skip(1).map(lookupType).toList();
2053 } 2054 }
2054 2055
2055 return new UnmodifiableListView<ClassMirror>(result); 2056 return new UnmodifiableListView<ClassMirror>(result);
2056 } 2057 }
2057 2058
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 type, 2182 type,
2182 isFinal, 2183 isFinal,
2183 isStatic, 2184 isStatic,
2184 metadataFunction, 2185 metadataFunction,
2185 owner); 2186 owner);
2186 } 2187 }
2187 2188
2188 String get _prettyName => 'VariableMirror'; 2189 String get _prettyName => 'VariableMirror';
2189 2190
2190 TypeMirror get type { 2191 TypeMirror get type {
2191 return typeMirrorFromRuntimeTypeRepresentation(owner, getMetadata(_type)); 2192 return typeMirrorFromRuntimeTypeRepresentation(owner, getType(_type));
2192 } 2193 }
2193 2194
2194 DeclarationMirror get owner => _owner; 2195 DeclarationMirror get owner => _owner;
2195 2196
2196 List<InstanceMirror> get metadata { 2197 List<InstanceMirror> get metadata {
2197 preserveMetadata(); 2198 preserveMetadata();
2198 if (_metadata == null) { 2199 if (_metadata == null) {
2199 _metadata = (_metadataFunction == null) 2200 _metadata = (_metadataFunction == null)
2200 ? const [] : JS('', '#()', _metadataFunction); 2201 ? const [] : JS('', '#()', _metadataFunction);
2201 } 2202 }
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 // have a part (following a '.') that starts with '_'. 3039 // have a part (following a '.') that starts with '_'.
3039 const int UNDERSCORE = 0x5f; 3040 const int UNDERSCORE = 0x5f;
3040 if (name.isEmpty) return true; 3041 if (name.isEmpty) return true;
3041 int index = -1; 3042 int index = -1;
3042 do { 3043 do {
3043 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false; 3044 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false;
3044 index = name.indexOf('.', index + 1); 3045 index = name.indexOf('.', index + 1);
3045 } while (index >= 0 && index + 1 < name.length); 3046 } while (index >= 0 && index + 1 < name.length);
3046 return true; 3047 return true;
3047 } 3048 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_helper.dart ('k') | sdk/lib/_internal/compiler/js_lib/shared/embedded_names.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698