OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 closureToClassMapper; | 5 library closureToClassMapper; |
6 | 6 |
7 import 'common.dart'; | 7 import 'common.dart'; |
8 import 'common/names.dart' show Identifiers; | 8 import 'common/names.dart' show Identifiers; |
9 import 'common/resolution.dart' show Parsing, Resolution; | 9 import 'common/resolution.dart' show Parsing, Resolution; |
10 import 'common/tasks.dart' show CompilerTask; | 10 import 'common/tasks.dart' show CompilerTask; |
(...skipping 12 matching lines...) Expand all Loading... |
23 import 'universe/universe.dart' show Universe; | 23 import 'universe/universe.dart' show Universe; |
24 | 24 |
25 class ClosureTask extends CompilerTask { | 25 class ClosureTask extends CompilerTask { |
26 Map<Node, ClosureClassMap> closureMappingCache; | 26 Map<Node, ClosureClassMap> closureMappingCache; |
27 ClosureTask(Compiler compiler) | 27 ClosureTask(Compiler compiler) |
28 : closureMappingCache = new Map<Node, ClosureClassMap>(), | 28 : closureMappingCache = new Map<Node, ClosureClassMap>(), |
29 super(compiler); | 29 super(compiler); |
30 | 30 |
31 String get name => "Closure Simplifier"; | 31 String get name => "Closure Simplifier"; |
32 | 32 |
33 ClosureClassMap computeClosureToClassMapping( | 33 ClosureClassMap computeClosureToClassMapping(ResolvedAst resolvedAst) { |
34 Element element, Node node, TreeElements elements) { | |
35 return measure(() { | 34 return measure(() { |
| 35 Element element = resolvedAst.element; |
| 36 if (resolvedAst.kind != ResolvedAstKind.PARSED) { |
| 37 return new ClosureClassMap(null, null, null, new ThisLocal(element)); |
| 38 } |
| 39 Node node = resolvedAst.node; |
| 40 TreeElements elements = resolvedAst.elements; |
| 41 |
36 ClosureClassMap cached = closureMappingCache[node]; | 42 ClosureClassMap cached = closureMappingCache[node]; |
37 if (cached != null) return cached; | 43 if (cached != null) return cached; |
38 | 44 |
39 ClosureTranslator translator = | 45 ClosureTranslator translator = |
40 new ClosureTranslator(compiler, elements, closureMappingCache); | 46 new ClosureTranslator(compiler, elements, closureMappingCache); |
41 | 47 |
42 // The translator will store the computed closure-mappings inside the | 48 // The translator will store the computed closure-mappings inside the |
43 // cache. One for given node and one for each nested closure. | 49 // cache. One for given node and one for each nested closure. |
44 if (node is FunctionExpression) { | 50 if (node is FunctionExpression) { |
45 translator.translateFunction(element, node); | 51 translator.translateFunction(element, node); |
46 } else if (element.isSynthesized) { | 52 } else if (element.isSynthesized) { |
| 53 reporter.internalError( |
| 54 element, "Unexpected synthesized element: $element"); |
47 return new ClosureClassMap(null, null, null, new ThisLocal(element)); | 55 return new ClosureClassMap(null, null, null, new ThisLocal(element)); |
48 } else { | 56 } else { |
49 assert(element.isField); | 57 assert(element.isField); |
50 VariableElement field = element; | 58 VariableElement field = element; |
51 if (field.initializer != null) { | 59 if (field.initializer != null) { |
52 // The lazy initializer of a static. | 60 // The lazy initializer of a static. |
53 translator.translateLazyInitializer(element, node, field.initializer); | 61 translator.translateLazyInitializer(element, node, field.initializer); |
54 } else { | 62 } else { |
55 assert(element.isInstanceMember); | 63 assert(element.isInstanceMember); |
56 closureMappingCache[node] = | 64 closureMappingCache[node] = |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 bool get hasNode => false; | 124 bool get hasNode => false; |
117 | 125 |
118 Node get node { | 126 Node get node { |
119 throw new SpannableAssertionFailure( | 127 throw new SpannableAssertionFailure( |
120 local, 'Should not access node of ClosureFieldElement.'); | 128 local, 'Should not access node of ClosureFieldElement.'); |
121 } | 129 } |
122 | 130 |
123 bool get hasResolvedAst => hasTreeElements; | 131 bool get hasResolvedAst => hasTreeElements; |
124 | 132 |
125 ResolvedAst get resolvedAst { | 133 ResolvedAst get resolvedAst { |
126 return new ResolvedAst(this, null, treeElements); | 134 return new ParsedResolvedAst(this, null, treeElements); |
127 } | 135 } |
128 | 136 |
129 Expression get initializer { | 137 Expression get initializer { |
130 throw new SpannableAssertionFailure( | 138 throw new SpannableAssertionFailure( |
131 local, 'Should not access initializer of ClosureFieldElement.'); | 139 local, 'Should not access initializer of ClosureFieldElement.'); |
132 } | 140 } |
133 | 141 |
134 bool get isInstanceMember => true; | 142 bool get isInstanceMember => true; |
135 bool get isAssignable => false; | 143 bool get isAssignable => false; |
136 | 144 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 return closureClass.methodElement.memberContext; | 339 return closureClass.methodElement.memberContext; |
332 } | 340 } |
333 | 341 |
334 bool get hasNode => expression.hasNode; | 342 bool get hasNode => expression.hasNode; |
335 | 343 |
336 FunctionExpression get node => expression.node; | 344 FunctionExpression get node => expression.node; |
337 | 345 |
338 FunctionExpression parseNode(Parsing parsing) => node; | 346 FunctionExpression parseNode(Parsing parsing) => node; |
339 | 347 |
340 ResolvedAst get resolvedAst { | 348 ResolvedAst get resolvedAst { |
341 return new ResolvedAst(this, node, treeElements); | 349 return new ParsedResolvedAst(this, node, treeElements); |
342 } | 350 } |
343 | 351 |
344 Element get analyzableElement => closureClass.methodElement.analyzableElement; | 352 Element get analyzableElement => closureClass.methodElement.analyzableElement; |
345 | 353 |
346 accept(ElementVisitor visitor, arg) { | 354 accept(ElementVisitor visitor, arg) { |
347 return visitor.visitMethodElement(this, arg); | 355 return visitor.visitMethodElement(this, arg); |
348 } | 356 } |
349 } | 357 } |
350 | 358 |
351 // The box-element for a scope, and the captured variables that need to be | 359 // The box-element for a scope, and the captured variables that need to be |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 /// | 1146 /// |
1139 /// Move the below classes to a JS model eventually. | 1147 /// Move the below classes to a JS model eventually. |
1140 /// | 1148 /// |
1141 abstract class JSEntity implements Entity { | 1149 abstract class JSEntity implements Entity { |
1142 Entity get declaredEntity; | 1150 Entity get declaredEntity; |
1143 } | 1151 } |
1144 | 1152 |
1145 abstract class PrivatelyNamedJSEntity implements JSEntity { | 1153 abstract class PrivatelyNamedJSEntity implements JSEntity { |
1146 Entity get rootOfScope; | 1154 Entity get rootOfScope; |
1147 } | 1155 } |
OLD | NEW |