| 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 dart2js.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 CodegenWorkItem; | 21 CodegenWorkItem; |
| 22 import 'common/names.dart' show | 22 import 'common/names.dart' show |
| 23 Identifiers, | 23 Identifiers, |
| 24 Uris; | 24 Uris; |
| 25 import 'common/registry.dart' show | 25 import 'common/registry.dart' show |
| 26 Registry; | 26 Registry; |
| 27 import 'common/resolution.dart' show | 27 import 'common/resolution.dart' show |
| 28 Parsing, | 28 Parsing, |
| 29 Resolution, | 29 Resolution, |
| 30 ResolutionWorkItem, | 30 ResolutionWorkItem, |
| 31 ResolutionWorldImpact; | 31 ResolutionImpact; |
| 32 import 'common/tasks.dart' show | 32 import 'common/tasks.dart' show |
| 33 CompilerTask, | 33 CompilerTask, |
| 34 GenericTask; | 34 GenericTask; |
| 35 import 'common/work.dart' show | 35 import 'common/work.dart' show |
| 36 WorkItem; | 36 WorkItem; |
| 37 import 'compile_time_constants.dart'; | 37 import 'compile_time_constants.dart'; |
| 38 import 'constants/values.dart'; | 38 import 'constants/values.dart'; |
| 39 import 'core_types.dart' show | 39 import 'core_types.dart' show |
| 40 CoreTypes; | 40 CoreTypes; |
| 41 import 'dart_backend/dart_backend.dart' as dart_backend; | 41 import 'dart_backend/dart_backend.dart' as dart_backend; |
| (...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 } | 1163 } |
| 1164 } | 1164 } |
| 1165 reporter.log('Excess resolution work: ${resolved.length}.'); | 1165 reporter.log('Excess resolution work: ${resolved.length}.'); |
| 1166 for (Element e in resolved) { | 1166 for (Element e in resolved) { |
| 1167 reporter.reportWarningMessage(e, | 1167 reporter.reportWarningMessage(e, |
| 1168 MessageKind.GENERIC, | 1168 MessageKind.GENERIC, |
| 1169 {'text': 'Warning: $e resolved but not compiled.'}); | 1169 {'text': 'Warning: $e resolved but not compiled.'}); |
| 1170 } | 1170 } |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 ResolutionWorldImpact analyzeElement(Element element) { | 1173 WorldImpact analyzeElement(Element element) { |
| 1174 assert(invariant(element, | 1174 assert(invariant(element, |
| 1175 element.impliesType || | 1175 element.impliesType || |
| 1176 element.isField || | 1176 element.isField || |
| 1177 element.isFunction || | 1177 element.isFunction || |
| 1178 element.isGenerativeConstructor || | 1178 element.isGenerativeConstructor || |
| 1179 element.isGetter || | 1179 element.isGetter || |
| 1180 element.isSetter, | 1180 element.isSetter, |
| 1181 message: 'Unexpected element kind: ${element.kind}')); | 1181 message: 'Unexpected element kind: ${element.kind}')); |
| 1182 assert(invariant(element, element is AnalyzableElement, | 1182 assert(invariant(element, element is AnalyzableElement, |
| 1183 message: 'Element $element is not analyzable.')); | 1183 message: 'Element $element is not analyzable.')); |
| 1184 assert(invariant(element, element.isDeclaration)); | 1184 assert(invariant(element, element.isDeclaration)); |
| 1185 return resolution.analyzeElement(element); | 1185 return resolution.computeWorldImpact(element); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 ResolutionWorldImpact analyze(ResolutionWorkItem work, | 1188 WorldImpact analyze(ResolutionWorkItem work, |
| 1189 ResolutionEnqueuer world) { | 1189 ResolutionEnqueuer world) { |
| 1190 assert(invariant(work.element, identical(world, enqueuer.resolution))); | 1190 assert(invariant(work.element, identical(world, enqueuer.resolution))); |
| 1191 assert(invariant(work.element, !work.isAnalyzed, | 1191 assert(invariant(work.element, !work.isAnalyzed, |
| 1192 message: 'Element ${work.element} has already been analyzed')); | 1192 message: 'Element ${work.element} has already been analyzed')); |
| 1193 if (shouldPrintProgress) { | 1193 if (shouldPrintProgress) { |
| 1194 // TODO(ahe): Add structured diagnostics to the compiler API and | 1194 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 1195 // use it to separate this from the --verbose option. | 1195 // use it to separate this from the --verbose option. |
| 1196 if (phase == PHASE_RESOLVING) { | 1196 if (phase == PHASE_RESOLVING) { |
| 1197 reporter.log( | 1197 reporter.log( |
| 1198 'Resolved ${enqueuer.resolution.processedElements.length} ' | 1198 'Resolved ${enqueuer.resolution.processedElements.length} ' |
| 1199 'elements.'); | 1199 'elements.'); |
| 1200 progress.reset(); | 1200 progress.reset(); |
| 1201 } | 1201 } |
| 1202 } | 1202 } |
| 1203 AstElement element = work.element; | 1203 AstElement element = work.element; |
| 1204 if (world.hasBeenProcessed(element)) { | 1204 if (world.hasBeenProcessed(element)) { |
| 1205 return const ResolutionWorldImpact(); | 1205 return const WorldImpact(); |
| 1206 } | 1206 } |
| 1207 ResolutionWorldImpact worldImpact = analyzeElement(element); | 1207 WorldImpact worldImpact = analyzeElement(element); |
| 1208 backend.onElementResolved(element, element.resolvedAst.elements); | 1208 backend.onElementResolved(element, element.resolvedAst.elements); |
| 1209 world.registerProcessedElement(element); | 1209 world.registerProcessedElement(element); |
| 1210 return worldImpact; | 1210 return worldImpact; |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 WorldImpact codegen(CodegenWorkItem work, CodegenEnqueuer world) { | 1213 WorldImpact codegen(CodegenWorkItem work, CodegenEnqueuer world) { |
| 1214 assert(invariant(work.element, identical(world, enqueuer.codegen))); | 1214 assert(invariant(work.element, identical(world, enqueuer.codegen))); |
| 1215 if (shouldPrintProgress) { | 1215 if (shouldPrintProgress) { |
| 1216 // TODO(ahe): Add structured diagnostics to the compiler API and | 1216 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 1217 // use it to separate this from the --verbose option. | 1217 // use it to separate this from the --verbose option. |
| (...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 const <DiagnosticMessage>[], | 1923 const <DiagnosticMessage>[], |
| 1924 api.Diagnostic.HINT); | 1924 api.Diagnostic.HINT); |
| 1925 }); | 1925 }); |
| 1926 } | 1926 } |
| 1927 } | 1927 } |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 // TODO(johnniwinther): Move [ResolverTask] here. | 1930 // TODO(johnniwinther): Move [ResolverTask] here. |
| 1931 class _CompilerResolution implements Resolution { | 1931 class _CompilerResolution implements Resolution { |
| 1932 final Compiler compiler; | 1932 final Compiler compiler; |
| 1933 final Map<Element, ResolutionWorldImpact> _worldImpactCache = | 1933 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; |
| 1934 <Element, ResolutionWorldImpact>{}; | |
| 1935 | 1934 |
| 1936 _CompilerResolution(this.compiler); | 1935 _CompilerResolution(this.compiler); |
| 1937 | 1936 |
| 1938 @override | 1937 @override |
| 1939 DiagnosticReporter get reporter => compiler.reporter; | 1938 DiagnosticReporter get reporter => compiler.reporter; |
| 1940 | 1939 |
| 1941 @override | 1940 @override |
| 1942 Parsing get parsing => compiler.parsing; | 1941 Parsing get parsing => compiler.parsing; |
| 1943 | 1942 |
| 1944 @override | 1943 @override |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1967 @override | 1966 @override |
| 1968 FunctionSignature resolveSignature(FunctionElement function) { | 1967 FunctionSignature resolveSignature(FunctionElement function) { |
| 1969 return compiler.resolver.resolveSignature(function); | 1968 return compiler.resolver.resolveSignature(function); |
| 1970 } | 1969 } |
| 1971 | 1970 |
| 1972 @override | 1971 @override |
| 1973 DartType resolveTypeAnnotation(Element element, TypeAnnotation node) { | 1972 DartType resolveTypeAnnotation(Element element, TypeAnnotation node) { |
| 1974 return compiler.resolver.resolveTypeAnnotation(element, node); | 1973 return compiler.resolver.resolveTypeAnnotation(element, node); |
| 1975 } | 1974 } |
| 1976 | 1975 |
| 1977 ResolutionWorldImpact analyzeElement(Element element) { | 1976 @override |
| 1977 WorldImpact getWorldImpact(Element element) { |
| 1978 WorldImpact worldImpact = _worldImpactCache[element]; |
| 1979 assert(invariant(element, worldImpact != null, |
| 1980 message: "WorldImpact not computed for $element.")); |
| 1981 return worldImpact; |
| 1982 } |
| 1983 |
| 1984 @override |
| 1985 WorldImpact computeWorldImpact(Element element) { |
| 1978 return _worldImpactCache.putIfAbsent(element, () { | 1986 return _worldImpactCache.putIfAbsent(element, () { |
| 1979 assert(compiler.parser != null); | 1987 assert(compiler.parser != null); |
| 1980 Node tree = compiler.parser.parse(element); | 1988 Node tree = compiler.parser.parse(element); |
| 1981 assert(invariant(element, !element.isSynthesized || tree == null)); | 1989 assert(invariant(element, !element.isSynthesized || tree == null)); |
| 1982 ResolutionWorldImpact worldImpact = compiler.resolver.resolve(element); | 1990 ResolutionImpact resolutionImpact = |
| 1991 compiler.resolver.resolve(element); |
| 1983 if (tree != null && | 1992 if (tree != null && |
| 1984 !compiler.analyzeSignaturesOnly && | 1993 !compiler.analyzeSignaturesOnly && |
| 1985 !reporter.options.suppressWarnings) { | 1994 !reporter.options.suppressWarnings) { |
| 1986 // Only analyze nodes with a corresponding [TreeElements]. | 1995 // Only analyze nodes with a corresponding [TreeElements]. |
| 1987 compiler.checker.check(element); | 1996 compiler.checker.check(element); |
| 1988 } | 1997 } |
| 1998 WorldImpact worldImpact = |
| 1999 compiler.backend.resolutionCallbacks.transformImpact( |
| 2000 resolutionImpact); |
| 1989 return worldImpact; | 2001 return worldImpact; |
| 1990 }); | 2002 }); |
| 1991 } | 2003 } |
| 1992 | 2004 |
| 1993 @override | 2005 @override |
| 1994 bool hasBeenResolved(Element element) { | 2006 bool hasBeenResolved(Element element) { |
| 1995 return _worldImpactCache.containsKey(element); | 2007 return _worldImpactCache.containsKey(element); |
| 1996 } | 2008 } |
| 1997 } | 2009 } |
| 1998 | 2010 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2011 | 2023 |
| 2012 @override | 2024 @override |
| 2013 void parsePatchClass(ClassElement cls) { | 2025 void parsePatchClass(ClassElement cls) { |
| 2014 compiler.patchParser.measure(() { | 2026 compiler.patchParser.measure(() { |
| 2015 if (cls.isPatch) { | 2027 if (cls.isPatch) { |
| 2016 compiler.patchParser.parsePatchClassNode(cls); | 2028 compiler.patchParser.parsePatchClassNode(cls); |
| 2017 } | 2029 } |
| 2018 }); | 2030 }); |
| 2019 } | 2031 } |
| 2020 } | 2032 } |
| OLD | NEW |