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

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

Issue 2969013002: Support creating elements from IR nodes in JsKernelToElementMap (Closed)
Patch Set: Updated cf. comments Created 3 years, 5 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 library dart2js.js_model.elements; 5 library dart2js.js_model.elements;
6 6
7 import '../common_elements.dart'; 7 import '../common_elements.dart';
8 import '../constants/constant_system.dart'; 8 import '../constants/constant_system.dart';
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../elements/entities.dart'; 10 import '../elements/entities.dart';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 91
92 TypeVariableEntity createTypeVariable( 92 TypeVariableEntity createTypeVariable(
93 Entity typeDeclaration, TypeVariableEntity typeVariable) { 93 Entity typeDeclaration, TypeVariableEntity typeVariable) {
94 return new JTypeVariable( 94 return new JTypeVariable(
95 typeDeclaration, typeVariable.name, typeVariable.index); 95 typeDeclaration, typeVariable.name, typeVariable.index);
96 } 96 }
97 } 97 }
98 98
99 class JsElementCreatorMixin { 99 class JsElementCreatorMixin {
100 LibraryEntity createLibrary(IndexedLibrary library) { 100 IndexedLibrary createLibrary(
101 return new JLibrary( 101 int libraryIndex, String name, Uri canonicalUri) {
102 return new JLibrary(libraryIndex, name, canonicalUri);
103 }
104
105 IndexedClass createClass(LibraryEntity library, int classIndex, String name,
106 {bool isAbstract}) {
107 return new JClass(library, classIndex, name, isAbstract: isAbstract);
108 }
109
110 TypeVariableEntity createTypeVariable(
111 Entity typeDeclaration, String name, int index) {
112 throw new UnsupportedError('JsElementCreatorMixin.createTypeVariable');
113 }
114
115 IndexedConstructor createGenerativeConstructor(
116 int memberIndex,
117 ClassEntity enclosingClass,
118 Name name,
119 ParameterStructure parameterStructure,
120 {bool isExternal,
121 bool isConst}) {
122 return new JGenerativeConstructor(
123 memberIndex, enclosingClass, name, parameterStructure,
124 isExternal: isExternal, isConst: isConst);
125 }
126
127 IndexedConstructor createFactoryConstructor(
128 int memberIndex,
129 ClassEntity enclosingClass,
130 Name name,
131 ParameterStructure parameterStructure,
132 {bool isExternal,
133 bool isConst,
134 bool isFromEnvironmentConstructor}) {
135 return new JFactoryConstructor(
136 memberIndex, enclosingClass, name, parameterStructure,
137 isExternal: isExternal,
138 isConst: isConst,
139 isFromEnvironmentConstructor: isFromEnvironmentConstructor);
140 }
141
142 IndexedFunction createGetter(int memberIndex, LibraryEntity library,
143 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker,
144 {bool isStatic, bool isExternal, bool isAbstract}) {
145 return new JGetter(memberIndex, library, enclosingClass, name, asyncMarker,
146 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract);
147 }
148
149 IndexedFunction createMethod(
150 int memberIndex,
151 LibraryEntity library,
152 ClassEntity enclosingClass,
153 Name name,
154 ParameterStructure parameterStructure,
155 AsyncMarker asyncMarker,
156 {bool isStatic,
157 bool isExternal,
158 bool isAbstract}) {
159 return new JMethod(memberIndex, library, enclosingClass, name,
160 parameterStructure, asyncMarker,
161 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract);
162 }
163
164 IndexedFunction createSetter(int memberIndex, LibraryEntity library,
165 ClassEntity enclosingClass, Name name,
166 {bool isStatic, bool isExternal, bool isAbstract}) {
167 return new JSetter(memberIndex, library, enclosingClass, name,
168 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract);
169 }
170
171 IndexedField createField(int memberIndex, LibraryEntity library,
172 ClassEntity enclosingClass, Name name,
173 {bool isStatic, bool isAssignable, bool isConst}) {
174 return new JField(memberIndex, library, enclosingClass, name,
175 isStatic: isStatic, isAssignable: isAssignable, isConst: isConst);
176 }
177
178 Local createLocalFunction(String name, MemberEntity memberContext,
179 Entity executableContext, FunctionType functionType) {
180 throw new UnsupportedError('JsElementCreatorMixin.createLocalFunction');
181 }
182
183 LibraryEntity convertLibrary(IndexedLibrary library) {
184 return createLibrary(
102 library.libraryIndex, library.name, library.canonicalUri); 185 library.libraryIndex, library.name, library.canonicalUri);
103 } 186 }
104 187
105 ClassEntity createClass(LibraryEntity library, IndexedClass cls) { 188 ClassEntity convertClass(LibraryEntity library, IndexedClass cls) {
106 return new JClass(library, cls.classIndex, cls.name, 189 return createClass(library, cls.classIndex, cls.name,
107 isAbstract: cls.isAbstract); 190 isAbstract: cls.isAbstract);
108 } 191 }
109 192
110 MemberEntity createMember( 193 MemberEntity convertMember(
111 LibraryEntity library, ClassEntity cls, IndexedMember member) { 194 LibraryEntity library, ClassEntity cls, IndexedMember member) {
112 Name memberName = new Name(member.memberName.text, library, 195 Name memberName = new Name(member.memberName.text, library,
113 isSetter: member.memberName.isSetter); 196 isSetter: member.memberName.isSetter);
114 if (member.isField) { 197 if (member.isField) {
115 IndexedField field = member; 198 IndexedField field = member;
116 return new JField(member.memberIndex, library, cls, memberName, 199 return createField(member.memberIndex, library, cls, memberName,
117 isStatic: field.isStatic, 200 isStatic: field.isStatic,
118 isAssignable: field.isAssignable, 201 isAssignable: field.isAssignable,
119 isConst: field.isConst); 202 isConst: field.isConst);
120 } else if (member.isConstructor) { 203 } else if (member.isConstructor) {
121 IndexedConstructor constructor = member; 204 IndexedConstructor constructor = member;
122 if (constructor.isFactoryConstructor) { 205 if (constructor.isFactoryConstructor) {
123 // TODO(redemption): This should be a JFunction. 206 // TODO(redemption): This should be a JFunction.
124 return new JFactoryConstructor( 207 return createFactoryConstructor(
125 member.memberIndex, cls, memberName, constructor.parameterStructure, 208 member.memberIndex, cls, memberName, constructor.parameterStructure,
126 isExternal: constructor.isExternal, 209 isExternal: constructor.isExternal,
127 isConst: constructor.isConst, 210 isConst: constructor.isConst,
128 isFromEnvironmentConstructor: 211 isFromEnvironmentConstructor:
129 constructor.isFromEnvironmentConstructor); 212 constructor.isFromEnvironmentConstructor);
130 } else { 213 } else {
131 return new JGenerativeConstructor( 214 return createGenerativeConstructor(
132 member.memberIndex, cls, memberName, constructor.parameterStructure, 215 member.memberIndex, cls, memberName, constructor.parameterStructure,
133 isExternal: constructor.isExternal, isConst: constructor.isConst); 216 isExternal: constructor.isExternal, isConst: constructor.isConst);
134 } 217 }
135 } else if (member.isGetter) { 218 } else if (member.isGetter) {
136 IndexedFunction getter = member; 219 IndexedFunction getter = member;
137 return new JGetter( 220 return createGetter(
138 member.memberIndex, library, cls, memberName, getter.asyncMarker, 221 member.memberIndex, library, cls, memberName, getter.asyncMarker,
139 isStatic: getter.isStatic, 222 isStatic: getter.isStatic,
140 isExternal: getter.isExternal, 223 isExternal: getter.isExternal,
141 isAbstract: getter.isAbstract); 224 isAbstract: getter.isAbstract);
142 } else if (member.isSetter) { 225 } else if (member.isSetter) {
143 IndexedFunction setter = member; 226 IndexedFunction setter = member;
144 return new JSetter(member.memberIndex, library, cls, memberName, 227 return createSetter(member.memberIndex, library, cls, memberName,
145 isStatic: setter.isStatic, 228 isStatic: setter.isStatic,
146 isExternal: setter.isExternal, 229 isExternal: setter.isExternal,
147 isAbstract: setter.isAbstract); 230 isAbstract: setter.isAbstract);
148 } else { 231 } else {
149 IndexedFunction function = member; 232 IndexedFunction function = member;
150 return new JMethod(member.memberIndex, library, cls, memberName, 233 return createMethod(member.memberIndex, library, cls, memberName,
151 function.parameterStructure, function.asyncMarker, 234 function.parameterStructure, function.asyncMarker,
152 isStatic: function.isStatic, 235 isStatic: function.isStatic,
153 isExternal: function.isExternal, 236 isExternal: function.isExternal,
154 isAbstract: function.isAbstract); 237 isAbstract: function.isAbstract);
155 } 238 }
156 } 239 }
157 } 240 }
158 241
159 typedef Entity EntityConverter(Entity cls); 242 typedef Entity EntityConverter(Entity cls);
160 243
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 TypeVariableType type, EntityConverter converter) { 283 TypeVariableType type, EntityConverter converter) {
201 return new TypeVariableType(converter(type.element)); 284 return new TypeVariableType(converter(type.element));
202 } 285 }
203 286
204 @override 287 @override
205 DartType visitVoidType(VoidType type, EntityConverter converter) { 288 DartType visitVoidType(VoidType type, EntityConverter converter) {
206 return const VoidType(); 289 return const VoidType();
207 } 290 }
208 } 291 }
209 292
293 const String jsElementPrefix = 'j';
294
210 class JLibrary implements LibraryEntity, IndexedLibrary { 295 class JLibrary implements LibraryEntity, IndexedLibrary {
211 /// Library index used for fast lookup in [JsToFrontendMapImpl]. 296 /// Library index used for fast lookup in [JsToFrontendMapImpl].
212 final int libraryIndex; 297 final int libraryIndex;
213 final String name; 298 final String name;
214 final Uri canonicalUri; 299 final Uri canonicalUri;
215 300
216 JLibrary(this.libraryIndex, this.name, this.canonicalUri); 301 JLibrary(this.libraryIndex, this.name, this.canonicalUri);
217 302
218 String toString() => 'library($name)'; 303 String toString() => '${jsElementPrefix}library($name)';
219 } 304 }
220 305
221 class JClass implements ClassEntity, IndexedClass { 306 class JClass implements ClassEntity, IndexedClass {
222 final JLibrary library; 307 final JLibrary library;
223 308
224 /// Class index used for fast lookup in [JsToFrontendMapImpl]. 309 /// Class index used for fast lookup in [JsToFrontendMapImpl].
225 final int classIndex; 310 final int classIndex;
226 311
227 final String name; 312 final String name;
228 final bool isAbstract; 313 final bool isAbstract;
229 314
230 JClass(this.library, this.classIndex, this.name, {this.isAbstract}); 315 JClass(this.library, this.classIndex, this.name, {this.isAbstract});
231 316
232 @override 317 @override
233 bool get isClosure => false; 318 bool get isClosure => false;
234 319
235 String toString() => 'class($name)'; 320 String toString() => '${jsElementPrefix}class($name)';
236 } 321 }
237 322
238 abstract class JMember implements MemberEntity, IndexedMember { 323 abstract class JMember implements MemberEntity, IndexedMember {
239 /// Member index used for fast lookup in [JsToFrontendMapImpl]. 324 /// Member index used for fast lookup in [JsToFrontendMapImpl].
240 final int memberIndex; 325 final int memberIndex;
241 final JLibrary library; 326 final JLibrary library;
242 final JClass enclosingClass; 327 final JClass enclosingClass;
243 final Name _name; 328 final Name _name;
244 final bool _isStatic; 329 final bool _isStatic;
245 330
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 bool get isInstanceMember => enclosingClass != null && !_isStatic; 364 bool get isInstanceMember => enclosingClass != null && !_isStatic;
280 365
281 @override 366 @override
282 bool get isStatic => enclosingClass != null && _isStatic; 367 bool get isStatic => enclosingClass != null && _isStatic;
283 368
284 @override 369 @override
285 bool get isTopLevel => enclosingClass == null; 370 bool get isTopLevel => enclosingClass == null;
286 371
287 String get _kind; 372 String get _kind;
288 373
289 String toString() => 374 String toString() => '${jsElementPrefix}$_kind'
290 '$_kind(${enclosingClass != null ? '${enclosingClass.name}.' : ''}$name)'; 375 '(${enclosingClass != null ? '${enclosingClass.name}.' : ''}$name)';
291 } 376 }
292 377
293 abstract class JFunction extends JMember 378 abstract class JFunction extends JMember
294 implements FunctionEntity, IndexedFunction { 379 implements FunctionEntity, IndexedFunction {
295 final ParameterStructure parameterStructure; 380 final ParameterStructure parameterStructure;
296 final bool isExternal; 381 final bool isExternal;
297 final AsyncMarker asyncMarker; 382 final AsyncMarker asyncMarker;
298 383
299 JFunction(int memberIndex, JLibrary library, JClass enclosingClass, Name name, 384 JFunction(int memberIndex, JLibrary library, JClass enclosingClass, Name name,
300 this.parameterStructure, this.asyncMarker, 385 this.parameterStructure, this.asyncMarker,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 String get _kind => 'field'; 509 String get _kind => 'field';
425 } 510 }
426 511
427 class JTypeVariable implements TypeVariableEntity { 512 class JTypeVariable implements TypeVariableEntity {
428 final Entity typeDeclaration; 513 final Entity typeDeclaration;
429 final String name; 514 final String name;
430 final int index; 515 final int index;
431 516
432 JTypeVariable(this.typeDeclaration, this.name, this.index); 517 JTypeVariable(this.typeDeclaration, this.name, this.index);
433 518
434 String toString() => 'type_variable(${typeDeclaration.name}.$name)'; 519 String toString() =>
520 '${jsElementPrefix}type_variable(${typeDeclaration.name}.$name)';
435 } 521 }
436 522
437 class JsClosedWorld extends ClosedWorldBase { 523 class JsClosedWorld extends ClosedWorldBase {
438 JsClosedWorld( 524 JsClosedWorld(
439 {ElementEnvironment elementEnvironment, 525 {ElementEnvironment elementEnvironment,
440 DartTypes dartTypes, 526 DartTypes dartTypes,
441 CommonElements commonElements, 527 CommonElements commonElements,
442 ConstantSystem constantSystem, 528 ConstantSystem constantSystem,
443 NativeData nativeData, 529 NativeData nativeData,
444 InterceptorData interceptorData, 530 InterceptorData interceptorData,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 773
688 @override 774 @override
689 bool get isFunctionApplyUsed => _backendUsage.isFunctionApplyUsed; 775 bool get isFunctionApplyUsed => _backendUsage.isFunctionApplyUsed;
690 776
691 @override 777 @override
692 bool get isMirrorsUsed => _backendUsage.isMirrorsUsed; 778 bool get isMirrorsUsed => _backendUsage.isMirrorsUsed;
693 779
694 @override 780 @override
695 bool get isNoSuchMethodUsed => _backendUsage.isNoSuchMethodUsed; 781 bool get isNoSuchMethodUsed => _backendUsage.isNoSuchMethodUsed;
696 } 782 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/common_elements.dart ('k') | pkg/compiler/lib/src/js_model/js_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698