| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
| 6 | 6 |
| 7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
| 8 import com.google.common.collect.ImmutableSet; | 8 import com.google.common.collect.ImmutableSet; |
| 9 import com.google.common.io.CharStreams; | 9 import com.google.common.io.CharStreams; |
| 10 import com.google.dart.compiler.DartCompilationError; | 10 import com.google.dart.compiler.DartCompilationError; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 import com.google.dart.compiler.ast.DartFunctionTypeAlias; | 44 import com.google.dart.compiler.ast.DartFunctionTypeAlias; |
| 45 import com.google.dart.compiler.ast.DartIdentifier; | 45 import com.google.dart.compiler.ast.DartIdentifier; |
| 46 import com.google.dart.compiler.ast.DartIfStatement; | 46 import com.google.dart.compiler.ast.DartIfStatement; |
| 47 import com.google.dart.compiler.ast.DartImportDirective; | 47 import com.google.dart.compiler.ast.DartImportDirective; |
| 48 import com.google.dart.compiler.ast.DartInitializer; | 48 import com.google.dart.compiler.ast.DartInitializer; |
| 49 import com.google.dart.compiler.ast.DartIntegerLiteral; | 49 import com.google.dart.compiler.ast.DartIntegerLiteral; |
| 50 import com.google.dart.compiler.ast.DartLabel; | 50 import com.google.dart.compiler.ast.DartLabel; |
| 51 import com.google.dart.compiler.ast.DartLibraryDirective; | 51 import com.google.dart.compiler.ast.DartLibraryDirective; |
| 52 import com.google.dart.compiler.ast.DartMapLiteral; | 52 import com.google.dart.compiler.ast.DartMapLiteral; |
| 53 import com.google.dart.compiler.ast.DartMapLiteralEntry; | 53 import com.google.dart.compiler.ast.DartMapLiteralEntry; |
| 54 import com.google.dart.compiler.ast.DartAnnotation; |
| 54 import com.google.dart.compiler.ast.DartMethodDefinition; | 55 import com.google.dart.compiler.ast.DartMethodDefinition; |
| 55 import com.google.dart.compiler.ast.DartMethodInvocation; | 56 import com.google.dart.compiler.ast.DartMethodInvocation; |
| 56 import com.google.dart.compiler.ast.DartNamedExpression; | 57 import com.google.dart.compiler.ast.DartNamedExpression; |
| 57 import com.google.dart.compiler.ast.DartNativeBlock; | 58 import com.google.dart.compiler.ast.DartNativeBlock; |
| 58 import com.google.dart.compiler.ast.DartNativeDirective; | 59 import com.google.dart.compiler.ast.DartNativeDirective; |
| 59 import com.google.dart.compiler.ast.DartNewExpression; | 60 import com.google.dart.compiler.ast.DartNewExpression; |
| 60 import com.google.dart.compiler.ast.DartNode; | 61 import com.google.dart.compiler.ast.DartNode; |
| 62 import com.google.dart.compiler.ast.DartNodeWithMetadata; |
| 61 import com.google.dart.compiler.ast.DartNullLiteral; | 63 import com.google.dart.compiler.ast.DartNullLiteral; |
| 62 import com.google.dart.compiler.ast.DartParameter; | 64 import com.google.dart.compiler.ast.DartParameter; |
| 63 import com.google.dart.compiler.ast.DartParameterizedTypeNode; | 65 import com.google.dart.compiler.ast.DartParameterizedTypeNode; |
| 64 import com.google.dart.compiler.ast.DartParenthesizedExpression; | 66 import com.google.dart.compiler.ast.DartParenthesizedExpression; |
| 65 import com.google.dart.compiler.ast.DartPartOfDirective; | 67 import com.google.dart.compiler.ast.DartPartOfDirective; |
| 66 import com.google.dart.compiler.ast.DartPropertyAccess; | 68 import com.google.dart.compiler.ast.DartPropertyAccess; |
| 67 import com.google.dart.compiler.ast.DartRedirectConstructorInvocation; | 69 import com.google.dart.compiler.ast.DartRedirectConstructorInvocation; |
| 68 import com.google.dart.compiler.ast.DartReturnBlock; | 70 import com.google.dart.compiler.ast.DartReturnBlock; |
| 69 import com.google.dart.compiler.ast.DartReturnStatement; | 71 import com.google.dart.compiler.ast.DartReturnStatement; |
| 70 import com.google.dart.compiler.ast.DartSourceDirective; | 72 import com.google.dart.compiler.ast.DartSourceDirective; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 298 |
| 297 try { | 299 try { |
| 298 beginCompilationUnit(); | 300 beginCompilationUnit(); |
| 299 ctx.unitAboutToCompile(dartSource, isDietParse); | 301 ctx.unitAboutToCompile(dartSource, isDietParse); |
| 300 DartUnit unit = new DartUnit(dartSource, isDietParse); | 302 DartUnit unit = new DartUnit(dartSource, isDietParse); |
| 301 | 303 |
| 302 // parse any directives at the beginning of the source | 304 // parse any directives at the beginning of the source |
| 303 parseDirectives(unit); | 305 parseDirectives(unit); |
| 304 | 306 |
| 305 while (!EOS()) { | 307 while (!EOS()) { |
| 306 DartNode node = null; | 308 DartNodeWithMetadata node = null; |
| 307 beginTopLevelElement(); | 309 beginTopLevelElement(); |
| 310 List<DartAnnotation> metadata = parseMetadata(); |
| 308 isParsingClass = isParsingInterface = false; | 311 isParsingClass = isParsingInterface = false; |
| 309 // Check for ABSTRACT_KEYWORD. | 312 // Check for ABSTRACT_KEYWORD. |
| 310 isTopLevelAbstract = false; | 313 isTopLevelAbstract = false; |
| 311 topLevelAbstractModifierPosition = 0; | 314 topLevelAbstractModifierPosition = 0; |
| 312 if (optionalPseudoKeyword(ABSTRACT_KEYWORD)) { | 315 if (optionalPseudoKeyword(ABSTRACT_KEYWORD)) { |
| 313 isTopLevelAbstract = true; | 316 isTopLevelAbstract = true; |
| 314 topLevelAbstractModifierPosition = position(); | 317 topLevelAbstractModifierPosition = position(); |
| 315 } | 318 } |
| 316 // Parse top level element. | 319 // Parse top level element. |
| 317 if (optional(Token.CLASS)) { | 320 if (optional(Token.CLASS)) { |
| 318 isParsingClass = true; | 321 isParsingClass = true; |
| 319 node = done(parseClass()); | 322 node = done(parseClass()); |
| 320 } else if (peekPseudoKeyword(0, INTERFACE_KEYWORD) && peek(1).equals(Tok
en.IDENTIFIER)) { | 323 } else if (peekPseudoKeyword(0, INTERFACE_KEYWORD) && peek(1).equals(Tok
en.IDENTIFIER)) { |
| 321 consume(Token.IDENTIFIER); | 324 consume(Token.IDENTIFIER); |
| 322 isParsingInterface = true; | 325 isParsingInterface = true; |
| 323 node = done(parseClass()); | 326 node = done(parseClass()); |
| 324 } else if (peekPseudoKeyword(0, TYPEDEF_KEYWORD) | 327 } else if (peekPseudoKeyword(0, TYPEDEF_KEYWORD) |
| 325 && (peek(1).equals(Token.IDENTIFIER) || peek(1).equals(Token.VOID)))
{ | 328 && (peek(1).equals(Token.IDENTIFIER) || peek(1).equals(Token.VOID)))
{ |
| 326 consume(Token.IDENTIFIER); | 329 consume(Token.IDENTIFIER); |
| 327 node = done(parseFunctionTypeAlias()); | 330 node = done(parseFunctionTypeAlias()); |
| 328 } else if (looksLikeDirective()) { | 331 } else if (looksLikeDirective()) { |
| 329 reportErrorWithoutAdvancing(ParserErrorCode.DIRECTIVE_OUT_OF_ORDER); | 332 reportErrorWithoutAdvancing(ParserErrorCode.DIRECTIVE_OUT_OF_ORDER); |
| 330 parseDirectives(unit); | 333 parseDirectives(unit); |
| 331 } else { | 334 } else { |
| 332 node = done(parseFieldOrMethod(false)); | 335 node = done(parseFieldOrMethod(false)); |
| 333 } | 336 } |
| 334 // Parsing was successful, add node. | 337 // Parsing was successful, add node. |
| 335 if (node != null) { | 338 if (node != null) { |
| 339 node.setMetadata(metadata); |
| 336 unit.getTopLevelNodes().add(node); | 340 unit.getTopLevelNodes().add(node); |
| 337 // Only "class" can be top-level abstract element. | 341 // Only "class" can be top-level abstract element. |
| 338 if (isTopLevelAbstract && !isParsingClass) { | 342 if (isTopLevelAbstract && !isParsingClass) { |
| 339 int abstractPositionEnd = topLevelAbstractModifierPosition + ABSTRAC
T_KEYWORD.length(); | 343 int abstractPositionEnd = topLevelAbstractModifierPosition + ABSTRAC
T_KEYWORD.length(); |
| 340 Location location = new Location(topLevelAbstractModifierPosition, a
bstractPositionEnd); | 344 Location location = new Location(topLevelAbstractModifierPosition, a
bstractPositionEnd); |
| 341 reportError(new DartCompilationError(source, location, | 345 reportError(new DartCompilationError(source, location, |
| 342 ParserErrorCode.ABSTRACT_TOP_LEVEL_ELEMENT)); | 346 ParserErrorCode.ABSTRACT_TOP_LEVEL_ELEMENT)); |
| 343 } | 347 } |
| 344 } | 348 } |
| 345 } | 349 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 nativePath.setSourceInfo(nativeDirective.getSourceInfo()); | 469 nativePath.setSourceInfo(nativeDirective.getSourceInfo()); |
| 466 libUnit.addNativePath(nativePath); | 470 libUnit.addNativePath(nativePath); |
| 467 } | 471 } |
| 468 | 472 |
| 469 // add ourselves to the list of sources, so inline dart code will be parsed | 473 // add ourselves to the list of sources, so inline dart code will be parsed |
| 470 libUnit.addSourcePath(libUnit.getSelfSourcePath()); | 474 libUnit.addSourcePath(libUnit.getSelfSourcePath()); |
| 471 return done(libUnit); | 475 return done(libUnit); |
| 472 } | 476 } |
| 473 | 477 |
| 474 private void parseDirectives(DartUnit unit) { | 478 private void parseDirectives(DartUnit unit) { |
| 479 List<DartAnnotation> metadata = parseMetadata(); |
| 475 if (peekPseudoKeyword(0, LIBRARY_KEYWORD)) { | 480 if (peekPseudoKeyword(0, LIBRARY_KEYWORD)) { |
| 476 DartLibraryDirective libraryDirective = parseLibraryDirective(); | 481 DartLibraryDirective libraryDirective = parseLibraryDirective(); |
| 477 for (DartDirective directive : unit.getDirectives()) { | 482 for (DartDirective directive : unit.getDirectives()) { |
| 478 if (directive instanceof DartLibraryDirective) { | 483 if (directive instanceof DartLibraryDirective) { |
| 479 reportError(position(), ParserErrorCode.ONLY_ONE_LIBRARY_DIRECTIVE); | 484 reportError(position(), ParserErrorCode.ONLY_ONE_LIBRARY_DIRECTIVE); |
| 480 break; | 485 break; |
| 481 } | 486 } |
| 482 } | 487 } |
| 488 libraryDirective.setMetadata(metadata); |
| 483 unit.getDirectives().add(libraryDirective); | 489 unit.getDirectives().add(libraryDirective); |
| 484 } | 490 } |
| 485 while (peekPseudoKeyword(0, IMPORT_KEYWORD)) { | 491 while (peekPseudoKeyword(0, IMPORT_KEYWORD)) { |
| 486 unit.getDirectives().add(parseImportDirective()); | 492 DartImportDirective importDirective = parseImportDirective(); |
| 493 importDirective.setMetadata(metadata); |
| 494 unit.getDirectives().add(importDirective); |
| 487 } | 495 } |
| 488 while (peekPseudoKeyword(0, PART_KEYWORD)) { | 496 while (peekPseudoKeyword(0, PART_KEYWORD)) { |
| 489 if (peekPseudoKeyword(1, OF_KEYWORD)) { | 497 if (peekPseudoKeyword(1, OF_KEYWORD)) { |
| 490 unit.getDirectives().add(parsePartOfDirective()); | 498 DartPartOfDirective partOfDirective = parsePartOfDirective(); |
| 499 partOfDirective.setMetadata(metadata); |
| 500 unit.getDirectives().add(partOfDirective); |
| 491 } else { | 501 } else { |
| 492 unit.getDirectives().add(parsePartDirective()); | 502 DartSourceDirective partDirective = parsePartDirective(); |
| 503 partDirective.setMetadata(metadata); |
| 504 unit.getDirectives().add(partDirective); |
| 493 } | 505 } |
| 494 } | 506 } |
| 495 // | 507 // |
| 496 // The code below is obsolete. We do not make any effort to find duplication
s between the old | 508 // The code below is obsolete. We do not make any effort to find duplication
s between the old |
| 497 // and the new syntax because support for the old syntax will be removed ver
y soon. | 509 // and the new syntax because support for the old syntax will be removed ver
y soon. |
| 498 // | 510 // |
| 499 if (peek(0) == Token.LIBRARY) { | 511 if (peek(0) == Token.LIBRARY) { |
| 500 beginLibraryDirective(); | 512 beginLibraryDirective(); |
| 501 DartLibraryDirective libraryDirective = parseObsoleteLibraryDirective(); | 513 DartLibraryDirective libraryDirective = parseObsoleteLibraryDirective(); |
| 502 for (DartDirective directive : unit.getDirectives()) { | 514 for (DartDirective directive : unit.getDirectives()) { |
| 503 if (directive instanceof DartLibraryDirective) { | 515 if (directive instanceof DartLibraryDirective) { |
| 504 reportError(position(), ParserErrorCode.ONLY_ONE_LIBRARY_DIRECTIVE); | 516 reportError(position(), ParserErrorCode.ONLY_ONE_LIBRARY_DIRECTIVE); |
| 505 break; | 517 break; |
| 506 } | 518 } |
| 507 } | 519 } |
| 520 libraryDirective.setMetadata(metadata); |
| 508 unit.getDirectives().add(libraryDirective); | 521 unit.getDirectives().add(libraryDirective); |
| 509 done(libraryDirective); | 522 done(libraryDirective); |
| 510 } | 523 } |
| 511 while (peek(0) == Token.IMPORT) { | 524 while (peek(0) == Token.IMPORT) { |
| 512 beginImportDirective(); | 525 beginImportDirective(); |
| 513 unit.getDirectives().add(done(parseObsoleteImportDirective())); | 526 DartImportDirective importDirective = parseObsoleteImportDirective(); |
| 527 importDirective.setMetadata(metadata); |
| 528 unit.getDirectives().add(done(importDirective)); |
| 514 } | 529 } |
| 515 while (peek(0) == Token.SOURCE) { | 530 while (peek(0) == Token.SOURCE) { |
| 516 beginSourceDirective(); | 531 beginSourceDirective(); |
| 517 unit.getDirectives().add(done(parseSourceDirective())); | 532 DartSourceDirective sourceDirective = parseSourceDirective(); |
| 533 sourceDirective.setMetadata(metadata); |
| 534 unit.getDirectives().add(done(sourceDirective)); |
| 518 } | 535 } |
| 519 while (peek(0) == Token.RESOURCE) { | 536 while (peek(0) == Token.RESOURCE) { |
| 520 parseResourceDirective(); | 537 parseResourceDirective(); |
| 521 } | 538 } |
| 522 while (peek(0) == Token.NATIVE) { | 539 while (peek(0) == Token.NATIVE) { |
| 523 beginNativeDirective(); | 540 beginNativeDirective(); |
| 524 unit.getDirectives().add(done(parseNativeDirective())); | 541 DartNativeDirective nativeDirective = parseNativeDirective(); |
| 542 nativeDirective.setMetadata(metadata); |
| 543 unit.getDirectives().add(done(nativeDirective)); |
| 525 } | 544 } |
| 526 } | 545 } |
| 527 | 546 |
| 528 private DartLibraryDirective parseLibraryDirective() { | 547 private DartLibraryDirective parseLibraryDirective() { |
| 529 beginLibraryDirective(); | 548 beginLibraryDirective(); |
| 530 next(); // "library" | 549 next(); // "library" |
| 531 DartExpression libraryName = parseLibraryName(); | 550 DartExpression libraryName = parseLibraryName(); |
| 532 expect(Token.SEMICOLON); | 551 expect(Token.SEMICOLON); |
| 533 return done(new DartLibraryDirective(libraryName)); | 552 return done(new DartLibraryDirective(libraryName)); |
| 534 } | 553 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 expect(Token.NATIVE); | 708 expect(Token.NATIVE); |
| 690 expect(Token.LPAREN); | 709 expect(Token.LPAREN); |
| 691 beginLiteral(); | 710 beginLiteral(); |
| 692 expect(Token.STRING); | 711 expect(Token.STRING); |
| 693 DartStringLiteral nativeUri = done(DartStringLiteral.get(ctx.getTokenString(
))); | 712 DartStringLiteral nativeUri = done(DartStringLiteral.get(ctx.getTokenString(
))); |
| 694 expect(Token.RPAREN); | 713 expect(Token.RPAREN); |
| 695 expect(Token.SEMICOLON); | 714 expect(Token.SEMICOLON); |
| 696 return new DartNativeDirective(nativeUri); | 715 return new DartNativeDirective(nativeUri); |
| 697 } | 716 } |
| 698 | 717 |
| 718 private List<DartAnnotation> parseMetadata() { |
| 719 List<DartAnnotation> metadata = new ArrayList<DartAnnotation>(); |
| 720 while (match(Token.AT)) { |
| 721 beginMetadata(); |
| 722 next(); |
| 723 beginQualifiedIdentifier(); |
| 724 DartExpression name = parseQualified(); |
| 725 if (optional(Token.PERIOD)) { |
| 726 name = new DartPropertyAccess(name, parseIdentifier()); |
| 727 } |
| 728 done(name); |
| 729 List<DartExpression> arguments = null; |
| 730 if (match(Token.LPAREN)) { |
| 731 arguments = parseArguments(); |
| 732 } |
| 733 metadata.add(done(new DartAnnotation(name, arguments))); |
| 734 } |
| 735 return metadata; |
| 736 } |
| 737 |
| 699 /** | 738 /** |
| 700 * <pre> | 739 * <pre> |
| 701 * typeParameter | 740 * typeParameter |
| 702 * : identifier (EXTENDS type)? | 741 * : identifier (EXTENDS type)? |
| 703 * ; | 742 * ; |
| 704 * | 743 * |
| 705 * typeParameters | 744 * typeParameters |
| 706 * : '<' typeParameter (',' typeParameter)* '>' | 745 * : '<' typeParameter (',' typeParameter)* '>' |
| 707 * ; | 746 * ; |
| 708 * </pre> | 747 * </pre> |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 members, | 918 members, |
| 880 typeParameters, | 919 typeParameters, |
| 881 modifiers)); | 920 modifiers)); |
| 882 } | 921 } |
| 883 } | 922 } |
| 884 | 923 |
| 885 /** | 924 /** |
| 886 * Helper for {@link #parseClass()}. | 925 * Helper for {@link #parseClass()}. |
| 887 * | 926 * |
| 888 * '{' classMemberDefinition* '}' | 927 * '{' classMemberDefinition* '}' |
| 889 * | |
| 890 */ | 928 */ |
| 891 @Terminals(tokens={Token.RBRACE, Token.SEMICOLON}) | 929 @Terminals(tokens={Token.RBRACE, Token.SEMICOLON}) |
| 892 private void parseClassOrInterfaceBody(List<DartNode> members) { | 930 private void parseClassOrInterfaceBody(List<DartNode> members) { |
| 893 if (optional(Token.LBRACE)) { | 931 if (optional(Token.LBRACE)) { |
| 894 while (!match(Token.RBRACE) && !EOS() && !looksLikeTopLevelKeyword()) { | 932 while (!match(Token.RBRACE) && !EOS() && !looksLikeTopLevelKeyword()) { |
| 895 DartNode member = parseFieldOrMethod(true); | 933 List<DartAnnotation> metadata = parseMetadata(); |
| 934 DartNodeWithMetadata member = parseFieldOrMethod(true); |
| 896 if (member != null) { | 935 if (member != null) { |
| 936 member.setMetadata(metadata); |
| 897 members.add(member); | 937 members.add(member); |
| 898 } | 938 } |
| 899 // Recover at a semicolon | 939 // Recover at a semicolon |
| 900 if (optional(Token.SEMICOLON)) { | 940 if (optional(Token.SEMICOLON)) { |
| 901 reportUnexpectedToken(position(), null, Token.SEMICOLON); | 941 reportUnexpectedToken(position(), null, Token.SEMICOLON); |
| 902 } | 942 } |
| 903 } | 943 } |
| 904 expectCloseBrace(true); | 944 expectCloseBrace(true); |
| 905 } else { | 945 } else { |
| 906 reportErrorWithoutAdvancing(ParserErrorCode.EXPECTED_CLASS_DECLARATION_LBR
ACE); | 946 reportErrorWithoutAdvancing(ParserErrorCode.EXPECTED_CLASS_DECLARATION_LBR
ACE); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 * | '[' ']' '=' { "[]=".equals($text) }? | 1153 * | '[' ']' '=' { "[]=".equals($text) }? |
| 1114 * | NEGATE | 1154 * | NEGATE |
| 1115 * | CALL | 1155 * | CALL |
| 1116 * ; | 1156 * ; |
| 1117 * </pre> | 1157 * </pre> |
| 1118 * | 1158 * |
| 1119 * @param allowStatic true if the static modifier is allowed | 1159 * @param allowStatic true if the static modifier is allowed |
| 1120 * @return a {@link DartNode} representing the grammar fragment above | 1160 * @return a {@link DartNode} representing the grammar fragment above |
| 1121 */ | 1161 */ |
| 1122 @Terminals(tokens={Token.SEMICOLON}) | 1162 @Terminals(tokens={Token.SEMICOLON}) |
| 1123 private DartNode parseFieldOrMethod(boolean allowStatic) { | 1163 private DartNodeWithMetadata parseFieldOrMethod(boolean allowStatic) { |
| 1124 beginClassMember(); | 1164 beginClassMember(); |
| 1125 Modifiers modifiers = Modifiers.NONE; | 1165 Modifiers modifiers = Modifiers.NONE; |
| 1126 if (peek(1) != Token.LPAREN && optionalPseudoKeyword(EXTERNAL_KEYWORD)) { | 1166 if (peek(1) != Token.LPAREN && optionalPseudoKeyword(EXTERNAL_KEYWORD)) { |
| 1127 modifiers = modifiers.makeExternal(); | 1167 modifiers = modifiers.makeExternal(); |
| 1128 } | 1168 } |
| 1129 if (peek(1) != Token.LPAREN && optionalPseudoKeyword(STATIC_KEYWORD)) { | 1169 if (peek(1) != Token.LPAREN && optionalPseudoKeyword(STATIC_KEYWORD)) { |
| 1130 if (!allowStatic) { | 1170 if (!allowStatic) { |
| 1131 reportError(position(), ParserErrorCode.TOP_LEVEL_CANNOT_BE_STATIC); | 1171 reportError(position(), ParserErrorCode.TOP_LEVEL_CANNOT_BE_STATIC); |
| 1132 } else { | 1172 } else { |
| 1133 if (isParsingInterface | 1173 if (isParsingInterface |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 // If factory is not allowed, ensure that it is valid as method. | 1221 // If factory is not allowed, ensure that it is valid as method. |
| 1182 DartExpression actualName = factoryNode.getName(); | 1222 DartExpression actualName = factoryNode.getName(); |
| 1183 if (!allowStatic && !(actualName instanceof DartIdentifier)) { | 1223 if (!allowStatic && !(actualName instanceof DartIdentifier)) { |
| 1184 DartExpression replacementName = new DartIdentifier(actualName.toString(
)); | 1224 DartExpression replacementName = new DartIdentifier(actualName.toString(
)); |
| 1185 factoryNode.setName(replacementName); | 1225 factoryNode.setName(replacementName); |
| 1186 } | 1226 } |
| 1187 // Done. | 1227 // Done. |
| 1188 return done(factoryNode); | 1228 return done(factoryNode); |
| 1189 } | 1229 } |
| 1190 | 1230 |
| 1191 final DartNode member; | 1231 final DartNodeWithMetadata member; |
| 1192 | 1232 |
| 1193 switch (peek(0)) { | 1233 switch (peek(0)) { |
| 1194 case VAR: { | 1234 case VAR: { |
| 1195 consume(Token.VAR); | 1235 consume(Token.VAR); |
| 1196 // Check for malformed method starting with 'var' : var ^ foo() { } | 1236 // Check for malformed method starting with 'var' : var ^ foo() { } |
| 1197 if (peek(0).equals(Token.IDENTIFIER) && looksLikeMethodOrAccessorDefinit
ion()) { | 1237 if (peek(0).equals(Token.IDENTIFIER) && looksLikeMethodOrAccessorDefinit
ion()) { |
| 1198 reportError(position(), ParserErrorCode.VAR_IS_NOT_ALLOWED_ON_A_METHOD
_DEFINITION); | 1238 reportError(position(), ParserErrorCode.VAR_IS_NOT_ALLOWED_ON_A_METHOD
_DEFINITION); |
| 1199 member = parseMethodOrAccessor(modifiers, null); | 1239 member = parseMethodOrAccessor(modifiers, null); |
| 1200 break; | 1240 break; |
| 1201 } | 1241 } |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 //if (!modifiers.isStatic()) { | 1667 //if (!modifiers.isStatic()) { |
| 1628 // reportError(position(), ParserErrorCode.EXPORTED_FUNCTIONS_MUST_BE_STA
TIC); | 1668 // reportError(position(), ParserErrorCode.EXPORTED_FUNCTIONS_MUST_BE_STA
TIC); |
| 1629 //} | 1669 //} |
| 1630 return done(parseFunctionStatementBody(!modifiers.isExternal(), true)); | 1670 return done(parseFunctionStatementBody(!modifiers.isExternal(), true)); |
| 1631 } else { | 1671 } else { |
| 1632 expect(Token.SEMICOLON); | 1672 expect(Token.SEMICOLON); |
| 1633 return done(new DartNativeBlock()); | 1673 return done(new DartNativeBlock()); |
| 1634 } | 1674 } |
| 1635 } | 1675 } |
| 1636 | 1676 |
| 1637 private DartNode parseMethodOrAccessor(Modifiers modifiers, DartTypeNode retur
nType) { | 1677 private DartNodeWithMetadata parseMethodOrAccessor(Modifiers modifiers, DartTy
peNode returnType) { |
| 1638 DartMethodDefinition method = done(parseMethod(modifiers, returnType)); | 1678 DartMethodDefinition method = done(parseMethod(modifiers, returnType)); |
| 1639 // Abstract method can not have a body. | 1679 // Abstract method can not have a body. |
| 1640 if (method.getFunction().getBody() != null) { | 1680 if (method.getFunction().getBody() != null) { |
| 1641 if (isParsingInterface) { | 1681 if (isParsingInterface) { |
| 1642 reportError(method.getName(), ParserErrorCode.INTERFACE_METHOD_WITH_BODY
); | 1682 reportError(method.getName(), ParserErrorCode.INTERFACE_METHOD_WITH_BODY
); |
| 1643 } | 1683 } |
| 1644 if (method.getModifiers().isAbstract()) { | 1684 if (method.getModifiers().isAbstract()) { |
| 1645 reportError(method.getName(), ParserErrorCode.ABSTRACT_METHOD_WITH_BODY)
; | 1685 reportError(method.getName(), ParserErrorCode.ABSTRACT_METHOD_WITH_BODY)
; |
| 1646 } | 1686 } |
| 1647 } | 1687 } |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 * : normalFormalParameter ('=' constantExpression)? | 1976 * : normalFormalParameter ('=' constantExpression)? |
| 1937 * ; | 1977 * ; |
| 1938 * | 1978 * |
| 1939 * defaultNamedParameter | 1979 * defaultNamedParameter |
| 1940 * : normalFormalParameter (':' constantExpression)? | 1980 * : normalFormalParameter (':' constantExpression)? |
| 1941 * ; | 1981 * ; |
| 1942 * </pre> | 1982 * </pre> |
| 1943 */ | 1983 */ |
| 1944 private DartParameter parseFormalParameter(boolean isOptional, boolean isNamed
) { | 1984 private DartParameter parseFormalParameter(boolean isOptional, boolean isNamed
) { |
| 1945 beginFormalParameter(); | 1985 beginFormalParameter(); |
| 1986 List<DartAnnotation> metadata = parseMetadata(); |
| 1946 DartExpression paramName = null; | 1987 DartExpression paramName = null; |
| 1947 DartTypeNode type = null; | 1988 DartTypeNode type = null; |
| 1948 DartExpression defaultExpr = null; | 1989 DartExpression defaultExpr = null; |
| 1949 List<DartParameter> functionParams = null; | 1990 List<DartParameter> functionParams = null; |
| 1950 boolean hasVar = false; | 1991 boolean hasVar = false; |
| 1951 Modifiers modifiers = Modifiers.NONE; | 1992 Modifiers modifiers = Modifiers.NONE; |
| 1952 | 1993 |
| 1953 if (isOptional) { | 1994 if (isOptional) { |
| 1954 modifiers = modifiers.makeOptional(); | 1995 modifiers = modifiers.makeOptional(); |
| 1955 // TODO(brianwilkerson) Remove the line below when we no longer need to su
pport the old syntax. | 1996 // TODO(brianwilkerson) Remove the line below when we no longer need to su
pport the old syntax. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2040 } else { | 2081 } else { |
| 2041 reportError(position(), ParserErrorCode.DEFAULT_POSITIONAL_PARAMETER); | 2082 reportError(position(), ParserErrorCode.DEFAULT_POSITIONAL_PARAMETER); |
| 2042 } | 2083 } |
| 2043 break; | 2084 break; |
| 2044 | 2085 |
| 2045 default: | 2086 default: |
| 2046 reportUnexpectedToken(position(), null, peek(0)); | 2087 reportUnexpectedToken(position(), null, peek(0)); |
| 2047 break; | 2088 break; |
| 2048 } | 2089 } |
| 2049 | 2090 |
| 2050 return done(new DartParameter(paramName, type, functionParams, defaultExpr,
modifiers)); | 2091 DartParameter parameter = new DartParameter(paramName, type, functionParams,
defaultExpr, modifiers); |
| 2092 parameter.setMetadata(metadata); |
| 2093 return done(parameter); |
| 2051 } | 2094 } |
| 2052 | 2095 |
| 2053 /** | 2096 /** |
| 2054 * <pre> | 2097 * <pre> |
| 2055 * simpleFormalParameter | 2098 * simpleFormalParameter |
| 2056 * : declaredIdentifier | 2099 * : declaredIdentifier |
| 2057 * | identifier | 2100 * | identifier |
| 2058 * ; | 2101 * ; |
| 2059 * | 2102 * |
| 2060 * fieldFormalParameter | 2103 * fieldFormalParameter |
| (...skipping 2928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4989 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { | 5032 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen
ts) { |
| 4990 if (node != null) { | 5033 if (node != null) { |
| 4991 reportError(new DartCompilationError(node, errorCode, arguments)); | 5034 reportError(new DartCompilationError(node, errorCode, arguments)); |
| 4992 } | 5035 } |
| 4993 } | 5036 } |
| 4994 | 5037 |
| 4995 private boolean currentlyParsingToplevel() { | 5038 private boolean currentlyParsingToplevel() { |
| 4996 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); | 5039 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); |
| 4997 } | 5040 } |
| 4998 } | 5041 } |
| OLD | NEW |