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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2846883005: Rollback instrumentation during analysis and validate resolved ASTs instead. (Closed)
Patch Set: Created 3 years, 7 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.generated.resolver; 5 library analyzer.src.generated.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
11 import 'package:analyzer/dart/ast/token.dart'; 11 import 'package:analyzer/dart/ast/token.dart';
12 import 'package:analyzer/dart/ast/visitor.dart'; 12 import 'package:analyzer/dart/ast/visitor.dart';
13 import 'package:analyzer/dart/element/element.dart'; 13 import 'package:analyzer/dart/element/element.dart';
14 import 'package:analyzer/dart/element/type.dart'; 14 import 'package:analyzer/dart/element/type.dart';
15 import 'package:analyzer/dart/element/visitor.dart'; 15 import 'package:analyzer/dart/element/visitor.dart';
16 import 'package:analyzer/error/error.dart'; 16 import 'package:analyzer/error/error.dart';
17 import 'package:analyzer/error/listener.dart'; 17 import 'package:analyzer/error/listener.dart';
18 import 'package:analyzer/exception/exception.dart'; 18 import 'package:analyzer/exception/exception.dart';
19 import 'package:analyzer/src/dart/ast/ast.dart'; 19 import 'package:analyzer/src/dart/ast/ast.dart';
20 import 'package:analyzer/src/dart/ast/utilities.dart'; 20 import 'package:analyzer/src/dart/ast/utilities.dart';
21 import 'package:analyzer/src/dart/element/element.dart'; 21 import 'package:analyzer/src/dart/element/element.dart';
22 import 'package:analyzer/src/dart/element/member.dart' show ConstructorMember; 22 import 'package:analyzer/src/dart/element/member.dart' show ConstructorMember;
23 import 'package:analyzer/src/dart/element/type.dart'; 23 import 'package:analyzer/src/dart/element/type.dart';
24 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; 24 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
25 import 'package:analyzer/src/dart/resolver/scope.dart'; 25 import 'package:analyzer/src/dart/resolver/scope.dart';
26 import 'package:analyzer/src/error/codes.dart'; 26 import 'package:analyzer/src/error/codes.dart';
27 import 'package:analyzer/src/fasta/uri_instrumentation.dart';
28 import 'package:analyzer/src/generated/constant.dart'; 27 import 'package:analyzer/src/generated/constant.dart';
29 import 'package:analyzer/src/generated/element_resolver.dart'; 28 import 'package:analyzer/src/generated/element_resolver.dart';
30 import 'package:analyzer/src/generated/engine.dart'; 29 import 'package:analyzer/src/generated/engine.dart';
31 import 'package:analyzer/src/generated/error_verifier.dart'; 30 import 'package:analyzer/src/generated/error_verifier.dart';
32 import 'package:analyzer/src/generated/source.dart'; 31 import 'package:analyzer/src/generated/source.dart';
33 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 32 import 'package:analyzer/src/generated/static_type_analyzer.dart';
34 import 'package:analyzer/src/generated/testing/element_factory.dart'; 33 import 'package:analyzer/src/generated/testing/element_factory.dart';
35 import 'package:analyzer/src/generated/type_system.dart'; 34 import 'package:analyzer/src/generated/type_system.dart';
36 import 'package:analyzer/src/generated/utilities_dart.dart'; 35 import 'package:analyzer/src/generated/utilities_dart.dart';
37 36
(...skipping 4167 matching lines...) Expand 10 before | Expand all | Expand 10 after
4205 // hash table help in an instance of this class. 4204 // hash table help in an instance of this class.
4206 static const String _typeProperty = 4205 static const String _typeProperty =
4207 'analyzer.src.generated.InferenceContext.contextType'; 4206 'analyzer.src.generated.InferenceContext.contextType';
4208 4207
4209 /** 4208 /**
4210 * The error listener on which to record inference information. 4209 * The error listener on which to record inference information.
4211 */ 4210 */
4212 final ErrorReporter _errorReporter; 4211 final ErrorReporter _errorReporter;
4213 4212
4214 /** 4213 /**
4215 * The instrumentation to report inference information.
4216 */
4217 final UriInstrumentation _instrumentation;
4218
4219 /**
4220 * If true, emit hints when types are inferred 4214 * If true, emit hints when types are inferred
4221 */ 4215 */
4222 final bool _inferenceHints; 4216 final bool _inferenceHints;
4223 4217
4224 /** 4218 /**
4225 * Type provider, needed for type matching. 4219 * Type provider, needed for type matching.
4226 */ 4220 */
4227 final TypeProvider _typeProvider; 4221 final TypeProvider _typeProvider;
4228 4222
4229 /** 4223 /**
4230 * The type system in use. 4224 * The type system in use.
4231 */ 4225 */
4232 final TypeSystem _typeSystem; 4226 final TypeSystem _typeSystem;
4233 4227
4234 /** 4228 /**
4235 * When no context type is available, this will track the least upper bound 4229 * When no context type is available, this will track the least upper bound
4236 * of all return statements in a lambda. 4230 * of all return statements in a lambda.
4237 * 4231 *
4238 * This will always be kept in sync with [_returnStack]. 4232 * This will always be kept in sync with [_returnStack].
4239 */ 4233 */
4240 final List<DartType> _inferredReturn = <DartType>[]; 4234 final List<DartType> _inferredReturn = <DartType>[];
4241 4235
4242 /** 4236 /**
4243 * A stack of return types for all of the enclosing 4237 * A stack of return types for all of the enclosing
4244 * functions and methods. 4238 * functions and methods.
4245 */ 4239 */
4246 final List<DartType> _returnStack = <DartType>[]; 4240 final List<DartType> _returnStack = <DartType>[];
4247 4241
4248 InferenceContext._(TypeProvider typeProvider, this._typeSystem, 4242 InferenceContext._(TypeProvider typeProvider, this._typeSystem,
4249 this._inferenceHints, this._errorReporter, this._instrumentation) 4243 this._inferenceHints, this._errorReporter)
4250 : _typeProvider = typeProvider; 4244 : _typeProvider = typeProvider;
4251 4245
4252 /** 4246 /**
4253 * Get the return type of the current enclosing function, if any. 4247 * Get the return type of the current enclosing function, if any.
4254 * 4248 *
4255 * The type returned for a function is the type that is expected 4249 * The type returned for a function is the type that is expected
4256 * to be used in a return or yield context. For ordinary functions 4250 * to be used in a return or yield context. For ordinary functions
4257 * this is the same as the return type of the function. For async 4251 * this is the same as the return type of the function. For async
4258 * functions returning Future<T> and for generator functions 4252 * functions returning Future<T> and for generator functions
4259 * returning Stream<T> or Iterable<T>, this is T. 4253 * returning Stream<T> or Iterable<T>, this is T.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4303 void pushReturnContext(BlockFunctionBody node) { 4297 void pushReturnContext(BlockFunctionBody node) {
4304 _returnStack.add(getContext(node)); 4298 _returnStack.add(getContext(node));
4305 _inferredReturn.add(_typeProvider.nullType); 4299 _inferredReturn.add(_typeProvider.nullType);
4306 } 4300 }
4307 4301
4308 /** 4302 /**
4309 * Place an info node into the error stream indicating that a 4303 * Place an info node into the error stream indicating that a
4310 * [type] has been inferred as the type of [node]. 4304 * [type] has been inferred as the type of [node].
4311 */ 4305 */
4312 void recordInference(Expression node, DartType type) { 4306 void recordInference(Expression node, DartType type) {
4313 _instrumentation?.recordInference(node.offset, type);
4314
4315 if (!_inferenceHints) { 4307 if (!_inferenceHints) {
4316 return; 4308 return;
4317 } 4309 }
4318 4310
4319 ErrorCode error; 4311 ErrorCode error;
4320 if (node is Literal) { 4312 if (node is Literal) {
4321 error = StrongModeCode.INFERRED_TYPE_LITERAL; 4313 error = StrongModeCode.INFERRED_TYPE_LITERAL;
4322 } else if (node is InstanceCreationExpression) { 4314 } else if (node is InstanceCreationExpression) {
4323 error = StrongModeCode.INFERRED_TYPE_ALLOCATION; 4315 error = StrongModeCode.INFERRED_TYPE_ALLOCATION;
4324 } else if (node is FunctionExpression) { 4316 } else if (node is FunctionExpression) {
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
4993 * The object used to compute the type associated with the current node. 4985 * The object used to compute the type associated with the current node.
4994 */ 4986 */
4995 StaticTypeAnalyzer typeAnalyzer; 4987 StaticTypeAnalyzer typeAnalyzer;
4996 4988
4997 /** 4989 /**
4998 * The type system in use during resolution. 4990 * The type system in use during resolution.
4999 */ 4991 */
5000 TypeSystem typeSystem; 4992 TypeSystem typeSystem;
5001 4993
5002 /** 4994 /**
5003 * The instrumentation to report inference information.
5004 */
5005 final UriInstrumentation instrumentation;
5006
5007 /**
5008 * The class declaration representing the class containing the current node, o r `null` if 4995 * The class declaration representing the class containing the current node, o r `null` if
5009 * the current node is not contained in a class. 4996 * the current node is not contained in a class.
5010 */ 4997 */
5011 ClassDeclaration _enclosingClassDeclaration = null; 4998 ClassDeclaration _enclosingClassDeclaration = null;
5012 4999
5013 /** 5000 /**
5014 * The function type alias representing the function type containing the curre nt node, or 5001 * The function type alias representing the function type containing the curre nt node, or
5015 * `null` if the current node is not contained in a function type alias. 5002 * `null` if the current node is not contained in a function type alias.
5016 */ 5003 */
5017 FunctionTypeAlias _enclosingFunctionTypeAlias = null; 5004 FunctionTypeAlias _enclosingFunctionTypeAlias = null;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5066 * node that will first be visited. If `null` or unspecified, a new 5053 * node that will first be visited. If `null` or unspecified, a new
5067 * [LibraryScope] will be created based on [definingLibrary] and 5054 * [LibraryScope] will be created based on [definingLibrary] and
5068 * [typeProvider]. The [inheritanceManager] is used to perform inheritance 5055 * [typeProvider]. The [inheritanceManager] is used to perform inheritance
5069 * lookups. If `null` or unspecified, a new [InheritanceManager] will be 5056 * lookups. If `null` or unspecified, a new [InheritanceManager] will be
5070 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to 5057 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to
5071 * create the type analyzer. If `null` or unspecified, a type analyzer of 5058 * create the type analyzer. If `null` or unspecified, a type analyzer of
5072 * type [StaticTypeAnalyzer] will be created. 5059 * type [StaticTypeAnalyzer] will be created.
5073 */ 5060 */
5074 ResolverVisitor(LibraryElement definingLibrary, Source source, 5061 ResolverVisitor(LibraryElement definingLibrary, Source source,
5075 TypeProvider typeProvider, AnalysisErrorListener errorListener, 5062 TypeProvider typeProvider, AnalysisErrorListener errorListener,
5076 {Scope nameScope, this.instrumentation}) 5063 {Scope nameScope})
5077 : super(definingLibrary, source, typeProvider, errorListener, 5064 : super(definingLibrary, source, typeProvider, errorListener,
5078 nameScope: nameScope) { 5065 nameScope: nameScope) {
5079 AnalysisOptions options = definingLibrary.context.analysisOptions; 5066 AnalysisOptions options = definingLibrary.context.analysisOptions;
5080 this.strongMode = options.strongMode; 5067 this.strongMode = options.strongMode;
5081 this.elementResolver = new ElementResolver(this); 5068 this.elementResolver = new ElementResolver(this);
5082 this.typeSystem = definingLibrary.context.typeSystem; 5069 this.typeSystem = definingLibrary.context.typeSystem;
5083 bool strongModeHints = false; 5070 bool strongModeHints = false;
5084 if (options is AnalysisOptionsImpl) { 5071 if (options is AnalysisOptionsImpl) {
5085 strongModeHints = options.strongModeHints; 5072 strongModeHints = options.strongModeHints;
5086 } 5073 }
5087 this.inferenceContext = new InferenceContext._(typeProvider, typeSystem, 5074 this.inferenceContext = new InferenceContext._(
5088 strongModeHints, errorReporter, instrumentation); 5075 typeProvider, typeSystem, strongModeHints, errorReporter);
5089 this.typeAnalyzer = new StaticTypeAnalyzer(this); 5076 this.typeAnalyzer = new StaticTypeAnalyzer(this);
5090 } 5077 }
5091 5078
5092 /** 5079 /**
5093 * Return the element representing the function containing the current node, o r `null` if 5080 * Return the element representing the function containing the current node, o r `null` if
5094 * the current node is not contained in a function. 5081 * the current node is not contained in a function.
5095 * 5082 *
5096 * @return the element representing the function containing the current node 5083 * @return the element representing the function containing the current node
5097 */ 5084 */
5098 ExecutableElement get enclosingFunction => _enclosingFunction; 5085 ExecutableElement get enclosingFunction => _enclosingFunction;
(...skipping 5852 matching lines...) Expand 10 before | Expand all | Expand 10 after
10951 return null; 10938 return null;
10952 } 10939 }
10953 if (identical(node.staticElement, variable)) { 10940 if (identical(node.staticElement, variable)) {
10954 if (node.inSetterContext()) { 10941 if (node.inSetterContext()) {
10955 result = true; 10942 result = true;
10956 } 10943 }
10957 } 10944 }
10958 return null; 10945 return null;
10959 } 10946 }
10960 } 10947 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/fasta/uri_instrumentation.dart ('k') | pkg/analyzer/lib/src/generated/static_type_analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698