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

Unified Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 834383005: Don't perform incremental resolution if curly brackets are not balanced. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/generated/incremental_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/incremental_resolver.dart b/pkg/analyzer/lib/src/generated/incremental_resolver.dart
index 2088c516164db58fa2af547947c8d47e8b549b8b..710c0ef58d38496f76c23811c066e8fe1db3d7fa 100644
--- a/pkg/analyzer/lib/src/generated/incremental_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/incremental_resolver.dart
@@ -1261,9 +1261,20 @@ class PoorMansIncrementalResolver {
bool resolve(String newCode) {
logger.enter('diff/resolve $_unitSource');
try {
+ // prepare old unit
CompilationUnit oldUnit = _units[_unitSource];
+ if (!_areCurlyBracketsBalanced(oldUnit.beginToken)) {
+ logger.log('Unbalanced number of curly brackets in the old unit.');
+ return false;
+ }
_unitElement = oldUnit.element;
+ // prepare ne unit
Brian Wilkerson 2015/01/20 19:08:27 'ne' --> 'new'
CompilationUnit newUnit = _parseUnit(newCode);
+ if (!_areCurlyBracketsBalanced(newUnit.beginToken)) {
+ logger.log('Unbalanced number of curly brackets in the new unit.');
+ return false;
+ }
+ // find difference
_TokenPair firstPair =
_findFirstDifferentToken(oldUnit.beginToken, newUnit.beginToken);
_TokenPair lastPair =
@@ -1485,6 +1496,17 @@ class PoorMansIncrementalResolver {
_entry.setValue(DartEntry.PARSE_ERRORS, _newParseErrors);
}
+ /**
+ * Checks if [token] has a balanced number of open and closed curly brackets.
+ */
+ static bool _areCurlyBracketsBalanced(Token token) {
Brian Wilkerson 2015/01/20 19:08:27 Not for this CL, but... The scanner already comput
+ int numOpen = _getTokenCount(token, TokenType.OPEN_CURLY_BRACKET);
+ int numOpen2 =
+ _getTokenCount(token, TokenType.STRING_INTERPOLATION_EXPRESSION);
+ int numClosed = _getTokenCount(token, TokenType.CLOSE_CURLY_BRACKET);
+ return numOpen + numOpen2 == numClosed;
+ }
+
static _TokenDifferenceKind _compareToken(Token oldToken, Token newToken,
int delta) {
if (oldToken == null && newToken == null) {
@@ -1580,7 +1602,6 @@ class PoorMansIncrementalResolver {
return oldBeginToken;
}
-
static List<AstNode> _getParents(AstNode node) {
List<AstNode> parents = <AstNode>[];
while (node != null) {
@@ -1590,6 +1611,21 @@ class PoorMansIncrementalResolver {
return parents;
}
+
+ /**
+ * Returns number of tokens with the given [type].
+ */
+ static int _getTokenCount(Token token, TokenType type) {
+ int count = 0;
+ while (token.type != TokenType.EOF) {
+ if (token.type == type) {
+ count++;
+ }
+ token = token.next;
+ }
+ return count;
+ }
+
/**
* Set the given [comment] as a "precedingComments" for [parent].
*/

Powered by Google App Engine
This is Rietveld 408576698