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

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

Issue 3004433002: Encapsulate the index based maps for entities. (Closed)
Patch Set: Updated cf. comments Created 3 years, 3 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/entities.dart'; 7 import '../elements/entities.dart';
8 import '../elements/names.dart'; 8 import '../elements/names.dart';
9 import '../elements/types.dart'; 9 import '../elements/types.dart';
10 import 'elements.dart'; 10 import 'indexed.dart';
11 11
12 const String kElementPrefix = 'k:'; 12 const String kElementPrefix = 'k:';
13 13
14 class KLibrary implements IndexedLibrary { 14 class KLibrary extends IndexedLibrary {
15 /// Library index used for fast lookup in [KernelWorldBuilder].
16 final int libraryIndex;
17 final String name; 15 final String name;
18 final Uri canonicalUri; 16 final Uri canonicalUri;
19 17
20 KLibrary(this.libraryIndex, this.name, this.canonicalUri); 18 KLibrary(this.name, this.canonicalUri);
21 19
22 String toString() => '${kElementPrefix}library($name)'; 20 String toString() => '${kElementPrefix}library($name)';
23 } 21 }
24 22
25 class KClass implements IndexedClass { 23 class KClass extends IndexedClass {
26 final KLibrary library; 24 final KLibrary library;
27 25
28 /// Class index used for fast lookup in [KernelWorldBuilder].
29 final int classIndex;
30
31 final String name; 26 final String name;
32 final bool isAbstract; 27 final bool isAbstract;
33 28
34 KClass(this.library, this.classIndex, this.name, {this.isAbstract}); 29 KClass(this.library, this.name, {this.isAbstract});
35 30
36 @override 31 @override
37 bool get isClosure => false; 32 bool get isClosure => false;
38 33
39 String toString() => '${kElementPrefix}class($name)'; 34 String toString() => '${kElementPrefix}class($name)';
40 } 35 }
41 36
42 abstract class KMember implements IndexedMember { 37 abstract class KMember extends IndexedMember {
43 /// Member index used for fast lookup in [KernelWorldBuilder].
44 final int memberIndex;
45 final KLibrary library; 38 final KLibrary library;
46 final KClass enclosingClass; 39 final KClass enclosingClass;
47 final Name _name; 40 final Name _name;
48 final bool _isStatic; 41 final bool _isStatic;
49 42
50 KMember(this.memberIndex, this.library, this.enclosingClass, this._name, 43 KMember(this.library, this.enclosingClass, this._name, {bool isStatic: false})
51 {bool isStatic: false})
52 : _isStatic = isStatic; 44 : _isStatic = isStatic;
53 45
54 String get name => _name.text; 46 String get name => _name.text;
55 47
56 Name get memberName => _name; 48 Name get memberName => _name;
57 49
58 @override 50 @override
59 bool get isAssignable => false; 51 bool get isAssignable => false;
60 52
61 @override 53 @override
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 String toString() => '${kElementPrefix}$_kind' 85 String toString() => '${kElementPrefix}$_kind'
94 '(${enclosingClass != null ? '${enclosingClass.name}.' : ''}$name)'; 86 '(${enclosingClass != null ? '${enclosingClass.name}.' : ''}$name)';
95 } 87 }
96 88
97 abstract class KFunction extends KMember 89 abstract class KFunction extends KMember
98 implements FunctionEntity, IndexedFunction { 90 implements FunctionEntity, IndexedFunction {
99 final ParameterStructure parameterStructure; 91 final ParameterStructure parameterStructure;
100 final bool isExternal; 92 final bool isExternal;
101 final AsyncMarker asyncMarker; 93 final AsyncMarker asyncMarker;
102 94
103 KFunction(int memberIndex, KLibrary library, KClass enclosingClass, Name name, 95 KFunction(KLibrary library, KClass enclosingClass, Name name,
104 this.parameterStructure, this.asyncMarker, 96 this.parameterStructure, this.asyncMarker,
105 {bool isStatic: false, this.isExternal: false}) 97 {bool isStatic: false, this.isExternal: false})
106 : super(memberIndex, library, enclosingClass, name, isStatic: isStatic); 98 : super(library, enclosingClass, name, isStatic: isStatic);
107 } 99 }
108 100
109 abstract class KConstructor extends KFunction 101 abstract class KConstructor extends KFunction
110 implements ConstructorEntity, IndexedConstructor { 102 implements ConstructorEntity, IndexedConstructor {
111 final bool isConst; 103 final bool isConst;
112 104
113 KConstructor(int memberIndex, KClass enclosingClass, Name name, 105 KConstructor(
114 ParameterStructure parameterStructure, {bool isExternal, this.isConst}) 106 KClass enclosingClass, Name name, ParameterStructure parameterStructure,
115 : super(memberIndex, enclosingClass.library, enclosingClass, name, 107 {bool isExternal, this.isConst})
116 parameterStructure, AsyncMarker.SYNC, 108 : super(enclosingClass.library, enclosingClass, name, parameterStructure,
109 AsyncMarker.SYNC,
117 isExternal: isExternal); 110 isExternal: isExternal);
118 111
119 @override 112 @override
120 bool get isConstructor => true; 113 bool get isConstructor => true;
121 114
122 @override 115 @override
123 bool get isInstanceMember => false; 116 bool get isInstanceMember => false;
124 117
125 @override 118 @override
126 bool get isStatic => false; 119 bool get isStatic => false;
127 120
128 @override 121 @override
129 bool get isTopLevel => false; 122 bool get isTopLevel => false;
130 123
131 @override 124 @override
132 bool get isFromEnvironmentConstructor => false; 125 bool get isFromEnvironmentConstructor => false;
133 126
134 String get _kind => 'constructor'; 127 String get _kind => 'constructor';
135 } 128 }
136 129
137 class KGenerativeConstructor extends KConstructor { 130 class KGenerativeConstructor extends KConstructor {
138 KGenerativeConstructor(int constructorIndex, KClass enclosingClass, Name name, 131 KGenerativeConstructor(
139 ParameterStructure parameterStructure, {bool isExternal, bool isConst}) 132 KClass enclosingClass, Name name, ParameterStructure parameterStructure,
140 : super(constructorIndex, enclosingClass, name, parameterStructure, 133 {bool isExternal, bool isConst})
134 : super(enclosingClass, name, parameterStructure,
141 isExternal: isExternal, isConst: isConst); 135 isExternal: isExternal, isConst: isConst);
142 136
143 @override 137 @override
144 bool get isFactoryConstructor => false; 138 bool get isFactoryConstructor => false;
145 139
146 @override 140 @override
147 bool get isGenerativeConstructor => true; 141 bool get isGenerativeConstructor => true;
148 } 142 }
149 143
150 class KFactoryConstructor extends KConstructor { 144 class KFactoryConstructor extends KConstructor {
151 @override 145 @override
152 final bool isFromEnvironmentConstructor; 146 final bool isFromEnvironmentConstructor;
153 147
154 KFactoryConstructor(int memberIndex, KClass enclosingClass, Name name, 148 KFactoryConstructor(
155 ParameterStructure parameterStructure, 149 KClass enclosingClass, Name name, ParameterStructure parameterStructure,
156 {bool isExternal, bool isConst, this.isFromEnvironmentConstructor}) 150 {bool isExternal, bool isConst, this.isFromEnvironmentConstructor})
157 : super(memberIndex, enclosingClass, name, parameterStructure, 151 : super(enclosingClass, name, parameterStructure,
158 isExternal: isExternal, isConst: isConst); 152 isExternal: isExternal, isConst: isConst);
159 153
160 @override 154 @override
161 bool get isFactoryConstructor => true; 155 bool get isFactoryConstructor => true;
162 156
163 @override 157 @override
164 bool get isGenerativeConstructor => false; 158 bool get isGenerativeConstructor => false;
165 } 159 }
166 160
167 class KConstructorBody extends KFunction implements ConstructorBodyEntity { 161 class KConstructorBody extends KFunction implements ConstructorBodyEntity {
168 final ConstructorEntity constructor; 162 final ConstructorEntity constructor;
169 163
170 KConstructorBody(int memberIndex, this.constructor) 164 KConstructorBody(this.constructor)
171 : super( 165 : super(
172 memberIndex,
173 constructor.library, 166 constructor.library,
174 constructor.enclosingClass, 167 constructor.enclosingClass,
175 constructor.memberName, 168 constructor.memberName,
176 constructor.parameterStructure, 169 constructor.parameterStructure,
177 AsyncMarker.SYNC, 170 AsyncMarker.SYNC,
178 isStatic: false, 171 isStatic: false,
179 isExternal: false); 172 isExternal: false);
180 173
181 @override 174 @override
182 bool get isFunction => true; 175 bool get isFunction => true;
183 176
184 String get _kind => 'constructor_body'; 177 String get _kind => 'constructor_body';
185 } 178 }
186 179
187 class KMethod extends KFunction { 180 class KMethod extends KFunction {
188 final bool isAbstract; 181 final bool isAbstract;
189 182
190 KMethod(int memberIndex, KLibrary library, KClass enclosingClass, Name name, 183 KMethod(KLibrary library, KClass enclosingClass, Name name,
191 ParameterStructure parameterStructure, AsyncMarker asyncMarker, 184 ParameterStructure parameterStructure, AsyncMarker asyncMarker,
192 {bool isStatic, bool isExternal, this.isAbstract}) 185 {bool isStatic, bool isExternal, this.isAbstract})
193 : super(memberIndex, library, enclosingClass, name, parameterStructure, 186 : super(library, enclosingClass, name, parameterStructure, asyncMarker,
194 asyncMarker,
195 isStatic: isStatic, isExternal: isExternal); 187 isStatic: isStatic, isExternal: isExternal);
196 188
197 @override 189 @override
198 bool get isFunction => true; 190 bool get isFunction => true;
199 191
200 String get _kind => 'method'; 192 String get _kind => 'method';
201 } 193 }
202 194
203 class KGetter extends KFunction { 195 class KGetter extends KFunction {
204 final bool isAbstract; 196 final bool isAbstract;
205 197
206 KGetter(int memberIndex, KLibrary library, KClass enclosingClass, Name name, 198 KGetter(KLibrary library, KClass enclosingClass, Name name,
207 AsyncMarker asyncMarker, 199 AsyncMarker asyncMarker,
208 {bool isStatic, bool isExternal, this.isAbstract}) 200 {bool isStatic, bool isExternal, this.isAbstract})
209 : super(memberIndex, library, enclosingClass, name, 201 : super(library, enclosingClass, name, const ParameterStructure.getter(),
210 const ParameterStructure.getter(), asyncMarker, 202 asyncMarker,
211 isStatic: isStatic, isExternal: isExternal); 203 isStatic: isStatic, isExternal: isExternal);
212 204
213 @override 205 @override
214 bool get isGetter => true; 206 bool get isGetter => true;
215 207
216 String get _kind => 'getter'; 208 String get _kind => 'getter';
217 } 209 }
218 210
219 class KSetter extends KFunction { 211 class KSetter extends KFunction {
220 final bool isAbstract; 212 final bool isAbstract;
221 213
222 KSetter(int memberIndex, KLibrary library, KClass enclosingClass, Name name, 214 KSetter(KLibrary library, KClass enclosingClass, Name name,
223 {bool isStatic, bool isExternal, this.isAbstract}) 215 {bool isStatic, bool isExternal, this.isAbstract})
224 : super(memberIndex, library, enclosingClass, name, 216 : super(library, enclosingClass, name, const ParameterStructure.setter(),
225 const ParameterStructure.setter(), AsyncMarker.SYNC, 217 AsyncMarker.SYNC,
226 isStatic: isStatic, isExternal: isExternal); 218 isStatic: isStatic, isExternal: isExternal);
227 219
228 @override 220 @override
229 bool get isAssignable => true; 221 bool get isAssignable => true;
230 222
231 @override 223 @override
232 bool get isSetter => true; 224 bool get isSetter => true;
233 225
234 String get _kind => 'setter'; 226 String get _kind => 'setter';
235 } 227 }
236 228
237 class KField extends KMember implements FieldEntity, IndexedField { 229 class KField extends KMember implements FieldEntity, IndexedField {
238 final bool isAssignable; 230 final bool isAssignable;
239 final bool isConst; 231 final bool isConst;
240 232
241 KField(int memberIndex, KLibrary library, KClass enclosingClass, Name name, 233 KField(KLibrary library, KClass enclosingClass, Name name,
242 {bool isStatic, this.isAssignable, this.isConst}) 234 {bool isStatic, this.isAssignable, this.isConst})
243 : super(memberIndex, library, enclosingClass, name, isStatic: isStatic); 235 : super(library, enclosingClass, name, isStatic: isStatic);
244 236
245 @override 237 @override
246 bool get isField => true; 238 bool get isField => true;
247 239
248 String get _kind => 'field'; 240 String get _kind => 'field';
249 } 241 }
250 242
251 class KTypeVariable implements TypeVariableEntity, IndexedTypeVariable { 243 class KTypeVariable extends IndexedTypeVariable {
252 final int typeVariableIndex;
253 final Entity typeDeclaration; 244 final Entity typeDeclaration;
254 final String name; 245 final String name;
255 final int index; 246 final int index;
256 247
257 KTypeVariable( 248 KTypeVariable(this.typeDeclaration, this.name, this.index);
258 this.typeVariableIndex, this.typeDeclaration, this.name, this.index);
259 249
260 String toString() => 250 String toString() =>
261 '${kElementPrefix}type_variable(${typeDeclaration.name}.$name)'; 251 '${kElementPrefix}type_variable(${typeDeclaration.name}.$name)';
262 } 252 }
263 253
264 class KLocalFunction implements Local { 254 class KLocalFunction implements Local {
265 final String name; 255 final String name;
266 final MemberEntity memberContext; 256 final MemberEntity memberContext;
267 final Entity executableContext; 257 final Entity executableContext;
268 final FunctionType functionType; 258 final FunctionType functionType;
269 259
270 KLocalFunction( 260 KLocalFunction(
271 this.name, this.memberContext, this.executableContext, this.functionType); 261 this.name, this.memberContext, this.executableContext, this.functionType);
272 262
273 String toString() => '${kElementPrefix}local_function' 263 String toString() => '${kElementPrefix}local_function'
274 '(${memberContext.name}.${name ?? '<anonymous>'})'; 264 '(${memberContext.name}.${name ?? '<anonymous>'})';
275 } 265 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/indexed.dart ('k') | tests/compiler/dart2js/kernel/test_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698