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

Side by Side 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, 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
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;
11 import 'dart:collection'; 11 import 'dart:collection';
12 12
13 import 'ast.dart'; 13 import 'ast.dart';
14 import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl; 14 import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl,
15 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
15 import 'error.dart'; 16 import 'error.dart';
16 import 'java_core.dart'; 17 import 'java_core.dart';
17 import 'java_engine.dart'; 18 import 'java_engine.dart';
18 import 'scanner.dart'; 19 import 'scanner.dart';
19 import 'source.dart'; 20 import 'source.dart';
20 import 'utilities_collection.dart' show TokenMap; 21 import 'utilities_collection.dart' show TokenMap;
21 import 'utilities_dart.dart'; 22 import 'utilities_dart.dart';
22 23
23 Map<String, MethodTrampoline> methodTable_Parser = <String, MethodTrampoline>{ 24 Map<String, MethodTrampoline> methodTable_Parser = <String, MethodTrampoline>{
24 'parseCompilationUnit_1': new MethodTrampoline( 25 'parseCompilationUnit_1': new MethodTrampoline(
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 //return parser.parseDeclaredIdentifier(); 1106 //return parser.parseDeclaredIdentifier();
1106 } else if (identical(_oldNode, node.identifier)) { 1107 } else if (identical(_oldNode, node.identifier)) {
1107 return _parser.parseSimpleIdentifier(); 1108 return _parser.parseSimpleIdentifier();
1108 } else if (identical(_oldNode, node.body)) { 1109 } else if (identical(_oldNode, node.body)) {
1109 return _parser.parseStatement2(); 1110 return _parser.parseStatement2();
1110 } 1111 }
1111 return _notAChild(node); 1112 return _notAChild(node);
1112 } 1113 }
1113 1114
1114 @override 1115 @override
1116 AstNode visitFormalParameterList(FormalParameterList node) {
1117 // We don't know which kind of parameter to parse.
1118 throw new InsufficientContextException();
1119 }
1120
1121 @override
1115 AstNode visitForStatement(ForStatement node) { 1122 AstNode visitForStatement(ForStatement node) {
1116 if (identical(_oldNode, node.variables)) { 1123 if (identical(_oldNode, node.variables)) {
1117 throw new InsufficientContextException(); 1124 throw new InsufficientContextException();
1118 } else if (identical(_oldNode, node.initialization)) { 1125 } else if (identical(_oldNode, node.initialization)) {
1119 throw new InsufficientContextException(); 1126 throw new InsufficientContextException();
1120 } else if (identical(_oldNode, node.condition)) { 1127 } else if (identical(_oldNode, node.condition)) {
1121 return _parser.parseExpression2(); 1128 return _parser.parseExpression2();
1122 } else if (node.updaters.contains(_oldNode)) { 1129 } else if (node.updaters.contains(_oldNode)) {
1123 return _parser.parseExpression2(); 1130 return _parser.parseExpression2();
1124 } else if (identical(_oldNode, node.body)) { 1131 } else if (identical(_oldNode, node.body)) {
1125 return _parser.parseStatement2(); 1132 return _parser.parseStatement2();
1126 } 1133 }
1127 return _notAChild(node); 1134 return _notAChild(node);
1128 } 1135 }
1129 1136
1130 @override 1137 @override
1131 AstNode visitFormalParameterList(FormalParameterList node) {
1132 // We don't know which kind of parameter to parse.
1133 throw new InsufficientContextException();
1134 }
1135
1136 @override
1137 AstNode visitFunctionDeclaration(FunctionDeclaration node) { 1138 AstNode visitFunctionDeclaration(FunctionDeclaration node) {
1138 if (identical(_oldNode, node.documentationComment)) { 1139 if (identical(_oldNode, node.documentationComment)) {
1139 throw new InsufficientContextException(); 1140 throw new InsufficientContextException();
1140 } else if (node.metadata.contains(_oldNode)) { 1141 } else if (node.metadata.contains(_oldNode)) {
1141 return _parser.parseAnnotation(); 1142 return _parser.parseAnnotation();
1142 } else if (identical(_oldNode, node.returnType)) { 1143 } else if (identical(_oldNode, node.returnType)) {
1143 return _parser.parseReturnType(); 1144 return _parser.parseReturnType();
1144 } else if (identical(_oldNode, node.name)) { 1145 } else if (identical(_oldNode, node.name)) {
1145 return _parser.parseSimpleIdentifier(); 1146 return _parser.parseSimpleIdentifier();
1146 } else if (identical(_oldNode, node.functionExpression)) { 1147 } else if (identical(_oldNode, node.functionExpression)) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 1476
1476 @override 1477 @override
1477 AstNode visitPostfixExpression(PostfixExpression node) { 1478 AstNode visitPostfixExpression(PostfixExpression node) {
1478 if (identical(_oldNode, node.operand)) { 1479 if (identical(_oldNode, node.operand)) {
1479 throw new InsufficientContextException(); 1480 throw new InsufficientContextException();
1480 } 1481 }
1481 return _notAChild(node); 1482 return _notAChild(node);
1482 } 1483 }
1483 1484
1484 @override 1485 @override
1485 AstNode visitPrefixExpression(PrefixExpression node) {
1486 if (identical(_oldNode, node.operand)) {
1487 throw new InsufficientContextException();
1488 }
1489 return _notAChild(node);
1490 }
1491
1492 @override
1493 AstNode visitPrefixedIdentifier(PrefixedIdentifier node) { 1486 AstNode visitPrefixedIdentifier(PrefixedIdentifier node) {
1494 if (identical(_oldNode, node.prefix)) { 1487 if (identical(_oldNode, node.prefix)) {
1495 return _parser.parseSimpleIdentifier(); 1488 return _parser.parseSimpleIdentifier();
1496 } else if (identical(_oldNode, node.identifier)) { 1489 } else if (identical(_oldNode, node.identifier)) {
1497 return _parser.parseSimpleIdentifier(); 1490 return _parser.parseSimpleIdentifier();
1498 } 1491 }
1499 return _notAChild(node); 1492 return _notAChild(node);
1500 } 1493 }
1501 1494
1502 @override 1495 @override
1496 AstNode visitPrefixExpression(PrefixExpression node) {
1497 if (identical(_oldNode, node.operand)) {
1498 throw new InsufficientContextException();
1499 }
1500 return _notAChild(node);
1501 }
1502
1503 @override
1503 AstNode visitPropertyAccess(PropertyAccess node) { 1504 AstNode visitPropertyAccess(PropertyAccess node) {
1504 if (identical(_oldNode, node.target)) { 1505 if (identical(_oldNode, node.target)) {
1505 throw new InsufficientContextException(); 1506 throw new InsufficientContextException();
1506 } else if (identical(_oldNode, node.propertyName)) { 1507 } else if (identical(_oldNode, node.propertyName)) {
1507 return _parser.parseSimpleIdentifier(); 1508 return _parser.parseSimpleIdentifier();
1508 } 1509 }
1509 return _notAChild(node); 1510 return _notAChild(node);
1510 } 1511 }
1511 1512
1512 @override 1513 @override
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 1819
1819 /** 1820 /**
1820 * Initialize a newly created exception to have no message and to have the giv en cause. 1821 * Initialize a newly created exception to have no message and to have the giv en cause.
1821 * 1822 *
1822 * @param cause the exception that caused this exception 1823 * @param cause the exception that caused this exception
1823 */ 1824 */
1824 IncrementalParseException.con2(Exception cause) : super(cause: cause); 1825 IncrementalParseException.con2(Exception cause) : super(cause: cause);
1825 } 1826 }
1826 1827
1827 /** 1828 /**
1828 * Visitor capable of inferring the correct parser state for incremental
1829 * parsing. This visitor visits each parent/child relationship in the chain of
1830 * ancestors of the node to be replaced (starting with the root of the parse
1831 * tree), updating the parser to the correct state for parsing the child of the
1832 * given parent. Once it has visited all of these relationships, the parser
1833 * will be in the correct state for reparsing the node to be replaced.
1834 *
1835 * TODO(paulberry): add support for other pieces of parser state (_inAsync,
1836 * _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch only
1837 * affect error message generation.
1838 */
1839 class IncrementalParseStateBuilder extends SimpleAstVisitor {
1840 /**
1841 * The parser whose state should be built.
1842 */
1843 final Parser _parser;
1844
1845 /**
1846 * The child node in the parent/child relationship currently being visited.
1847 * (The corresponding parent is the node passed to the visit...() function.)
1848 */
1849 AstNode _childNode;
1850
1851 /**
1852 * Create an IncrementalParseStateBuilder which will build the correct state
1853 * for [_parser].
1854 */
1855 IncrementalParseStateBuilder(this._parser);
1856
1857 /**
1858 * Build the correct parser state for parsing a replacement for [node].
1859 */
1860 void buildState(AstNode node) {
1861 List<AstNode> ancestors = <AstNode>[];
1862 while (node != null) {
1863 ancestors.add(node);
1864 node = node.parent;
1865 }
1866 _parser._inInitializer = false;
1867 for (int i = ancestors.length - 2; i >= 0; i--) {
1868 _childNode = ancestors[i];
1869 ancestors[i + 1].accept(this);
1870 }
1871 }
1872
1873 @override
1874 void visitArgumentList(ArgumentList node) {
1875 _parser._inInitializer = false;
1876 }
1877
1878 @override
1879 void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
1880 if (identical(_childNode, node.expression)) {
1881 _parser._inInitializer = true;
1882 }
1883 }
1884
1885 @override
1886 void visitIndexExpression(IndexExpression node) {
1887 if (identical(_childNode, node.index)) {
1888 _parser._inInitializer = false;
1889 }
1890 }
1891
1892 @override
1893 void visitInterpolationExpression(InterpolationExpression node) {
1894 if (identical(_childNode, node.expression)) {
1895 _parser._inInitializer = false;
1896 }
1897 }
1898
1899 @override
1900 void visitListLiteral(ListLiteral node) {
1901 if (node.elements.contains(_childNode)) {
1902 _parser._inInitializer = false;
1903 }
1904 }
1905
1906 @override
1907 void visitMapLiteral(MapLiteral node) {
1908 if (node.entries.contains(_childNode)) {
1909 _parser._inInitializer = false;
1910 }
1911 }
1912
1913 @override
1914 void visitParenthesizedExpression(ParenthesizedExpression node) {
1915 if (identical(_childNode, node.expression)) {
1916 _parser._inInitializer = false;
1917 }
1918 }
1919 }
1920
1921 /**
1922 * Instances of the class `IncrementalParser` re-parse a single AST structure wi thin a larger 1829 * Instances of the class `IncrementalParser` re-parse a single AST structure wi thin a larger
1923 * AST structure. 1830 * AST structure.
1924 */ 1831 */
1925 class IncrementalParser { 1832 class IncrementalParser {
1926 /** 1833 /**
1927 * The source being parsed. 1834 * The source being parsed.
1928 */ 1835 */
1929 final Source _source; 1836 final Source _source;
1930 1837
1931 /** 1838 /**
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 */ 1996 */
2090 Token _findTokenAt(Token firstToken, int offset) { 1997 Token _findTokenAt(Token firstToken, int offset) {
2091 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) { 1998 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) {
2092 firstToken = firstToken.previous; 1999 firstToken = firstToken.previous;
2093 } 2000 }
2094 return firstToken; 2001 return firstToken;
2095 } 2002 }
2096 } 2003 }
2097 2004
2098 /** 2005 /**
2006 * Visitor capable of inferring the correct parser state for incremental
2007 * parsing. This visitor visits each parent/child relationship in the chain of
2008 * ancestors of the node to be replaced (starting with the root of the parse
2009 * tree), updating the parser to the correct state for parsing the child of the
2010 * given parent. Once it has visited all of these relationships, the parser
2011 * will be in the correct state for reparsing the node to be replaced.
2012 *
2013 * TODO(paulberry): add support for other pieces of parser state (_inAsync,
2014 * _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch only
2015 * affect error message generation.
2016 */
2017 class IncrementalParseStateBuilder extends SimpleAstVisitor {
2018 /**
2019 * The parser whose state should be built.
2020 */
2021 final Parser _parser;
2022
2023 /**
2024 * The child node in the parent/child relationship currently being visited.
2025 * (The corresponding parent is the node passed to the visit...() function.)
2026 */
2027 AstNode _childNode;
2028
2029 /**
2030 * Create an IncrementalParseStateBuilder which will build the correct state
2031 * for [_parser].
2032 */
2033 IncrementalParseStateBuilder(this._parser);
2034
2035 /**
2036 * Build the correct parser state for parsing a replacement for [node].
2037 */
2038 void buildState(AstNode node) {
2039 List<AstNode> ancestors = <AstNode>[];
2040 while (node != null) {
2041 ancestors.add(node);
2042 node = node.parent;
2043 }
2044 _parser._inInitializer = false;
2045 for (int i = ancestors.length - 2; i >= 0; i--) {
2046 _childNode = ancestors[i];
2047 ancestors[i + 1].accept(this);
2048 }
2049 }
2050
2051 @override
2052 void visitArgumentList(ArgumentList node) {
2053 _parser._inInitializer = false;
2054 }
2055
2056 @override
2057 void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
2058 if (identical(_childNode, node.expression)) {
2059 _parser._inInitializer = true;
2060 }
2061 }
2062
2063 @override
2064 void visitIndexExpression(IndexExpression node) {
2065 if (identical(_childNode, node.index)) {
2066 _parser._inInitializer = false;
2067 }
2068 }
2069
2070 @override
2071 void visitInterpolationExpression(InterpolationExpression node) {
2072 if (identical(_childNode, node.expression)) {
2073 _parser._inInitializer = false;
2074 }
2075 }
2076
2077 @override
2078 void visitListLiteral(ListLiteral node) {
2079 if (node.elements.contains(_childNode)) {
2080 _parser._inInitializer = false;
2081 }
2082 }
2083
2084 @override
2085 void visitMapLiteral(MapLiteral node) {
2086 if (node.entries.contains(_childNode)) {
2087 _parser._inInitializer = false;
2088 }
2089 }
2090
2091 @override
2092 void visitParenthesizedExpression(ParenthesizedExpression node) {
2093 if (identical(_childNode, node.expression)) {
2094 _parser._inInitializer = false;
2095 }
2096 }
2097 }
2098
2099 /**
2099 * Instances of the class `InsufficientContextException` represent a situation i n which an AST 2100 * Instances of the class `InsufficientContextException` represent a situation i n which an AST
2100 * node cannot be re-parsed because there is not enough context to know how to r e-parse the node. 2101 * node cannot be re-parsed because there is not enough context to know how to r e-parse the node.
2101 * Clients can attempt to re-parse the parent of the node. 2102 * Clients can attempt to re-parse the parent of the node.
2102 */ 2103 */
2103 class InsufficientContextException extends IncrementalParseException { 2104 class InsufficientContextException extends IncrementalParseException {
2104 /** 2105 /**
2105 * Initialize a newly created exception to have no message and to be its own c ause. 2106 * Initialize a newly created exception to have no message and to be its own c ause.
2106 */ 2107 */
2107 InsufficientContextException() : super(); 2108 InsufficientContextException() : super();
2108 2109
(...skipping 3890 matching lines...) Expand 10 before | Expand all | Expand 10 after
5999 } 6000 }
6000 return new CompilationUnit( 6001 return new CompilationUnit(
6001 firstToken, 6002 firstToken,
6002 scriptTag, 6003 scriptTag,
6003 directives, 6004 directives,
6004 new List<CompilationUnitMember>(), 6005 new List<CompilationUnitMember>(),
6005 _currentToken); 6006 _currentToken);
6006 } 6007 }
6007 6008
6008 /** 6009 /**
6009 * Parse a do statement.
6010 *
6011 * <pre>
6012 * doStatement ::=
6013 * 'do' statement 'while' '(' expression ')' ';'
6014 * </pre>
6015 *
6016 * @return the do statement that was parsed
6017 */
6018 Statement _parseDoStatement() {
6019 bool wasInLoop = _inLoop;
6020 _inLoop = true;
6021 try {
6022 Token doKeyword = _expectKeyword(Keyword.DO);
6023 Statement body = parseStatement2();
6024 Token whileKeyword = _expectKeyword(Keyword.WHILE);
6025 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
6026 Expression condition = parseExpression2();
6027 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
6028 Token semicolon = _expect(TokenType.SEMICOLON);
6029 return new DoStatement(
6030 doKeyword,
6031 body,
6032 whileKeyword,
6033 leftParenthesis,
6034 condition,
6035 rightParenthesis,
6036 semicolon);
6037 } finally {
6038 _inLoop = wasInLoop;
6039 }
6040 }
6041
6042 /**
6043 * Parse a documentation comment. 6010 * Parse a documentation comment.
6044 * 6011 *
6045 * <pre> 6012 * <pre>
6046 * documentationComment ::= 6013 * documentationComment ::=
6047 * multiLineComment? 6014 * multiLineComment?
6048 * | singleLineComment* 6015 * | singleLineComment*
6049 * </pre> 6016 * </pre>
6050 * 6017 *
6051 * @return the documentation comment that was parsed, or `null` if there was n o comment 6018 * @return the documentation comment that was parsed, or `null` if there was n o comment
6052 */ 6019 */
(...skipping 21 matching lines...) Expand all
6074 return null; 6041 return null;
6075 } 6042 }
6076 List<CommentReference> references = 6043 List<CommentReference> references =
6077 _parseCommentReferences(documentationTokens); 6044 _parseCommentReferences(documentationTokens);
6078 return Comment.createDocumentationCommentWithReferences( 6045 return Comment.createDocumentationCommentWithReferences(
6079 documentationTokens, 6046 documentationTokens,
6080 references); 6047 references);
6081 } 6048 }
6082 6049
6083 /** 6050 /**
6051 * Parse a do statement.
6052 *
6053 * <pre>
6054 * doStatement ::=
6055 * 'do' statement 'while' '(' expression ')' ';'
6056 * </pre>
6057 *
6058 * @return the do statement that was parsed
6059 */
6060 Statement _parseDoStatement() {
6061 bool wasInLoop = _inLoop;
6062 _inLoop = true;
6063 try {
6064 Token doKeyword = _expectKeyword(Keyword.DO);
6065 Statement body = parseStatement2();
6066 Token whileKeyword = _expectKeyword(Keyword.WHILE);
6067 Token leftParenthesis = _expect(TokenType.OPEN_PAREN);
6068 Expression condition = parseExpression2();
6069 Token rightParenthesis = _expect(TokenType.CLOSE_PAREN);
6070 Token semicolon = _expect(TokenType.SEMICOLON);
6071 return new DoStatement(
6072 doKeyword,
6073 body,
6074 whileKeyword,
6075 leftParenthesis,
6076 condition,
6077 rightParenthesis,
6078 semicolon);
6079 } finally {
6080 _inLoop = wasInLoop;
6081 }
6082 }
6083
6084 /**
6084 * Parse an empty statement. 6085 * Parse an empty statement.
6085 * 6086 *
6086 * <pre> 6087 * <pre>
6087 * emptyStatement ::= 6088 * emptyStatement ::=
6088 * ';' 6089 * ';'
6089 * </pre> 6090 * </pre>
6090 * 6091 *
6091 * @return the empty statement that was parsed 6092 * @return the empty statement that was parsed
6092 */ 6093 */
6093 Statement _parseEmptyStatement() => new EmptyStatement(getAndAdvance()); 6094 Statement _parseEmptyStatement() => new EmptyStatement(getAndAdvance());
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
6270 type = parseReturnType(); 6271 type = parseReturnType();
6271 } else if (!optional) { 6272 } else if (!optional) {
6272 _reportErrorForCurrentToken( 6273 _reportErrorForCurrentToken(
6273 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); 6274 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
6274 } 6275 }
6275 } 6276 }
6276 return new FinalConstVarOrType(keyword, type); 6277 return new FinalConstVarOrType(keyword, type);
6277 } 6278 }
6278 6279
6279 /** 6280 /**
6281 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
6282 * `true`.
6283 *
6284 * <pre>
6285 * defaultFormalParameter ::=
6286 * normalFormalParameter ('=' expression)?
6287 *
6288 * defaultNamedParameter ::=
6289 * normalFormalParameter (':' expression)?
6290 * </pre>
6291 *
6292 * @param kind the kind of parameter being expected based on the presence or a bsence of group
6293 * delimiters
6294 * @return the formal parameter that was parsed
6295 */
6296 FormalParameter _parseFormalParameter(ParameterKind kind) {
6297 NormalFormalParameter parameter = parseNormalFormalParameter();
6298 if (_matches(TokenType.EQ)) {
6299 Token seperator = getAndAdvance();
6300 Expression defaultValue = parseExpression2();
6301 if (kind == ParameterKind.NAMED) {
6302 _reportErrorForToken(
6303 ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER,
6304 seperator);
6305 } else if (kind == ParameterKind.REQUIRED) {
6306 _reportErrorForNode(
6307 ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP,
6308 parameter);
6309 }
6310 return new DefaultFormalParameter(
6311 parameter,
6312 kind,
6313 seperator,
6314 defaultValue);
6315 } else if (_matches(TokenType.COLON)) {
6316 Token seperator = getAndAdvance();
6317 Expression defaultValue = parseExpression2();
6318 if (kind == ParameterKind.POSITIONAL) {
6319 _reportErrorForToken(
6320 ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER,
6321 seperator);
6322 } else if (kind == ParameterKind.REQUIRED) {
6323 _reportErrorForNode(
6324 ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP,
6325 parameter);
6326 }
6327 return new DefaultFormalParameter(
6328 parameter,
6329 kind,
6330 seperator,
6331 defaultValue);
6332 } else if (kind != ParameterKind.REQUIRED) {
6333 return new DefaultFormalParameter(parameter, kind, null, null);
6334 }
6335 return parameter;
6336 }
6337
6338 /**
6280 * Parse a for statement. 6339 * Parse a for statement.
6281 * 6340 *
6282 * <pre> 6341 * <pre>
6283 * forStatement ::= 6342 * forStatement ::=
6284 * 'for' '(' forLoopParts ')' statement 6343 * 'for' '(' forLoopParts ')' statement
6285 * 6344 *
6286 * forLoopParts ::= 6345 * forLoopParts ::=
6287 * forInitializerStatement expression? ';' expressionList? 6346 * forInitializerStatement expression? ';' expressionList?
6288 * | declaredIdentifier 'in' expression 6347 * | declaredIdentifier 'in' expression
6289 * | identifier 'in' expression 6348 * | identifier 'in' expression
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
6421 rightSeparator, 6480 rightSeparator,
6422 updaters, 6481 updaters,
6423 rightParenthesis, 6482 rightParenthesis,
6424 body); 6483 body);
6425 } finally { 6484 } finally {
6426 _inLoop = wasInLoop; 6485 _inLoop = wasInLoop;
6427 } 6486 }
6428 } 6487 }
6429 6488
6430 /** 6489 /**
6431 * Parse a formal parameter. At most one of `isOptional` and `isNamed` can be
6432 * `true`.
6433 *
6434 * <pre>
6435 * defaultFormalParameter ::=
6436 * normalFormalParameter ('=' expression)?
6437 *
6438 * defaultNamedParameter ::=
6439 * normalFormalParameter (':' expression)?
6440 * </pre>
6441 *
6442 * @param kind the kind of parameter being expected based on the presence or a bsence of group
6443 * delimiters
6444 * @return the formal parameter that was parsed
6445 */
6446 FormalParameter _parseFormalParameter(ParameterKind kind) {
6447 NormalFormalParameter parameter = parseNormalFormalParameter();
6448 if (_matches(TokenType.EQ)) {
6449 Token seperator = getAndAdvance();
6450 Expression defaultValue = parseExpression2();
6451 if (kind == ParameterKind.NAMED) {
6452 _reportErrorForToken(
6453 ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER,
6454 seperator);
6455 } else if (kind == ParameterKind.REQUIRED) {
6456 _reportErrorForNode(
6457 ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP,
6458 parameter);
6459 }
6460 return new DefaultFormalParameter(
6461 parameter,
6462 kind,
6463 seperator,
6464 defaultValue);
6465 } else if (_matches(TokenType.COLON)) {
6466 Token seperator = getAndAdvance();
6467 Expression defaultValue = parseExpression2();
6468 if (kind == ParameterKind.POSITIONAL) {
6469 _reportErrorForToken(
6470 ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER,
6471 seperator);
6472 } else if (kind == ParameterKind.REQUIRED) {
6473 _reportErrorForNode(
6474 ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP,
6475 parameter);
6476 }
6477 return new DefaultFormalParameter(
6478 parameter,
6479 kind,
6480 seperator,
6481 defaultValue);
6482 } else if (kind != ParameterKind.REQUIRED) {
6483 return new DefaultFormalParameter(parameter, kind, null, null);
6484 }
6485 return parameter;
6486 }
6487
6488 /**
6489 * Parse a function body. 6490 * Parse a function body.
6490 * 6491 *
6491 * <pre> 6492 * <pre>
6492 * functionBody ::= 6493 * functionBody ::=
6493 * '=>' expression ';' 6494 * '=>' expression ';'
6494 * | block 6495 * | block
6495 * 6496 *
6496 * functionExpressionBody ::= 6497 * functionExpressionBody ::=
6497 * '=>' expression 6498 * '=>' expression
6498 * | block 6499 * | block
(...skipping 3497 matching lines...) Expand 10 before | Expand all | Expand 10 after
9996 _reportErrorForToken( 9997 _reportErrorForToken(
9997 ParserErrorCode.FINAL_TYPEDEF, 9998 ParserErrorCode.FINAL_TYPEDEF,
9998 modifiers.finalKeyword); 9999 modifiers.finalKeyword);
9999 } 10000 }
10000 if (modifiers.varKeyword != null) { 10001 if (modifiers.varKeyword != null) {
10001 _reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword); 10002 _reportErrorForToken(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword);
10002 } 10003 }
10003 } 10004 }
10004 } 10005 }
10005 /** 10006 /**
10007 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
10008 */
10009 class Parser_SyntheticKeywordToken extends KeywordToken {
10010 /**
10011 * Initialize a newly created token to represent the given keyword.
10012 *
10013 * @param keyword the keyword being represented by this token
10014 * @param offset the offset from the beginning of the file to the first charac ter in the token
10015 */
10016 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
10017 : super(keyword, offset);
10018
10019 @override
10020 int get length => 0;
10021
10022 @override
10023 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
10024 }
10025
10026
10027 /**
10006 * The enumeration `ParserErrorCode` defines the error codes used for errors 10028 * The enumeration `ParserErrorCode` defines the error codes used for errors
10007 * detected by the parser. The convention for this class is for the name of the 10029 * detected by the parser. The convention for this class is for the name of the
10008 * error code to indicate the problem that caused the error to be generated and 10030 * error code to indicate the problem that caused the error to be generated and
10009 * for the error message to explain what is wrong and, when appropriate, how the 10031 * for the error message to explain what is wrong and, when appropriate, how the
10010 * problem can be corrected. 10032 * problem can be corrected.
10011 */ 10033 */
10012 class ParserErrorCode extends ErrorCode { 10034 class ParserErrorCode extends ErrorCode {
10013 static const ParserErrorCode ABSTRACT_CLASS_MEMBER = const ParserErrorCode( 10035 static const ParserErrorCode ABSTRACT_CLASS_MEMBER = const ParserErrorCode(
10014 'ABSTRACT_CLASS_MEMBER', 10036 'ABSTRACT_CLASS_MEMBER',
10015 "Members of classes cannot be declared to be 'abstract'"); 10037 "Members of classes cannot be declared to be 'abstract'");
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
10713 10735
10714 @override 10736 @override
10715 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; 10737 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
10716 10738
10717 @override 10739 @override
10718 ErrorType get type => ErrorType.SYNTACTIC_ERROR; 10740 ErrorType get type => ErrorType.SYNTACTIC_ERROR;
10719 } 10741 }
10720 10742
10721 10743
10722 /** 10744 /**
10723 * Instances of the class `SyntheticKeywordToken` implement a synthetic keyword token.
10724 */
10725 class Parser_SyntheticKeywordToken extends KeywordToken {
10726 /**
10727 * Initialize a newly created token to represent the given keyword.
10728 *
10729 * @param keyword the keyword being represented by this token
10730 * @param offset the offset from the beginning of the file to the first charac ter in the token
10731 */
10732 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
10733 : super(keyword, offset);
10734
10735 @override
10736 int get length => 0;
10737
10738 @override
10739 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
10740 }
10741
10742
10743 /**
10744 * Instances of the class `ResolutionCopier` copies resolution information from one AST 10745 * Instances of the class `ResolutionCopier` copies resolution information from one AST
10745 * structure to another as long as the structures of the corresponding children of a pair of nodes 10746 * structure to another as long as the structures of the corresponding children of a pair of nodes
10746 * are the same. 10747 * are the same.
10747 */ 10748 */
10748 class ResolutionCopier implements AstVisitor<bool> { 10749 class ResolutionCopier implements AstVisitor<bool> {
10749 /** 10750 /**
10750 * The AST node with which the node being visited is to be compared. This is o nly valid at the 10751 * The AST node with which the node being visited is to be compared. This is o nly valid at the
10751 * beginning of each visit method (until [isEqualNodes] is invoked). 10752 * beginning of each visit method (until [isEqualNodes] is invoked).
10752 */ 10753 */
10753 AstNode _toNode; 10754 AstNode _toNode;
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
11210 _isEqualTokens(node.forKeyword, toNode.forKeyword), 11211 _isEqualTokens(node.forKeyword, toNode.forKeyword),
11211 _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis), 11212 _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis),
11212 _isEqualNodes(node.loopVariable, toNode.loopVariable), 11213 _isEqualNodes(node.loopVariable, toNode.loopVariable),
11213 _isEqualTokens(node.inKeyword, toNode.inKeyword), 11214 _isEqualTokens(node.inKeyword, toNode.inKeyword),
11214 _isEqualNodes(node.iterable, toNode.iterable), 11215 _isEqualNodes(node.iterable, toNode.iterable),
11215 _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis), 11216 _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis),
11216 _isEqualNodes(node.body, toNode.body)); 11217 _isEqualNodes(node.body, toNode.body));
11217 } 11218 }
11218 11219
11219 @override 11220 @override
11221 bool visitFormalParameterList(FormalParameterList node) {
11222 FormalParameterList toNode = this._toNode as FormalParameterList;
11223 return _and(
11224 _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis),
11225 _isEqualNodeLists(node.parameters, toNode.parameters),
11226 _isEqualTokens(node.leftDelimiter, toNode.leftDelimiter),
11227 _isEqualTokens(node.rightDelimiter, toNode.rightDelimiter),
11228 _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis));
11229 }
11230
11231 @override
11220 bool visitForStatement(ForStatement node) { 11232 bool visitForStatement(ForStatement node) {
11221 ForStatement toNode = this._toNode as ForStatement; 11233 ForStatement toNode = this._toNode as ForStatement;
11222 return _and( 11234 return _and(
11223 _isEqualTokens(node.forKeyword, toNode.forKeyword), 11235 _isEqualTokens(node.forKeyword, toNode.forKeyword),
11224 _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis), 11236 _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis),
11225 _isEqualNodes(node.variables, toNode.variables), 11237 _isEqualNodes(node.variables, toNode.variables),
11226 _isEqualNodes(node.initialization, toNode.initialization), 11238 _isEqualNodes(node.initialization, toNode.initialization),
11227 _isEqualTokens(node.leftSeparator, toNode.leftSeparator), 11239 _isEqualTokens(node.leftSeparator, toNode.leftSeparator),
11228 _isEqualNodes(node.condition, toNode.condition), 11240 _isEqualNodes(node.condition, toNode.condition),
11229 _isEqualTokens(node.rightSeparator, toNode.rightSeparator), 11241 _isEqualTokens(node.rightSeparator, toNode.rightSeparator),
11230 _isEqualNodeLists(node.updaters, toNode.updaters), 11242 _isEqualNodeLists(node.updaters, toNode.updaters),
11231 _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis), 11243 _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis),
11232 _isEqualNodes(node.body, toNode.body)); 11244 _isEqualNodes(node.body, toNode.body));
11233 } 11245 }
11234 11246
11235 @override 11247 @override
11236 bool visitFormalParameterList(FormalParameterList node) {
11237 FormalParameterList toNode = this._toNode as FormalParameterList;
11238 return _and(
11239 _isEqualTokens(node.leftParenthesis, toNode.leftParenthesis),
11240 _isEqualNodeLists(node.parameters, toNode.parameters),
11241 _isEqualTokens(node.leftDelimiter, toNode.leftDelimiter),
11242 _isEqualTokens(node.rightDelimiter, toNode.rightDelimiter),
11243 _isEqualTokens(node.rightParenthesis, toNode.rightParenthesis));
11244 }
11245
11246 @override
11247 bool visitFunctionDeclaration(FunctionDeclaration node) { 11248 bool visitFunctionDeclaration(FunctionDeclaration node) {
11248 FunctionDeclaration toNode = this._toNode as FunctionDeclaration; 11249 FunctionDeclaration toNode = this._toNode as FunctionDeclaration;
11249 return _and( 11250 return _and(
11250 _isEqualNodes(node.documentationComment, toNode.documentationComment), 11251 _isEqualNodes(node.documentationComment, toNode.documentationComment),
11251 _isEqualNodeLists(node.metadata, toNode.metadata), 11252 _isEqualNodeLists(node.metadata, toNode.metadata),
11252 _isEqualTokens(node.externalKeyword, toNode.externalKeyword), 11253 _isEqualTokens(node.externalKeyword, toNode.externalKeyword),
11253 _isEqualNodes(node.returnType, toNode.returnType), 11254 _isEqualNodes(node.returnType, toNode.returnType),
11254 _isEqualTokens(node.propertyKeyword, toNode.propertyKeyword), 11255 _isEqualTokens(node.propertyKeyword, toNode.propertyKeyword),
11255 _isEqualNodes(node.name, toNode.name), 11256 _isEqualNodes(node.name, toNode.name),
11256 _isEqualNodes(node.functionExpression, toNode.functionExpression)); 11257 _isEqualNodes(node.functionExpression, toNode.functionExpression));
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
11650 toNode.propagatedElement = node.propagatedElement; 11651 toNode.propagatedElement = node.propagatedElement;
11651 toNode.propagatedType = node.propagatedType; 11652 toNode.propagatedType = node.propagatedType;
11652 toNode.staticElement = node.staticElement; 11653 toNode.staticElement = node.staticElement;
11653 toNode.staticType = node.staticType; 11654 toNode.staticType = node.staticType;
11654 return true; 11655 return true;
11655 } 11656 }
11656 return false; 11657 return false;
11657 } 11658 }
11658 11659
11659 @override 11660 @override
11660 bool visitPrefixExpression(PrefixExpression node) { 11661 bool visitPrefixedIdentifier(PrefixedIdentifier node) {
11661 PrefixExpression toNode = this._toNode as PrefixExpression; 11662 PrefixedIdentifier toNode = this._toNode as PrefixedIdentifier;
11662 if (_and( 11663 if (_and(
11663 _isEqualTokens(node.operator, toNode.operator), 11664 _isEqualNodes(node.prefix, toNode.prefix),
11664 _isEqualNodes(node.operand, toNode.operand))) { 11665 _isEqualTokens(node.period, toNode.period),
11665 toNode.propagatedElement = node.propagatedElement; 11666 _isEqualNodes(node.identifier, toNode.identifier))) {
11666 toNode.propagatedType = node.propagatedType; 11667 toNode.propagatedType = node.propagatedType;
11667 toNode.staticElement = node.staticElement;
11668 toNode.staticType = node.staticType; 11668 toNode.staticType = node.staticType;
11669 return true; 11669 return true;
11670 } 11670 }
11671 return false; 11671 return false;
11672 } 11672 }
11673 11673
11674 @override 11674 @override
11675 bool visitPrefixedIdentifier(PrefixedIdentifier node) { 11675 bool visitPrefixExpression(PrefixExpression node) {
11676 PrefixedIdentifier toNode = this._toNode as PrefixedIdentifier; 11676 PrefixExpression toNode = this._toNode as PrefixExpression;
11677 if (_and( 11677 if (_and(
11678 _isEqualNodes(node.prefix, toNode.prefix), 11678 _isEqualTokens(node.operator, toNode.operator),
11679 _isEqualTokens(node.period, toNode.period), 11679 _isEqualNodes(node.operand, toNode.operand))) {
11680 _isEqualNodes(node.identifier, toNode.identifier))) { 11680 toNode.propagatedElement = node.propagatedElement;
11681 toNode.propagatedType = node.propagatedType; 11681 toNode.propagatedType = node.propagatedType;
11682 toNode.staticElement = node.staticElement;
11682 toNode.staticType = node.staticType; 11683 toNode.staticType = node.staticType;
11683 return true; 11684 return true;
11684 } 11685 }
11685 return false; 11686 return false;
11686 } 11687 }
11687 11688
11688 @override 11689 @override
11689 bool visitPropertyAccess(PropertyAccess node) { 11690 bool visitPropertyAccess(PropertyAccess node) {
11690 PropertyAccess toNode = this._toNode as PropertyAccess; 11691 PropertyAccess toNode = this._toNode as PropertyAccess;
11691 if (_and( 11692 if (_and(
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
12145 * Copy resolution data from one node to another. 12146 * Copy resolution data from one node to another.
12146 * 12147 *
12147 * @param fromNode the node from which resolution information will be copied 12148 * @param fromNode the node from which resolution information will be copied
12148 * @param toNode the node to which resolution information will be copied 12149 * @param toNode the node to which resolution information will be copied
12149 */ 12150 */
12150 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 12151 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
12151 ResolutionCopier copier = new ResolutionCopier(); 12152 ResolutionCopier copier = new ResolutionCopier();
12152 copier._isEqualNodes(fromNode, toNode); 12153 copier._isEqualNodes(fromNode, toNode);
12153 } 12154 }
12154 } 12155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698