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

Unified Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 100413007: Revert "Support type argument substitution on unnamed mixin applications." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/lib/js_mirrors.dart
diff --git a/sdk/lib/_internal/lib/js_mirrors.dart b/sdk/lib/_internal/lib/js_mirrors.dart
index b36e3b7d69c29fe0b802c52997dda8df33a8943e..18829bf7038177cfd16067e19184be43f43138a3 100644
--- a/sdk/lib/_internal/lib/js_mirrors.dart
+++ b/sdk/lib/_internal/lib/js_mirrors.dart
@@ -146,31 +146,6 @@ abstract class JsMirror implements Mirror {
}
}
-// TODO(zarah): This should be a common superclass for instead of a common
-// interface.
-abstract class JsClassMirror implements ClassMirror {
- get _jsConstructor;
-
- String get _mangledName;
-
- // For implementation purposes this does not return the same as the api
- // getter for typeVariables. Specifically for mixins we add synthestic type
- // variables.
- List<TypeVariableMirror> get _typeVariables;
-
- List<TypeMirror> get _typeArguments;
-
- List<VariableMirror> _getFieldsWithOwner(DeclarationMirror owner);
-
- List<MethodMirror> _getMethodsWithOwner(DeclarationMirror owner);
-
- List<ClassMirror> _getSuperinterfacesWithOwner(DeclarationMirror owner);
-
- _getInvokedInstance(Symbol constructorName,
- List positionalArguments,
- [Map<Symbol, dynamic> namedArguments]);
-}
-
// This class is somewhat silly in the current implementation.
class JsIsolateMirror extends JsMirror implements IsolateMirror {
final _isolateContext = JS_CURRENT_ISOLATE_CONTEXT();
@@ -330,7 +305,7 @@ class JsLibraryMirror extends JsDeclarationMirror with JsObjectMirror
var cls = reflectClassByMangledName(className);
if (cls is ClassMirror) {
cls = cls.originalDeclaration;
- if (cls is JsClassDeclarationMirror) {
+ if (cls is JsClassMirror) {
result[cls.simpleName] = cls;
cls._owner = this;
}
@@ -550,15 +525,14 @@ var classMirrors;
TypeMirror reflectClassByName(Symbol symbol, String mangledName) {
if (classMirrors == null) classMirrors = JsCache.allocate();
var mirror = JsCache.fetch(classMirrors, mangledName);
- if (mirror != null && mirror is! JsMixinApplication) return mirror;
+ if (mirror != null) return mirror;
disableTreeShaking();
int typeArgIndex = mangledName.indexOf("<");
if (typeArgIndex != -1) {
- mirror =
- new JsTypeBoundClassMirror(reflectClassByMangledName(
- mangledName.substring(0, typeArgIndex)).originalDeclaration,
- // Remove the angle brackets enclosing the type arguments.
- mangledName.substring(typeArgIndex + 1, mangledName.length - 1));
+ mirror = new JsTypeBoundClassMirror(reflectClassByMangledName(
+ mangledName.substring(0, typeArgIndex)).originalDeclaration,
+ // Remove the angle brackets enclosing the type arguments.
+ mangledName.substring(typeArgIndex + 1, mangledName.length - 1));
JsCache.update(classMirrors, mangledName, mirror);
return mirror;
}
@@ -600,9 +574,9 @@ TypeMirror reflectClassByName(Symbol symbol, String mangledName) {
var superclassName = fields.split(';')[0];
var mixins = superclassName.split('+');
if (mixins.length > 1 && mangledGlobalNames[mangledName] == null) {
- mirror = reflectMixinApplication(mixins, mangledName, constructor);
+ mirror = reflectMixinApplication(mixins, mangledName);
} else {
- ClassMirror classMirror = new JsClassDeclarationMirror(
+ ClassMirror classMirror = new JsClassMirror(
symbol, mangledName, constructorOrInterceptor, fields, fieldsMetadata);
List typeVariables =
JS('JSExtendableArray|Null', '#.prototype["<>"]', constructor);
@@ -693,8 +667,7 @@ Map<Symbol, Mirror> filterMembers(List<MethodMirror> methods,
int counter = 0;
-ClassMirror reflectMixinApplication(mixinNames, String mangledName,
- var jsConstructor) {
+ClassMirror reflectMixinApplication(mixinNames, String mangledName) {
disableTreeShaking();
var mixins = [];
for (String mangledName in mixinNames) {
@@ -704,21 +677,21 @@ ClassMirror reflectMixinApplication(mixinNames, String mangledName,
it.moveNext();
var superclass = it.current;
while (it.moveNext()) {
- superclass = new JsMixinApplication(mangledName, jsConstructor);
+ superclass = new JsMixinApplication(superclass, it.current, mangledName);
}
return superclass;
}
class JsMixinApplication extends JsTypeMirror with JsObjectMirror
- implements JsClassMirror {
- ClassMirror _superclass;
- ClassMirror _mixin;
+ implements ClassMirror {
+ final ClassMirror superclass;
+ final ClassMirror mixin;
Symbol _cachedSimpleName;
- String _mangledName;
- final _jsConstructor;
- JsMixinApplication(String mangledName, this._jsConstructor)
- : this._mangledName = mangledName,
+ JsMixinApplication(ClassMirror superclass, ClassMirror mixin,
+ String mangledName)
+ : this.superclass = superclass,
+ this.mixin = mixin,
super(s(mangledName));
String get _prettyName => 'ClassMirror';
@@ -733,50 +706,18 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror
Symbol get qualifiedName => simpleName;
- ClassMirror _getTypeAtTypeInformationIndex(int index) {
- List<int> typeInformation =
- JS('List|Null', 'init.typeInformation[#]', _mangledName);
- if (typeInformation != null) {
- var type = getMetadata(typeInformation[index]);
- return typeMirrorFromRuntimeTypeRepresentation(this, type);
- }
- return null;
- }
-
- ClassMirror get superclass {
- if (_superclass != null) return _superclass;
- return _superclass = _getTypeAtTypeInformationIndex(0);
- }
-
- ClassMirror get mixin {
- if (_mixin != null) return _mixin;
- return _mixin = _getTypeAtTypeInformationIndex(1);
- }
-
- List<MethodMirror> _getMethodsWithOwner(DeclarationMirror owner) {
- return __mixin._getMethodsWithOwner(owner);
- }
-
- List<VariableMirror> _getFieldsWithOwner(DeclarationMirror owner) {
- return __mixin._getFieldsWithOwner(owner);
- }
-
- List<ClassMirror> _getSuperinterfacesWithOwner(DeclarationMirror owner) {
- return __mixin._getSuperinterfacesWithOwner(owner);
- }
-
// TODO(ahe): Remove this method, only here to silence warning.
- get __mixin => mixin;
+ get _mixin => mixin;
- Map<Symbol, Mirror> get members => __mixin.members;
+ Map<Symbol, Mirror> get __members => _mixin.__members;
- Map<Symbol, MethodMirror> get methods => __mixin.methods;
+ Map<Symbol, MethodMirror> get __methods => _mixin.__methods;
- Map<Symbol, MethodMirror> get __getters => __mixin.__getters;
+ Map<Symbol, MethodMirror> get __getters => _mixin.__getters;
- Map<Symbol, MethodMirror> get __setters => __mixin.__setters;
+ Map<Symbol, MethodMirror> get __setters => _mixin.__setters;
- Map<Symbol, VariableMirror> get __variables => __mixin.__variables;
+ Map<Symbol, VariableMirror> get __variables => _mixin.__variables;
Map<Symbol, DeclarationMirror> get declarations => mixin.declarations;
@@ -791,13 +732,6 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror
positionalArguments, namedArguments);
}
- _getInvokedInstance(Symbol constructorName,
- List positionalArguments,
- [Map<Symbol, dynamic> namedArguments]) {
- throw new NoSuchMethodError(this, constructorName,
- positionalArguments, namedArguments);
- }
-
InstanceMirror getField(Symbol fieldName) {
// TODO(ahe): What receiver to use?
throw new NoSuchMethodError(this, fieldName, null, null);
@@ -810,7 +744,7 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror
List<ClassMirror> get superinterfaces => [mixin];
- Map<Symbol, MethodMirror> get __constructors => __mixin.__constructors;
+ Map<Symbol, MethodMirror> get __constructors => _mixin.__constructors;
InstanceMirror newInstance(
Symbol constructorName,
@@ -824,23 +758,11 @@ class JsMixinApplication extends JsTypeMirror with JsObjectMirror
ClassMirror get originalDeclaration => this;
- List<TypeVariableMirror> get typeVariables => const <TypeVariableMirror>[];
-
- List<TypeVariableMirror> get _typeVariables {
- List result = new List();
- List typeVariables =
- JS('JSExtendableArray|Null', '#.prototype["<>"]', _jsConstructor);
- if (typeVariables == null) return result;
- for (int i = 0; i < typeVariables.length; i++) {
- TypeVariable typeVariable = getMetadata(typeVariables[i]);
- result.add(
- new JsTypeVariableMirror(typeVariable, this, typeVariables[i]));
- }
- return new UnmodifiableListView(result);
+ // TODO(ahe): Implement this.
+ List<TypeVariableMirror> get typeVariables {
+ throw new UnimplementedError();
}
- List<TypeMirror> get _typeArguments => typeArguments;
-
List<TypeMirror> get typeArguments => const <TypeMirror>[];
// TODO(ahe): Implement this.
@@ -1017,7 +939,7 @@ class JsInstanceMirror extends JsObjectMirror implements InstanceMirror {
* declarations and classes that are not generic.
*/
class JsTypeBoundClassMirror extends JsDeclarationMirror
- implements JsClassMirror {
+ implements ClassMirror {
final JsClassMirror _class;
/**
@@ -1032,7 +954,7 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
* If an integer is encountered as a type argument, it represents the type
* variable at the corresponding entry in [emitter.globalMetadata].
*/
- String _typeArgumentsString;
+ String _typeArguments;
UnmodifiableListView<TypeMirror> _cachedTypeArguments;
UnmodifiableMapView<Symbol, DeclarationMirror> _cachedDeclarations;
@@ -1046,8 +968,7 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
ClassMirror _superclass;
List<ClassMirror> _cachedSuperinterfaces;
- JsTypeBoundClassMirror(JsClassMirror originalDeclaration,
- this._typeArgumentsString)
+ JsTypeBoundClassMirror(JsClassMirror originalDeclaration, this._typeArguments)
: _class = originalDeclaration,
super(originalDeclaration.simpleName);
@@ -1055,7 +976,7 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
String get _mangledName {
for (TypeMirror typeArgument in typeArguments) {
if (typeArgument != JsMirrorSystem._dynamicType) {
- return '${_class._mangledName}<$_typeArgumentsString>';
+ return '${_class._mangledName}<$_typeArguments>';
}
}
// When all type arguments are dynamic, the canonical representation is to
@@ -1065,14 +986,7 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
List<TypeVariableMirror> get typeVariables => _class.typeVariables;
- List<TypeVariableMirror> get _typeVariables => _class._typeVariables;
-
List<TypeMirror> get typeArguments {
- if (_class is JsMixinApplication) return const <TypeMirror>[];
- return _typeArguments;
- }
-
- List<TypeMirror> get _typeArguments {
if (_cachedTypeArguments != null) return _cachedTypeArguments;
List result = new List();
@@ -1089,14 +1003,14 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
}
}
- if (_typeArgumentsString.indexOf('<') == -1) {
- _typeArgumentsString.split(',').forEach((t) => addTypeArgument(t));
+ if (_typeArguments.indexOf('<') == -1) {
+ _typeArguments.split(',').forEach((t) => addTypeArgument(t));
} else {
int level = 0;
String currentTypeArgument = '';
- for (int i = 0; i < _typeArgumentsString.length; i++) {
- var character = _typeArgumentsString[i];
+ for (int i = 0; i < _typeArguments.length; i++) {
+ var character = _typeArguments[i];
if (character == ' ') {
continue;
} else if (character == '<') {
@@ -1121,29 +1035,9 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
return _cachedTypeArguments = new UnmodifiableListView(result);
}
- List<MethodMirror> _getMethodsWithOwner(DeclarationMirror owner) {
- return _class._getMethodsWithOwner(owner);
- }
-
- List<VariableMirror> _getFieldsWithOwner(DeclarationMirror owner) {
- return _class._getFieldsWithOwner(owner);
- }
-
- List<ClassMirror> _getSuperinterfacesWithOwner(DeclarationMirror owner) {
- return _class._getSuperinterfacesWithOwner(owner);
- }
-
- _getInvokedInstance(Symbol constructorName,
- List positionalArguments,
- [Map<Symbol, dynamic> namedArguments]) {
- return _class._getInvokedInstance(constructorName,
- positionalArguments,
- namedArguments);
- }
-
List<JsMethodMirror> get _methods {
if (_cachedMethods != null) return _cachedMethods;
- return _cachedMethods =_getMethodsWithOwner(this);
+ return _cachedMethods =_class._getMethodsWithOwner(this);
}
Map<Symbol, MethodMirror> get __methods {
@@ -1174,7 +1068,7 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
Map<Symbol, VariableMirror> get __variables {
if (_cachedVariables != null) return _cachedVariables;
var result = new Map();
- for (JsVariableMirror mirror in _getFieldsWithOwner(this)) {
+ for (JsVariableMirror mirror in _class._getFieldsWithOwner(this)) {
result[mirror.simpleName] = mirror;
}
return _cachedVariables =
@@ -1207,15 +1101,15 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
InstanceMirror newInstance(Symbol constructorName,
List positionalArguments,
[Map<Symbol, dynamic> namedArguments]) {
- var instance = _getInvokedInstance(constructorName,
- positionalArguments,
- namedArguments);
+ var instance = _class._getInvokedInstance(constructorName,
+ positionalArguments,
+ namedArguments);
return reflect(setRuntimeTypeInfo(
instance, typeArguments.map((t) => t._asRuntimeType()).toList()));
}
_asRuntimeType() {
- return [_jsConstructor].addAll(
+ return [_class._jsConstructor].addAll(
typeArguments.map((t) => t._asRuntimeType()));
}
@@ -1224,8 +1118,8 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
List<InstanceMirror> get metadata => _class.metadata;
ClassMirror get superclass {
-
if (_superclass != null) return _superclass;
+
List<int> typeInformation =
JS('List|Null', 'init.typeInformation[#]', _class._mangledName);
assert(typeInformation != null);
@@ -1238,27 +1132,6 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
[Map<Symbol,dynamic> namedArguments]) {
return _class.invoke(memberName, positionalArguments, namedArguments);
}
- ClassMirror get mixin {
- String name = JS('String', '#.prototype[""]', _class._jsConstructor);
- if (name.contains('+')) {
- var mixin = _getTypeAtTypeInformationIndex(1);
- return mixin;
- }
- }
-
- get _jsConstructor {
- return _class._jsConstructor;
- }
-
- ClassMirror _getTypeAtTypeInformationIndex(int index) {
- List<int> typeInformation =
- JS('List|Null', 'init.typeInformation[#]', _class._mangledName);
- if (typeInformation != null) {
- var type = getMetadata(typeInformation[index]);
- return typeMirrorFromRuntimeTypeRepresentation(this, type);
- }
- return null;
- }
bool get isOriginalDeclaration => false;
@@ -1266,7 +1139,7 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
List<ClassMirror> get superinterfaces {
if (_cachedSuperinterfaces != null) return _cachedSuperinterfaces;
- return _cachedSuperinterfaces = _getSuperinterfacesWithOwner(this);
+ return _cachedSuperinterfaces = _class._getSuperinterfacesWithOwner(this);
}
bool get isPrivate => _class.isPrivate;
@@ -1275,6 +1148,8 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
SourceLocation get location => _class.location;
+ MirrorSystem get mirrors => _class.mirrors;
+
Symbol get qualifiedName => _class.qualifiedName;
bool get hasReflectedType => true;
@@ -1291,11 +1166,14 @@ class JsTypeBoundClassMirror extends JsDeclarationMirror
Map<Symbol, MethodMirror> get staticMembers => throw new UnimplementedError();
// TODO(ahe): Implement this.
+ ClassMirror get mixin => throw new UnimplementedError();
+
+ // TODO(ahe): Implement this.
Function operator [](Symbol name) => throw new UnimplementedError();
}
-class JsClassDeclarationMirror extends JsTypeMirror with JsObjectMirror
- implements JsClassMirror {
+class JsClassMirror extends JsTypeMirror with JsObjectMirror
+ implements ClassMirror {
final String _mangledName;
final _jsConstructorOrInterceptor;
final String _fieldsDescriptor;
@@ -1319,7 +1197,7 @@ class JsClassDeclarationMirror extends JsTypeMirror with JsObjectMirror
// Set as side-effect of accessing JsLibraryMirror.classes.
JsLibraryMirror _owner;
- JsClassDeclarationMirror(Symbol simpleName,
+ JsClassMirror(Symbol simpleName,
this._mangledName,
this._jsConstructorOrInterceptor,
this._fieldsDescriptor,
@@ -1647,9 +1525,7 @@ class JsClassDeclarationMirror extends JsTypeMirror with JsObjectMirror
return _cachedSuperinterfaces = _getSuperinterfacesWithOwner(this);
}
- List<TypeVariableMirror> get typeVariables => _typeVariables;
-
- List<TypeVariableMirror> get _typeVariables {
+ List<TypeVariableMirror> get typeVariables {
if (_cachedTypeVariables != null) return _cachedTypeVariables;
List result = new List();
List typeVariables =
@@ -1663,8 +1539,6 @@ class JsClassDeclarationMirror extends JsTypeMirror with JsObjectMirror
return _cachedTypeVariables = new UnmodifiableListView(result);
}
- List<TypeMirror> get _typeArguments => typeArguments;
-
List<TypeMirror> get typeArguments => const <TypeMirror>[];
bool get hasReflectedType => typeVariables.length == 0;
@@ -1930,15 +1804,7 @@ class JsMethodMirror extends JsDeclarationMirror implements MethodMirror {
return hasReflectableProperty(_jsFunction);
}
- DeclarationMirror get owner {
- if (_owner is! ClassMirror)
- return _owner;
- ClassMirror ownerClass = _owner;
- if (ownerClass.originalDeclaration is JsMixinApplication) {
- return ownerClass.mixin;
- }
- return _owner;
- }
+ DeclarationMirror get owner => _owner;
TypeMirror get returnType {
metadata; // Compute _returnType as a side-effect of extracting metadata.
@@ -1962,7 +1828,7 @@ class JsMethodMirror extends JsDeclarationMirror implements MethodMirror {
type = new JsFunctionTypeMirror(info.computeFunctionRti(null), owner);
} else {
TypeMirror ownerType = owner;
- JsClassDeclarationMirror ownerClass = ownerType.originalDeclaration;
+ JsClassMirror ownerClass = ownerType.originalDeclaration;
type = new JsFunctionTypeMirror(
info.computeFunctionRti(ownerClass._jsConstructorOrInterceptor),
owner);
@@ -2299,10 +2165,10 @@ TypeMirror typeMirrorFromRuntimeTypeRepresentation(
var /*int|List|JsFunction*/ type) {
// TODO(ahe): This method might benefit from using convertRtiToRuntimeType
// instead of working on strings.
- JsClassMirror ownerClass;
+ ClassMirror ownerClass;
DeclarationMirror context = owner;
while (context != null) {
- if (context is JsClassMirror) {
+ if (context is ClassMirror) {
ownerClass = context;
break;
}
@@ -2321,7 +2187,7 @@ TypeMirror typeMirrorFromRuntimeTypeRepresentation(
// [type] represents a type variable so in the context of an original
// declaration the corresponding type variable should be returned.
TypeVariable typeVariable = getMetadata(type);
- List<TypeVariableMirror> typeVariables = ownerClass._typeVariables;
+ List<TypeVariableMirror> typeVariables = ownerClass.typeVariables;
int index = findTypeVariableIndex(typeVariables, typeVariable.name);
return typeVariables[index];
} else {
@@ -2333,8 +2199,8 @@ TypeMirror typeMirrorFromRuntimeTypeRepresentation(
getTypeArgument(int index) {
TypeVariable typeVariable = getMetadata(index);
int variableIndex =
- findTypeVariableIndex(ownerClass._typeVariables, typeVariable.name);
- return ownerClass._typeArguments[variableIndex];
+ findTypeVariableIndex(ownerClass.typeVariables, typeVariable.name);
+ return ownerClass.typeArguments[variableIndex];
}
if (type is num) {
@@ -2348,7 +2214,7 @@ TypeMirror typeMirrorFromRuntimeTypeRepresentation(
var typeArgument = getTypeArgument(index);
if (typeArgument is JsTypeVariableMirror)
return '${typeArgument._metadataIndex}';
- assert(typeArgument is JsClassDeclarationMirror ||
+ assert(typeArgument is JsClassMirror ||
typeArgument is JsTypeBoundClassMirror);
return typeArgument._mangledName;
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_emitter/reflection_data_parser.dart ('k') | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698