| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 class ClassElementParser extends PartialParser { | 7 class ClassElementParser extends PartialParser { |
| 8 ClassElementParser(Listener listener) : super(listener); | 8 ClassElementParser(Listener listener) : super(listener); |
| 9 | 9 |
| 10 Token parseClassBody(Token token) => fullParseClassBody(token); | 10 Token parseClassBody(Token token) => fullParseClassBody(token); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 message: "Node has not been computed for $this.")); | 42 message: "Node has not been computed for $this.")); |
| 43 return cachedNode; | 43 return cachedNode; |
| 44 } | 44 } |
| 45 | 45 |
| 46 ClassNode parseNode(Compiler compiler) { | 46 ClassNode parseNode(Compiler compiler) { |
| 47 if (cachedNode != null) return cachedNode; | 47 if (cachedNode != null) return cachedNode; |
| 48 compiler.withCurrentElement(this, () { | 48 compiler.withCurrentElement(this, () { |
| 49 compiler.parser.measure(() { | 49 compiler.parser.measure(() { |
| 50 MemberListener listener = new MemberListener(compiler, this); | 50 MemberListener listener = new MemberListener(compiler, this); |
| 51 Parser parser = new ClassElementParser(listener); | 51 Parser parser = new ClassElementParser(listener); |
| 52 Token token = parser.parseTopLevelDeclaration(beginToken); | 52 try { |
| 53 assert(identical(token, endToken.next)); | 53 Token token = parser.parseTopLevelDeclaration(beginToken); |
| 54 cachedNode = listener.popNode(); | 54 assert(identical(token, endToken.next)); |
| 55 assert(invariant(beginToken, listener.nodes.isEmpty, | 55 cachedNode = listener.popNode(); |
| 56 message: "Non-empty listener stack: ${listener.nodes}")); | 56 assert( |
| 57 invariant( |
| 58 beginToken, listener.nodes.isEmpty, |
| 59 message: "Non-empty listener stack: ${listener.nodes}")); |
| 60 } on ParserError catch (e) { |
| 61 // TODO(ahe): Often, a ParserError is thrown while parsing the class |
| 62 // body. This means that the stack actually contains most of the |
| 63 // information synthesized below. Consider rewriting the parser so |
| 64 // endClassDeclaration is called before parsing the class body. |
| 65 Identifier name = new Identifier(findMyName(beginToken)); |
| 66 NodeList typeParameters = null; |
| 67 Node supertype = null; |
| 68 NodeList interfaces = listener.makeNodeList(0, null, null, ","); |
| 69 Token extendsKeyword = null; |
| 70 NodeList body = listener.makeNodeList(0, beginToken, endToken, null); |
| 71 cachedNode = new ClassNode( |
| 72 Modifiers.EMPTY, name, typeParameters, supertype, interfaces, |
| 73 beginToken, extendsKeyword, body, endToken); |
| 74 hasParseError = true; |
| 75 } |
| 57 }); | 76 }); |
| 58 compiler.patchParser.measure(() { | 77 compiler.patchParser.measure(() { |
| 59 if (isPatched) { | 78 if (isPatched) { |
| 60 // TODO(lrn): Perhaps extract functionality so it doesn't | 79 // TODO(lrn): Perhaps extract functionality so it doesn't |
| 61 // need compiler. | 80 // need compiler. |
| 62 compiler.patchParser.parsePatchClassNode(patch); | 81 compiler.patchParser.parsePatchClassNode(patch); |
| 63 } | 82 } |
| 64 }); | 83 }); |
| 65 }); | 84 }); |
| 66 return cachedNode; | 85 return cachedNode; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 236 |
| 218 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 237 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
| 219 popNode(); // Discard arguments. | 238 popNode(); // Discard arguments. |
| 220 if (periodBeforeName != null) { | 239 if (periodBeforeName != null) { |
| 221 popNode(); // Discard name. | 240 popNode(); // Discard name. |
| 222 } | 241 } |
| 223 popNode(); // Discard node (Send or Identifier). | 242 popNode(); // Discard node (Send or Identifier). |
| 224 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); | 243 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); |
| 225 } | 244 } |
| 226 } | 245 } |
| OLD | NEW |