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

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

Issue 1355773002: Make type system changes backwards compatible (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments, rebase Created 5 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) 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 engine.resolver; 5 library engine.resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'constant.dart'; 10 import 'constant.dart';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 /** 75 /**
76 * The type system primitives 76 * The type system primitives
77 */ 77 */
78 TypeSystem _typeSystem; 78 TypeSystem _typeSystem;
79 79
80 /** 80 /**
81 * Create a new instance of the [BestPracticesVerifier]. 81 * Create a new instance of the [BestPracticesVerifier].
82 * 82 *
83 * @param errorReporter the error reporter 83 * @param errorReporter the error reporter
84 */ 84 */
85 BestPracticesVerifier( 85 BestPracticesVerifier(this._errorReporter, TypeProvider typeProvider,
86 this._errorReporter, TypeProvider typeProvider, this._typeSystem) 86 {TypeSystem typeSystem})
87 : _futureNullType = typeProvider.futureNullType; 87 : _futureNullType = typeProvider.futureNullType,
88 _typeSystem = (typeSystem != null) ? typeSystem : new TypeSystemImpl();
88 89
89 @override 90 @override
90 Object visitArgumentList(ArgumentList node) { 91 Object visitArgumentList(ArgumentList node) {
91 _checkForArgumentTypesNotAssignableInList(node); 92 _checkForArgumentTypesNotAssignableInList(node);
92 return super.visitArgumentList(node); 93 return super.visitArgumentList(node);
93 } 94 }
94 95
95 @override 96 @override
96 Object visitAsExpression(AsExpression node) { 97 Object visitAsExpression(AsExpression node) {
97 _checkForUnnecessaryCast(node); 98 _checkForUnnecessaryCast(node);
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 /** 879 /**
879 * The current library that is being analyzed. 880 * The current library that is being analyzed.
880 */ 881 */
881 final LibraryElement _currentLibrary; 882 final LibraryElement _currentLibrary;
882 883
883 /** 884 /**
884 * Initialize a newly created constant verifier. 885 * Initialize a newly created constant verifier.
885 * 886 *
886 * @param errorReporter the error reporter by which errors will be reported 887 * @param errorReporter the error reporter by which errors will be reported
887 */ 888 */
888 ConstantVerifier(this._errorReporter, this._currentLibrary, 889 ConstantVerifier(this._errorReporter, LibraryElement currentLibrary,
889 this._typeProvider, this._typeSystem, this.declaredVariables) { 890 this._typeProvider, this.declaredVariables)
891 : _currentLibrary = currentLibrary,
892 _typeSystem = currentLibrary.context.typeSystem {
890 this._boolType = _typeProvider.boolType; 893 this._boolType = _typeProvider.boolType;
891 this._intType = _typeProvider.intType; 894 this._intType = _typeProvider.intType;
892 this._numType = _typeProvider.numType; 895 this._numType = _typeProvider.numType;
893 this._stringType = _typeProvider.stringType; 896 this._stringType = _typeProvider.stringType;
894 } 897 }
895 898
896 @override 899 @override
897 Object visitAnnotation(Annotation node) { 900 Object visitAnnotation(Annotation node) {
898 super.visitAnnotation(node); 901 super.visitAnnotation(node);
899 // check annotation creation 902 // check annotation creation
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 } 940 }
938 941
939 @override 942 @override
940 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 943 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
941 if (node.isConst) { 944 if (node.isConst) {
942 // We need to evaluate the constant to see if any errors occur during its 945 // We need to evaluate the constant to see if any errors occur during its
943 // evaluation. 946 // evaluation.
944 ConstructorElement constructor = node.staticElement; 947 ConstructorElement constructor = node.staticElement;
945 if (constructor != null) { 948 if (constructor != null) {
946 ConstantEvaluationEngine evaluationEngine = 949 ConstantEvaluationEngine evaluationEngine =
947 new ConstantEvaluationEngine( 950 new ConstantEvaluationEngine(_typeProvider, declaredVariables,
948 _typeProvider, _typeSystem, declaredVariables); 951 typeSystem: _typeSystem);
949 ConstantVisitor constantVisitor = 952 ConstantVisitor constantVisitor =
950 new ConstantVisitor(evaluationEngine, _errorReporter); 953 new ConstantVisitor(evaluationEngine, _errorReporter);
951 evaluationEngine.evaluateConstructorCall( 954 evaluationEngine.evaluateConstructorCall(
952 node, 955 node,
953 node.argumentList.arguments, 956 node.argumentList.arguments,
954 constructor, 957 constructor,
955 constantVisitor, 958 constantVisitor,
956 _errorReporter); 959 _errorReporter);
957 } 960 }
958 } 961 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 [type.displayName]); 1015 [type.displayName]);
1013 } 1016 }
1014 } 1017 }
1015 } else { 1018 } else {
1016 // Note: we throw the errors away because this isn't actually a const. 1019 // Note: we throw the errors away because this isn't actually a const.
1017 AnalysisErrorListener errorListener = 1020 AnalysisErrorListener errorListener =
1018 AnalysisErrorListener.NULL_LISTENER; 1021 AnalysisErrorListener.NULL_LISTENER;
1019 ErrorReporter subErrorReporter = 1022 ErrorReporter subErrorReporter =
1020 new ErrorReporter(errorListener, _errorReporter.source); 1023 new ErrorReporter(errorListener, _errorReporter.source);
1021 DartObjectImpl result = key.accept(new ConstantVisitor( 1024 DartObjectImpl result = key.accept(new ConstantVisitor(
1022 new ConstantEvaluationEngine( 1025 new ConstantEvaluationEngine(_typeProvider, declaredVariables,
1023 _typeProvider, _typeSystem, declaredVariables), 1026 typeSystem: _typeSystem),
1024 subErrorReporter)); 1027 subErrorReporter));
1025 if (result != null) { 1028 if (result != null) {
1026 if (keys.contains(result)) { 1029 if (keys.contains(result)) {
1027 invalidKeys.add(key); 1030 invalidKeys.add(key);
1028 } else { 1031 } else {
1029 keys.add(result); 1032 keys.add(result);
1030 } 1033 }
1031 } else { 1034 } else {
1032 reportEqualKeys = false; 1035 reportEqualKeys = false;
1033 } 1036 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 * 1222 *
1220 * @param expression the expression to be validated 1223 * @param expression the expression to be validated
1221 * @param errorCode the error code to be used if the expression is not a compi le time constant 1224 * @param errorCode the error code to be used if the expression is not a compi le time constant
1222 * @return the value of the compile time constant 1225 * @return the value of the compile time constant
1223 */ 1226 */
1224 DartObjectImpl _validate(Expression expression, ErrorCode errorCode) { 1227 DartObjectImpl _validate(Expression expression, ErrorCode errorCode) {
1225 RecordingErrorListener errorListener = new RecordingErrorListener(); 1228 RecordingErrorListener errorListener = new RecordingErrorListener();
1226 ErrorReporter subErrorReporter = 1229 ErrorReporter subErrorReporter =
1227 new ErrorReporter(errorListener, _errorReporter.source); 1230 new ErrorReporter(errorListener, _errorReporter.source);
1228 DartObjectImpl result = expression.accept(new ConstantVisitor( 1231 DartObjectImpl result = expression.accept(new ConstantVisitor(
1229 new ConstantEvaluationEngine( 1232 new ConstantEvaluationEngine(_typeProvider, declaredVariables,
1230 _typeProvider, _typeSystem, declaredVariables), 1233 typeSystem: _typeSystem),
1231 subErrorReporter)); 1234 subErrorReporter));
1232 _reportErrors(errorListener.errors, errorCode); 1235 _reportErrors(errorListener.errors, errorCode);
1233 return result; 1236 return result;
1234 } 1237 }
1235 1238
1236 /** 1239 /**
1237 * Validate that if the passed arguments are constant expressions. 1240 * Validate that if the passed arguments are constant expressions.
1238 * 1241 *
1239 * @param argumentList the argument list to evaluate 1242 * @param argumentList the argument list to evaluate
1240 */ 1243 */
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 in fieldDeclaration.fields.variables) { 1331 in fieldDeclaration.fields.variables) {
1329 Expression initializer = variableDeclaration.initializer; 1332 Expression initializer = variableDeclaration.initializer;
1330 if (initializer != null) { 1333 if (initializer != null) {
1331 // Ignore any errors produced during validation--if the constant 1334 // Ignore any errors produced during validation--if the constant
1332 // can't be eavluated we'll just report a single error. 1335 // can't be eavluated we'll just report a single error.
1333 AnalysisErrorListener errorListener = 1336 AnalysisErrorListener errorListener =
1334 AnalysisErrorListener.NULL_LISTENER; 1337 AnalysisErrorListener.NULL_LISTENER;
1335 ErrorReporter subErrorReporter = 1338 ErrorReporter subErrorReporter =
1336 new ErrorReporter(errorListener, _errorReporter.source); 1339 new ErrorReporter(errorListener, _errorReporter.source);
1337 DartObjectImpl result = initializer.accept(new ConstantVisitor( 1340 DartObjectImpl result = initializer.accept(new ConstantVisitor(
1338 new ConstantEvaluationEngine( 1341 new ConstantEvaluationEngine(_typeProvider, declaredVariables,
1339 _typeProvider, _typeSystem, declaredVariables), 1342 typeSystem: _typeSystem),
1340 subErrorReporter)); 1343 subErrorReporter));
1341 if (result == null) { 1344 if (result == null) {
1342 _errorReporter.reportErrorForNode( 1345 _errorReporter.reportErrorForNode(
1343 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE D_BY_NON_CONST, 1346 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZE D_BY_NON_CONST,
1344 errorSite, 1347 errorSite,
1345 [variableDeclaration.name.name]); 1348 [variableDeclaration.name.name]);
1346 } 1349 }
1347 } 1350 }
1348 } 1351 }
1349 } 1352 }
1350 } 1353 }
1351 } 1354 }
1352 } 1355 }
1353 1356
1354 /** 1357 /**
1355 * Validates that the given expression is a compile time constant. 1358 * Validates that the given expression is a compile time constant.
1356 * 1359 *
1357 * @param parameterElements the elements of parameters of constant constructor , they are 1360 * @param parameterElements the elements of parameters of constant constructor , they are
1358 * considered as a valid potentially constant expressions 1361 * considered as a valid potentially constant expressions
1359 * @param expression the expression to validate 1362 * @param expression the expression to validate
1360 */ 1363 */
1361 void _validateInitializerExpression( 1364 void _validateInitializerExpression(
1362 List<ParameterElement> parameterElements, Expression expression) { 1365 List<ParameterElement> parameterElements, Expression expression) {
1363 RecordingErrorListener errorListener = new RecordingErrorListener(); 1366 RecordingErrorListener errorListener = new RecordingErrorListener();
1364 ErrorReporter subErrorReporter = 1367 ErrorReporter subErrorReporter =
1365 new ErrorReporter(errorListener, _errorReporter.source); 1368 new ErrorReporter(errorListener, _errorReporter.source);
1366 DartObjectImpl result = expression.accept( 1369 DartObjectImpl result = expression.accept(
1367 new _ConstantVerifier_validateInitializerExpression( 1370 new _ConstantVerifier_validateInitializerExpression(_typeProvider,
1368 _typeProvider, 1371 subErrorReporter, this, parameterElements, declaredVariables,
1369 _typeSystem, 1372 typeSystem: _typeSystem));
1370 subErrorReporter,
1371 this,
1372 parameterElements,
1373 declaredVariables));
1374 _reportErrors(errorListener.errors, 1373 _reportErrors(errorListener.errors,
1375 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER); 1374 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER);
1376 if (result != null) { 1375 if (result != null) {
1377 _reportErrorIfFromDeferredLibrary(expression, 1376 _reportErrorIfFromDeferredLibrary(expression,
1378 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_L IBRARY); 1377 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_L IBRARY);
1379 } 1378 }
1380 } 1379 }
1381 1380
1382 /** 1381 /**
1383 * Validates that all of the arguments of a constructor initializer are compil e time constants. 1382 * Validates that all of the arguments of a constructor initializer are compil e time constants.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 /** 1496 /**
1498 * The type system for this visitor 1497 * The type system for this visitor
1499 */ 1498 */
1500 final TypeSystem _typeSystem; 1499 final TypeSystem _typeSystem;
1501 1500
1502 /** 1501 /**
1503 * Create a new instance of the [DeadCodeVerifier]. 1502 * Create a new instance of the [DeadCodeVerifier].
1504 * 1503 *
1505 * @param errorReporter the error reporter 1504 * @param errorReporter the error reporter
1506 */ 1505 */
1507 DeadCodeVerifier(this._errorReporter, this._typeSystem); 1506 DeadCodeVerifier(this._errorReporter, {TypeSystem typeSystem})
1507 : this._typeSystem =
1508 (typeSystem != null) ? typeSystem : new TypeSystemImpl();
1508 1509
1509 @override 1510 @override
1510 Object visitBinaryExpression(BinaryExpression node) { 1511 Object visitBinaryExpression(BinaryExpression node) {
1511 sc.Token operator = node.operator; 1512 sc.Token operator = node.operator;
1512 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND; 1513 bool isAmpAmp = operator.type == sc.TokenType.AMPERSAND_AMPERSAND;
1513 bool isBarBar = operator.type == sc.TokenType.BAR_BAR; 1514 bool isBarBar = operator.type == sc.TokenType.BAR_BAR;
1514 if (isAmpAmp || isBarBar) { 1515 if (isAmpAmp || isBarBar) {
1515 Expression lhsCondition = node.leftOperand; 1516 Expression lhsCondition = node.leftOperand;
1516 if (!_isDebugConstant(lhsCondition)) { 1517 if (!_isDebugConstant(lhsCondition)) {
1517 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition); 1518 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition);
(...skipping 3299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4817 } 4818 }
4818 _library.accept(new UnusedLocalElementsVerifier( 4819 _library.accept(new UnusedLocalElementsVerifier(
4819 _errorListener, _usedLocalElementsVisitor.usedElements)); 4820 _errorListener, _usedLocalElementsVisitor.usedElements));
4820 }); 4821 });
4821 } 4822 }
4822 4823
4823 void _generateForCompilationUnit(CompilationUnit unit, Source source) { 4824 void _generateForCompilationUnit(CompilationUnit unit, Source source) {
4824 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 4825 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
4825 unit.accept(_usedImportedElementsVisitor); 4826 unit.accept(_usedImportedElementsVisitor);
4826 // dead code analysis 4827 // dead code analysis
4827 unit.accept(new DeadCodeVerifier(errorReporter, _context.typeSystem)); 4828 unit.accept(
4829 new DeadCodeVerifier(errorReporter, typeSystem: _context.typeSystem));
4828 unit.accept(_usedLocalElementsVisitor); 4830 unit.accept(_usedLocalElementsVisitor);
4829 // dart2js analysis 4831 // dart2js analysis
4830 if (_enableDart2JSHints) { 4832 if (_enableDart2JSHints) {
4831 unit.accept(new Dart2JSVerifier(errorReporter)); 4833 unit.accept(new Dart2JSVerifier(errorReporter));
4832 } 4834 }
4833 // Dart best practices 4835 // Dart best practices
4834 unit.accept(new BestPracticesVerifier( 4836 unit.accept(new BestPracticesVerifier(errorReporter, _context.typeProvider,
4835 errorReporter, _context.typeProvider, _context.typeSystem)); 4837 typeSystem: _context.typeSystem));
4836 unit.accept(new OverrideVerifier(errorReporter, _manager)); 4838 unit.accept(new OverrideVerifier(errorReporter, _manager));
4837 // Find to-do comments 4839 // Find to-do comments
4838 new ToDoFinder(errorReporter).findIn(unit); 4840 new ToDoFinder(errorReporter).findIn(unit);
4839 // pub analysis 4841 // pub analysis
4840 // TODO(danrubel/jwren) Commented out until bugs in the pub verifier are 4842 // TODO(danrubel/jwren) Commented out until bugs in the pub verifier are
4841 // fixed 4843 // fixed
4842 // unit.accept(new PubVerifier(context, errorReporter)); 4844 // unit.accept(new PubVerifier(context, errorReporter));
4843 } 4845 }
4844 } 4846 }
4845 4847
(...skipping 3474 matching lines...) Expand 10 before | Expand all | Expand 10 after
8320 } 8322 }
8321 8323
8322 /** 8324 /**
8323 * Compute a value for all of the constants in the libraries being analyzed. 8325 * Compute a value for all of the constants in the libraries being analyzed.
8324 */ 8326 */
8325 void _performConstantEvaluation() { 8327 void _performConstantEvaluation() {
8326 PerformanceStatistics.resolve.makeCurrentWhile(() { 8328 PerformanceStatistics.resolve.makeCurrentWhile(() {
8327 ConstantValueComputer computer = new ConstantValueComputer( 8329 ConstantValueComputer computer = new ConstantValueComputer(
8328 analysisContext, 8330 analysisContext,
8329 _typeProvider, 8331 _typeProvider,
8330 _typeSystem, 8332 analysisContext.declaredVariables,
8331 analysisContext.declaredVariables); 8333 null,
8334 _typeSystem);
8332 for (Library library in _librariesInCycles) { 8335 for (Library library in _librariesInCycles) {
8333 for (Source source in library.compilationUnitSources) { 8336 for (Source source in library.compilationUnitSources) {
8334 try { 8337 try {
8335 CompilationUnit unit = library.getAST(source); 8338 CompilationUnit unit = library.getAST(source);
8336 if (unit != null) { 8339 if (unit != null) {
8337 computer.add(unit, source, library.librarySource); 8340 computer.add(unit, source, library.librarySource);
8338 } 8341 }
8339 } on AnalysisException catch (exception, stackTrace) { 8342 } on AnalysisException catch (exception, stackTrace) {
8340 AnalysisEngine.instance.logger.logError( 8343 AnalysisEngine.instance.logger.logError(
8341 "Internal Error: Could not access AST for ${source.fullName} dur ing constant evaluation", 8344 "Internal Error: Could not access AST for ${source.fullName} dur ing constant evaluation",
8342 new CaughtException(exception, stackTrace)); 8345 new CaughtException(exception, stackTrace));
8343 } 8346 }
8344 } 8347 }
8345 } 8348 }
8346 computer.computeValues(); 8349 computer.computeValues();
8347 // As a temporary workaround for issue 21572, run ConstantVerifier now. 8350 // As a temporary workaround for issue 21572, run ConstantVerifier now.
8348 // TODO(paulberry): remove this workaround once issue 21572 is fixed. 8351 // TODO(paulberry): remove this workaround once issue 21572 is fixed.
8349 for (Library library in _librariesInCycles) { 8352 for (Library library in _librariesInCycles) {
8350 for (Source source in library.compilationUnitSources) { 8353 for (Source source in library.compilationUnitSources) {
8351 try { 8354 try {
8352 CompilationUnit unit = library.getAST(source); 8355 CompilationUnit unit = library.getAST(source);
8353 ErrorReporter errorReporter = 8356 ErrorReporter errorReporter =
8354 new ErrorReporter(_errorListener, source); 8357 new ErrorReporter(_errorListener, source);
8355 ConstantVerifier constantVerifier = new ConstantVerifier( 8358 ConstantVerifier constantVerifier = new ConstantVerifier(
8356 errorReporter, 8359 errorReporter,
8357 library.libraryElement, 8360 library.libraryElement,
8358 _typeProvider, 8361 _typeProvider,
8359 _typeSystem,
8360 analysisContext.declaredVariables); 8362 analysisContext.declaredVariables);
8361 unit.accept(constantVerifier); 8363 unit.accept(constantVerifier);
8362 } on AnalysisException catch (exception, stackTrace) { 8364 } on AnalysisException catch (exception, stackTrace) {
8363 AnalysisEngine.instance.logger.logError( 8365 AnalysisEngine.instance.logger.logError(
8364 "Internal Error: Could not access AST for ${source.fullName} " 8366 "Internal Error: Could not access AST for ${source.fullName} "
8365 "during constant verification", 8367 "during constant verification",
8366 new CaughtException(exception, stackTrace)); 8368 new CaughtException(exception, stackTrace));
8367 } 8369 }
8368 } 8370 }
8369 } 8371 }
(...skipping 12 matching lines...) Expand all
8382 for (Source source in library.compilationUnitSources) { 8384 for (Source source in library.compilationUnitSources) {
8383 CompilationUnit ast = library.getAST(source); 8385 CompilationUnit ast = library.getAST(source);
8384 ast.accept(new VariableResolverVisitor(library.libraryElement, source, 8386 ast.accept(new VariableResolverVisitor(library.libraryElement, source,
8385 _typeProvider, library.errorListener, 8387 _typeProvider, library.errorListener,
8386 nameScope: library.libraryScope)); 8388 nameScope: library.libraryScope));
8387 ResolverVisitorFactory visitorFactory = 8389 ResolverVisitorFactory visitorFactory =
8388 analysisContext.resolverVisitorFactory; 8390 analysisContext.resolverVisitorFactory;
8389 ResolverVisitor visitor = visitorFactory != null 8391 ResolverVisitor visitor = visitorFactory != null
8390 ? visitorFactory(library, source, _typeProvider) 8392 ? visitorFactory(library, source, _typeProvider)
8391 : new ResolverVisitor(library.libraryElement, source, _typeProvider, 8393 : new ResolverVisitor(library.libraryElement, source, _typeProvider,
8392 _typeSystem, library.errorListener, 8394 library.errorListener,
8393 nameScope: library.libraryScope, 8395 nameScope: library.libraryScope,
8394 inheritanceManager: library.inheritanceManager); 8396 inheritanceManager: library.inheritanceManager);
8395 ast.accept(visitor); 8397 ast.accept(visitor);
8396 } 8398 }
8397 }); 8399 });
8398 } 8400 }
8399 8401
8400 /** 8402 /**
8401 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the 8403 * Return the result of resolving the URI of the given URI-based directive aga inst the URI of the
8402 * given library, or `null` if the URI is not valid. 8404 * given library, or `null` if the URI is not valid.
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
8825 } 8827 }
8826 8828
8827 /** 8829 /**
8828 * Compute a value for all of the constants in the libraries being analyzed. 8830 * Compute a value for all of the constants in the libraries being analyzed.
8829 */ 8831 */
8830 void _performConstantEvaluation() { 8832 void _performConstantEvaluation() {
8831 PerformanceStatistics.resolve.makeCurrentWhile(() { 8833 PerformanceStatistics.resolve.makeCurrentWhile(() {
8832 ConstantValueComputer computer = new ConstantValueComputer( 8834 ConstantValueComputer computer = new ConstantValueComputer(
8833 analysisContext, 8835 analysisContext,
8834 _typeProvider, 8836 _typeProvider,
8835 _typeSystem, 8837 analysisContext.declaredVariables,
8836 analysisContext.declaredVariables); 8838 null,
8839 _typeSystem);
8837 for (ResolvableLibrary library in _librariesInCycle) { 8840 for (ResolvableLibrary library in _librariesInCycle) {
8838 for (ResolvableCompilationUnit unit 8841 for (ResolvableCompilationUnit unit
8839 in library.resolvableCompilationUnits) { 8842 in library.resolvableCompilationUnits) {
8840 CompilationUnit ast = unit.compilationUnit; 8843 CompilationUnit ast = unit.compilationUnit;
8841 if (ast != null) { 8844 if (ast != null) {
8842 computer.add(ast, unit.source, library.librarySource); 8845 computer.add(ast, unit.source, library.librarySource);
8843 } 8846 }
8844 } 8847 }
8845 } 8848 }
8846 computer.computeValues(); 8849 computer.computeValues();
8847 // As a temporary workaround for issue 21572, run ConstantVerifier now. 8850 // As a temporary workaround for issue 21572, run ConstantVerifier now.
8848 // TODO(paulberry): remove this workaround once issue 21572 is fixed. 8851 // TODO(paulberry): remove this workaround once issue 21572 is fixed.
8849 for (ResolvableLibrary library in _librariesInCycle) { 8852 for (ResolvableLibrary library in _librariesInCycle) {
8850 for (ResolvableCompilationUnit unit 8853 for (ResolvableCompilationUnit unit
8851 in library.resolvableCompilationUnits) { 8854 in library.resolvableCompilationUnits) {
8852 CompilationUnit ast = unit.compilationUnit; 8855 CompilationUnit ast = unit.compilationUnit;
8853 ErrorReporter errorReporter = 8856 ErrorReporter errorReporter =
8854 new ErrorReporter(_errorListener, unit.source); 8857 new ErrorReporter(_errorListener, unit.source);
8855 ConstantVerifier constantVerifier = new ConstantVerifier( 8858 ConstantVerifier constantVerifier = new ConstantVerifier(
8856 errorReporter, 8859 errorReporter,
8857 library.libraryElement, 8860 library.libraryElement,
8858 _typeProvider, 8861 _typeProvider,
8859 _typeSystem,
8860 analysisContext.declaredVariables); 8862 analysisContext.declaredVariables);
8861 ast.accept(constantVerifier); 8863 ast.accept(constantVerifier);
8862 } 8864 }
8863 } 8865 }
8864 }); 8866 });
8865 } 8867 }
8866 8868
8867 /** 8869 /**
8868 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle. 8870 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
8869 * 8871 *
(...skipping 15 matching lines...) Expand all
8885 */ 8887 */
8886 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) { 8888 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) {
8887 PerformanceStatistics.resolve.makeCurrentWhile(() { 8889 PerformanceStatistics.resolve.makeCurrentWhile(() {
8888 for (ResolvableCompilationUnit unit 8890 for (ResolvableCompilationUnit unit
8889 in library.resolvableCompilationUnits) { 8891 in library.resolvableCompilationUnits) {
8890 Source source = unit.source; 8892 Source source = unit.source;
8891 CompilationUnit ast = unit.compilationUnit; 8893 CompilationUnit ast = unit.compilationUnit;
8892 ast.accept(new VariableResolverVisitor(library.libraryElement, source, 8894 ast.accept(new VariableResolverVisitor(library.libraryElement, source,
8893 _typeProvider, library.libraryScope.errorListener, 8895 _typeProvider, library.libraryScope.errorListener,
8894 nameScope: library.libraryScope)); 8896 nameScope: library.libraryScope));
8895 ResolverVisitor visitor = new ResolverVisitor( 8897 ResolverVisitor visitor = new ResolverVisitor(library.libraryElement,
8896 library.libraryElement, 8898 source, _typeProvider, library._libraryScope.errorListener,
8897 source,
8898 _typeProvider,
8899 _typeSystem,
8900 library._libraryScope.errorListener,
8901 nameScope: library._libraryScope, 8899 nameScope: library._libraryScope,
8902 inheritanceManager: library.inheritanceManager); 8900 inheritanceManager: library.inheritanceManager);
8903 ast.accept(visitor); 8901 ast.accept(visitor);
8904 } 8902 }
8905 }); 8903 });
8906 } 8904 }
8907 8905
8908 /** 8906 /**
8909 * Report that the async library could not be resolved in the given 8907 * Report that the async library could not be resolved in the given
8910 * [analysisContext] and throw an exception. [asyncLibrarySource] is the sour ce 8908 * [analysisContext] and throw an exception. [asyncLibrarySource] is the sour ce
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
9639 * listener that will be informed of any errors that are found during 9637 * listener that will be informed of any errors that are found during
9640 * resolution. The [nameScope] is the scope used to resolve identifiers in the 9638 * resolution. The [nameScope] is the scope used to resolve identifiers in the
9641 * node that will first be visited. If `null` or unspecified, a new 9639 * node that will first be visited. If `null` or unspecified, a new
9642 * [LibraryScope] will be created based on [definingLibrary] and 9640 * [LibraryScope] will be created based on [definingLibrary] and
9643 * [typeProvider]. The [inheritanceManager] is used to perform inheritance 9641 * [typeProvider]. The [inheritanceManager] is used to perform inheritance
9644 * lookups. If `null` or unspecified, a new [InheritanceManager] will be 9642 * lookups. If `null` or unspecified, a new [InheritanceManager] will be
9645 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to 9643 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to
9646 * create the type analyzer. If `null` or unspecified, a type analyzer of 9644 * create the type analyzer. If `null` or unspecified, a type analyzer of
9647 * type [StaticTypeAnalyzer] will be created. 9645 * type [StaticTypeAnalyzer] will be created.
9648 */ 9646 */
9649 PartialResolverVisitor( 9647 PartialResolverVisitor(LibraryElement definingLibrary, Source source,
9650 LibraryElement definingLibrary, 9648 TypeProvider typeProvider, AnalysisErrorListener errorListener,
9651 Source source,
9652 TypeProvider typeProvider,
9653 TypeSystem typeSystem,
9654 AnalysisErrorListener errorListener,
9655 {Scope nameScope, 9649 {Scope nameScope,
9656 InheritanceManager inheritanceManager, 9650 InheritanceManager inheritanceManager,
9657 StaticTypeAnalyzerFactory typeAnalyzerFactory}) 9651 StaticTypeAnalyzerFactory typeAnalyzerFactory})
9658 : strongMode = definingLibrary.context.analysisOptions.strongMode, 9652 : strongMode = definingLibrary.context.analysisOptions.strongMode,
9659 super(definingLibrary, source, typeProvider, typeSystem, 9653 super(definingLibrary, source, typeProvider,
9660 new DisablableErrorListener(errorListener)); 9654 new DisablableErrorListener(errorListener));
9661 9655
9662 @override 9656 @override
9663 Object visitBlockFunctionBody(BlockFunctionBody node) { 9657 Object visitBlockFunctionBody(BlockFunctionBody node) {
9664 if (_shouldBeSkipped(node)) { 9658 if (_shouldBeSkipped(node)) {
9665 return null; 9659 return null;
9666 } 9660 }
9667 return super.visitBlockFunctionBody(node); 9661 return super.visitBlockFunctionBody(node);
9668 } 9662 }
9669 9663
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
10281 /** 10275 /**
10282 * The object used to resolve the element associated with the current node. 10276 * The object used to resolve the element associated with the current node.
10283 */ 10277 */
10284 ElementResolver elementResolver; 10278 ElementResolver elementResolver;
10285 10279
10286 /** 10280 /**
10287 * The object used to compute the type associated with the current node. 10281 * The object used to compute the type associated with the current node.
10288 */ 10282 */
10289 StaticTypeAnalyzer typeAnalyzer; 10283 StaticTypeAnalyzer typeAnalyzer;
10290 10284
10285 /*
10286 * The type system in use during resolution.
10287 */
10288 TypeSystem typeSystem;
10289
10291 /** 10290 /**
10292 * The class element representing the class containing the current node, 10291 * The class element representing the class containing the current node,
10293 * or `null` if the current node is not contained in a class. 10292 * or `null` if the current node is not contained in a class.
10294 */ 10293 */
10295 ClassElement enclosingClass = null; 10294 ClassElement enclosingClass = null;
10296 10295
10297 /** 10296 /**
10298 * The class declaration representing the class containing the current node, o r `null` if 10297 * The class declaration representing the class containing the current node, o r `null` if
10299 * the current node is not contained in a class. 10298 * the current node is not contained in a class.
10300 */ 10299 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
10348 * listener that will be informed of any errors that are found during 10347 * listener that will be informed of any errors that are found during
10349 * resolution. The [nameScope] is the scope used to resolve identifiers in the 10348 * resolution. The [nameScope] is the scope used to resolve identifiers in the
10350 * node that will first be visited. If `null` or unspecified, a new 10349 * node that will first be visited. If `null` or unspecified, a new
10351 * [LibraryScope] will be created based on [definingLibrary] and 10350 * [LibraryScope] will be created based on [definingLibrary] and
10352 * [typeProvider]. The [inheritanceManager] is used to perform inheritance 10351 * [typeProvider]. The [inheritanceManager] is used to perform inheritance
10353 * lookups. If `null` or unspecified, a new [InheritanceManager] will be 10352 * lookups. If `null` or unspecified, a new [InheritanceManager] will be
10354 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to 10353 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to
10355 * create the type analyzer. If `null` or unspecified, a type analyzer of 10354 * create the type analyzer. If `null` or unspecified, a type analyzer of
10356 * type [StaticTypeAnalyzer] will be created. 10355 * type [StaticTypeAnalyzer] will be created.
10357 */ 10356 */
10358 ResolverVisitor( 10357 ResolverVisitor(LibraryElement definingLibrary, Source source,
10359 LibraryElement definingLibrary, 10358 TypeProvider typeProvider, AnalysisErrorListener errorListener,
10360 Source source,
10361 TypeProvider typeProvider,
10362 TypeSystem typeSystem,
10363 AnalysisErrorListener errorListener,
10364 {Scope nameScope, 10359 {Scope nameScope,
10365 InheritanceManager inheritanceManager, 10360 InheritanceManager inheritanceManager,
10366 StaticTypeAnalyzerFactory typeAnalyzerFactory}) 10361 StaticTypeAnalyzerFactory typeAnalyzerFactory})
10367 : super(definingLibrary, source, typeProvider, errorListener, 10362 : super(definingLibrary, source, typeProvider, errorListener,
10368 nameScope: nameScope) { 10363 nameScope: nameScope) {
10369 if (inheritanceManager == null) { 10364 if (inheritanceManager == null) {
10370 this._inheritanceManager = new InheritanceManager(definingLibrary); 10365 this._inheritanceManager = new InheritanceManager(definingLibrary);
10371 } else { 10366 } else {
10372 this._inheritanceManager = inheritanceManager; 10367 this._inheritanceManager = inheritanceManager;
10373 } 10368 }
10374 this.elementResolver = new ElementResolver(this); 10369 this.elementResolver = new ElementResolver(this);
10370 this.typeSystem = definingLibrary.context.typeSystem;
10375 if (typeAnalyzerFactory == null) { 10371 if (typeAnalyzerFactory == null) {
10376 this.typeAnalyzer = new StaticTypeAnalyzer(this, typeSystem); 10372 this.typeAnalyzer = new StaticTypeAnalyzer(this);
10377 } else { 10373 } else {
10378 this.typeAnalyzer = typeAnalyzerFactory(this); 10374 this.typeAnalyzer = typeAnalyzerFactory(this);
10379 } 10375 }
10380 } 10376 }
10381 10377
10382 /** 10378 /**
10383 * Initialize a newly created visitor to resolve the nodes in a compilation un it. 10379 * Initialize a newly created visitor to resolve the nodes in a compilation un it.
10384 * 10380 *
10385 * @param library the library containing the compilation unit being resolved 10381 * @param library the library containing the compilation unit being resolved
10386 * @param source the source representing the compilation unit being visited 10382 * @param source the source representing the compilation unit being visited
10387 * @param typeProvider the object used to access the types from the core libra ry 10383 * @param typeProvider the object used to access the types from the core libra ry
10388 * 10384 *
10389 * Deprecated. Please use unnamed constructor instead. 10385 * Deprecated. Please use unnamed constructor instead.
10390 */ 10386 */
10391 @deprecated 10387 @deprecated
10392 ResolverVisitor.con1(Library library, Source source, 10388 ResolverVisitor.con1(
10393 TypeProvider typeProvider, TypeSystem typeSystem, 10389 Library library, Source source, TypeProvider typeProvider,
10394 {StaticTypeAnalyzerFactory typeAnalyzerFactory}) 10390 {StaticTypeAnalyzerFactory typeAnalyzerFactory})
10395 : this(library.libraryElement, source, typeProvider, typeSystem, 10391 : this(
10396 library.errorListener, 10392 library.libraryElement, source, typeProvider, library.errorListener,
10397 nameScope: library.libraryScope, 10393 nameScope: library.libraryScope,
10398 inheritanceManager: library.inheritanceManager, 10394 inheritanceManager: library.inheritanceManager,
10399 typeAnalyzerFactory: typeAnalyzerFactory); 10395 typeAnalyzerFactory: typeAnalyzerFactory);
10400 10396
10401 /** 10397 /**
10402 * Return the element representing the function containing the current node, o r `null` if 10398 * Return the element representing the function containing the current node, o r `null` if
10403 * the current node is not contained in a function. 10399 * the current node is not contained in a function.
10404 * 10400 *
10405 * @return the element representing the function containing the current node 10401 * @return the element representing the function containing the current node
10406 */ 10402 */
(...skipping 5385 matching lines...) Expand 10 before | Expand all | Expand 10 after
15792 15788
15793 class _ConstantVerifier_validateInitializerExpression extends ConstantVisitor { 15789 class _ConstantVerifier_validateInitializerExpression extends ConstantVisitor {
15794 final ConstantVerifier verifier; 15790 final ConstantVerifier verifier;
15795 15791
15796 List<ParameterElement> parameterElements; 15792 List<ParameterElement> parameterElements;
15797 15793
15798 TypeSystem _typeSystem; 15794 TypeSystem _typeSystem;
15799 15795
15800 _ConstantVerifier_validateInitializerExpression( 15796 _ConstantVerifier_validateInitializerExpression(
15801 TypeProvider typeProvider, 15797 TypeProvider typeProvider,
15802 TypeSystem typeSystem,
15803 ErrorReporter errorReporter, 15798 ErrorReporter errorReporter,
15804 this.verifier, 15799 this.verifier,
15805 this.parameterElements, 15800 this.parameterElements,
15806 DeclaredVariables declaredVariables) 15801 DeclaredVariables declaredVariables,
15807 : _typeSystem = typeSystem, 15802 {TypeSystem typeSystem})
15803 : _typeSystem = (typeSystem != null) ? typeSystem : new TypeSystemImpl(),
15808 super( 15804 super(
15809 new ConstantEvaluationEngine( 15805 new ConstantEvaluationEngine(typeProvider, declaredVariables,
15810 typeProvider, typeSystem, declaredVariables), 15806 typeSystem: typeSystem),
15811 errorReporter); 15807 errorReporter);
15812 15808
15813 @override 15809 @override
15814 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { 15810 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) {
15815 Element element = node.staticElement; 15811 Element element = node.staticElement;
15816 for (ParameterElement parameterElement in parameterElements) { 15812 for (ParameterElement parameterElement in parameterElements) {
15817 if (identical(parameterElement, element) && parameterElement != null) { 15813 if (identical(parameterElement, element) && parameterElement != null) {
15818 DartType type = parameterElement.type; 15814 DartType type = parameterElement.type;
15819 if (type != null) { 15815 if (type != null) {
15820 if (type.isDynamic) { 15816 if (type.isDynamic) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
15959 nonFields.add(node); 15955 nonFields.add(node);
15960 return null; 15956 return null;
15961 } 15957 }
15962 15958
15963 @override 15959 @override
15964 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15960 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15965 15961
15966 @override 15962 @override
15967 Object visitWithClause(WithClause node) => null; 15963 Object visitWithClause(WithClause node) => null;
15968 } 15964 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_resolver.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