Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 'ast.dart'; | 10 import 'ast.dart'; |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 final int _updateEndNew; | 790 final int _updateEndNew; |
| 791 | 791 |
| 792 int _updateDelta; | 792 int _updateDelta; |
| 793 | 793 |
| 794 RecordingErrorListener errorListener = new RecordingErrorListener(); | 794 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 795 ResolutionContext _resolutionContext; | 795 ResolutionContext _resolutionContext; |
| 796 | 796 |
| 797 List<AnalysisError> _resolveErrors = AnalysisError.NO_ERRORS; | 797 List<AnalysisError> _resolveErrors = AnalysisError.NO_ERRORS; |
| 798 List<AnalysisError> _verifyErrors = AnalysisError.NO_ERRORS; | 798 List<AnalysisError> _verifyErrors = AnalysisError.NO_ERRORS; |
| 799 List<AnalysisError> _hints = AnalysisError.NO_ERRORS; | 799 List<AnalysisError> _hints = AnalysisError.NO_ERRORS; |
| 800 List<AnalysisError> _lints = AnalysisError.NO_ERRORS; | |
| 800 | 801 |
| 801 /** | 802 /** |
| 802 * The elements that should be resolved because of API changes. | 803 * The elements that should be resolved because of API changes. |
| 803 */ | 804 */ |
| 804 HashSet<Element> _resolutionQueue = new HashSet<Element>(); | 805 HashSet<Element> _resolutionQueue = new HashSet<Element>(); |
| 805 | 806 |
| 806 /** | 807 /** |
| 807 * Initialize a newly created incremental resolver to resolve a node in the | 808 * Initialize a newly created incremental resolver to resolve a node in the |
| 808 * given source in the given library. | 809 * given source in the given library. |
| 809 */ | 810 */ |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 833 _updateElementNameOffsets(); | 834 _updateElementNameOffsets(); |
| 834 _buildElements(rootNode); | 835 _buildElements(rootNode); |
| 835 if (!_canBeIncrementallyResolved(rootNode)) { | 836 if (!_canBeIncrementallyResolved(rootNode)) { |
| 836 return false; | 837 return false; |
| 837 } | 838 } |
| 838 // resolve | 839 // resolve |
| 839 _resolveReferences(rootNode); | 840 _resolveReferences(rootNode); |
| 840 // verify | 841 // verify |
| 841 _verify(rootNode); | 842 _verify(rootNode); |
| 842 _generateHints(rootNode); | 843 _generateHints(rootNode); |
| 844 _generateLints(rootNode); | |
| 843 // update entry errors | 845 // update entry errors |
| 844 _updateEntry(); | 846 _updateEntry(); |
| 845 // resolve queue in response of API changes | 847 // resolve queue in response of API changes |
| 846 _resolveQueue(); | 848 _resolveQueue(); |
| 847 // OK | 849 // OK |
| 848 return true; | 850 return true; |
| 849 } finally { | 851 } finally { |
| 850 logger.exit(); | 852 logger.exit(); |
| 851 } | 853 } |
| 852 } | 854 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 AnalysisContext analysisContext = _definingLibrary.context; | 962 AnalysisContext analysisContext = _definingLibrary.context; |
| 961 HintGenerator hintGenerator = | 963 HintGenerator hintGenerator = |
| 962 new HintGenerator(<CompilationUnit>[unit], analysisContext, errorListe ner); | 964 new HintGenerator(<CompilationUnit>[unit], analysisContext, errorListe ner); |
| 963 hintGenerator.generateForLibrary(); | 965 hintGenerator.generateForLibrary(); |
| 964 _hints = errorListener.getErrorsForSource(_source); | 966 _hints = errorListener.getErrorsForSource(_source); |
| 965 } finally { | 967 } finally { |
| 966 timer.stop('generate hints'); | 968 timer.stop('generate hints'); |
| 967 } | 969 } |
| 968 } | 970 } |
| 969 | 971 |
| 972 void _generateLints(AstNode node) { | |
| 973 LoggingTimer timer = logger.startTimer(); | |
| 974 try { | |
| 975 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 976 CompilationUnit unit = node.getAncestor((n) => n is CompilationUnit); | |
| 977 LintGenerator lintGenerator = | |
| 978 new LintGenerator(<CompilationUnit>[unit], errorListener); | |
| 979 lintGenerator.generate(); | |
| 980 _lints = errorListener.getErrorsForSource(_source); | |
| 981 } finally { | |
| 982 timer.stop('generate hints'); | |
|
danrubel
2015/01/07 20:17:57
hint -> lint
pquitslund
2015/01/08 00:29:52
Done.
| |
| 983 } | |
| 984 } | |
| 985 | |
| 970 /** | 986 /** |
| 971 * Return the element defined by [node], or `null` if the node does not | 987 * Return the element defined by [node], or `null` if the node does not |
| 972 * define an element. | 988 * define an element. |
| 973 */ | 989 */ |
| 974 Element _getElement(AstNode node) { | 990 Element _getElement(AstNode node) { |
| 975 if (node is Declaration) { | 991 if (node is Declaration) { |
| 976 return node.element; | 992 return node.element; |
| 977 } else if (node is CompilationUnit) { | 993 } else if (node is CompilationUnit) { |
| 978 return node.element; | 994 return node.element; |
| 979 } | 995 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1002 logger.enter('resolve $element'); | 1018 logger.enter('resolve $element'); |
| 1003 try { | 1019 try { |
| 1004 AstNode node = element.node; | 1020 AstNode node = element.node; |
| 1005 CompilationUnitElement unit = | 1021 CompilationUnitElement unit = |
| 1006 element.getAncestor((e) => e is CompilationUnitElement); | 1022 element.getAncestor((e) => e is CompilationUnitElement); |
| 1007 IncrementalResolver resolver = | 1023 IncrementalResolver resolver = |
| 1008 new IncrementalResolver(unit, node.offset, node.end, node.end); | 1024 new IncrementalResolver(unit, node.offset, node.end, node.end); |
| 1009 resolver._resolveReferences(node); | 1025 resolver._resolveReferences(node); |
| 1010 resolver._verify(node); | 1026 resolver._verify(node); |
| 1011 resolver._generateHints(node); | 1027 resolver._generateHints(node); |
| 1028 resolver._generateLints(node); | |
| 1012 resolver._updateEntry(); | 1029 resolver._updateEntry(); |
| 1013 } finally { | 1030 } finally { |
| 1014 logger.exit(); | 1031 logger.exit(); |
| 1015 } | 1032 } |
| 1016 } | 1033 } |
| 1017 } | 1034 } |
| 1018 | 1035 |
| 1019 _resolveReferences(AstNode node) { | 1036 _resolveReferences(AstNode node) { |
| 1020 LoggingTimer timer = logger.startTimer(); | 1037 LoggingTimer timer = logger.startTimer(); |
| 1021 try { | 1038 try { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 _resolveErrors = errorListener.getErrorsForSource(_source); | 1081 _resolveErrors = errorListener.getErrorsForSource(_source); |
| 1065 } finally { | 1082 } finally { |
| 1066 timer.stop('resolve references'); | 1083 timer.stop('resolve references'); |
| 1067 } | 1084 } |
| 1068 } | 1085 } |
| 1069 | 1086 |
| 1070 void _shiftEntryErrors() { | 1087 void _shiftEntryErrors() { |
| 1071 _shiftErrors(DartEntry.RESOLUTION_ERRORS); | 1088 _shiftErrors(DartEntry.RESOLUTION_ERRORS); |
| 1072 _shiftErrors(DartEntry.VERIFICATION_ERRORS); | 1089 _shiftErrors(DartEntry.VERIFICATION_ERRORS); |
| 1073 _shiftErrors(DartEntry.HINTS); | 1090 _shiftErrors(DartEntry.HINTS); |
| 1091 _shiftErrors(DartEntry.LINTS); | |
| 1074 } | 1092 } |
| 1075 | 1093 |
| 1076 void _shiftErrors(DataDescriptor<List<AnalysisError>> descriptor) { | 1094 void _shiftErrors(DataDescriptor<List<AnalysisError>> descriptor) { |
| 1077 Source librarySource = _definingLibrary.source; | 1095 Source librarySource = _definingLibrary.source; |
| 1078 List<AnalysisError> errors = | 1096 List<AnalysisError> errors = |
| 1079 entry.getValueInLibrary(descriptor, librarySource); | 1097 entry.getValueInLibrary(descriptor, librarySource); |
| 1080 for (AnalysisError error in errors) { | 1098 for (AnalysisError error in errors) { |
| 1081 int errorOffset = error.offset; | 1099 int errorOffset = error.offset; |
| 1082 if (errorOffset > _updateOffset) { | 1100 if (errorOffset > _updateOffset) { |
| 1083 error.offset += _updateDelta; | 1101 error.offset += _updateDelta; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1109 { | 1127 { |
| 1110 List<AnalysisError> oldErrors = | 1128 List<AnalysisError> oldErrors = |
| 1111 entry.getValueInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource); | 1129 entry.getValueInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource); |
| 1112 List<AnalysisError> errors = _updateErrors(oldErrors, _verifyErrors); | 1130 List<AnalysisError> errors = _updateErrors(oldErrors, _verifyErrors); |
| 1113 entry.setValueInLibrary( | 1131 entry.setValueInLibrary( |
| 1114 DartEntry.VERIFICATION_ERRORS, | 1132 DartEntry.VERIFICATION_ERRORS, |
| 1115 librarySource, | 1133 librarySource, |
| 1116 errors); | 1134 errors); |
| 1117 } | 1135 } |
| 1118 entry.setValueInLibrary(DartEntry.HINTS, librarySource, _hints); | 1136 entry.setValueInLibrary(DartEntry.HINTS, librarySource, _hints); |
| 1137 entry.setValueInLibrary(DartEntry.LINTS, librarySource, _lints); | |
| 1119 } | 1138 } |
| 1120 | 1139 |
| 1121 List<AnalysisError> _updateErrors(List<AnalysisError> oldErrors, | 1140 List<AnalysisError> _updateErrors(List<AnalysisError> oldErrors, |
| 1122 List<AnalysisError> newErrors) { | 1141 List<AnalysisError> newErrors) { |
| 1123 List<AnalysisError> errors = new List<AnalysisError>(); | 1142 List<AnalysisError> errors = new List<AnalysisError>(); |
| 1124 // add updated old errors | 1143 // add updated old errors |
| 1125 for (AnalysisError error in oldErrors) { | 1144 for (AnalysisError error in oldErrors) { |
| 1126 int errorOffset = error.offset; | 1145 int errorOffset = error.offset; |
| 1127 if (errorOffset < _updateOffset) { | 1146 if (errorOffset < _updateOffset) { |
| 1128 errors.add(error); | 1147 errors.add(error); |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1807 String toString() => name; | 1826 String toString() => name; |
| 1808 } | 1827 } |
| 1809 | 1828 |
| 1810 | 1829 |
| 1811 class _TokenPair { | 1830 class _TokenPair { |
| 1812 final _TokenDifferenceKind kind; | 1831 final _TokenDifferenceKind kind; |
| 1813 final Token oldToken; | 1832 final Token oldToken; |
| 1814 final Token newToken; | 1833 final Token newToken; |
| 1815 _TokenPair(this.kind, this.oldToken, this.newToken); | 1834 _TokenPair(this.kind, this.oldToken, this.newToken); |
| 1816 } | 1835 } |
| OLD | NEW |