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

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

Issue 736813002: Fix incremental parsing of function literals in initializer lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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/parser_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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import "dart:math" as math; 10 import "dart:math" as math;
(...skipping 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 AstNode parent = oldNode.parent; 1906 AstNode parent = oldNode.parent;
1907 if (parent == null) { 1907 if (parent == null) {
1908 parseToken = _findFirstToken(parseToken); 1908 parseToken = _findFirstToken(parseToken);
1909 parser.currentToken = parseToken; 1909 parser.currentToken = parseToken;
1910 return parser.parseCompilationUnit2(); 1910 return parser.parseCompilationUnit2();
1911 } 1911 }
1912 bool advanceToParent = false; 1912 bool advanceToParent = false;
1913 try { 1913 try {
1914 IncrementalParseDispatcher dispatcher = 1914 IncrementalParseDispatcher dispatcher =
1915 new IncrementalParseDispatcher(parser, oldNode); 1915 new IncrementalParseDispatcher(parser, oldNode);
1916 IncrementalParseStateBuilder contextBuilder =
1917 new IncrementalParseStateBuilder(parser);
1918 contextBuilder.buildState(oldNode);
1916 newNode = parent.accept(dispatcher); 1919 newNode = parent.accept(dispatcher);
1917 // 1920 //
1918 // Validate that the new node can replace the old node. 1921 // Validate that the new node can replace the old node.
1919 // 1922 //
1920 Token mappedToken = _tokenMap.get(oldNode.endToken.next); 1923 Token mappedToken = _tokenMap.get(oldNode.endToken.next);
1921 if (mappedToken == null || 1924 if (mappedToken == null ||
1922 mappedToken.offset != newNode.endToken.next.offset || 1925 mappedToken.offset != newNode.endToken.next.offset ||
1923 newNode.offset != oldNode.offset) { 1926 newNode.offset != oldNode.offset) {
1924 advanceToParent = true; 1927 advanceToParent = true;
1925 } 1928 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 */ 1979 */
1977 Token _findTokenAt(Token firstToken, int offset) { 1980 Token _findTokenAt(Token firstToken, int offset) {
1978 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) { 1981 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) {
1979 firstToken = firstToken.previous; 1982 firstToken = firstToken.previous;
1980 } 1983 }
1981 return firstToken; 1984 return firstToken;
1982 } 1985 }
1983 } 1986 }
1984 1987
1985 /** 1988 /**
1989 * Visitor capable of inferring the correct parser state for incremental
1990 * parsing. This visitor visits each parent/child relationship in the chain of
1991 * ancestors of the node to be replaced (starting with the root of the parse
1992 * tree), updating the parser to the correct state for parsing the child of the
1993 * given parent. Once it has visited all of these relationships, the parser
1994 * will be in the correct state for reparsing the node to be replaced.
1995 *
1996 * TODO(paulberry): add support for other pieces of parser state (_inAsync,
1997 * _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch only
1998 * affect error message generation.
1999 */
2000 class IncrementalParseStateBuilder extends SimpleAstVisitor {
2001 /**
2002 * The parser whose state should be built.
2003 */
2004 final Parser _parser;
2005
2006 /**
2007 * The child node in the parent/child relationship currently being visited.
2008 * (The corresponding parent is the node passed to the visit...() function.)
2009 */
2010 AstNode _childNode;
2011
2012 /**
2013 * Create an IncrementalParseStateBuilder which will build the correct state
2014 * for [_parser].
2015 */
2016 IncrementalParseStateBuilder(this._parser);
2017
2018 /**
2019 * Build the correct parser state for parsing a replacement for [node].
2020 */
2021 void buildState(AstNode node) {
2022 List<AstNode> ancestors = <AstNode>[];
2023 while (node != null) {
2024 ancestors.add(node);
2025 node = node.parent;
2026 }
2027 _parser._inInitializer = false;
2028 for (int i = ancestors.length - 2; i >= 0; i--) {
2029 _childNode = ancestors[i];
2030 ancestors[i + 1].accept(this);
2031 }
2032 }
2033
2034 @override
2035 void visitArgumentList(ArgumentList node) {
2036 _parser._inInitializer = false;
2037 }
2038
2039 @override
2040 void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
2041 if (identical(_childNode, node.expression)) {
2042 _parser._inInitializer = true;
2043 }
2044 }
2045
2046 @override
2047 void visitIndexExpression(IndexExpression node) {
2048 if (identical(_childNode, node.index)) {
2049 _parser._inInitializer = false;
2050 }
2051 }
2052
2053 @override
2054 void visitInterpolationExpression(InterpolationExpression node) {
2055 if (identical(_childNode, node.expression)) {
2056 _parser._inInitializer = false;
2057 }
2058 }
2059
2060 @override
2061 void visitListLiteral(ListLiteral node) {
2062 if (node.elements.contains(_childNode)) {
2063 _parser._inInitializer = false;
2064 }
2065 }
2066
2067 @override
2068 void visitMapLiteral(MapLiteral node) {
2069 if (node.entries.contains(_childNode)) {
2070 _parser._inInitializer = false;
2071 }
2072 }
2073
2074 @override
2075 void visitParenthesizedExpression(ParenthesizedExpression node) {
2076 if (identical(_childNode, node.expression)) {
2077 _parser._inInitializer = false;
2078 }
2079 }
2080 }
2081
2082 /**
1986 * Instances of the class `InsufficientContextException` represent a situation i n which an AST 2083 * Instances of the class `InsufficientContextException` represent a situation i n which an AST
1987 * node cannot be re-parsed because there is not enough context to know how to r e-parse the node. 2084 * node cannot be re-parsed because there is not enough context to know how to r e-parse the node.
1988 * Clients can attempt to re-parse the parent of the node. 2085 * Clients can attempt to re-parse the parent of the node.
1989 */ 2086 */
1990 class InsufficientContextException extends IncrementalParseException { 2087 class InsufficientContextException extends IncrementalParseException {
1991 /** 2088 /**
1992 * Initialize a newly created exception to have no message and to be its own c ause. 2089 * Initialize a newly created exception to have no message and to be its own c ause.
1993 */ 2090 */
1994 InsufficientContextException() : super(); 2091 InsufficientContextException() : super();
1995 2092
(...skipping 9905 matching lines...) Expand 10 before | Expand all | Expand 10 after
11901 * Copy resolution data from one node to another. 11998 * Copy resolution data from one node to another.
11902 * 11999 *
11903 * @param fromNode the node from which resolution information will be copied 12000 * @param fromNode the node from which resolution information will be copied
11904 * @param toNode the node to which resolution information will be copied 12001 * @param toNode the node to which resolution information will be copied
11905 */ 12002 */
11906 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 12003 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
11907 ResolutionCopier copier = new ResolutionCopier(); 12004 ResolutionCopier copier = new ResolutionCopier();
11908 copier._isEqualNodes(fromNode, toNode); 12005 copier._isEqualNodes(fromNode, toNode);
11909 } 12006 }
11910 } 12007 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698