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

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

Issue 967703002: Avoid unnecessary parsing/resolution when running command line analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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/parser.dart
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index ca76b3a5ae3c809c6b6568630098dbed39c72dde..a54658d8d1c75f4b362690345d770b1c46916fe9 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -11,7 +11,8 @@ import "dart:math" as math;
import 'dart:collection';
import 'ast.dart';
-import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl;
+import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl,
+ AnalyzeFunctionBodiesPredicate;
Brian Wilkerson 2015/02/27 23:52:05 Other than the change to this import and some sort
Paul Berry 2015/03/02 19:09:46 My apologies--this was a mistake. I'll upload a n
import 'error.dart';
import 'java_core.dart';
import 'java_engine.dart';
@@ -1112,6 +1113,12 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
}
@override
+ AstNode visitFormalParameterList(FormalParameterList node) {
+ // We don't know which kind of parameter to parse.
+ throw new InsufficientContextException();
+ }
+
+ @override
AstNode visitForStatement(ForStatement node) {
if (identical(_oldNode, node.variables)) {
throw new InsufficientContextException();
@@ -1128,12 +1135,6 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
}
@override
- AstNode visitFormalParameterList(FormalParameterList node) {
- // We don't know which kind of parameter to parse.
- throw new InsufficientContextException();
- }
-
- @override
AstNode visitFunctionDeclaration(FunctionDeclaration node) {
if (identical(_oldNode, node.documentationComment)) {
throw new InsufficientContextException();
@@ -1482,14 +1483,6 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
}
@override
- AstNode visitPrefixExpression(PrefixExpression node) {
- if (identical(_oldNode, node.operand)) {
- throw new InsufficientContextException();
- }
- return _notAChild(node);
- }
-
- @override
AstNode visitPrefixedIdentifier(PrefixedIdentifier node) {
if (identical(_oldNode, node.prefix)) {
return _parser.parseSimpleIdentifier();
@@ -1500,6 +1493,14 @@ class IncrementalParseDispatcher implements AstVisitor<AstNode> {
}
@override
+ AstNode visitPrefixExpression(PrefixExpression node) {
+ if (identical(_oldNode, node.operand)) {
+ throw new InsufficientContextException();
+ }
+ return _notAChild(node);
+ }
+
+ @override
AstNode visitPropertyAccess(PropertyAccess node) {
if (identical(_oldNode, node.target)) {
throw new InsufficientContextException();
@@ -1825,100 +1826,6 @@ class IncrementalParseException extends RuntimeException {
}
/**
- * Visitor capable of inferring the correct parser state for incremental
- * parsing. This visitor visits each parent/child relationship in the chain of
- * ancestors of the node to be replaced (starting with the root of the parse
- * tree), updating the parser to the correct state for parsing the child of the
- * given parent. Once it has visited all of these relationships, the parser
- * will be in the correct state for reparsing the node to be replaced.
- *
- * TODO(paulberry): add support for other pieces of parser state (_inAsync,
- * _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch only
- * affect error message generation.
- */
-class IncrementalParseStateBuilder extends SimpleAstVisitor {
- /**
- * The parser whose state should be built.
- */
- final Parser _parser;
-
- /**
- * The child node in the parent/child relationship currently being visited.
- * (The corresponding parent is the node passed to the visit...() function.)
- */
- AstNode _childNode;
-
- /**
- * Create an IncrementalParseStateBuilder which will build the correct state
- * for [_parser].
- */
- IncrementalParseStateBuilder(this._parser);
-
- /**
- * Build the correct parser state for parsing a replacement for [node].
- */
- void buildState(AstNode node) {
- List<AstNode> ancestors = <AstNode>[];
- while (node != null) {
- ancestors.add(node);
- node = node.parent;
- }
- _parser._inInitializer = false;
- for (int i = ancestors.length - 2; i >= 0; i--) {
- _childNode = ancestors[i];
- ancestors[i + 1].accept(this);
- }
- }
-
- @override
- void visitArgumentList(ArgumentList node) {
- _parser._inInitializer = false;
- }
-
- @override
- void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
- if (identical(_childNode, node.expression)) {
- _parser._inInitializer = true;
- }
- }
-
- @override
- void visitIndexExpression(IndexExpression node) {
- if (identical(_childNode, node.index)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitInterpolationExpression(InterpolationExpression node) {
- if (identical(_childNode, node.expression)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitListLiteral(ListLiteral node) {
- if (node.elements.contains(_childNode)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitMapLiteral(MapLiteral node) {
- if (node.entries.contains(_childNode)) {
- _parser._inInitializer = false;
- }
- }
-
- @override
- void visitParenthesizedExpression(ParenthesizedExpression node) {
- if (identical(_childNode, node.expression)) {
- _parser._inInitializer = false;
- }
- }
-}
-
-/**
* Instances of the class `IncrementalParser` re-parse a single AST structure within a larger
* AST structure.
*/
@@ -2096,6 +2003,100 @@ class IncrementalParser {
}
/**
+ * Visitor capable of inferring the correct parser state for incremental
+ * parsing. This visitor visits each parent/child relationship in the chain of
+ * ancestors of the node to be replaced (starting with the root of the parse
+ * tree), updating the parser to the correct state for parsing the child of the
+ * given parent. Once it has visited all of these relationships, the parser
+ * will be in the correct state for reparsing the node to be replaced.
+ *
+ * TODO(paulberry): add support for other pieces of parser state (_inAsync,
+ * _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch only
+ * affect error message generation.
+ */
+class IncrementalParseStateBuilder extends SimpleAstVisitor {
+ /**
+ * The parser whose state should be built.
+ */
+ final Parser _parser;
+
+ /**
+ * The child node in the parent/child relationship currently being visited.
+ * (The corresponding parent is the node passed to the visit...() function.)
+ */
+ AstNode _childNode;
+
+ /**
+ * Create an IncrementalParseStateBuilder which will build the correct state
+ * for [_parser].
+ */
+ IncrementalParseStateBuilder(this._parser);
+
+ /**
+ * Build the correct parser state for parsing a replacement for [node].
+ */
+ void buildState(AstNode node) {
+ List<AstNode> ancestors = <AstNode>[];
+ while (node != null) {
+ ancestors.add(node);
+ node = node.parent;
+ }
+ _parser._inInitializer = false;
+ for (int i = ancestors.length - 2; i >= 0; i--) {
+ _childNode = ancestors[i];
+ ancestors[i + 1].accept(this);
+ }
+ }
+
+ @override
+ void visitArgumentList(ArgumentList node) {
+ _parser._inInitializer = false;
+ }
+
+ @override
+ void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
+ if (identical(_childNode, node.expression)) {
+ _parser._inInitializer = true;
+ }
+ }
+
+ @override
+ void visitIndexExpression(IndexExpression node) {
+ if (identical(_childNode, node.index)) {
+ _parser._inInitializer = false;
+ }
+ }
+
+ @override
+ void visitInterpolationExpression(InterpolationExpression node) {
+ if (identical(_childNode, node.expression)) {
+ _parser._inInitializer = false;
+ }
+ }
+
+ @override
+ void visitListLiteral(ListLiteral node) {
+ if (node.elements.contains(_childNode)) {
+ _parser._inInitializer = false;
+ }
+ }
+
+ @override
+ void visitMapLiteral(MapLiteral node) {
+ if (node.entries.contains(_childNode)) {
+ _parser._inInitializer = false;
+ }
+ }
+
+ @override
+ void visitParenthesizedExpression(ParenthesizedExpression node) {
+ if (identical(_childNode, node.expression)) {
+ _parser._inInitializer = false;
+ }
+ }
+}
+
+/**
* Instances of the class `InsufficientContextException` represent a situation in which an AST
* node cannot be re-parsed because there is not enough context to know how to re-parse the node.
* Clients can attempt to re-parse the parent of the node.
@@ -6006,40 +6007,6 @@ class Parser {
}
/**
- * Parse a do statement.
- *
- * <pre>
- * doStatement ::=
- * 'do' statement 'while' '(' expression ')' ';'
- * </pre>
- *
- * @return the do statement that was parsed
- */
- Statement _parseDoStatement() {
- bool wasInLoop = _inLoop;
- _inLoop = true;
- try {
- Token doKeyword = _expectKeyword(Keyword.DO);
- Statement body = parseStatement2();
- Token whileKeyword = _expectKeyword(Keyword.WHILE);
- Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
- Expression condition = parseExpression2();
- Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
- Token semicolon = _expect(TokenType.SEMICOLON);
- return new DoStatement(
- doKeyword,
- body,
- whileKeyword,
- leftParenthesis,
- condition,
- rightParenthesis,
- semicolon);
- } finally {
- _inLoop = wasInLoop;
- }
- }
-
- /**
* Parse a documentation comment.
*
* <pre>
@@ -6081,6 +6048,40 @@ class Parser {
}
/**
+ * Parse a do statement.
+ *
+ * <pre>
+ * doStatement ::=
+ * 'do' statement 'while' '(' expression ')' ';'
+ * </pre>
+ *
+ * @return the do statement that was parsed
+ */
+ Statement _parseDoStatement() {
+ bool wasInLoop = _inLoop;
+ _inLoop = true;
+ try {
+ Token doKeyword = _expectKeyword(Keyword.DO);
+ Statement body = parseStatement2();
+ Token whileKeyword = _expectKeyword(Keyword.WHILE);
+ Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
+ Expression condition = parseExpression2();
+ Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
+ Token semicolon = _expect(TokenType.SEMICOLON);
+ return new DoStatement(
+ doKeyword,
+ body,
+ whileKeyword,
+ leftParenthesis,
+ condition,
+ rightParenthesis,
+ semicolon);
+ } finally {
+ _inLoop = wasInLoop;
+ }
+ }
+
+ /**
* Parse an empty statement.
*
* <pre>
@@ -6277,6 +6278,64 @@ class Parser {
}
/**
+ * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
+ * `true`.
+ *
+ * <pre>
+ * defaultFormalParameter ::=
+ * normalFormalParameter ('=' expression)?
+ *
+ * defaultNamedParameter ::=
+ * normalFormalParameter (':' expression)?
+ * </pre>
+ *
+ * @param kind the kind of parameter being expected based on the presence or absence of group
+ * delimiters
+ * @return the formal parameter that was parsed
+ */
+ FormalParameter _parseFormalParameter(ParameterKind kind) {
+ NormalFormalParameter parameter = parseNormalFormalParameter();
+ if (_matches(TokenType.EQ)) {
+ Token seperator = getAndAdvance();
+ Expression defaultValue = parseExpression2();
+ if (kind == ParameterKind.NAMED) {
+ _reportErrorForToken(
+ ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER,
+ seperator);
+ } else if (kind == ParameterKind.REQUIRED) {
+ _reportErrorForNode(
+ ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP,
+ parameter);
+ }
+ return new DefaultFormalParameter(
+ parameter,
+ kind,
+ seperator,
+ defaultValue);
+ } else if (_matches(TokenType.COLON)) {
+ Token seperator = getAndAdvance();
+ Expression defaultValue = parseExpression2();
+ if (kind == ParameterKind.POSITIONAL) {
+ _reportErrorForToken(
+ ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER,
+ seperator);
+ } else if (kind == ParameterKind.REQUIRED) {
+ _reportErrorForNode(
+ ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP,
+ parameter);
+ }
+ return new DefaultFormalParameter(
+ parameter,
+ kind,
+ seperator,
+ defaultValue);
+ } else if (kind != ParameterKind.REQUIRED) {
+ return new DefaultFormalParameter(parameter, kind, null, null);
+ }
+ return parameter;
+ }
+
+ /**
* Parse a for statement.
*
* <pre>
@@ -6428,64 +6487,6 @@ class Parser {
}
/**
- * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
- * `true`.
- *
- * <pre>
- * defaultFormalParameter ::=
- * normalFormalParameter ('=' expression)?
- *
- * defaultNamedParameter ::=
- * normalFormalParameter (':' expression)?
- * </pre>
- *
- * @param kind the kind of parameter being expected based on the presence or absence of group
- * delimiters
- * @return the formal parameter that was parsed
- */
- FormalParameter _parseFormalParameter(ParameterKind kind) {
- NormalFormalParameter parameter = parseNormalFormalParameter();
- if (_matches(TokenType.EQ)) {
- Token seperator = getAndAdvance();
- Expression defaultValue = parseExpression2();
- if (kind == ParameterKind.NAMED) {
- _reportErrorForToken(
- ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER,
- seperator);
- } else if (kind == ParameterKind.REQUIRED) {
- _reportErrorForNode(
- ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP,
- parameter);
- }
- return new DefaultFormalParameter(
- parameter,
- kind,
- seperator,
- defaultValue);
- } else if (_matches(TokenType.COLON)) {
- Token seperator = getAndAdvance();
- Expression defaultValue = parseExpression2();
- if (kind == ParameterKind.POSITIONAL) {
- _reportErrorForToken(
- ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER,
- seperator);
- } else if (kind == ParameterKind.REQUIRED) {
- _reportErrorForNode(
- ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP,
- parameter);
- }
- return new DefaultFormalParameter(
- parameter,
- kind,
- seperator,
- defaultValue);
- } else if (kind != ParameterKind.REQUIRED) {
- return new DefaultFormalParameter(parameter, kind, null, null);
- }
- return parameter;
- }
-
- /**
* Parse a function body.
*
* <pre>
@@ -10003,6 +10004,27 @@ class Parser {
}
}
/**
+ * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
+ */
+class Parser_SyntheticKeywordToken extends KeywordToken {
+ /**
+ * Initialize a newly created token to represent the given keyword.
+ *
+ * @param keyword the keyword being represented by this token
+ * @param offset the offset from the beginning of the file to the first character in the token
+ */
+ Parser_SyntheticKeywordToken(Keyword keyword, int offset)
+ : super(keyword, offset);
+
+ @override
+ int get length => 0;
+
+ @override
+ Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
+}
+
+
+/**
* The enumeration `ParserErrorCode` defines the error codes used for errors
* detected by the parser. The convention for this class is for the name of the
* error code to indicate the problem that caused the error to be generated and
@@ -10720,27 +10742,6 @@ class ParserErrorCode extends ErrorCode {
/**
- * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
- */
-class Parser_SyntheticKeywordToken extends KeywordToken {
- /**
- * Initialize a newly created token to represent the given keyword.
- *
- * @param keyword the keyword being represented by this token
- * @param offset the offset from the beginning of the file to the first character in the token
- */
- Parser_SyntheticKeywordToken(Keyword keyword, int offset)
- : super(keyword, offset);
-
- @override
- int get length => 0;
-
- @override
- Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
-}
-
-
-/**
* Instances of the class `ResolutionCopier` copies resolution information from one AST
* structure to another as long as the structures of the corresponding children of a pair of nodes
* are the same.
@@ -11217,6 +11218,17 @@ class ResolutionCopier implements AstVisitor<bool> {
}
@override
+ bool visitFormalParameterList(FormalParameterList node) {
+ FormalParameterList toNode = this._toNode as FormalParameterList;
+ return _and(
+ _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis),
+ _isEqualNodeLists(node.parameters, toNode.parameters),
+ _isEqualTokens(node.leftDelimiter, toNode.leftDelimiter),
+ _isEqualTokens(node.rightDelimiter, toNode.rightDelimiter),
+ _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis));
+ }
+
+ @override
bool visitForStatement(ForStatement node) {
ForStatement toNode = this._toNode as ForStatement;
return _and(
@@ -11233,17 +11245,6 @@ class ResolutionCopier implements AstVisitor<bool> {
}
@override
- bool visitFormalParameterList(FormalParameterList node) {
- FormalParameterList toNode = this._toNode as FormalParameterList;
- return _and(
- _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis),
- _isEqualNodeLists(node.parameters, toNode.parameters),
- _isEqualTokens(node.leftDelimiter, toNode.leftDelimiter),
- _isEqualTokens(node.rightDelimiter, toNode.rightDelimiter),
- _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis));
- }
-
- @override
bool visitFunctionDeclaration(FunctionDeclaration node) {
FunctionDeclaration toNode = this._toNode as FunctionDeclaration;
return _and(
@@ -11657,14 +11658,13 @@ class ResolutionCopier implements AstVisitor<bool> {
}
@override
- bool visitPrefixExpression(PrefixExpression node) {
- PrefixExpression toNode = this._toNode as PrefixExpression;
+ bool visitPrefixedIdentifier(PrefixedIdentifier node) {
+ PrefixedIdentifier toNode = this._toNode as PrefixedIdentifier;
if (_and(
- _isEqualTokens(node.operator, toNode.operator),
- _isEqualNodes(node.operand, toNode.operand))) {
- toNode.propagatedElement = node.propagatedElement;
+ _isEqualNodes(node.prefix, toNode.prefix),
+ _isEqualTokens(node.period, toNode.period),
+ _isEqualNodes(node.identifier, toNode.identifier))) {
toNode.propagatedType = node.propagatedType;
- toNode.staticElement = node.staticElement;
toNode.staticType = node.staticType;
return true;
}
@@ -11672,13 +11672,14 @@ class ResolutionCopier implements AstVisitor<bool> {
}
@override
- bool visitPrefixedIdentifier(PrefixedIdentifier node) {
- PrefixedIdentifier toNode = this._toNode as PrefixedIdentifier;
+ bool visitPrefixExpression(PrefixExpression node) {
+ PrefixExpression toNode = this._toNode as PrefixExpression;
if (_and(
- _isEqualNodes(node.prefix, toNode.prefix),
- _isEqualTokens(node.period, toNode.period),
- _isEqualNodes(node.identifier, toNode.identifier))) {
+ _isEqualTokens(node.operator, toNode.operator),
+ _isEqualNodes(node.operand, toNode.operand))) {
+ toNode.propagatedElement = node.propagatedElement;
toNode.propagatedType = node.propagatedType;
+ toNode.staticElement = node.staticElement;
toNode.staticType = node.staticType;
return true;
}

Powered by Google App Engine
This is Rietveld 408576698