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

Side by Side Diff: pkg/compiler/lib/src/kernel/elements.dart

Issue 2731173002: Add ClassEntity.library, MemberEntity.library and FunctionEntity.isExternal (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 /// Entity model for elements derived from Kernel IR. 5 /// Entity model for elements derived from Kernel IR.
6 6
7 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
8 import '../elements/entities.dart'; 8 import '../elements/entities.dart';
9 9
10 class KLibrary implements LibraryEntity { 10 class KLibrary implements LibraryEntity {
11 /// Library index used for fast lookup in [KernelWorldBuilder]. 11 /// Library index used for fast lookup in [KernelWorldBuilder].
12 final int libraryIndex; 12 final int libraryIndex;
13 final String name; 13 final String name;
14 14
15 KLibrary(this.libraryIndex, this.name); 15 KLibrary(this.libraryIndex, this.name);
16 16
17 String toString() => 'library($name)'; 17 String toString() => 'library($name)';
18 } 18 }
19 19
20 class KClass implements ClassEntity { 20 class KClass implements ClassEntity {
21 final KLibrary library;
22
21 /// Class index used for fast lookup in [KernelWorldBuilder]. 23 /// Class index used for fast lookup in [KernelWorldBuilder].
22 final int classIndex; 24 final int classIndex;
23 final String name; 25 final String name;
24 26
25 KClass(this.classIndex, this.name); 27 KClass(this.library, this.classIndex, this.name);
26 28
27 @override 29 @override
28 bool get isClosure => false; 30 bool get isClosure => false;
29 31
30 String toString() => 'class($name)'; 32 String toString() => 'class($name)';
31 } 33 }
32 34
33 abstract class KMember implements MemberEntity { 35 abstract class KMember implements MemberEntity {
36 final KLibrary library;
34 final KClass enclosingClass; 37 final KClass enclosingClass;
35 final Name _name; 38 final Name _name;
36 final bool _isStatic; 39 final bool _isStatic;
37 40
38 KMember(this.enclosingClass, this._name, {bool isStatic: false}) 41 KMember(this.library, this.enclosingClass, this._name, {bool isStatic: false})
39 : _isStatic = isStatic; 42 : _isStatic = isStatic;
40 43
41 String get name => _name.text; 44 String get name => _name.text;
42 45
43 @override 46 @override
44 bool get isAssignable => false; 47 bool get isAssignable => false;
45 48
46 @override 49 @override
47 bool get isSetter => false; 50 bool get isSetter => false;
48 51
(...skipping 18 matching lines...) Expand all
67 @override 70 @override
68 bool get isTopLevel => enclosingClass == null; 71 bool get isTopLevel => enclosingClass == null;
69 72
70 String get _kind; 73 String get _kind;
71 74
72 String toString() => 75 String toString() =>
73 '$_kind(${enclosingClass != null ? '${enclosingClass.name}.' : ''}$name)'; 76 '$_kind(${enclosingClass != null ? '${enclosingClass.name}.' : ''}$name)';
74 } 77 }
75 78
76 abstract class KFunction extends KMember implements FunctionEntity { 79 abstract class KFunction extends KMember implements FunctionEntity {
77 KFunction(KClass enclosingClass, Name name, {bool isStatic: false}) 80 final bool isExternal;
78 : super(enclosingClass, name, isStatic: isStatic); 81
82 KFunction(KLibrary library, KClass enclosingClass, Name name,
83 {bool isStatic: false, this.isExternal: false})
84 : super(library, enclosingClass, name, isStatic: isStatic);
79 } 85 }
80 86
81 abstract class KConstructor extends KFunction implements ConstructorEntity { 87 abstract class KConstructor extends KFunction implements ConstructorEntity {
82 /// Constructor index used for fast lookup in [KernelWorldBuilder]. 88 /// Constructor index used for fast lookup in [KernelWorldBuilder].
83 final int constructorIndex; 89 final int constructorIndex;
84 90
85 KConstructor(this.constructorIndex, KClass enclosingClass, Name name) 91 KConstructor(this.constructorIndex, KClass enclosingClass, Name name,
86 : super(enclosingClass, name); 92 {bool isExternal})
93 : super(enclosingClass.library, enclosingClass, name,
94 isExternal: isExternal);
87 95
88 @override 96 @override
89 bool get isConstructor => true; 97 bool get isConstructor => true;
90 98
91 @override 99 @override
92 bool get isInstanceMember => false; 100 bool get isInstanceMember => false;
93 101
94 @override 102 @override
95 bool get isStatic => false; 103 bool get isStatic => false;
96 104
97 @override 105 @override
98 bool get isTopLevel => false; 106 bool get isTopLevel => false;
99 107
100 String get _kind => 'constructor'; 108 String get _kind => 'constructor';
101 } 109 }
102 110
103 class KGenerativeConstructor extends KConstructor { 111 class KGenerativeConstructor extends KConstructor {
104 KGenerativeConstructor(int constructorIndex, KClass enclosingClass, Name name) 112 KGenerativeConstructor(int constructorIndex, KClass enclosingClass, Name name,
105 : super(constructorIndex, enclosingClass, name); 113 {bool isExternal})
114 : super(constructorIndex, enclosingClass, name, isExternal: isExternal);
106 115
107 @override 116 @override
108 bool get isFactoryConstructor => false; 117 bool get isFactoryConstructor => false;
109 118
110 @override 119 @override
111 bool get isGenerativeConstructor => true; 120 bool get isGenerativeConstructor => true;
112 } 121 }
113 122
114 class KFactoryConstructor extends KConstructor { 123 class KFactoryConstructor extends KConstructor {
115 KFactoryConstructor(int constructorIndex, KClass enclosingClass, Name name) 124 KFactoryConstructor(int constructorIndex, KClass enclosingClass, Name name,
116 : super(constructorIndex, enclosingClass, name); 125 {bool isExternal})
126 : super(constructorIndex, enclosingClass, name, isExternal: isExternal);
117 127
118 @override 128 @override
119 bool get isFactoryConstructor => true; 129 bool get isFactoryConstructor => true;
120 130
121 @override 131 @override
122 bool get isGenerativeConstructor => false; 132 bool get isGenerativeConstructor => false;
123 } 133 }
124 134
125 class KMethod extends KFunction { 135 class KMethod extends KFunction {
126 KMethod(KClass enclosingClass, Name name, {bool isStatic}) 136 KMethod(KLibrary library, KClass enclosingClass, Name name,
127 : super(enclosingClass, name, isStatic: isStatic); 137 {bool isStatic, bool isExternal})
138 : super(library, enclosingClass, name,
139 isStatic: isStatic, isExternal: isExternal);
128 140
129 @override 141 @override
130 bool get isFunction => true; 142 bool get isFunction => true;
131 143
132 String get _kind => 'method'; 144 String get _kind => 'method';
133 } 145 }
134 146
135 class KGetter extends KFunction { 147 class KGetter extends KFunction {
136 KGetter(KClass enclosingClass, Name name, {bool isStatic}) 148 KGetter(KLibrary library, KClass enclosingClass, Name name,
137 : super(enclosingClass, name, isStatic: isStatic); 149 {bool isStatic, bool isExternal})
150 : super(library, enclosingClass, name,
151 isStatic: isStatic, isExternal: isExternal);
138 152
139 @override 153 @override
140 bool get isGetter => true; 154 bool get isGetter => true;
141 155
142 String get _kind => 'getter'; 156 String get _kind => 'getter';
143 } 157 }
144 158
145 class KSetter extends KFunction { 159 class KSetter extends KFunction {
146 KSetter(KClass enclosingClass, Name name, {bool isStatic}) 160 KSetter(KLibrary library, KClass enclosingClass, Name name,
147 : super(enclosingClass, name, isStatic: isStatic); 161 {bool isStatic, bool isExternal})
162 : super(library, enclosingClass, name,
163 isStatic: isStatic, isExternal: isExternal);
148 164
149 @override 165 @override
150 bool get isAssignable => true; 166 bool get isAssignable => true;
151 167
152 @override 168 @override
153 bool get isSetter => true; 169 bool get isSetter => true;
154 170
155 String get _kind => 'setter'; 171 String get _kind => 'setter';
156 } 172 }
157 173
158 class KField extends KMember implements FieldEntity { 174 class KField extends KMember implements FieldEntity {
159 /// Field index used for fast lookup in [KernelWorldBuilder]. 175 /// Field index used for fast lookup in [KernelWorldBuilder].
160 final int fieldIndex; 176 final int fieldIndex;
161 final bool isAssignable; 177 final bool isAssignable;
162 178
163 KField(this.fieldIndex, KClass enclosingClass, Name name, 179 KField(this.fieldIndex, KLibrary library, KClass enclosingClass, Name name,
164 {bool isStatic, this.isAssignable}) 180 {bool isStatic, this.isAssignable})
165 : super(enclosingClass, name, isStatic: isStatic); 181 : super(library, enclosingClass, name, isStatic: isStatic);
166 182
167 @override 183 @override
168 bool get isField => true; 184 bool get isField => true;
169 185
170 String get _kind => 'field'; 186 String get _kind => 'field';
171 } 187 }
172 188
173 class KTypeVariable implements TypeVariableEntity { 189 class KTypeVariable implements TypeVariableEntity {
174 final Entity typeDeclaration; 190 final Entity typeDeclaration;
175 final String name; 191 final String name;
176 final int index; 192 final int index;
177 193
178 KTypeVariable(this.typeDeclaration, this.name, this.index); 194 KTypeVariable(this.typeDeclaration, this.name, this.index);
179 195
180 String toString() => 'type_variable(${typeDeclaration.name}.$name)'; 196 String toString() => 'type_variable(${typeDeclaration.name}.$name)';
181 } 197 }
182 198
183 class KLocalFunction implements Local { 199 class KLocalFunction implements Local {
184 final String name; 200 final String name;
185 final MemberEntity memberContext; 201 final MemberEntity memberContext;
186 final Entity executableContext; 202 final Entity executableContext;
187 203
188 KLocalFunction(this.name, this.memberContext, this.executableContext); 204 KLocalFunction(this.name, this.memberContext, this.executableContext);
189 205
190 String toString() => 206 String toString() =>
191 'local_function(${memberContext.name}.${name ?? '<anonymous>'})'; 207 'local_function(${memberContext.name}.${name ?? '<anonymous>'})';
192 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698