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

Side by Side Diff: lib/src/checker/resolver.dart

Issue 1174643003: expose strong checker API, for use by analyzer_cli (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « lib/src/checker/checker.dart ('k') | lib/src/checker/rules.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /// Encapsulates how to invoke the analyzer resolver and overrides how it 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it
6 /// computes types on expressions to use our restricted set of types. 6 /// computes types on expressions to use our restricted set of types.
7 library dev_compiler.src.checker.resolver; 7 library dev_compiler.src.checker.resolver;
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart'; 11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/resolver.dart'; 12 import 'package:analyzer/src/generated/resolver.dart';
13 import 'package:analyzer/src/generated/source.dart' show Source; 13 import 'package:analyzer/src/generated/source.dart' show Source;
14 import 'package:analyzer/src/generated/source_io.dart'; 14 import 'package:analyzer/src/generated/source_io.dart';
15 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 15 import 'package:analyzer/src/generated/static_type_analyzer.dart';
16 import 'package:analyzer/src/generated/utilities_collection.dart' 16 import 'package:analyzer/src/generated/utilities_collection.dart'
17 show DirectedGraph; 17 show DirectedGraph;
18 import 'package:logging/logging.dart' as logger; 18 import 'package:logging/logging.dart' as logger;
19 19
20 import 'package:dev_compiler/src/options.dart';
21 import 'package:dev_compiler/src/utils.dart'; 20 import 'package:dev_compiler/src/utils.dart';
21 import 'package:dev_compiler/strong_mode.dart' show StrongModeOptions;
22 22
23 final _log = new logger.Logger('dev_compiler.src.resolver'); 23 final _log = new logger.Logger('dev_compiler.src.resolver');
24 24
25 /// A [LibraryResolver] that performs inference on top-levels and fields based 25 /// A [LibraryResolver] that performs inference on top-levels and fields based
26 /// on the value of the initializer, and on fields and methods based on 26 /// on the value of the initializer, and on fields and methods based on
27 /// overridden members in super classes. 27 /// overridden members in super classes.
28 class LibraryResolverWithInference extends LibraryResolver { 28 class LibraryResolverWithInference extends LibraryResolver {
29 final ResolverOptions _options; 29 final StrongModeOptions _options;
30 30
31 LibraryResolverWithInference(context, this._options) : super(context); 31 LibraryResolverWithInference(context, this._options) : super(context);
32 32
33 @override 33 @override
34 void resolveReferencesAndTypes() { 34 void resolveReferencesAndTypes() {
35 _resolveVariableReferences(); 35 _resolveVariableReferences();
36 36
37 // Run resolution in two stages, skipping method bodies first, so we can run 37 // Run resolution in two stages, skipping method bodies first, so we can run
38 // type-inference before we fully analyze methods. 38 // type-inference before we fully analyze methods.
39 var visitors = _createVisitors(); 39 var visitors = _createVisitors();
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // here will be dynamic. 206 // here will be dynamic.
207 var enclosingElement = varElement.enclosingElement; 207 var enclosingElement = varElement.enclosingElement;
208 var type = searchTypeFor(enclosingElement.type, getter); 208 var type = searchTypeFor(enclosingElement.type, getter);
209 209
210 // Infer from the RHS when there are no overrides. 210 // Infer from the RHS when there are no overrides.
211 if (type == null) { 211 if (type == null) {
212 if (variable.initializer != null) pending.add(variable); 212 if (variable.initializer != null) pending.add(variable);
213 continue; 213 continue;
214 } 214 }
215 215
216 // When field is final and overriden getter is dynamic, we can infer from 216 // When field is final and overridden getter is dynamic, we can infer from
217 // the RHS without breaking subtyping rules (return type is covariant). 217 // the RHS without breaking subtyping rules (return type is covariant).
218 if (type.returnType.isDynamic) { 218 if (type.returnType.isDynamic) {
219 if (variables.isFinal && variable.initializer != null) { 219 if (variables.isFinal && variable.initializer != null) {
220 pending.add(variable); 220 pending.add(variable);
221 } 221 }
222 continue; 222 continue;
223 } 223 }
224 224
225 // Use type from the override. 225 // Use type from the override.
226 var newType = type.returnType; 226 var newType = type.returnType;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 /// Internal state, whether we are revisiting an initializer, so we minimize 349 /// Internal state, whether we are revisiting an initializer, so we minimize
350 /// the work being done elsewhere. 350 /// the work being done elsewhere.
351 bool _revisiting = false; 351 bool _revisiting = false;
352 352
353 /// Initializers that have been visited, reanalyzed, and for which no node was 353 /// Initializers that have been visited, reanalyzed, and for which no node was
354 /// internally skipped. These initializers are fully resolved and don't need 354 /// internally skipped. These initializers are fully resolved and don't need
355 /// to be re-resolved on a sunsequent pass. 355 /// to be re-resolved on a sunsequent pass.
356 final _visitedInitializers = new Set<VariableDeclaration>(); 356 final _visitedInitializers = new Set<VariableDeclaration>();
357 357
358 RestrictedResolverVisitor(Library library, Source source, 358 RestrictedResolverVisitor(Library library, Source source,
359 TypeProvider typeProvider, ResolverOptions options) 359 TypeProvider typeProvider, StrongModeOptions options)
360 : _typeProvider = typeProvider, 360 : _typeProvider = typeProvider,
361 super.con1(library, source, typeProvider, 361 super.con1(library, source, typeProvider,
362 typeAnalyzerFactory: RestrictedStaticTypeAnalyzer.constructor); 362 typeAnalyzerFactory: RestrictedStaticTypeAnalyzer.constructor);
363 363
364 reanalyzeInitializer(VariableDeclaration variable) { 364 reanalyzeInitializer(VariableDeclaration variable) {
365 try { 365 try {
366 _revisiting = true; 366 _revisiting = true;
367 _nodeWasSkipped = false; 367 _nodeWasSkipped = false;
368 var node = variable.parent.parent; 368 var node = variable.parent.parent;
369 var oldState; 369 var oldState;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 686 }
687 } 687 }
688 688
689 // Review note: no longer need to override visitFunctionExpression, this is 689 // Review note: no longer need to override visitFunctionExpression, this is
690 // handled by the analyzer internally. 690 // handled by the analyzer internally.
691 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? 691 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result?
692 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression 692 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression
693 // type in a (...) => expr or just the written type? 693 // type in a (...) => expr or just the written type?
694 694
695 } 695 }
OLDNEW
« no previous file with comments | « lib/src/checker/checker.dart ('k') | lib/src/checker/rules.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698