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

Unified Diff: pkg/compiler/lib/src/kernel/element_map_impl.dart

Issue 2996723002: Support typedef type literals (Closed)
Patch Set: Cleanup Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/kernel/element_map_impl.dart
diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart
index 71e0ad180e7a3030a442d6865f94765f845bf362..8db70b2e06990dfb7c15c70e05e08e57f8dfb783 100644
--- a/pkg/compiler/lib/src/kernel/element_map_impl.dart
+++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart
@@ -82,6 +82,7 @@ abstract class KernelToElementMapBase extends KernelToElementMapBaseMixin {
List<ClassEntity> _classList = <ClassEntity>[];
List<MemberEntity> _memberList = <MemberEntity>[];
List<TypeVariableEntity> _typeVariableList = <TypeVariableEntity>[];
+ List<TypedefEntity> _typedefList = <TypedefEntity>[];
/// List of library environments by `IndexedLibrary.libraryIndex`. This is
/// used for fast lookup into library classes and members.
@@ -103,6 +104,10 @@ abstract class KernelToElementMapBase extends KernelToElementMapBaseMixin {
/// fast lookup into member properties.
List<MemberData> _memberData = <MemberData>[];
+ /// List of typedef data by `IndexedTypedef.typedefIndex`. This is used for
+ /// fast lookup into typedef properties.
+ List<TypedefData> _typedefData = <TypedefData>[];
+
KernelToElementMapBase(this.reporter, Environment environment) {
_elementEnvironment = new KernelElementEnvironment(this);
_commonElements = new CommonElements(_elementEnvironment);
@@ -324,6 +329,14 @@ abstract class KernelToElementMapBase extends KernelToElementMapBaseMixin {
}
@override
+ TypedefType getTypedefType(ir.Typedef node) {
+ IndexedTypedef typedef = _getTypedef(node);
+ return _typedefData[typedef.typedefIndex].rawType;
+ }
+
+ TypedefEntity _getTypedef(ir.Typedef node);
+
+ @override
MemberEntity getMember(ir.Member node) {
if (node is ir.Field) {
return _getField(node);
@@ -611,9 +624,12 @@ abstract class ElementCreatorMixin {
List<MemberEntity> get _memberList;
List<MemberData> get _memberData;
List<TypeVariableEntity> get _typeVariableList;
+ List<TypedefEntity> get _typedefList;
+ List<TypedefData> get _typedefData;
Siggi Cherem (dart-lang) 2017/08/09 16:38:07 given we have so many of these now, it might be wo
Johnni Winther 2017/08/10 08:18:34 Acknowledged. Will do in a follow-up.
Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{};
Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{};
+ Map<ir.Typedef, IndexedTypedef> _typedefMap = <ir.Typedef, IndexedTypedef>{};
Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap =
<ir.TypeParameter, IndexedTypeVariable>{};
Map<ir.Member, IndexedConstructor> _constructorMap =
@@ -671,6 +687,21 @@ abstract class ElementCreatorMixin {
});
}
+ TypedefEntity _getTypedef(ir.Typedef node) {
+ return _typedefMap.putIfAbsent(node, () {
+ IndexedLibrary library = _getLibrary(node.enclosingLibrary);
+ TypedefEntity typedef =
+ createTypedef(library, _typedefList.length, node.name);
+ TypedefType typedefType = new TypedefType(
+ typedef,
+ new List<DartType>.filled(
+ node.typeParameters.length, const DynamicType()));
+ _typedefData.add(new TypedefData(node, typedef, typedefType));
+ _typedefList.add(typedef);
+ return typedef;
+ });
+ }
+
TypeVariableEntity _getTypeVariable(ir.TypeParameter node) {
return _typeVariableMap.putIfAbsent(node, () {
if (node.parent is ir.Class) {
@@ -855,6 +886,9 @@ abstract class ElementCreatorMixin {
IndexedClass createClass(LibraryEntity library, int classIndex, String name,
{bool isAbstract});
+ IndexedTypedef createTypedef(
+ LibraryEntity library, int typedefIndex, String name);
+
TypeVariableEntity createTypeVariable(
int typeVariableIndex, Entity typeDeclaration, String name, int index);
@@ -911,6 +945,12 @@ abstract class KElementCreatorMixin implements ElementCreatorMixin {
return new KClass(library, classIndex, name, isAbstract: isAbstract);
}
+ @override
+ IndexedTypedef createTypedef(
+ LibraryEntity library, int typedefIndex, String name) {
+ throw new UnsupportedError('KElementCreatorMixin.createTypedef');
+ }
+
TypeVariableEntity createTypeVariable(
int typeVariableIndex, Entity typeDeclaration, String name, int index) {
return new KTypeVariable(typeVariableIndex, typeDeclaration, name, index);

Powered by Google App Engine
This is Rietveld 408576698