| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * A listener for parser events. | 6 * A listener for parser events. |
| 7 */ | 7 */ |
| 8 class Listener { | 8 class Listener { |
| 9 int classCount = 0; | 9 int classCount = 0; |
| 10 int aliasCount = 0; | 10 int aliasCount = 0; |
| 11 int interfaceCount = 0; | 11 int interfaceCount = 0; |
| 12 int libraryTagCount = 0; | 12 int libraryTagCount = 0; |
| 13 int topLevelMemberCount = 0; | 13 int topLevelMemberCount = 0; |
| 14 Identifier previousIdentifier = null; | 14 Identifier previousIdentifier = null; |
| 15 final Canceler canceler; | 15 final Canceler canceler; |
| 16 | 16 |
| 17 Link<DeclarationBuilder> builders; | 17 Link<DeclarationBuilder> builders; |
| 18 Link<Element> topLevelElements; | 18 Link<Element> topLevelElements; |
| 19 | 19 |
| 20 Listener(Canceler this.canceler) | 20 Listener(Canceler this.canceler) |
| 21 : builders = const EmptyLink<DeclarationBuilder>(), | 21 : builders = const EmptyLink<DeclarationBuilder>(), |
| 22 topLevelElements = const EmptyLink<Element>(); | 22 topLevelElements = const EmptyLink<Element>(); |
| 23 | 23 |
| 24 void beginLibraryTag(Token token) { | 24 void beginLibraryTag(Token token) { |
| 25 canceler.cancel("Cannot handle library tags"); |
| 25 libraryTagCount++; | 26 libraryTagCount++; |
| 26 } | 27 } |
| 27 | 28 |
| 28 void beginClass(Token token) { | 29 void beginClass(Token token) { |
| 29 classCount++; | 30 classCount++; |
| 30 push(token, buildClassElement); | 31 push(token, buildClassElement); |
| 31 } | 32 } |
| 32 | 33 |
| 33 Element buildClassElement(DeclarationBuilder declaration) => null; | 34 Element buildClassElement(DeclarationBuilder declaration) { |
| 35 canceler.cancel("Cannot handle classes"); |
| 36 } |
| 34 | 37 |
| 35 void endClass(Token token) { | 38 void endClass(Token token) { |
| 36 handleDeclaration(pop(), token); | 39 handleDeclaration(pop(), token); |
| 37 } | 40 } |
| 38 | 41 |
| 39 void beginInterface(Token token) { | 42 void beginInterface(Token token) { |
| 40 interfaceCount++; | 43 interfaceCount++; |
| 41 push(token, buildInterfaceElement); | 44 push(token, buildInterfaceElement); |
| 42 } | 45 } |
| 43 | 46 |
| 44 Element buildInterfaceElement(DeclarationBuilder declaration) => null; | 47 Element buildInterfaceElement(DeclarationBuilder declaration) { |
| 48 canceler.cancel("Cannot handle interfaces"); |
| 49 } |
| 45 | 50 |
| 46 void endInterface(Token token) { | 51 void endInterface(Token token) { |
| 47 handleDeclaration(pop(), token); | 52 handleDeclaration(pop(), token); |
| 48 } | 53 } |
| 49 | 54 |
| 50 void beginFunctionTypeAlias(Token token) { | 55 void beginFunctionTypeAlias(Token token) { |
| 51 aliasCount++; | 56 aliasCount++; |
| 52 push(token, buildFunctionTypeAliasElement); | 57 push(token, buildFunctionTypeAliasElement); |
| 53 } | 58 } |
| 54 | 59 |
| 55 Element buildFunctionTypeAliasElement(DeclarationBuilder declaration) => null; | 60 Element buildFunctionTypeAliasElement(DeclarationBuilder declaration) { |
| 61 canceler.cancel("Cannot handle typedefs"); |
| 62 } |
| 56 | 63 |
| 57 void endFunctionTypeAlias(Token token) { | 64 void endFunctionTypeAlias(Token token) { |
| 58 handleDeclaration(pop(), token); | 65 handleDeclaration(pop(), token); |
| 59 } | 66 } |
| 60 | 67 |
| 61 void beginTopLevelMember(Token token) { | 68 void beginTopLevelMember(Token token) { |
| 62 topLevelMemberCount++; | 69 topLevelMemberCount++; |
| 63 } | 70 } |
| 64 | 71 |
| 65 void topLevelMethod(Token token) { | 72 void topLevelMethod(Token token) { |
| 66 push(token, buildMethod); | 73 push(token, buildMethod); |
| 67 builders.head.name = previousIdentifier.source; | 74 builders.head.name = previousIdentifier.source; |
| 68 } | 75 } |
| 69 | 76 |
| 70 Element buildMethod(DeclarationBuilder declaration) { | 77 Element buildMethod(DeclarationBuilder declaration) { |
| 71 return new PartialFunctionElement(declaration.name, | 78 return new PartialFunctionElement(declaration.name, |
| 72 declaration.beginToken, | 79 declaration.beginToken, |
| 73 declaration.endToken); | 80 declaration.endToken); |
| 74 } | 81 } |
| 75 | 82 |
| 76 void topLevelField(Token token) { | 83 void topLevelField(Token token) { |
| 77 push(token, buildField); | 84 push(token, buildField); |
| 78 builders.head.name = previousIdentifier.source; | 85 builders.head.name = previousIdentifier.source; |
| 79 } | 86 } |
| 80 | 87 |
| 81 Element buildField(DeclarationBuilder declaration) => null; | 88 Element buildField(DeclarationBuilder declaration) { |
| 89 canceler.cancel("Cannot handle fields"); |
| 90 } |
| 82 | 91 |
| 83 void endTopLevelMember(Token token) { | 92 void endTopLevelMember(Token token) { |
| 84 handleDeclaration(pop(), token); | 93 handleDeclaration(pop(), token); |
| 85 } | 94 } |
| 86 | 95 |
| 87 void beginTypeVariable(Token token) { | 96 void beginTypeVariable(Token token) { |
| 88 } | 97 } |
| 89 | 98 |
| 90 void endTypeVariable(Token token) { | 99 void endTypeVariable(Token token) { |
| 91 } | 100 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 405 |
| 397 void popExpressionContext() { | 406 void popExpressionContext() { |
| 398 assert(expressionContext.expressions.isEmpty()); | 407 assert(expressionContext.expressions.isEmpty()); |
| 399 expressionContext = expressionContext.previous; | 408 expressionContext = expressionContext.previous; |
| 400 } | 409 } |
| 401 | 410 |
| 402 void pushStatement(Statement statement) { | 411 void pushStatement(Statement statement) { |
| 403 functionContext.push(statement); | 412 functionContext.push(statement); |
| 404 } | 413 } |
| 405 } | 414 } |
| OLD | NEW |