| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.analyzer.ast_builder; | 5 library fasta.analyzer.ast_builder; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; | 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
| 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
| 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; | 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 show JumpTargetKind, NullValue, ScopeListener; | 30 show JumpTargetKind, NullValue, ScopeListener; |
| 31 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; | 31 import 'package:analyzer/src/dart/error/syntactic_errors.dart'; |
| 32 | 32 |
| 33 class AstBuilder extends ScopeListener { | 33 class AstBuilder extends ScopeListener { |
| 34 final AstFactory ast = standard.astFactory; | 34 final AstFactory ast = standard.astFactory; |
| 35 | 35 |
| 36 final ErrorReporter errorReporter; | 36 final ErrorReporter errorReporter; |
| 37 final KernelLibraryBuilder library; | 37 final KernelLibraryBuilder library; |
| 38 final Builder member; | 38 final Builder member; |
| 39 | 39 |
| 40 ScriptTag scriptTag; |
| 41 final List<Directive> directives = <Directive>[]; |
| 42 final List<CompilationUnitMember> declarations = <CompilationUnitMember>[]; |
| 43 |
| 40 @override | 44 @override |
| 41 final Uri uri; | 45 final Uri uri; |
| 42 | 46 |
| 43 /** | 47 /** |
| 44 * The [Parser] that uses this listener, used to parse optional parts, e.g. | 48 * The [Parser] that uses this listener, used to parse optional parts, e.g. |
| 45 * `native` support. | 49 * `native` support. |
| 46 */ | 50 */ |
| 47 Parser parser; | 51 Parser parser; |
| 48 | 52 |
| 49 bool parseGenericMethodComments = false; | 53 bool parseGenericMethodComments = false; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 167 } |
| 164 } | 168 } |
| 165 elements.add(ast.interpolationString( | 169 elements.add(ast.interpolationString( |
| 166 last, unescapeLastStringPart(last.lexeme, quote))); | 170 last, unescapeLastStringPart(last.lexeme, quote))); |
| 167 push(ast.stringInterpolation(elements)); | 171 push(ast.stringInterpolation(elements)); |
| 168 } | 172 } |
| 169 } | 173 } |
| 170 | 174 |
| 171 void handleScript(Token token) { | 175 void handleScript(Token token) { |
| 172 debugEvent("Script"); | 176 debugEvent("Script"); |
| 173 push(ast.scriptTag(token)); | 177 scriptTag = ast.scriptTag(token); |
| 174 } | 178 } |
| 175 | 179 |
| 176 void handleStringJuxtaposition(int literalCount) { | 180 void handleStringJuxtaposition(int literalCount) { |
| 177 debugEvent("StringJuxtaposition"); | 181 debugEvent("StringJuxtaposition"); |
| 178 push(ast.adjacentStrings(popList(literalCount))); | 182 push(ast.adjacentStrings(popList(literalCount))); |
| 179 } | 183 } |
| 180 | 184 |
| 181 void endArguments(int count, Token beginToken, Token endToken) { | 185 void endArguments(int count, Token beginToken, Token endToken) { |
| 182 debugEvent("Arguments"); | 186 debugEvent("Arguments"); |
| 183 List expressions = popList(count); | 187 List expressions = popList(count); |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 FunctionBody body = pop(); | 1105 FunctionBody body = pop(); |
| 1102 FormalParameterList parameters = pop(); | 1106 FormalParameterList parameters = pop(); |
| 1103 TypeParameterList typeParameters = pop(); | 1107 TypeParameterList typeParameters = pop(); |
| 1104 SimpleIdentifier name = pop(); | 1108 SimpleIdentifier name = pop(); |
| 1105 Token propertyKeyword = getOrSet; | 1109 Token propertyKeyword = getOrSet; |
| 1106 TypeAnnotation returnType = pop(); | 1110 TypeAnnotation returnType = pop(); |
| 1107 _Modifiers modifiers = pop(); | 1111 _Modifiers modifiers = pop(); |
| 1108 Token externalKeyword = modifiers?.externalKeyword; | 1112 Token externalKeyword = modifiers?.externalKeyword; |
| 1109 List<Annotation> metadata = pop(); | 1113 List<Annotation> metadata = pop(); |
| 1110 Comment comment = pop(); | 1114 Comment comment = pop(); |
| 1111 push(ast.functionDeclaration( | 1115 declarations.add(ast.functionDeclaration( |
| 1112 comment, | 1116 comment, |
| 1113 metadata, | 1117 metadata, |
| 1114 externalKeyword, | 1118 externalKeyword, |
| 1115 returnType, | 1119 returnType, |
| 1116 propertyKeyword, | 1120 propertyKeyword, |
| 1117 name, | 1121 name, |
| 1118 ast.functionExpression(typeParameters, parameters, body))); | 1122 ast.functionExpression(typeParameters, parameters, body))); |
| 1119 } | 1123 } |
| 1120 | 1124 |
| 1121 @override | 1125 @override |
| 1122 void endTopLevelDeclaration(Token token) { | 1126 void endTopLevelDeclaration(Token token) { |
| 1123 debugEvent("TopLevelDeclaration"); | 1127 debugEvent("TopLevelDeclaration"); |
| 1124 } | 1128 } |
| 1125 | 1129 |
| 1126 @override | 1130 @override |
| 1127 void handleInvalidTopLevelDeclaration(Token endToken) { | 1131 void handleInvalidTopLevelDeclaration(Token endToken) { |
| 1128 debugEvent("InvalidTopLevelDeclaration"); | 1132 debugEvent("InvalidTopLevelDeclaration"); |
| 1129 pop(); // metadata star | 1133 pop(); // metadata star |
| 1130 // TODO(danrubel): consider creating a AST node | 1134 // TODO(danrubel): consider creating a AST node |
| 1131 // representing the invalid declaration to better support code completion, | 1135 // representing the invalid declaration to better support code completion, |
| 1132 // quick fixes, etc, rather than discarding the metadata and token | 1136 // quick fixes, etc, rather than discarding the metadata and token |
| 1133 push(NullValue.InvalidTopLevelDeclaration); | |
| 1134 } | 1137 } |
| 1135 | 1138 |
| 1136 @override | 1139 @override |
| 1137 void beginCompilationUnit(Token token) { | 1140 void beginCompilationUnit(Token token) { |
| 1138 push(token); | 1141 push(token); |
| 1139 } | 1142 } |
| 1140 | 1143 |
| 1141 @override | 1144 @override |
| 1142 void endCompilationUnit(int count, Token endToken) { | 1145 void endCompilationUnit(int count, Token endToken) { |
| 1143 debugEvent("CompilationUnit"); | 1146 debugEvent("CompilationUnit"); |
| 1144 List<Object> elements = popList(count); | |
| 1145 Token beginToken = pop(); | 1147 Token beginToken = pop(); |
| 1146 | 1148 checkEmpty(endToken.charOffset); |
| 1147 ScriptTag scriptTag = null; | |
| 1148 var directives = <Directive>[]; | |
| 1149 var declarations = <CompilationUnitMember>[]; | |
| 1150 if (elements != null) { | |
| 1151 for (AstNode node in elements) { | |
| 1152 if (node is ScriptTag) { | |
| 1153 scriptTag = node; | |
| 1154 } else if (node is Directive) { | |
| 1155 directives.add(node); | |
| 1156 } else if (node is CompilationUnitMember) { | |
| 1157 declarations.add(node); | |
| 1158 } else if (node == NullValue.InvalidTopLevelDeclaration) { | |
| 1159 // TODO(danrubel): consider creating a AST node | |
| 1160 // representing the invalid declaration | |
| 1161 // to better support code completion, quick fixes, etc, | |
| 1162 // rather than discarding the metadata and token | |
| 1163 } else { | |
| 1164 unhandled( | |
| 1165 "${node.runtimeType}", "compilation unit", node?.offset, uri); | |
| 1166 } | |
| 1167 } | |
| 1168 } | |
| 1169 | 1149 |
| 1170 push(ast.compilationUnit( | 1150 push(ast.compilationUnit( |
| 1171 beginToken, scriptTag, directives, declarations, endToken)); | 1151 beginToken, scriptTag, directives, declarations, endToken)); |
| 1172 } | 1152 } |
| 1173 | 1153 |
| 1174 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, | 1154 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, |
| 1175 Token semicolon) { | 1155 Token semicolon) { |
| 1176 debugEvent("Import"); | 1156 debugEvent("Import"); |
| 1177 List<Combinator> combinators = pop(); | 1157 List<Combinator> combinators = pop(); |
| 1178 SimpleIdentifier prefix; | 1158 SimpleIdentifier prefix; |
| 1179 if (asKeyword != null) prefix = pop(); | 1159 if (asKeyword != null) prefix = pop(); |
| 1180 List<Configuration> configurations = pop(); | 1160 List<Configuration> configurations = pop(); |
| 1181 StringLiteral uri = pop(); | 1161 StringLiteral uri = pop(); |
| 1182 List<Annotation> metadata = pop(); | 1162 List<Annotation> metadata = pop(); |
| 1183 assert(metadata == null); // TODO(paulberry): fix. | 1163 assert(metadata == null); // TODO(paulberry): fix. |
| 1184 Comment comment = pop(); | 1164 Comment comment = pop(); |
| 1185 push(ast.importDirective( | 1165 directives.add(ast.importDirective( |
| 1186 comment, | 1166 comment, |
| 1187 metadata, | 1167 metadata, |
| 1188 importKeyword, | 1168 importKeyword, |
| 1189 uri, | 1169 uri, |
| 1190 configurations, | 1170 configurations, |
| 1191 deferredKeyword, | 1171 deferredKeyword, |
| 1192 asKeyword, | 1172 asKeyword, |
| 1193 prefix, | 1173 prefix, |
| 1194 combinators, | 1174 combinators, |
| 1195 semicolon)); | 1175 semicolon)); |
| 1196 } | 1176 } |
| 1197 | 1177 |
| 1198 void endExport(Token exportKeyword, Token semicolon) { | 1178 void endExport(Token exportKeyword, Token semicolon) { |
| 1199 debugEvent("Export"); | 1179 debugEvent("Export"); |
| 1200 List<Combinator> combinators = pop(); | 1180 List<Combinator> combinators = pop(); |
| 1201 List<Configuration> configurations = pop(); | 1181 List<Configuration> configurations = pop(); |
| 1202 StringLiteral uri = pop(); | 1182 StringLiteral uri = pop(); |
| 1203 List<Annotation> metadata = pop(); | 1183 List<Annotation> metadata = pop(); |
| 1204 assert(metadata == null); | 1184 assert(metadata == null); |
| 1205 Comment comment = pop(); | 1185 Comment comment = pop(); |
| 1206 push(ast.exportDirective(comment, metadata, exportKeyword, uri, | 1186 directives.add(ast.exportDirective(comment, metadata, exportKeyword, uri, |
| 1207 configurations, combinators, semicolon)); | 1187 configurations, combinators, semicolon)); |
| 1208 } | 1188 } |
| 1209 | 1189 |
| 1210 @override | 1190 @override |
| 1211 void endDottedName(int count, Token firstIdentifier) { | 1191 void endDottedName(int count, Token firstIdentifier) { |
| 1212 debugEvent("DottedName"); | 1192 debugEvent("DottedName"); |
| 1213 List<SimpleIdentifier> components = popList(count); | 1193 List<SimpleIdentifier> components = popList(count); |
| 1214 push(ast.dottedName(components)); | 1194 push(ast.dottedName(components)); |
| 1215 } | 1195 } |
| 1216 | 1196 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 extendsKeyword.charOffset, uri); | 1307 extendsKeyword.charOffset, uri); |
| 1328 } | 1308 } |
| 1329 TypeParameterList typeParameters = pop(); | 1309 TypeParameterList typeParameters = pop(); |
| 1330 SimpleIdentifier name = pop(); | 1310 SimpleIdentifier name = pop(); |
| 1331 assert(className == name.name); | 1311 assert(className == name.name); |
| 1332 className = null; | 1312 className = null; |
| 1333 _Modifiers modifiers = pop(); | 1313 _Modifiers modifiers = pop(); |
| 1334 Token abstractKeyword = modifiers?.abstractKeyword; | 1314 Token abstractKeyword = modifiers?.abstractKeyword; |
| 1335 List<Annotation> metadata = pop(); | 1315 List<Annotation> metadata = pop(); |
| 1336 Comment comment = pop(); | 1316 Comment comment = pop(); |
| 1337 push(ast.classDeclaration( | 1317 declarations.add(ast.classDeclaration( |
| 1338 comment, | 1318 comment, |
| 1339 metadata, | 1319 metadata, |
| 1340 abstractKeyword, | 1320 abstractKeyword, |
| 1341 classKeyword, | 1321 classKeyword, |
| 1342 name, | 1322 name, |
| 1343 typeParameters, | 1323 typeParameters, |
| 1344 extendsClause, | 1324 extendsClause, |
| 1345 withClause, | 1325 withClause, |
| 1346 implementsClause, | 1326 implementsClause, |
| 1347 body.beginToken, | 1327 body.beginToken, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1370 var superclass = mixinApplication.supertype; | 1350 var superclass = mixinApplication.supertype; |
| 1371 var withClause = ast.withClause( | 1351 var withClause = ast.withClause( |
| 1372 mixinApplication.withKeyword, mixinApplication.mixinTypes); | 1352 mixinApplication.withKeyword, mixinApplication.mixinTypes); |
| 1373 Token equals = equalsToken; | 1353 Token equals = equalsToken; |
| 1374 TypeParameterList typeParameters = pop(); | 1354 TypeParameterList typeParameters = pop(); |
| 1375 SimpleIdentifier name = pop(); | 1355 SimpleIdentifier name = pop(); |
| 1376 _Modifiers modifiers = pop(); | 1356 _Modifiers modifiers = pop(); |
| 1377 Token abstractKeyword = modifiers?.abstractKeyword; | 1357 Token abstractKeyword = modifiers?.abstractKeyword; |
| 1378 List<Annotation> metadata = pop(); | 1358 List<Annotation> metadata = pop(); |
| 1379 Comment comment = pop(); | 1359 Comment comment = pop(); |
| 1380 push(ast.classTypeAlias( | 1360 declarations.add(ast.classTypeAlias( |
| 1381 comment, | 1361 comment, |
| 1382 metadata, | 1362 metadata, |
| 1383 classKeyword, | 1363 classKeyword, |
| 1384 name, | 1364 name, |
| 1385 typeParameters, | 1365 typeParameters, |
| 1386 equals, | 1366 equals, |
| 1387 abstractKeyword, | 1367 abstractKeyword, |
| 1388 superclass, | 1368 superclass, |
| 1389 withClause, | 1369 withClause, |
| 1390 implementsClause, | 1370 implementsClause, |
| 1391 endToken)); | 1371 endToken)); |
| 1392 } | 1372 } |
| 1393 | 1373 |
| 1394 @override | 1374 @override |
| 1395 void endLabeledStatement(int labelCount) { | 1375 void endLabeledStatement(int labelCount) { |
| 1396 debugEvent("LabeledStatement"); | 1376 debugEvent("LabeledStatement"); |
| 1397 Statement statement = pop(); | 1377 Statement statement = pop(); |
| 1398 List<Label> labels = popList(labelCount); | 1378 List<Label> labels = popList(labelCount); |
| 1399 push(ast.labeledStatement(labels, statement)); | 1379 push(ast.labeledStatement(labels, statement)); |
| 1400 } | 1380 } |
| 1401 | 1381 |
| 1402 @override | 1382 @override |
| 1403 void endLibraryName(Token libraryKeyword, Token semicolon) { | 1383 void endLibraryName(Token libraryKeyword, Token semicolon) { |
| 1404 debugEvent("LibraryName"); | 1384 debugEvent("LibraryName"); |
| 1405 List<SimpleIdentifier> libraryName = pop(); | 1385 List<SimpleIdentifier> libraryName = pop(); |
| 1406 var name = ast.libraryIdentifier(libraryName); | 1386 var name = ast.libraryIdentifier(libraryName); |
| 1407 List<Annotation> metadata = pop(); | 1387 List<Annotation> metadata = pop(); |
| 1408 Comment comment = pop(); | 1388 Comment comment = pop(); |
| 1409 push(ast.libraryDirective( | 1389 directives.add(ast.libraryDirective( |
| 1410 comment, metadata, libraryKeyword, name, semicolon)); | 1390 comment, metadata, libraryKeyword, name, semicolon)); |
| 1411 } | 1391 } |
| 1412 | 1392 |
| 1413 @override | 1393 @override |
| 1414 void handleQualified(Token period) { | 1394 void handleQualified(Token period) { |
| 1415 SimpleIdentifier identifier = pop(); | 1395 SimpleIdentifier identifier = pop(); |
| 1416 var prefix = pop(); | 1396 var prefix = pop(); |
| 1417 if (prefix is List) { | 1397 if (prefix is List) { |
| 1418 // We're just accumulating components into a list. | 1398 // We're just accumulating components into a list. |
| 1419 prefix.add(identifier); | 1399 prefix.add(identifier); |
| 1420 push(prefix); | 1400 push(prefix); |
| 1421 } else if (prefix is SimpleIdentifier) { | 1401 } else if (prefix is SimpleIdentifier) { |
| 1422 // TODO(paulberry): resolve [identifier]. Note that BodyBuilder handles | 1402 // TODO(paulberry): resolve [identifier]. Note that BodyBuilder handles |
| 1423 // this situation using SendAccessor. | 1403 // this situation using SendAccessor. |
| 1424 push(ast.prefixedIdentifier(prefix, period, identifier)); | 1404 push(ast.prefixedIdentifier(prefix, period, identifier)); |
| 1425 } else { | 1405 } else { |
| 1426 // TODO(paulberry): implement. | 1406 // TODO(paulberry): implement. |
| 1427 logEvent('Qualified with >1 dot'); | 1407 logEvent('Qualified with >1 dot'); |
| 1428 } | 1408 } |
| 1429 } | 1409 } |
| 1430 | 1410 |
| 1431 @override | 1411 @override |
| 1432 void endPart(Token partKeyword, Token semicolon) { | 1412 void endPart(Token partKeyword, Token semicolon) { |
| 1433 debugEvent("Part"); | 1413 debugEvent("Part"); |
| 1434 StringLiteral uri = pop(); | 1414 StringLiteral uri = pop(); |
| 1435 List<Annotation> metadata = pop(); | 1415 List<Annotation> metadata = pop(); |
| 1436 Comment comment = pop(); | 1416 Comment comment = pop(); |
| 1437 push(ast.partDirective(comment, metadata, partKeyword, uri, semicolon)); | 1417 directives |
| 1418 .add(ast.partDirective(comment, metadata, partKeyword, uri, semicolon)); |
| 1438 } | 1419 } |
| 1439 | 1420 |
| 1440 @override | 1421 @override |
| 1441 void endPartOf(Token partKeyword, Token semicolon, bool hasName) { | 1422 void endPartOf(Token partKeyword, Token semicolon, bool hasName) { |
| 1442 debugEvent("PartOf"); | 1423 debugEvent("PartOf"); |
| 1443 List<SimpleIdentifier> libraryName = pop(); | 1424 List<SimpleIdentifier> libraryName = pop(); |
| 1444 var name = ast.libraryIdentifier(libraryName); | 1425 var name = ast.libraryIdentifier(libraryName); |
| 1445 StringLiteral uri = null; // TODO(paulberry) | 1426 StringLiteral uri = null; // TODO(paulberry) |
| 1446 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed | 1427 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed |
| 1447 // in a reference to the "of" keyword. | 1428 // in a reference to the "of" keyword. |
| 1448 var ofKeyword = partKeyword.next; | 1429 var ofKeyword = partKeyword.next; |
| 1449 List<Annotation> metadata = pop(); | 1430 List<Annotation> metadata = pop(); |
| 1450 Comment comment = pop(); | 1431 Comment comment = pop(); |
| 1451 push(ast.partOfDirective( | 1432 directives.add(ast.partOfDirective( |
| 1452 comment, metadata, partKeyword, ofKeyword, uri, name, semicolon)); | 1433 comment, metadata, partKeyword, ofKeyword, uri, name, semicolon)); |
| 1453 } | 1434 } |
| 1454 | 1435 |
| 1455 @override | 1436 @override |
| 1456 void endFunctionExpression(Token beginToken, Token token) { | 1437 void endFunctionExpression(Token beginToken, Token token) { |
| 1457 // TODO(paulberry): set up scopes properly to resolve parameters and type | 1438 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 1458 // variables. Note that this is tricky due to the handling of initializers | 1439 // variables. Note that this is tricky due to the handling of initializers |
| 1459 // in constructors, so the logic should be shared with BodyBuilder as much | 1440 // in constructors, so the logic should be shared with BodyBuilder as much |
| 1460 // as possible. | 1441 // as possible. |
| 1461 debugEvent("FunctionExpression"); | 1442 debugEvent("FunctionExpression"); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 void endTopLevelFields(int count, Token beginToken, Token endToken) { | 1549 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
| 1569 debugEvent("TopLevelFields"); | 1550 debugEvent("TopLevelFields"); |
| 1570 List<VariableDeclaration> variables = popList(count); | 1551 List<VariableDeclaration> variables = popList(count); |
| 1571 TypeAnnotation type = pop(); | 1552 TypeAnnotation type = pop(); |
| 1572 _Modifiers modifiers = pop(); | 1553 _Modifiers modifiers = pop(); |
| 1573 Token keyword = modifiers?.finalConstOrVarKeyword; | 1554 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 1574 var variableList = | 1555 var variableList = |
| 1575 ast.variableDeclarationList(null, null, keyword, type, variables); | 1556 ast.variableDeclarationList(null, null, keyword, type, variables); |
| 1576 List<Annotation> metadata = pop(); | 1557 List<Annotation> metadata = pop(); |
| 1577 Comment comment = pop(); | 1558 Comment comment = pop(); |
| 1578 push(ast.topLevelVariableDeclaration( | 1559 declarations.add(ast.topLevelVariableDeclaration( |
| 1579 comment, metadata, variableList, endToken)); | 1560 comment, metadata, variableList, endToken)); |
| 1580 } | 1561 } |
| 1581 | 1562 |
| 1582 @override | 1563 @override |
| 1583 void endTypeVariable(Token token, Token extendsOrSuper) { | 1564 void endTypeVariable(Token token, Token extendsOrSuper) { |
| 1584 // TODO(paulberry): set up scopes properly to resolve parameters and type | 1565 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 1585 // variables. Note that this is tricky due to the handling of initializers | 1566 // variables. Note that this is tricky due to the handling of initializers |
| 1586 // in constructors, so the logic should be shared with BodyBuilder as much | 1567 // in constructors, so the logic should be shared with BodyBuilder as much |
| 1587 // as possible. | 1568 // as possible. |
| 1588 debugEvent("TypeVariable"); | 1569 debugEvent("TypeVariable"); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 void endFunctionTypeAlias( | 1663 void endFunctionTypeAlias( |
| 1683 Token typedefKeyword, Token equals, Token endToken) { | 1664 Token typedefKeyword, Token equals, Token endToken) { |
| 1684 debugEvent("FunctionTypeAlias"); | 1665 debugEvent("FunctionTypeAlias"); |
| 1685 if (equals == null) { | 1666 if (equals == null) { |
| 1686 FormalParameterList parameters = pop(); | 1667 FormalParameterList parameters = pop(); |
| 1687 TypeParameterList typeParameters = pop(); | 1668 TypeParameterList typeParameters = pop(); |
| 1688 SimpleIdentifier name = pop(); | 1669 SimpleIdentifier name = pop(); |
| 1689 TypeAnnotation returnType = pop(); | 1670 TypeAnnotation returnType = pop(); |
| 1690 List<Annotation> metadata = pop(); | 1671 List<Annotation> metadata = pop(); |
| 1691 Comment comment = pop(); | 1672 Comment comment = pop(); |
| 1692 push(ast.functionTypeAlias(comment, metadata, typedefKeyword, returnType, | 1673 declarations.add(ast.functionTypeAlias(comment, metadata, typedefKeyword, |
| 1693 name, typeParameters, parameters, endToken)); | 1674 returnType, name, typeParameters, parameters, endToken)); |
| 1694 } else { | 1675 } else { |
| 1695 TypeAnnotation type = pop(); | 1676 TypeAnnotation type = pop(); |
| 1696 TypeParameterList templateParameters = pop(); | 1677 TypeParameterList templateParameters = pop(); |
| 1697 SimpleIdentifier name = pop(); | 1678 SimpleIdentifier name = pop(); |
| 1698 List<Annotation> metadata = pop(); | 1679 List<Annotation> metadata = pop(); |
| 1699 Comment comment = pop(); | 1680 Comment comment = pop(); |
| 1700 if (type is! GenericFunctionType) { | 1681 if (type is! GenericFunctionType) { |
| 1701 // TODO(paulberry) Generate an error and recover (better than | 1682 // TODO(paulberry) Generate an error and recover (better than |
| 1702 // this). | 1683 // this). |
| 1703 type = null; | 1684 type = null; |
| 1704 } | 1685 } |
| 1705 push(ast.genericTypeAlias(comment, metadata, typedefKeyword, name, | 1686 declarations.add(ast.genericTypeAlias(comment, metadata, typedefKeyword, |
| 1706 templateParameters, equals, type, endToken)); | 1687 name, templateParameters, equals, type, endToken)); |
| 1707 } | 1688 } |
| 1708 } | 1689 } |
| 1709 | 1690 |
| 1710 @override | 1691 @override |
| 1711 void endEnum(Token enumKeyword, Token endBrace, int count) { | 1692 void endEnum(Token enumKeyword, Token endBrace, int count) { |
| 1712 debugEvent("Enum"); | 1693 debugEvent("Enum"); |
| 1713 List<EnumConstantDeclaration> constants = popList(count); | 1694 List<EnumConstantDeclaration> constants = popList(count); |
| 1714 // TODO(paulberry,ahe): the parser should pass in the openBrace token. | 1695 // TODO(paulberry,ahe): the parser should pass in the openBrace token. |
| 1715 var openBrace = enumKeyword.next.next as analyzer.BeginToken; | 1696 var openBrace = enumKeyword.next.next as analyzer.BeginToken; |
| 1716 // TODO(paulberry): what if the '}' is missing and the parser has performed | 1697 // TODO(paulberry): what if the '}' is missing and the parser has performed |
| 1717 // error recovery? | 1698 // error recovery? |
| 1718 Token closeBrace = openBrace.endGroup; | 1699 Token closeBrace = openBrace.endGroup; |
| 1719 SimpleIdentifier name = pop(); | 1700 SimpleIdentifier name = pop(); |
| 1720 List<Annotation> metadata = pop(); | 1701 List<Annotation> metadata = pop(); |
| 1721 Comment comment = pop(); | 1702 Comment comment = pop(); |
| 1722 push(ast.enumDeclaration(comment, metadata, enumKeyword, name, openBrace, | 1703 declarations.add(ast.enumDeclaration(comment, metadata, enumKeyword, name, |
| 1723 constants, closeBrace)); | 1704 openBrace, constants, closeBrace)); |
| 1724 } | 1705 } |
| 1725 | 1706 |
| 1726 @override | 1707 @override |
| 1727 void endTypeArguments(int count, Token beginToken, Token endToken) { | 1708 void endTypeArguments(int count, Token beginToken, Token endToken) { |
| 1728 debugEvent("TypeArguments"); | 1709 debugEvent("TypeArguments"); |
| 1729 List<TypeAnnotation> arguments = popList(count); | 1710 List<TypeAnnotation> arguments = popList(count); |
| 1730 push(ast.typeArgumentList(beginToken, arguments, endToken)); | 1711 push(ast.typeArgumentList(beginToken, arguments, endToken)); |
| 1731 } | 1712 } |
| 1732 | 1713 |
| 1733 @override | 1714 @override |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1746 metadata: metadata, | 1727 metadata: metadata, |
| 1747 covariantKeyword: covariantKeyword, | 1728 covariantKeyword: covariantKeyword, |
| 1748 staticKeyword: modifiers?.staticKeyword, | 1729 staticKeyword: modifiers?.staticKeyword, |
| 1749 fieldList: variableList, | 1730 fieldList: variableList, |
| 1750 semicolon: endToken)); | 1731 semicolon: endToken)); |
| 1751 } | 1732 } |
| 1752 | 1733 |
| 1753 @override | 1734 @override |
| 1754 AstNode finishFields() { | 1735 AstNode finishFields() { |
| 1755 debugEvent("finishFields"); | 1736 debugEvent("finishFields"); |
| 1756 return pop(); | 1737 return declarations.removeLast(); |
| 1757 } | 1738 } |
| 1758 | 1739 |
| 1759 @override | 1740 @override |
| 1760 void handleOperatorName(Token operatorKeyword, Token token) { | 1741 void handleOperatorName(Token operatorKeyword, Token token) { |
| 1761 debugEvent("OperatorName"); | 1742 debugEvent("OperatorName"); |
| 1762 push(new _OperatorName( | 1743 push(new _OperatorName( |
| 1763 operatorKeyword, ast.simpleIdentifier(token, isDeclaration: true))); | 1744 operatorKeyword, ast.simpleIdentifier(token, isDeclaration: true))); |
| 1764 } | 1745 } |
| 1765 | 1746 |
| 1766 @override | 1747 @override |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 } else if (identical('var', s)) { | 2006 } else if (identical('var', s)) { |
| 2026 finalConstOrVarKeyword = token; | 2007 finalConstOrVarKeyword = token; |
| 2027 } else if (identical('covariant', s)) { | 2008 } else if (identical('covariant', s)) { |
| 2028 covariantKeyword = token; | 2009 covariantKeyword = token; |
| 2029 } else { | 2010 } else { |
| 2030 unhandled("$s", "modifier", token.charOffset, null); | 2011 unhandled("$s", "modifier", token.charOffset, null); |
| 2031 } | 2012 } |
| 2032 } | 2013 } |
| 2033 } | 2014 } |
| 2034 } | 2015 } |
| OLD | NEW |