OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.resolution.registry; | 5 library dart2js.resolution.registry; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/backend_api.dart' show | 8 import '../common/backend_api.dart' show Backend, ForeignResolver; |
9 Backend, | 9 import '../common/resolution.dart' |
10 ForeignResolver; | 10 show Feature, ListLiteralUse, MapLiteralUse, ResolutionImpact; |
11 import '../common/resolution.dart' show | 11 import '../common/registry.dart' show Registry; |
12 Feature, | 12 import '../compiler.dart' show Compiler; |
13 ListLiteralUse, | |
14 MapLiteralUse, | |
15 ResolutionImpact; | |
16 import '../common/registry.dart' show | |
17 Registry; | |
18 import '../compiler.dart' show | |
19 Compiler; | |
20 import '../constants/expressions.dart'; | 13 import '../constants/expressions.dart'; |
21 import '../dart_types.dart'; | 14 import '../dart_types.dart'; |
22 import '../diagnostics/source_span.dart'; | 15 import '../diagnostics/source_span.dart'; |
23 import '../enqueue.dart' show | 16 import '../enqueue.dart' show ResolutionEnqueuer; |
24 ResolutionEnqueuer; | |
25 import '../elements/elements.dart'; | 17 import '../elements/elements.dart'; |
26 import '../tree/tree.dart'; | 18 import '../tree/tree.dart'; |
27 import '../util/util.dart' show | 19 import '../util/util.dart' show Setlet; |
28 Setlet; | 20 import '../universe/call_structure.dart' show CallStructure; |
29 import '../universe/call_structure.dart' show | 21 import '../universe/selector.dart' show Selector; |
30 CallStructure; | 22 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
31 import '../universe/selector.dart' show | 23 import '../universe/world_impact.dart' show WorldImpactBuilder; |
32 Selector; | 24 import '../util/enumset.dart' show EnumSet; |
33 import '../universe/use.dart' show | 25 import '../world.dart' show World; |
34 DynamicUse, | |
35 StaticUse, | |
36 TypeUse; | |
37 import '../universe/world_impact.dart' show | |
38 WorldImpactBuilder; | |
39 import '../util/enumset.dart' show | |
40 EnumSet; | |
41 import '../world.dart' show | |
42 World; | |
43 | 26 |
44 import 'send_structure.dart'; | 27 import 'send_structure.dart'; |
45 | 28 |
46 import 'members.dart' show | 29 import 'members.dart' show ResolverVisitor; |
47 ResolverVisitor; | 30 import 'tree_elements.dart' show TreeElementMapping; |
48 import 'tree_elements.dart' show | |
49 TreeElementMapping; | |
50 | 31 |
51 class _ResolutionWorldImpact extends ResolutionImpact with WorldImpactBuilder { | 32 class _ResolutionWorldImpact extends ResolutionImpact with WorldImpactBuilder { |
52 final String name; | 33 final String name; |
53 EnumSet<Feature> _features; | 34 EnumSet<Feature> _features; |
54 Setlet<MapLiteralUse> _mapLiterals; | 35 Setlet<MapLiteralUse> _mapLiterals; |
55 Setlet<ListLiteralUse> _listLiterals; | 36 Setlet<ListLiteralUse> _listLiterals; |
56 Setlet<String> _constSymbolNames; | 37 Setlet<String> _constSymbolNames; |
57 Setlet<ConstantExpression> _constantLiterals; | 38 Setlet<ConstantExpression> _constantLiterals; |
58 | 39 |
59 _ResolutionWorldImpact(this.name); | 40 _ResolutionWorldImpact(this.name); |
60 | 41 |
61 void registerMapLiteral(MapLiteralUse mapLiteralUse) { | 42 void registerMapLiteral(MapLiteralUse mapLiteralUse) { |
62 assert(mapLiteralUse != null); | 43 assert(mapLiteralUse != null); |
63 if (_mapLiterals == null) { | 44 if (_mapLiterals == null) { |
64 _mapLiterals = new Setlet<MapLiteralUse>(); | 45 _mapLiterals = new Setlet<MapLiteralUse>(); |
65 } | 46 } |
66 _mapLiterals.add(mapLiteralUse); | 47 _mapLiterals.add(mapLiteralUse); |
67 } | 48 } |
68 | 49 |
69 @override | 50 @override |
70 Iterable<MapLiteralUse> get mapLiterals { | 51 Iterable<MapLiteralUse> get mapLiterals { |
71 return _mapLiterals != null | 52 return _mapLiterals != null ? _mapLiterals : const <MapLiteralUse>[]; |
72 ? _mapLiterals : const <MapLiteralUse>[]; | |
73 } | 53 } |
74 | 54 |
75 void registerListLiteral(ListLiteralUse listLiteralUse) { | 55 void registerListLiteral(ListLiteralUse listLiteralUse) { |
76 assert(listLiteralUse != null); | 56 assert(listLiteralUse != null); |
77 if (_listLiterals == null) { | 57 if (_listLiterals == null) { |
78 _listLiterals = new Setlet<ListLiteralUse>(); | 58 _listLiterals = new Setlet<ListLiteralUse>(); |
79 } | 59 } |
80 _listLiterals.add(listLiteralUse); | 60 _listLiterals.add(listLiteralUse); |
81 } | 61 } |
82 | 62 |
83 @override | 63 @override |
84 Iterable<ListLiteralUse> get listLiterals { | 64 Iterable<ListLiteralUse> get listLiterals { |
85 return _listLiterals != null | 65 return _listLiterals != null ? _listLiterals : const <ListLiteralUse>[]; |
86 ? _listLiterals : const <ListLiteralUse>[]; | |
87 } | 66 } |
88 | 67 |
89 void registerConstSymbolName(String name) { | 68 void registerConstSymbolName(String name) { |
90 if (_constSymbolNames == null) { | 69 if (_constSymbolNames == null) { |
91 _constSymbolNames = new Setlet<String>(); | 70 _constSymbolNames = new Setlet<String>(); |
92 } | 71 } |
93 _constSymbolNames.add(name); | 72 _constSymbolNames.add(name); |
94 } | 73 } |
95 | 74 |
96 @override | 75 @override |
97 Iterable<String> get constSymbolNames { | 76 Iterable<String> get constSymbolNames { |
98 return _constSymbolNames != null | 77 return _constSymbolNames != null ? _constSymbolNames : const <String>[]; |
99 ? _constSymbolNames : const <String>[]; | |
100 } | 78 } |
101 | 79 |
102 void registerFeature(Feature feature) { | 80 void registerFeature(Feature feature) { |
103 if (_features == null) { | 81 if (_features == null) { |
104 _features = new EnumSet<Feature>(); | 82 _features = new EnumSet<Feature>(); |
105 } | 83 } |
106 _features.add(feature); | 84 _features.add(feature); |
107 } | 85 } |
108 | 86 |
109 @override | 87 @override |
110 Iterable<Feature> get features { | 88 Iterable<Feature> get features { |
111 return _features != null | 89 return _features != null |
112 ? _features.iterable(Feature.values) : const <Feature>[]; | 90 ? _features.iterable(Feature.values) |
| 91 : const <Feature>[]; |
113 } | 92 } |
114 | 93 |
115 void registerConstantLiteral(ConstantExpression constant) { | 94 void registerConstantLiteral(ConstantExpression constant) { |
116 if (_constantLiterals == null) { | 95 if (_constantLiterals == null) { |
117 _constantLiterals = new Setlet<ConstantExpression>(); | 96 _constantLiterals = new Setlet<ConstantExpression>(); |
118 } | 97 } |
119 _constantLiterals.add(constant); | 98 _constantLiterals.add(constant); |
120 } | 99 } |
121 | 100 |
122 Iterable<ConstantExpression> get constantLiterals { | 101 Iterable<ConstantExpression> get constantLiterals { |
123 return _constantLiterals != null | 102 return _constantLiterals != null |
124 ? _constantLiterals : const <ConstantExpression>[]; | 103 ? _constantLiterals |
| 104 : const <ConstantExpression>[]; |
125 } | 105 } |
126 | 106 |
127 String toString() => '_ResolutionWorldImpact($name)'; | 107 String toString() => '_ResolutionWorldImpact($name)'; |
128 } | 108 } |
129 | 109 |
130 /// [ResolutionRegistry] collects all resolution information. It stores node | 110 /// [ResolutionRegistry] collects all resolution information. It stores node |
131 /// related information in a [TreeElements] mapping and registers calls with | 111 /// related information in a [TreeElements] mapping and registers calls with |
132 /// [Backend], [World] and [Enqueuer]. | 112 /// [Backend], [World] and [Enqueuer]. |
133 // TODO(johnniwinther): Split this into an interface and implementation class. | 113 // TODO(johnniwinther): Split this into an interface and implementation class. |
134 class ResolutionRegistry extends Registry { | 114 class ResolutionRegistry extends Registry { |
135 final Compiler compiler; | 115 final Compiler compiler; |
136 final TreeElementMapping mapping; | 116 final TreeElementMapping mapping; |
137 final _ResolutionWorldImpact worldImpact; | 117 final _ResolutionWorldImpact worldImpact; |
138 | 118 |
139 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) | 119 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) |
140 : this.compiler = compiler, | 120 : this.compiler = compiler, |
141 this.mapping = mapping, | 121 this.mapping = mapping, |
142 this.worldImpact = new _ResolutionWorldImpact( | 122 this.worldImpact = |
143 mapping.analyzedElement.toString()); | 123 new _ResolutionWorldImpact(mapping.analyzedElement.toString()); |
144 | 124 |
145 bool get isForResolution => true; | 125 bool get isForResolution => true; |
146 | 126 |
147 ResolutionEnqueuer get world => compiler.enqueuer.resolution; | 127 ResolutionEnqueuer get world => compiler.enqueuer.resolution; |
148 | 128 |
149 World get universe => compiler.world; | 129 World get universe => compiler.world; |
150 | 130 |
151 Backend get backend => compiler.backend; | 131 Backend get backend => compiler.backend; |
152 | 132 |
153 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; | 133 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; |
(...skipping 26 matching lines...) Expand all Loading... |
180 Element getDefinition(Node node) { | 160 Element getDefinition(Node node) { |
181 return mapping[node]; | 161 return mapping[node]; |
182 } | 162 } |
183 | 163 |
184 /// Sets the loop variable of the for-in [node] to be [element]. | 164 /// Sets the loop variable of the for-in [node] to be [element]. |
185 void setForInVariable(ForIn node, Element element) { | 165 void setForInVariable(ForIn node, Element element) { |
186 mapping[node] = element; | 166 mapping[node] = element; |
187 } | 167 } |
188 | 168 |
189 /// Sets the target constructor [node] to be [element]. | 169 /// Sets the target constructor [node] to be [element]. |
190 void setRedirectingTargetConstructor(RedirectingFactoryBody node, | 170 void setRedirectingTargetConstructor( |
191 ConstructorElement element) { | 171 RedirectingFactoryBody node, ConstructorElement element) { |
192 useElement(node, element); | 172 useElement(node, element); |
193 } | 173 } |
194 | 174 |
195 ////////////////////////////////////////////////////////////////////////////// | 175 ////////////////////////////////////////////////////////////////////////////// |
196 // Node-to-Selector mapping functionality. | 176 // Node-to-Selector mapping functionality. |
197 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
198 | 178 |
199 void setSelector(Node node, Selector selector) { | 179 void setSelector(Node node, Selector selector) { |
200 mapping.setSelector(node, selector); | 180 mapping.setSelector(node, selector); |
201 } | 181 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 256 |
277 /// Register the target of [node] to be [target]. | 257 /// Register the target of [node] to be [target]. |
278 void registerTargetOf(GotoStatement node, JumpTarget target) { | 258 void registerTargetOf(GotoStatement node, JumpTarget target) { |
279 mapping.registerTargetOf(node, target); | 259 mapping.registerTargetOf(node, target); |
280 } | 260 } |
281 | 261 |
282 ////////////////////////////////////////////////////////////////////////////// | 262 ////////////////////////////////////////////////////////////////////////////// |
283 // Potential access registration. | 263 // Potential access registration. |
284 ////////////////////////////////////////////////////////////////////////////// | 264 ////////////////////////////////////////////////////////////////////////////// |
285 | 265 |
286 void setAccessedByClosureIn(Node contextNode, VariableElement element, | 266 void setAccessedByClosureIn( |
287 Node accessNode) { | 267 Node contextNode, VariableElement element, Node accessNode) { |
288 mapping.setAccessedByClosureIn(contextNode, element, accessNode); | 268 mapping.setAccessedByClosureIn(contextNode, element, accessNode); |
289 } | 269 } |
290 | 270 |
291 void registerPotentialMutation(VariableElement element, Node mutationNode) { | 271 void registerPotentialMutation(VariableElement element, Node mutationNode) { |
292 mapping.registerPotentialMutation(element, mutationNode); | 272 mapping.registerPotentialMutation(element, mutationNode); |
293 } | 273 } |
294 | 274 |
295 void registerPotentialMutationInClosure(VariableElement element, | 275 void registerPotentialMutationInClosure( |
296 Node mutationNode) { | 276 VariableElement element, Node mutationNode) { |
297 mapping.registerPotentialMutationInClosure(element, mutationNode); | 277 mapping.registerPotentialMutationInClosure(element, mutationNode); |
298 } | 278 } |
299 | 279 |
300 void registerPotentialMutationIn(Node contextNode, VariableElement element, | 280 void registerPotentialMutationIn( |
301 Node mutationNode) { | 281 Node contextNode, VariableElement element, Node mutationNode) { |
302 mapping.registerPotentialMutationIn(contextNode, element, mutationNode); | 282 mapping.registerPotentialMutationIn(contextNode, element, mutationNode); |
303 } | 283 } |
304 | 284 |
305 ////////////////////////////////////////////////////////////////////////////// | 285 ////////////////////////////////////////////////////////////////////////////// |
306 // Various Backend/Enqueuer/World registration. | 286 // Various Backend/Enqueuer/World registration. |
307 ////////////////////////////////////////////////////////////////////////////// | 287 ////////////////////////////////////////////////////////////////////////////// |
308 | 288 |
309 void registerStaticUse(StaticUse staticUse) { | 289 void registerStaticUse(StaticUse staticUse) { |
310 worldImpact.registerStaticUse(staticUse); | 290 worldImpact.registerStaticUse(staticUse); |
311 } | 291 } |
312 | 292 |
313 void registerMetadataConstant(MetadataAnnotation metadata) { | 293 void registerMetadataConstant(MetadataAnnotation metadata) { |
314 backend.registerMetadataConstant(metadata, metadata.annotatedElement, this); | 294 backend.registerMetadataConstant(metadata, metadata.annotatedElement, this); |
315 } | 295 } |
316 | 296 |
317 /// Register the use of a type. | 297 /// Register the use of a type. |
318 void registerTypeUse(TypeUse typeUse) { | 298 void registerTypeUse(TypeUse typeUse) { |
319 worldImpact.registerTypeUse(typeUse); | 299 worldImpact.registerTypeUse(typeUse); |
320 } | 300 } |
321 | 301 |
322 void registerSuperUse(SourceSpan span) { | 302 void registerSuperUse(SourceSpan span) { |
323 mapping.addSuperUse(span); | 303 mapping.addSuperUse(span); |
324 } | 304 } |
325 | 305 |
326 void registerTypeLiteral(Send node, DartType type) { | 306 void registerTypeLiteral(Send node, DartType type) { |
327 mapping.setType(node, type); | 307 mapping.setType(node, type); |
328 worldImpact.registerTypeUse(new TypeUse.typeLiteral(type)); | 308 worldImpact.registerTypeUse(new TypeUse.typeLiteral(type)); |
329 } | 309 } |
330 | 310 |
331 void registerLiteralList(Node node, | 311 void registerLiteralList(Node node, InterfaceType type, |
332 InterfaceType type, | 312 {bool isConstant, bool isEmpty}) { |
333 {bool isConstant, | |
334 bool isEmpty}) { | |
335 setType(node, type); | 313 setType(node, type); |
336 worldImpact.registerListLiteral( | 314 worldImpact.registerListLiteral( |
337 new ListLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | 315 new ListLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); |
338 } | 316 } |
339 | 317 |
340 void registerMapLiteral(Node node, | 318 void registerMapLiteral(Node node, InterfaceType type, |
341 InterfaceType type, | 319 {bool isConstant, bool isEmpty}) { |
342 {bool isConstant, | |
343 bool isEmpty}) { | |
344 setType(node, type); | 320 setType(node, type); |
345 worldImpact.registerMapLiteral( | 321 worldImpact.registerMapLiteral( |
346 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | 322 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); |
347 } | 323 } |
348 | 324 |
349 void registerForeignCall(Node node, | 325 void registerForeignCall(Node node, Element element, |
350 Element element, | 326 CallStructure callStructure, ResolverVisitor visitor) { |
351 CallStructure callStructure, | 327 backend.registerForeignCall(node, element, callStructure, |
352 ResolverVisitor visitor) { | |
353 backend.registerForeignCall( | |
354 node, element, callStructure, | |
355 new ForeignResolutionResolver(visitor, this)); | 328 new ForeignResolutionResolver(visitor, this)); |
356 } | 329 } |
357 | 330 |
358 void registerDynamicUse(DynamicUse dynamicUse) { | 331 void registerDynamicUse(DynamicUse dynamicUse) { |
359 worldImpact.registerDynamicUse(dynamicUse); | 332 worldImpact.registerDynamicUse(dynamicUse); |
360 } | 333 } |
361 | 334 |
362 void registerFeature(Feature feature) { | 335 void registerFeature(Feature feature) { |
363 worldImpact.registerFeature(feature); | 336 worldImpact.registerFeature(feature); |
364 } | 337 } |
365 | 338 |
366 void registerConstSymbol(String name) { | 339 void registerConstSymbol(String name) { |
367 worldImpact.registerConstSymbolName(name); | 340 worldImpact.registerConstSymbolName(name); |
368 } | 341 } |
369 | 342 |
370 void registerConstantLiteral(ConstantExpression constant) { | 343 void registerConstantLiteral(ConstantExpression constant) { |
371 worldImpact.registerConstantLiteral(constant); | 344 worldImpact.registerConstantLiteral(constant); |
372 } | 345 } |
373 | 346 |
374 ClassElement defaultSuperclass(ClassElement element) { | 347 ClassElement defaultSuperclass(ClassElement element) { |
375 return backend.defaultSuperclass(element); | 348 return backend.defaultSuperclass(element); |
376 } | 349 } |
377 | 350 |
378 void registerMixinUse(MixinApplicationElement mixinApplication, | 351 void registerMixinUse( |
379 ClassElement mixin) { | 352 MixinApplicationElement mixinApplication, ClassElement mixin) { |
380 universe.registerMixinUse(mixinApplication, mixin); | 353 universe.registerMixinUse(mixinApplication, mixin); |
381 } | 354 } |
382 | 355 |
383 void registerInstantiation(InterfaceType type) { | 356 void registerInstantiation(InterfaceType type) { |
384 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); | 357 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); |
385 } | 358 } |
386 | 359 |
387 void registerSendStructure(Send node, SendStructure sendStructure) { | 360 void registerSendStructure(Send node, SendStructure sendStructure) { |
388 mapping.setSendStructure(node, sendStructure); | 361 mapping.setSendStructure(node, sendStructure); |
389 } | 362 } |
(...skipping 27 matching lines...) Expand all Loading... |
417 @override | 390 @override |
418 void registerInstantiatedType(InterfaceType type) { | 391 void registerInstantiatedType(InterfaceType type) { |
419 registry.registerInstantiation(type); | 392 registry.registerInstantiation(type); |
420 } | 393 } |
421 | 394 |
422 @override | 395 @override |
423 DartType resolveTypeFromString(Node node, String typeName) { | 396 DartType resolveTypeFromString(Node node, String typeName) { |
424 return visitor.resolveTypeFromString(node, typeName); | 397 return visitor.resolveTypeFromString(node, typeName); |
425 } | 398 } |
426 } | 399 } |
OLD | NEW |