| 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 EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
| 8 | 8 |
| 9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
| 10 import 'closure.dart' as closureMapping show ClosureTask; | 10 import 'closure.dart' as closureMapping show ClosureTask; |
| 11 import 'common/backend_api.dart' show Backend; | 11 import 'common/backend_api.dart' show Backend; |
| 12 import 'common/names.dart' show Selectors; | 12 import 'common/names.dart' show Selectors; |
| 13 import 'common/names.dart' show Identifiers, Uris; | 13 import 'common/names.dart' show Identifiers, Uris; |
| 14 import 'common/resolution.dart' | 14 import 'common/resolution.dart' |
| 15 show | 15 show |
| 16 ParsingContext, | 16 ParsingContext, |
| 17 Resolution, | 17 Resolution, |
| 18 ResolutionWorkItem, | 18 ResolutionWorkItem, |
| 19 ResolutionImpact, | 19 ResolutionImpact, |
| 20 Target; | 20 Target; |
| 21 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; | 21 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; |
| 22 import 'common/work.dart' show WorkItem; | 22 import 'common/work.dart' show WorkItem; |
| 23 import 'common.dart'; | 23 import 'common.dart'; |
| 24 import 'compile_time_constants.dart'; | 24 import 'compile_time_constants.dart'; |
| 25 import 'constants/values.dart'; | 25 import 'constants/values.dart'; |
| 26 import 'core_types.dart' show CommonElements, CommonElementsMixin; | 26 import 'core_types.dart' |
| 27 show CommonElements, CommonElementsMixin, ElementEnvironment; |
| 27 import 'deferred_load.dart' show DeferredLoadTask; | 28 import 'deferred_load.dart' show DeferredLoadTask; |
| 28 import 'diagnostics/code_location.dart'; | 29 import 'diagnostics/code_location.dart'; |
| 29 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; | 30 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; |
| 30 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; | 31 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; |
| 31 import 'diagnostics/messages.dart' show Message, MessageTemplate; | 32 import 'diagnostics/messages.dart' show Message, MessageTemplate; |
| 32 import 'dump_info.dart' show DumpInfoTask; | 33 import 'dump_info.dart' show DumpInfoTask; |
| 33 import 'elements/elements.dart'; | 34 import 'elements/elements.dart'; |
| 34 import 'elements/entities.dart'; | 35 import 'elements/entities.dart'; |
| 35 import 'elements/modelx.dart' show ErroneousElementX; | 36 import 'elements/modelx.dart' show ErroneousElementX; |
| 36 import 'elements/resolution_types.dart' | 37 import 'elements/resolution_types.dart' |
| 37 show | 38 show |
| 38 ResolutionDartType, | 39 ResolutionDartType, |
| 39 ResolutionDynamicType, | 40 ResolutionDynamicType, |
| 40 ResolutionInterfaceType, | 41 ResolutionInterfaceType, |
| 41 Types; | 42 Types; |
| 42 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; | 43 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; |
| 43 import 'environment.dart'; | 44 import 'environment.dart'; |
| 44 import 'id_generator.dart'; | 45 import 'id_generator.dart'; |
| 45 import 'io/source_information.dart' show SourceInformation; | 46 import 'io/source_information.dart' show SourceInformation; |
| 46 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; | 47 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; |
| 47 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; | 48 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; |
| 48 import 'library_loader.dart' | 49 import 'library_loader.dart' |
| 49 show | 50 show |
| 50 ElementScanner, | 51 ElementScanner, |
| 51 LibraryLoader, | 52 LibraryLoader, |
| 52 LibraryLoaderTask, | 53 LibraryLoaderTask, |
| 53 LoadedLibraries, | 54 LoadedLibraries, |
| 54 LibraryLoaderListener, | 55 LibraryLoaderListener, |
| 56 LibraryProvider, |
| 55 ScriptLoader; | 57 ScriptLoader; |
| 56 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; | 58 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; |
| 57 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; | 59 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; |
| 58 import 'options.dart' show CompilerOptions, DiagnosticOptions; | 60 import 'options.dart' show CompilerOptions, DiagnosticOptions; |
| 59 import 'parser/diet_parser_task.dart' show DietParserTask; | 61 import 'parser/diet_parser_task.dart' show DietParserTask; |
| 60 import 'parser/parser_task.dart' show ParserTask; | 62 import 'parser/parser_task.dart' show ParserTask; |
| 61 import 'patch_parser.dart' show PatchParserTask; | 63 import 'patch_parser.dart' show PatchParserTask; |
| 62 import 'resolution/resolution.dart' show ResolverTask; | 64 import 'resolution/resolution.dart' show ResolverTask; |
| 63 import 'resolved_uri_translator.dart'; | 65 import 'resolved_uri_translator.dart'; |
| 64 import 'scanner/scanner_task.dart' show ScannerTask; | 66 import 'scanner/scanner_task.dart' show ScannerTask; |
| 65 import 'script.dart' show Script; | 67 import 'script.dart' show Script; |
| 66 import 'serialization/task.dart' show SerializationTask; | 68 import 'serialization/task.dart' show SerializationTask; |
| 67 import 'ssa/nodes.dart' show HInstruction; | 69 import 'ssa/nodes.dart' show HInstruction; |
| 68 import 'package:front_end/src/fasta/scanner.dart' | 70 import 'package:front_end/src/fasta/scanner.dart' show StringToken, Token; |
| 69 show StringToken, Token; | |
| 70 import 'tokens/token_map.dart' show TokenMap; | 71 import 'tokens/token_map.dart' show TokenMap; |
| 71 import 'tree/tree.dart' show Node, TypeAnnotation; | 72 import 'tree/tree.dart' show Node, TypeAnnotation; |
| 72 import 'typechecker.dart' show TypeCheckerTask; | 73 import 'typechecker.dart' show TypeCheckerTask; |
| 73 import 'types/types.dart' show GlobalTypeInferenceTask; | 74 import 'types/types.dart' show GlobalTypeInferenceTask; |
| 74 import 'universe/selector.dart' show Selector; | 75 import 'universe/selector.dart' show Selector; |
| 75 import 'universe/world_builder.dart' | 76 import 'universe/world_builder.dart' |
| 76 show ResolutionWorldBuilder, CodegenWorldBuilder; | 77 show ResolutionWorldBuilder, CodegenWorldBuilder; |
| 77 import 'universe/use.dart' show StaticUse, TypeUse; | 78 import 'universe/use.dart' show StaticUse, TypeUse; |
| 78 import 'universe/world_impact.dart' | 79 import 'universe/world_impact.dart' |
| 79 show | 80 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; |
| 80 ImpactStrategy, | |
| 81 WorldImpact, | |
| 82 WorldImpactBuilderImpl; | |
| 83 import 'util/util.dart' show Link, Setlet; | 81 import 'util/util.dart' show Link, Setlet; |
| 84 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; | 82 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; |
| 85 | 83 |
| 86 typedef Backend MakeBackendFunction(Compiler compiler); | 84 typedef Backend MakeBackendFunction(Compiler compiler); |
| 87 | 85 |
| 88 typedef CompilerDiagnosticReporter MakeReporterFunction( | 86 typedef CompilerDiagnosticReporter MakeReporterFunction( |
| 89 Compiler compiler, CompilerOptions options); | 87 Compiler compiler, CompilerOptions options); |
| 90 | 88 |
| 91 abstract class Compiler implements LibraryLoaderListener { | 89 abstract class Compiler implements LibraryLoaderListener { |
| 92 Measurer get measurer; | 90 Measurer get measurer; |
| 93 | 91 |
| 94 final IdGenerator idGenerator = new IdGenerator(); | 92 final IdGenerator idGenerator = new IdGenerator(); |
| 95 Types types; | 93 Types types; |
| 96 _CompilerCommonElements _commonElements; | 94 _CompilerCommonElements _commonElements; |
| 95 _CompilerElementEnvironment _elementEnvironment; |
| 97 CompilerDiagnosticReporter _reporter; | 96 CompilerDiagnosticReporter _reporter; |
| 98 CompilerResolution _resolution; | 97 CompilerResolution _resolution; |
| 99 ParsingContext _parsingContext; | 98 ParsingContext _parsingContext; |
| 100 | 99 |
| 101 ImpactStrategy impactStrategy = const ImpactStrategy(); | 100 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 102 | 101 |
| 103 /** | 102 /** |
| 104 * Map from token to the first preceding comment token. | 103 * Map from token to the first preceding comment token. |
| 105 */ | 104 */ |
| 106 final TokenMap commentMap = new TokenMap(); | 105 final TokenMap commentMap = new TokenMap(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 127 api.CompilerOutput userOutputProvider; | 126 api.CompilerOutput userOutputProvider; |
| 128 | 127 |
| 129 List<Uri> librariesToAnalyzeWhenRun; | 128 List<Uri> librariesToAnalyzeWhenRun; |
| 130 | 129 |
| 131 ResolvedUriTranslator get resolvedUriTranslator; | 130 ResolvedUriTranslator get resolvedUriTranslator; |
| 132 | 131 |
| 133 LibraryElement mainApp; | 132 LibraryElement mainApp; |
| 134 MethodElement mainFunction; | 133 MethodElement mainFunction; |
| 135 | 134 |
| 136 DiagnosticReporter get reporter => _reporter; | 135 DiagnosticReporter get reporter => _reporter; |
| 136 ElementEnvironment get elementEnvironment => _elementEnvironment; |
| 137 CommonElements get commonElements => _commonElements; | 137 CommonElements get commonElements => _commonElements; |
| 138 Resolution get resolution => _resolution; | 138 Resolution get resolution => _resolution; |
| 139 ParsingContext get parsingContext => _parsingContext; | 139 ParsingContext get parsingContext => _parsingContext; |
| 140 | 140 |
| 141 // TODO(zarah): Remove this map and incorporate compile-time errors | 141 // TODO(zarah): Remove this map and incorporate compile-time errors |
| 142 // in the model. | 142 // in the model. |
| 143 /// Tracks elements with compile-time errors. | 143 /// Tracks elements with compile-time errors. |
| 144 final Map<Element, List<DiagnosticMessage>> elementsWithCompileTimeErrors = | 144 final Map<Element, List<DiagnosticMessage>> elementsWithCompileTimeErrors = |
| 145 new Map<Element, List<DiagnosticMessage>>(); | 145 new Map<Element, List<DiagnosticMessage>>(); |
| 146 | 146 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 : this.options = options, | 201 : this.options = options, |
| 202 this.userOutputProvider = outputProvider == null | 202 this.userOutputProvider = outputProvider == null |
| 203 ? const NullCompilerOutput() | 203 ? const NullCompilerOutput() |
| 204 : outputProvider { | 204 : outputProvider { |
| 205 if (makeReporter != null) { | 205 if (makeReporter != null) { |
| 206 _reporter = makeReporter(this, options); | 206 _reporter = makeReporter(this, options); |
| 207 } else { | 207 } else { |
| 208 _reporter = new CompilerDiagnosticReporter(this, options); | 208 _reporter = new CompilerDiagnosticReporter(this, options); |
| 209 } | 209 } |
| 210 _resolution = createResolution(); | 210 _resolution = createResolution(); |
| 211 _commonElements = new _CompilerCommonElements(_resolution, reporter); | 211 _elementEnvironment = new _CompilerElementEnvironment(this); |
| 212 _commonElements = |
| 213 new _CompilerCommonElements(_elementEnvironment, _resolution, reporter); |
| 212 types = new Types(_resolution); | 214 types = new Types(_resolution); |
| 213 | 215 |
| 214 if (options.verbose) { | 216 if (options.verbose) { |
| 215 progress = new Stopwatch()..start(); | 217 progress = new Stopwatch()..start(); |
| 216 } | 218 } |
| 217 | 219 |
| 218 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing | 220 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing |
| 219 // for global dependencies. | 221 // for global dependencies. |
| 220 globalDependencies = new GlobalDependencyRegistry(); | 222 globalDependencies = new GlobalDependencyRegistry(); |
| 221 | 223 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 }); | 332 }); |
| 331 | 333 |
| 332 /// This method is called immediately after the [LibraryElement] [library] has | 334 /// This method is called immediately after the [LibraryElement] [library] has |
| 333 /// been created. | 335 /// been created. |
| 334 /// | 336 /// |
| 335 /// Use this callback method to store references to specific libraries. | 337 /// Use this callback method to store references to specific libraries. |
| 336 /// Note that [library] has not been scanned yet, nor has its imports/exports | 338 /// Note that [library] has not been scanned yet, nor has its imports/exports |
| 337 /// been resolved. | 339 /// been resolved. |
| 338 void onLibraryCreated(LibraryElement library) { | 340 void onLibraryCreated(LibraryElement library) { |
| 339 _commonElements.onLibraryCreated(library); | 341 _commonElements.onLibraryCreated(library); |
| 340 backend.onLibraryCreated(library); | |
| 341 } | 342 } |
| 342 | 343 |
| 343 /// This method is called immediately after the [library] and its parts have | 344 /// This method is called immediately after the [library] and its parts have |
| 344 /// been scanned. | 345 /// been scanned. |
| 345 /// | 346 /// |
| 346 /// Use this callback method to store references to specific member declared | 347 /// Use this callback method to store references to specific member declared |
| 347 /// in certain libraries. Note that [library] has not been patched yet, nor | 348 /// in certain libraries. Note that [library] has not been patched yet, nor |
| 348 /// has its imports/exports been resolved. | 349 /// has its imports/exports been resolved. |
| 349 /// | 350 /// |
| 350 /// Use [loader] to register the creation and scanning of a patch library | 351 /// Use [loader] to register the creation and scanning of a patch library |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 /// Information about suppressed warnings and hints for a given library. | 1105 /// Information about suppressed warnings and hints for a given library. |
| 1105 class SuppressionInfo { | 1106 class SuppressionInfo { |
| 1106 int warnings = 0; | 1107 int warnings = 0; |
| 1107 int hints = 0; | 1108 int hints = 0; |
| 1108 } | 1109 } |
| 1109 | 1110 |
| 1110 class _CompilerCommonElements extends CommonElementsMixin { | 1111 class _CompilerCommonElements extends CommonElementsMixin { |
| 1111 final Resolution resolution; | 1112 final Resolution resolution; |
| 1112 final DiagnosticReporter reporter; | 1113 final DiagnosticReporter reporter; |
| 1113 | 1114 |
| 1115 final ElementEnvironment environment; |
| 1116 |
| 1114 LibraryElement coreLibrary; | 1117 LibraryElement coreLibrary; |
| 1115 LibraryElement asyncLibrary; | 1118 LibraryElement asyncLibrary; |
| 1116 LibraryElement mirrorsLibrary; | 1119 LibraryElement mirrorsLibrary; |
| 1117 LibraryElement typedDataLibrary; | 1120 LibraryElement typedDataLibrary; |
| 1118 | 1121 |
| 1119 // TODO(sigmund): possibly move this to target-specific collection of | 1122 // TODO(sigmund): possibly move this to target-specific collection of |
| 1120 // elements, or refactor the library so that the helpers we need are in a | 1123 // elements, or refactor the library so that the helpers we need are in a |
| 1121 // target-agnostic place. Currently we are using @patch and @Native from | 1124 // target-agnostic place. Currently we are using @patch and @Native from |
| 1122 // here. We hope we can make those independent of the backend and generic | 1125 // here. We hope we can make those independent of the backend and generic |
| 1123 // enough so the patching algorithm can work without being configured for a | 1126 // enough so the patching algorithm can work without being configured for a |
| 1124 // specific backend. | 1127 // specific backend. |
| 1125 LibraryElement jsHelperLibrary; | 1128 LibraryElement jsHelperLibrary; |
| 1126 | 1129 |
| 1127 _CompilerCommonElements(this.resolution, this.reporter); | 1130 _CompilerCommonElements(this.environment, this.resolution, this.reporter); |
| 1128 | 1131 |
| 1129 // From dart:_js_helper | 1132 // From dart:_js_helper |
| 1130 // TODO(sigmund,johnniwinther): refactor needed: either these move to a | 1133 // TODO(sigmund,johnniwinther): refactor needed: either these move to a |
| 1131 // backend-specific collection of helpers, or the helper code moves to a | 1134 // backend-specific collection of helpers, or the helper code moves to a |
| 1132 // backend agnostic library (see commend above on [jsHelperLibrary]. | 1135 // backend agnostic library (see commend above on [jsHelperLibrary]. |
| 1133 | 1136 |
| 1134 ClassElement _patchAnnotationClass; | 1137 ClassElement _patchAnnotationClass; |
| 1135 ClassElement get patchAnnotationClass => | 1138 ClassElement get patchAnnotationClass => |
| 1136 _patchAnnotationClass ??= _findLibraryMember(jsHelperLibrary, '_Patch'); | 1139 _patchAnnotationClass ??= _findLibraryMember(jsHelperLibrary, '_Patch'); |
| 1137 | 1140 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1152 typedDataLibrary = library; | 1155 typedDataLibrary = library; |
| 1153 } else if (uri == Uris.dart_mirrors) { | 1156 } else if (uri == Uris.dart_mirrors) { |
| 1154 mirrorsLibrary = library; | 1157 mirrorsLibrary = library; |
| 1155 } else if (uri == js_backend.BackendHelpers.DART_JS_HELPER) { | 1158 } else if (uri == js_backend.BackendHelpers.DART_JS_HELPER) { |
| 1156 jsHelperLibrary = library; | 1159 jsHelperLibrary = library; |
| 1157 } | 1160 } |
| 1158 } | 1161 } |
| 1159 | 1162 |
| 1160 @override | 1163 @override |
| 1161 MemberElement findLibraryMember(LibraryElement library, String name, | 1164 MemberElement findLibraryMember(LibraryElement library, String name, |
| 1162 {bool required: true}) { | 1165 {bool setter: false, bool required: true}) { |
| 1163 return _findLibraryMember(library, name, required: required); | 1166 Element member = _findLibraryMember(library, name, required: required); |
| 1167 if (member != null && member.isAbstractField) { |
| 1168 AbstractFieldElement abstractField = member; |
| 1169 if (setter) { |
| 1170 member = abstractField.setter; |
| 1171 } else { |
| 1172 member = abstractField.getter; |
| 1173 } |
| 1174 if (member == null && required) { |
| 1175 reporter.internalError( |
| 1176 library, |
| 1177 "The library '${library.canonicalUri}' does not contain required " |
| 1178 "${setter ? 'setter' : 'getter'}: '$name'."); |
| 1179 } |
| 1180 } |
| 1181 return member; |
| 1164 } | 1182 } |
| 1165 | 1183 |
| 1166 @override | 1184 @override |
| 1167 MemberElement findClassMember(ClassElement cls, String name, | 1185 MemberElement findClassMember(ClassElement cls, String name, |
| 1168 {bool required: true}) { | 1186 {bool setter: false, bool required: true}) { |
| 1169 cls.ensureResolved(resolution); | 1187 cls.ensureResolved(resolution); |
| 1170 MemberElement member = cls.lookupLocalMember(name); | 1188 Element member = cls.lookupLocalMember(name); |
| 1189 if (member != null && member.isAbstractField) { |
| 1190 AbstractFieldElement abstractField = member; |
| 1191 if (setter) { |
| 1192 member = abstractField.setter; |
| 1193 } else { |
| 1194 member = abstractField.getter; |
| 1195 } |
| 1196 } |
| 1171 if (member == null && required) { | 1197 if (member == null && required) { |
| 1172 reporter.internalError( | 1198 reporter.internalError( |
| 1173 cls, | 1199 cls, |
| 1174 "The class '${cls}' in '${cls.library.canonicalUri}' does not " | 1200 "The class '${cls}' in '${cls.library.canonicalUri}' does not " |
| 1175 "contain required member: '$name'."); | 1201 "contain required member: '$name'."); |
| 1176 } | 1202 } |
| 1177 return member; | 1203 return member; |
| 1178 } | 1204 } |
| 1179 | 1205 |
| 1180 @override | 1206 @override |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1208 | 1234 |
| 1209 Element element = library.find(name); | 1235 Element element = library.find(name); |
| 1210 if (element == null && required) { | 1236 if (element == null && required) { |
| 1211 reporter.internalError( | 1237 reporter.internalError( |
| 1212 library, | 1238 library, |
| 1213 "The library '${library.canonicalUri}' does not contain required " | 1239 "The library '${library.canonicalUri}' does not contain required " |
| 1214 "element: '$name'."); | 1240 "element: '$name'."); |
| 1215 } | 1241 } |
| 1216 return element; | 1242 return element; |
| 1217 } | 1243 } |
| 1218 | |
| 1219 @override | |
| 1220 ResolutionInterfaceType createInterfaceType( | |
| 1221 ClassElement cls, List<ResolutionDartType> typeArguments) { | |
| 1222 cls.ensureResolved(resolution); | |
| 1223 return new ResolutionInterfaceType(cls, typeArguments); | |
| 1224 } | |
| 1225 | |
| 1226 @override | |
| 1227 ResolutionInterfaceType getRawType(ClassElement cls) { | |
| 1228 cls.ensureResolved(resolution); | |
| 1229 return cls.rawType; | |
| 1230 } | |
| 1231 } | 1244 } |
| 1232 | 1245 |
| 1233 class CompilerDiagnosticReporter extends DiagnosticReporter { | 1246 class CompilerDiagnosticReporter extends DiagnosticReporter { |
| 1234 final Compiler compiler; | 1247 final Compiler compiler; |
| 1235 final DiagnosticOptions options; | 1248 final DiagnosticOptions options; |
| 1236 | 1249 |
| 1237 Element _currentElement; | 1250 Element _currentElement; |
| 1238 bool hasCrashed = false; | 1251 bool hasCrashed = false; |
| 1239 | 1252 |
| 1240 /// `true` if the last diagnostic was filtered, in which case the | 1253 /// `true` if the last diagnostic was filtered, in which case the |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 _ElementScanner(this.scanner); | 1974 _ElementScanner(this.scanner); |
| 1962 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1975 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 1963 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1976 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 1964 } | 1977 } |
| 1965 | 1978 |
| 1966 class _EmptyEnvironment implements Environment { | 1979 class _EmptyEnvironment implements Environment { |
| 1967 const _EmptyEnvironment(); | 1980 const _EmptyEnvironment(); |
| 1968 | 1981 |
| 1969 String valueOf(String key) => null; | 1982 String valueOf(String key) => null; |
| 1970 } | 1983 } |
| 1984 |
| 1985 /// An element environment base on a [Compiler]. |
| 1986 class _CompilerElementEnvironment implements ElementEnvironment { |
| 1987 final Compiler _compiler; |
| 1988 |
| 1989 _CompilerElementEnvironment(this._compiler); |
| 1990 |
| 1991 LibraryProvider get _libraryProvider => _compiler.libraryLoader; |
| 1992 Resolution get _resolution => _compiler.resolution; |
| 1993 |
| 1994 @override |
| 1995 ResolutionInterfaceType getThisType(ClassElement cls) { |
| 1996 cls.ensureResolved(_resolution); |
| 1997 return cls.thisType; |
| 1998 } |
| 1999 |
| 2000 @override |
| 2001 ResolutionInterfaceType getRawType(ClassElement cls) { |
| 2002 cls.ensureResolved(_resolution); |
| 2003 return cls.rawType; |
| 2004 } |
| 2005 |
| 2006 @override |
| 2007 ResolutionInterfaceType createInterfaceType( |
| 2008 ClassElement cls, List<ResolutionDartType> typeArguments) { |
| 2009 cls.ensureResolved(_resolution); |
| 2010 return cls.thisType.createInstantiation(typeArguments); |
| 2011 } |
| 2012 |
| 2013 @override |
| 2014 MemberElement lookupClassMember(ClassElement cls, String name, |
| 2015 {bool setter: false, bool required: false}) { |
| 2016 cls.ensureResolved(_resolution); |
| 2017 Element member = cls.implementation.lookupLocalMember(name); |
| 2018 if (member != null && member.isAbstractField) { |
| 2019 AbstractFieldElement abstractField = member; |
| 2020 if (setter) { |
| 2021 member = abstractField.setter; |
| 2022 } else { |
| 2023 member = abstractField.getter; |
| 2024 } |
| 2025 if (member == null && required) { |
| 2026 throw new SpannableAssertionFailure( |
| 2027 cls, |
| 2028 "The class '${cls.name}' does not contain required " |
| 2029 "${setter ? 'setter' : 'getter'}: '$name'."); |
| 2030 } |
| 2031 } |
| 2032 if (member == null && required) { |
| 2033 throw new SpannableAssertionFailure( |
| 2034 cls, |
| 2035 "The class '${cls.name}' does not " |
| 2036 "contain required member: '$name'."); |
| 2037 } |
| 2038 return member?.declaration; |
| 2039 } |
| 2040 |
| 2041 @override |
| 2042 ConstructorElement lookupConstructor(ClassElement cls, String name, |
| 2043 {bool required: false}) { |
| 2044 cls.ensureResolved(_resolution); |
| 2045 ConstructorElement constructor = cls.implementation.lookupConstructor(name); |
| 2046 if (constructor == null && required) { |
| 2047 throw new SpannableAssertionFailure( |
| 2048 cls, |
| 2049 "The class '${cls.name}' does not contain " |
| 2050 "required constructor: '$name'."); |
| 2051 } |
| 2052 return constructor?.declaration; |
| 2053 } |
| 2054 |
| 2055 @override |
| 2056 MemberElement lookupLibraryMember(LibraryElement library, String name, |
| 2057 {bool setter: false, bool required: false}) { |
| 2058 Element member = library.implementation.findLocal(name); |
| 2059 if (member != null && member.isAbstractField) { |
| 2060 AbstractFieldElement abstractField = member; |
| 2061 if (setter) { |
| 2062 member = abstractField.setter; |
| 2063 } else { |
| 2064 member = abstractField.getter; |
| 2065 } |
| 2066 if (member == null && required) { |
| 2067 throw new SpannableAssertionFailure( |
| 2068 library, |
| 2069 "The library '${library.canonicalUri}' does not contain required " |
| 2070 "${setter ? 'setter' : 'getter'}: '$name'."); |
| 2071 } |
| 2072 } |
| 2073 if (member == null && required) { |
| 2074 throw new SpannableAssertionFailure( |
| 2075 member, |
| 2076 "The library '${library.libraryName}' does not " |
| 2077 "contain required member: '$name'."); |
| 2078 } |
| 2079 return member?.declaration; |
| 2080 } |
| 2081 |
| 2082 @override |
| 2083 ClassElement lookupClass(LibraryElement library, String name, |
| 2084 {bool required: false}) { |
| 2085 ClassElement cls = library.implementation.findLocal(name); |
| 2086 if (cls == null && required) { |
| 2087 throw new SpannableAssertionFailure( |
| 2088 cls, |
| 2089 "The library '${library.libraryName}' does not " |
| 2090 "contain required class: '$name'."); |
| 2091 } |
| 2092 return cls?.declaration; |
| 2093 } |
| 2094 |
| 2095 @override |
| 2096 LibraryElement lookupLibrary(Uri uri, {bool required: false}) { |
| 2097 LibraryElement library = _libraryProvider.lookupLibrary(uri); |
| 2098 if (library != null && library.isSynthesized) { |
| 2099 return null; |
| 2100 } |
| 2101 if (library == null && required) { |
| 2102 throw new SpannableAssertionFailure( |
| 2103 library, "The library '${uri}' was not found."); |
| 2104 } |
| 2105 return library; |
| 2106 } |
| 2107 } |
| OLD | NEW |