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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 try { | 52 try { |
53 Token token = parser.parseTopLevelDeclaration(beginToken); | 53 Token token = parser.parseTopLevelDeclaration(beginToken); |
54 assert(identical(token, endToken.next)); | 54 assert(identical(token, endToken.next)); |
55 cachedNode = listener.popNode(); | 55 cachedNode = listener.popNode(); |
56 assert( | 56 assert( |
57 invariant( | 57 invariant( |
58 beginToken, listener.nodes.isEmpty, | 58 beginToken, listener.nodes.isEmpty, |
59 message: "Non-empty listener stack: ${listener.nodes}")); | 59 message: "Non-empty listener stack: ${listener.nodes}")); |
60 } on ParserError catch (e) { | 60 } on ParserError { |
61 // TODO(ahe): Often, a ParserError is thrown while parsing the class | 61 // TODO(ahe): Often, a ParserError is thrown while parsing the class |
62 // body. This means that the stack actually contains most of the | 62 // body. This means that the stack actually contains most of the |
63 // information synthesized below. Consider rewriting the parser so | 63 // information synthesized below. Consider rewriting the parser so |
64 // endClassDeclaration is called before parsing the class body. | 64 // endClassDeclaration is called before parsing the class body. |
65 Identifier name = new Identifier(findMyName(beginToken)); | 65 Identifier name = new Identifier(findMyName(beginToken)); |
66 NodeList typeParameters = null; | 66 NodeList typeParameters = null; |
67 Node supertype = null; | 67 Node supertype = null; |
68 NodeList interfaces = listener.makeNodeList(0, null, null, ","); | 68 NodeList interfaces = listener.makeNodeList(0, null, null, ","); |
69 Token extendsKeyword = null; | 69 Token extendsKeyword = null; |
70 NodeList body = listener.makeNodeList(0, beginToken, endToken, null); | 70 NodeList body = listener.makeNodeList(0, beginToken, endToken, null); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 pushNode(null); | 179 pushNode(null); |
180 String name = getMethodNameHack(method.name); | 180 String name = getMethodNameHack(method.name); |
181 Identifier singleIdentifierName = method.name.asIdentifier(); | 181 Identifier singleIdentifierName = method.name.asIdentifier(); |
182 if (singleIdentifierName != null && singleIdentifierName.source == name) { | 182 if (singleIdentifierName != null && singleIdentifierName.source == name) { |
183 if (name != enclosingClass.name) { | 183 if (name != enclosingClass.name) { |
184 listener.reportError(singleIdentifierName, | 184 listener.reportError(singleIdentifierName, |
185 MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME, | 185 MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME, |
186 {'name': enclosingClass.name}); | 186 {'name': enclosingClass.name}); |
187 } | 187 } |
188 } | 188 } |
189 ElementKind kind = ElementKind.FUNCTION; | |
190 Element memberElement = new PartialConstructorElement( | 189 Element memberElement = new PartialConstructorElement( |
191 name, beginToken, endToken, | 190 name, beginToken, endToken, |
192 ElementKind.FUNCTION, | 191 ElementKind.FUNCTION, |
193 method.modifiers, | 192 method.modifiers, |
194 enclosingClass); | 193 enclosingClass); |
195 addMember(memberElement); | 194 addMember(memberElement); |
196 } | 195 } |
197 | 196 |
198 void endFields(int count, Token beginToken, Token endToken) { | 197 void endFields(int count, Token beginToken, Token endToken) { |
199 bool hasParseError = memberErrors.head; | 198 bool hasParseError = memberErrors.head; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 235 |
237 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 236 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
238 popNode(); // Discard arguments. | 237 popNode(); // Discard arguments. |
239 if (periodBeforeName != null) { | 238 if (periodBeforeName != null) { |
240 popNode(); // Discard name. | 239 popNode(); // Discard name. |
241 } | 240 } |
242 popNode(); // Discard node (Send or Identifier). | 241 popNode(); // Discard node (Send or Identifier). |
243 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); | 242 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); |
244 } | 243 } |
245 } | 244 } |
OLD | NEW |