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

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

Issue 1037313002: Issue 23010. Compute constant and report related errors during incremental resolution. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.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) 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.incremental_resolver; 5 library engine.incremental_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/services/lint.dart'; 11 import 'package:analyzer/src/services/lint.dart';
11 12
12 import 'ast.dart'; 13 import 'ast.dart';
13 import 'element.dart'; 14 import 'element.dart';
14 import 'engine.dart'; 15 import 'engine.dart';
15 import 'error.dart'; 16 import 'error.dart';
16 import 'error_verifier.dart'; 17 import 'error_verifier.dart';
17 import 'incremental_logger.dart' show logger, LoggingTimer; 18 import 'incremental_logger.dart' show logger, LoggingTimer;
18 import 'java_engine.dart'; 19 import 'java_engine.dart';
19 import 'parser.dart'; 20 import 'parser.dart';
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 AstNode rootNode = _findResolutionRoot(node); 877 AstNode rootNode = _findResolutionRoot(node);
877 _prepareResolutionContext(rootNode); 878 _prepareResolutionContext(rootNode);
878 // update elements 879 // update elements
879 _updateElementNameOffsets(); 880 _updateElementNameOffsets();
880 _buildElements(rootNode); 881 _buildElements(rootNode);
881 if (!_canBeIncrementallyResolved(rootNode)) { 882 if (!_canBeIncrementallyResolved(rootNode)) {
882 return false; 883 return false;
883 } 884 }
884 // resolve 885 // resolve
885 _resolveReferences(rootNode); 886 _resolveReferences(rootNode);
887 _computeConstants(rootNode);
888 _resolveErrors = errorListener.getErrorsForSource(_source);
886 // verify 889 // verify
887 _verify(rootNode); 890 _verify(rootNode);
888 _context.invalidateLibraryHints(_librarySource); 891 _context.invalidateLibraryHints(_librarySource);
889 _generateLints(rootNode); 892 _generateLints(rootNode);
890 // update entry errors 893 // update entry errors
891 _updateEntry(); 894 _updateEntry();
892 // OK 895 // OK
893 return true; 896 return true;
894 } finally { 897 } finally {
895 logger.exit(); 898 logger.exit();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 bool _canBeResolved(AstNode node) => node is ClassDeclaration || 954 bool _canBeResolved(AstNode node) => node is ClassDeclaration ||
952 node is ClassTypeAlias || 955 node is ClassTypeAlias ||
953 node is CompilationUnit || 956 node is CompilationUnit ||
954 node is ConstructorDeclaration || 957 node is ConstructorDeclaration ||
955 node is FunctionDeclaration || 958 node is FunctionDeclaration ||
956 node is FunctionTypeAlias || 959 node is FunctionTypeAlias ||
957 node is MethodDeclaration || 960 node is MethodDeclaration ||
958 node is TopLevelVariableDeclaration; 961 node is TopLevelVariableDeclaration;
959 962
960 /** 963 /**
964 * Compute a value for all of the constants in the given [node].
965 */
966 void _computeConstants(AstNode node) {
967 // compute values
968 {
969 CompilationUnit unit = node.getAncestor((n) => n is CompilationUnit);
970 ConstantValueComputer computer =
971 new ConstantValueComputer(_typeProvider, _context.declaredVariables);
972 computer.add(unit);
973 computer.computeValues();
974 }
975 // validate
976 {
977 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
978 ConstantVerifier constantVerifier =
979 new ConstantVerifier(errorReporter, _definingLibrary, _typeProvider);
980 node.accept(constantVerifier);
981 }
982 }
983
984 /**
961 * Starting at [node], find the smallest AST node that can be resolved 985 * Starting at [node], find the smallest AST node that can be resolved
962 * independently of any other nodes. Return the node that was found. 986 * independently of any other nodes. Return the node that was found.
963 * 987 *
964 * [node] - the node at which the search is to begin 988 * [node] - the node at which the search is to begin
965 * 989 *
966 * Throws [AnalysisException] if there is no such node. 990 * Throws [AnalysisException] if there is no such node.
967 */ 991 */
968 AstNode _findResolutionRoot(AstNode node) { 992 AstNode _findResolutionRoot(AstNode node) {
969 while (node != null) { 993 while (node != null) {
970 if (_canBeResolved(node)) { 994 if (_canBeResolved(node)) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 visitor.visitClassDeclarationIncrementally( 1058 visitor.visitClassDeclarationIncrementally(
1035 _resolutionContext.enclosingClassDeclaration); 1059 _resolutionContext.enclosingClassDeclaration);
1036 } 1060 }
1037 if (node is Comment) { 1061 if (node is Comment) {
1038 visitor.resolveOnlyCommentInFunctionBody = true; 1062 visitor.resolveOnlyCommentInFunctionBody = true;
1039 node = node.parent; 1063 node = node.parent;
1040 } 1064 }
1041 visitor.initForIncrementalResolution(); 1065 visitor.initForIncrementalResolution();
1042 node.accept(visitor); 1066 node.accept(visitor);
1043 } 1067 }
1044 // remember errors
1045 _resolveErrors = errorListener.getErrorsForSource(_source);
1046 } finally { 1068 } finally {
1047 timer.stop('resolve references'); 1069 timer.stop('resolve references');
1048 } 1070 }
1049 } 1071 }
1050 1072
1051 void _shiftEntryErrors() { 1073 void _shiftEntryErrors() {
1052 _shiftErrors(DartEntry.RESOLUTION_ERRORS); 1074 _shiftErrors(DartEntry.RESOLUTION_ERRORS);
1053 _shiftErrors(DartEntry.VERIFICATION_ERRORS); 1075 _shiftErrors(DartEntry.VERIFICATION_ERRORS);
1054 _shiftErrors(DartEntry.HINTS); 1076 _shiftErrors(DartEntry.HINTS);
1055 _shiftErrors(DartEntry.LINTS); 1077 _shiftErrors(DartEntry.LINTS);
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 @override 1838 @override
1817 String toString() => name; 1839 String toString() => name;
1818 } 1840 }
1819 1841
1820 class _TokenPair { 1842 class _TokenPair {
1821 final _TokenDifferenceKind kind; 1843 final _TokenDifferenceKind kind;
1822 final Token oldToken; 1844 final Token oldToken;
1823 final Token newToken; 1845 final Token newToken;
1824 _TokenPair(this.kind, this.oldToken, this.newToken); 1846 _TokenPair(this.kind, this.oldToken, this.newToken);
1825 } 1847 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698