| 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/names.dart' show Identifiers; | 7 import 'common/names.dart' show Identifiers; |
| 8 import 'common/resolution.dart' show ParsingContext, Resolution; | 8 import 'common/resolution.dart' show ParsingContext, Resolution; |
| 9 import 'common/tasks.dart' show CompilerTask; | 9 import 'common/tasks.dart' show CompilerTask; |
| 10 import 'common.dart'; | 10 import 'common.dart'; |
| 11 import 'compiler.dart' show Compiler; | 11 import 'compiler.dart' show Compiler; |
| 12 import 'constants/expressions.dart'; | 12 import 'constants/expressions.dart'; |
| 13 import 'elements/resolution_types.dart'; | 13 import 'elements/resolution_types.dart'; |
| 14 import 'elements/elements.dart'; | 14 import 'elements/elements.dart'; |
| 15 import 'elements/entities.dart'; | 15 import 'elements/entities.dart'; |
| 16 import 'elements/modelx.dart' | 16 import 'elements/modelx.dart' |
| 17 show BaseFunctionElementX, ClassElementX, ElementX; | 17 show BaseFunctionElementX, ClassElementX, ElementX; |
| 18 import 'elements/visitor.dart' show ElementVisitor; | 18 import 'elements/visitor.dart' show ElementVisitor; |
| 19 import 'js_backend/js_backend.dart' show JavaScriptBackend; | 19 import 'js_backend/js_backend.dart' show JavaScriptBackend; |
| 20 import 'resolution/tree_elements.dart' show TreeElements; | 20 import 'resolution/tree_elements.dart' show TreeElements; |
| 21 import 'package:front_end/src/fasta/scanner.dart' show Token; | 21 import 'package:front_end/src/fasta/scanner.dart' show Token; |
| 22 import 'tree/tree.dart'; | 22 import 'tree/tree.dart'; |
| 23 import 'util/util.dart'; | 23 import 'util/util.dart'; |
| 24 import 'world.dart' show ClosedWorldRefiner; | 24 import 'world.dart' show ClosedWorldRefiner; |
| 25 | 25 |
| 26 class ClosureTask extends CompilerTask { | 26 abstract class ClosureClassMaps { |
| 27 ClosureClassMap getMemberMap(MemberEntity member); |
| 28 ClosureClassMap getLocalFunctionMap(Local localFunction); |
| 29 } |
| 30 |
| 31 class ClosureTask extends CompilerTask implements ClosureClassMaps { |
| 27 Map<Element, ClosureClassMap> _closureMappingCache = | 32 Map<Element, ClosureClassMap> _closureMappingCache = |
| 28 <Element, ClosureClassMap>{}; | 33 <Element, ClosureClassMap>{}; |
| 29 Compiler compiler; | 34 Compiler compiler; |
| 30 ClosureTask(Compiler compiler) | 35 ClosureTask(Compiler compiler) |
| 31 : compiler = compiler, | 36 : compiler = compiler, |
| 32 super(compiler.measurer); | 37 super(compiler.measurer); |
| 33 | 38 |
| 34 String get name => "Closure Simplifier"; | 39 String get name => "Closure Simplifier"; |
| 35 | 40 |
| 36 DiagnosticReporter get reporter => compiler.reporter; | 41 DiagnosticReporter get reporter => compiler.reporter; |
| 37 | 42 |
| 43 ClosureClassMap getMemberMap(MemberElement member) { |
| 44 return getClosureToClassMapping(member.resolvedAst); |
| 45 } |
| 46 |
| 47 ClosureClassMap getLocalFunctionMap(LocalFunctionElement localFunction) { |
| 48 return getClosureToClassMapping(localFunction.resolvedAst); |
| 49 } |
| 50 |
| 38 /// Returns the [ClosureClassMap] computed for [resolvedAst]. | 51 /// Returns the [ClosureClassMap] computed for [resolvedAst]. |
| 39 ClosureClassMap getClosureToClassMapping(ResolvedAst resolvedAst) { | 52 ClosureClassMap getClosureToClassMapping(ResolvedAst resolvedAst) { |
| 40 return measure(() { | 53 return measure(() { |
| 41 Element element = resolvedAst.element; | 54 Element element = resolvedAst.element; |
| 42 if (element.isGenerativeConstructorBody) { | 55 if (element.isGenerativeConstructorBody) { |
| 43 ConstructorBodyElement constructorBody = element; | 56 ConstructorBodyElement constructorBody = element; |
| 44 element = constructorBody.constructor; | 57 element = constructorBody.constructor; |
| 45 } | 58 } |
| 46 ClosureClassMap closureClassMap = _closureMappingCache[element]; | 59 ClosureClassMap closureClassMap = _closureMappingCache[element]; |
| 47 assert(invariant(resolvedAst.element, closureClassMap != null, | 60 assert(invariant(resolvedAst.element, closureClassMap != null, |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 /// | 1235 /// |
| 1223 /// Move the below classes to a JS model eventually. | 1236 /// Move the below classes to a JS model eventually. |
| 1224 /// | 1237 /// |
| 1225 abstract class JSEntity implements Entity { | 1238 abstract class JSEntity implements Entity { |
| 1226 Entity get declaredEntity; | 1239 Entity get declaredEntity; |
| 1227 } | 1240 } |
| 1228 | 1241 |
| 1229 abstract class PrivatelyNamedJSEntity implements JSEntity { | 1242 abstract class PrivatelyNamedJSEntity implements JSEntity { |
| 1230 Entity get rootOfScope; | 1243 Entity get rootOfScope; |
| 1231 } | 1244 } |
| OLD | NEW |