Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: frog/leg/scanner/class_element_parser.dart

Issue 9243011: Implement named constructors and resolving of redirecting constructors and super-initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename field. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class ClassElementParser extends PartialParser { 5 class ClassElementParser extends PartialParser {
6 ClassElementParser(Listener listener) : super(listener); 6 ClassElementParser(Listener listener) : super(listener);
7 7
8 Token parseClassBody(Token token) => fullParseClassBody(token); 8 Token parseClassBody(Token token) => fullParseClassBody(token);
9 } 9 }
10 10
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 } 32 }
33 33
34 class MemberListener extends NodeListener { 34 class MemberListener extends NodeListener {
35 final ClassElement enclosingElement; 35 final ClassElement enclosingElement;
36 36
37 MemberListener(Canceler canceler, Logger logger, 37 MemberListener(Canceler canceler, Logger logger,
38 [Element this.enclosingElement = null]) 38 [Element this.enclosingElement = null])
39 : super(canceler, logger); 39 : super(canceler, logger);
40 40
41 bool isConstructor(Identifier name) { 41 bool isConstructorName(Node nameNode) {
42 return enclosingElement !== null && 42 if (enclosingElement === null ||
43 enclosingElement.kind == ElementKind.CLASS && 43 enclosingElement.kind != ElementKind.CLASS) {
44 enclosingElement.name == name.source; 44 return false;
45 }
46 SourceString name;
47 if (nameNode.asIdentifier() != null) {
48 name = nameNode.asIdentifier().source;
49 } else {
50 Send send = nameNode.asSend();
51 name = send.receiver.asIdentifier().source;
52 }
53 return enclosingElement.name == name;
45 } 54 }
46 55
47 void endMethod(Token beginToken, Token endToken) { 56 void endMethod(Token beginToken, Token endToken) {
48 super.endMethod(beginToken, endToken); 57 super.endMethod(beginToken, endToken);
49 FunctionExpression method = popNode(); 58 FunctionExpression method = popNode();
50 pushNode(null); 59 pushNode(null);
51 Expression qualified = method.name; 60 bool isConstructor = isConstructorName(method.name);
52 Identifier name = qualified.asIdentifier(); 61 SourceString name;
53 if (name === null) { 62 if (method.name.asSend() != null) {
54 canceler.cancel('qualified names are not implemented', node: qualified); 63 Identifier receiver = method.name.asSend().receiver.asIdentifier();
64 Identifier selector = method.name.asSend().selector.asIdentifier();
65 SourceString className = receiver.source;
66 SourceString constructorName = selector.source;
67 name = new SourceString('$className.$constructorName');
68 } else {
69 name = method.name.asIdentifier().source;
55 } 70 }
56 ElementKind kind = isConstructor(name) ? 71 ElementKind kind = isConstructor ?
57 ElementKind.GENERATIVE_CONSTRUCTOR : 72 ElementKind.GENERATIVE_CONSTRUCTOR :
58 ElementKind.FUNCTION; 73 ElementKind.FUNCTION;
59 Element memberElement = 74 Element memberElement =
60 new PartialFunctionElement(name.source, beginToken, endToken, 75 new PartialFunctionElement(name, beginToken, endToken,
61 kind, method.modifiers, enclosingElement); 76 kind, method.modifiers, enclosingElement);
62 enclosingElement.addMember(memberElement); 77 enclosingElement.addMember(memberElement);
63 } 78 }
64 79
65 void endFactoryMethod(Token factoryKeyword, Token periodBeforeName, 80 void endFactoryMethod(Token factoryKeyword, Token periodBeforeName,
66 Token endToken) { 81 Token endToken) {
67 super.endFactoryMethod(factoryKeyword, periodBeforeName, endToken); 82 super.endFactoryMethod(factoryKeyword, periodBeforeName, endToken);
68 FunctionExpression method = popNode(); 83 FunctionExpression method = popNode();
69 pushNode(null); 84 pushNode(null);
70 // TODO(ahe): Named constructors. 85 // TODO(ahe): Named constructors.
(...skipping 25 matching lines...) Expand all
96 void endInitializer(Token assignmentOperator) { 111 void endInitializer(Token assignmentOperator) {
97 pushNode(null); // Super expects an expression, but 112 pushNode(null); // Super expects an expression, but
98 // ClassElementParser just skips expressions. 113 // ClassElementParser just skips expressions.
99 super.endInitializer(assignmentOperator); 114 super.endInitializer(assignmentOperator);
100 } 115 }
101 116
102 void endInitializers(int count, Token beginToken, Token endToken) { 117 void endInitializers(int count, Token beginToken, Token endToken) {
103 pushNode(null); 118 pushNode(null);
104 } 119 }
105 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698