Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: pkg/dev_compiler/lib/src/analyzer/context.dart

Issue 2353133004: fix #27403, use AST summaries in DDC (Closed)
Patch Set: merge Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'package:args/args.dart' show ArgParser, ArgResults; 5 import 'package:args/args.dart' show ArgParser, ArgResults;
6 import 'package:analyzer/file_system/file_system.dart' 6 import 'package:analyzer/file_system/file_system.dart'
7 show ResourceProvider, ResourceUriResolver; 7 show ResourceProvider, ResourceUriResolver;
8 import 'package:analyzer/file_system/physical_file_system.dart' 8 import 'package:analyzer/file_system/physical_file_system.dart'
9 show PhysicalResourceProvider; 9 show PhysicalResourceProvider;
10 import 'package:analyzer/source/custom_resolver.dart'; 10 import 'package:analyzer/source/custom_resolver.dart';
11 import 'package:analyzer/source/package_map_resolver.dart'; 11 import 'package:analyzer/source/package_map_resolver.dart';
12 import 'package:analyzer/src/context/builder.dart'; 12 import 'package:analyzer/src/context/builder.dart';
13 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 13 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
14 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk; 14 import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
15 import 'package:analyzer/src/generated/engine.dart' 15 import 'package:analyzer/src/generated/engine.dart'
16 show AnalysisContext, AnalysisEngine, AnalysisOptionsImpl; 16 show AnalysisEngine, AnalysisOptionsImpl;
17 import 'package:analyzer/src/generated/source.dart' 17 import 'package:analyzer/src/generated/source.dart'
18 show DartUriResolver, SourceFactory, UriResolver; 18 show DartUriResolver, SourceFactory, UriResolver;
19 import 'package:analyzer/src/summary/package_bundle_reader.dart' 19 import 'package:analyzer/src/summary/package_bundle_reader.dart'
20 show InSummaryUriResolver, InputPackagesResultProvider, SummaryDataStore; 20 show InSummaryUriResolver, SummaryDataStore;
21 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; 21 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
22 import 'package:cli_util/cli_util.dart' show getSdkDir; 22 import 'package:cli_util/cli_util.dart' show getSdkDir;
23 import 'package:path/path.dart' as path; 23 import 'package:path/path.dart' as path;
24 24
25 import 'multi_package_resolver.dart' show MultiPackageResolver; 25 import 'multi_package_resolver.dart' show MultiPackageResolver;
26 26
27 /// Options used to set up Source URI resolution in the analysis context. 27 /// Options used to set up Source URI resolution in the analysis context.
28 class AnalyzerOptions { 28 class AnalyzerOptions {
29 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" 29 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart"
30 final Map<String, String> customUrlMappings; 30 final Map<String, String> customUrlMappings;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 for (var mapping in argument) { 91 for (var mapping in argument) {
92 var splitMapping = mapping.split(','); 92 var splitMapping = mapping.split(',');
93 if (splitMapping.length >= 2) { 93 if (splitMapping.length >= 2) {
94 mappings[splitMapping[0]] = path.absolute(splitMapping[1]); 94 mappings[splitMapping[0]] = path.absolute(splitMapping[1]);
95 } 95 }
96 } 96 }
97 return mappings; 97 return mappings;
98 } 98 }
99 } 99 }
100 100
101 /// Creates an [AnalysisContext] with dev_compiler type rules and inference,
102 /// using [createSourceFactory] to set up its [SourceFactory].
103 AnalysisContext createAnalysisContextWithSources(AnalyzerOptions options,
104 {DartUriResolver sdkResolver,
105 List<UriResolver> fileResolvers,
106 ResourceProvider resourceProvider}) {
107 AnalysisEngine.instance.processRequiredPlugins();
108
109 sdkResolver ??=
110 createSdkPathResolver(options.dartSdkSummaryPath, options.dartSdkPath);
111
112 // Read the summaries.
113 SummaryDataStore summaryData;
114 if (options.summaryPaths.isNotEmpty) {
115 summaryData = new SummaryDataStore(options.summaryPaths);
116 }
117
118 var srcFactory = _createSourceFactory(options,
119 sdkResolver: sdkResolver,
120 fileResolvers: fileResolvers,
121 summaryData: summaryData,
122 resourceProvider: resourceProvider);
123
124 var context = createAnalysisContext();
125 context.sourceFactory = srcFactory;
126 if (summaryData != null) {
127 context.typeProvider = sdkResolver.dartSdk.context.typeProvider;
128 context.resultProvider =
129 new InputPackagesResultProvider(context, summaryData);
130 }
131 return context;
132 }
133
134 /// Creates an analysis context that contains our restricted typing rules. 101 /// Creates an analysis context that contains our restricted typing rules.
135 AnalysisContextImpl createAnalysisContext() { 102 AnalysisContextImpl createAnalysisContext() {
136 var res = AnalysisEngine.instance.createAnalysisContext(); 103 var res = AnalysisEngine.instance.createAnalysisContext();
137 res.analysisOptions = new AnalysisOptionsImpl() 104 res.analysisOptions = new AnalysisOptionsImpl()
138 ..strongMode = true 105 ..strongMode = true
139 ..trackCacheDependencies = false; 106 ..trackCacheDependencies = false;
140 return res; 107 return res;
141 } 108 }
142 109
143 /// Creates a SourceFactory configured by the [options]. 110 /// Creates a SourceFactory configured by the [options].
144 /// 111 ///
145 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver] 112 /// Use [options.useMockSdk] to specify the SDK mode, or use [sdkResolver]
146 /// to entirely override the DartUriResolver. 113 /// to entirely override the DartUriResolver.
147 /// 114 ///
148 /// If supplied, [fileResolvers] will override the default `file:` and 115 /// If supplied, [fileResolvers] will override the default `file:` and
149 /// `package:` URI resolvers. 116 /// `package:` URI resolvers.
150 SourceFactory _createSourceFactory(AnalyzerOptions options, 117 SourceFactory createSourceFactory(AnalyzerOptions options,
151 {DartUriResolver sdkResolver, 118 {DartUriResolver sdkResolver,
152 List<UriResolver> fileResolvers, 119 List<UriResolver> fileResolvers,
153 SummaryDataStore summaryData, 120 SummaryDataStore summaryData,
154 ResourceProvider resourceProvider}) { 121 ResourceProvider resourceProvider}) {
155 resourceProvider ??= PhysicalResourceProvider.INSTANCE; 122 resourceProvider ??= PhysicalResourceProvider.INSTANCE;
156 var resolvers = <UriResolver>[]; 123 var resolvers = <UriResolver>[];
157 if (options.customUrlMappings.isNotEmpty) { 124 if (options.customUrlMappings.isNotEmpty) {
158 resolvers.add( 125 resolvers.add(
159 new CustomUriResolver(resourceProvider, options.customUrlMappings)); 126 new CustomUriResolver(resourceProvider, options.customUrlMappings));
160 } 127 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return sdk; 164 return sdk;
198 } 165 }
199 166
200 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. 167 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath].
201 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { 168 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) {
202 var sdk = (sdkSummaryPath != null) 169 var sdk = (sdkSummaryPath != null)
203 ? new SummaryBasedDartSdk(sdkSummaryPath, true) 170 ? new SummaryBasedDartSdk(sdkSummaryPath, true)
204 : _createFolderBasedDartSdk(sdkPath); 171 : _createFolderBasedDartSdk(sdkPath);
205 return new DartUriResolver(sdk); 172 return new DartUriResolver(sdk);
206 } 173 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/js/legacy/dart_sdk.js ('k') | pkg/dev_compiler/lib/src/compiler/code_generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698