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

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: Address comments. 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 21 matching lines...) Expand all
32 } 32 }
33 } 33 }
34 34
35 class MemberListener extends NodeListener { 35 class MemberListener extends NodeListener {
36 final ClassElement enclosingElement; 36 final ClassElement enclosingElement;
37 37
38 MemberListener(Canceler canceler, Logger logger, 38 MemberListener(Canceler canceler, Logger logger,
39 [Element this.enclosingElement = null]) 39 [Element this.enclosingElement = null])
40 : super(canceler, logger); 40 : super(canceler, logger);
41 41
42 bool isConstructor(Identifier name) { 42 bool isConstructorName(Node nameNode) {
ngeoffray 2012/01/19 08:56:12 Why renaming it to isConstructorName? isConstructo
karlklose 2012/01/19 13:51:24 Because it operates on a 'name'-node, not the cons
ngeoffray 2012/01/19 14:36:33 OK.
43 return enclosingElement !== null && 43 if (enclosingElement === null ||
44 enclosingElement.kind == ElementKind.CLASS && 44 enclosingElement.kind != ElementKind.CLASS) {
45 enclosingElement.name == name.source; 45 return false;
46 }
47 SourceString name;
48 if (nameNode.asIdentifier() != null) {
49 name = nameNode.asIdentifier().source;
50 } else {
51 Send send = nameNode.asSend();
52 name = send.receiver.asIdentifier().source;
53 }
54 return enclosingElement.name == name;
46 } 55 }
47 56
48 void endMethod(Token beginToken, Token endToken) { 57 void endMethod(Token beginToken, Token endToken) {
49 super.endMethod(beginToken, endToken); 58 super.endMethod(beginToken, endToken);
50 FunctionExpression method = popNode(); 59 FunctionExpression method = popNode();
51 pushNode(null); 60 pushNode(null);
52 Expression qualified = method.name; 61 bool isConstructor = isConstructorName(method.name);
53 Identifier name = qualified.asIdentifier(); 62 SourceString name;
54 if (name === null) { 63 if (method.name.asSend() != null) {
55 canceler.cancel('qualified names are not implemented', node: qualified); 64 Identifier receiver = method.name.asSend().receiver.asIdentifier();
65 Identifier selector = method.name.asSend().selector.asIdentifier();
66 SourceString className = receiver.source;
67 SourceString constructorName = selector.source;
68 name = new SourceString('$className.$constructorName');
ngeoffray 2012/01/19 08:56:12 Since you are putting constructors in a different
karlklose 2012/01/19 13:51:24 The map contains factories, too.
ngeoffray 2012/01/19 14:36:33 The 'constructor' map right? That's no problem, ge
69 } else {
70 name = method.name.asIdentifier().source;
56 } 71 }
57 ElementKind kind = isConstructor(name) ? 72 ElementKind kind = isConstructor ?
58 ElementKind.GENERATIVE_CONSTRUCTOR : 73 ElementKind.GENERATIVE_CONSTRUCTOR :
59 ElementKind.FUNCTION; 74 ElementKind.FUNCTION;
60 Element memberElement = 75 Element memberElement =
61 new PartialFunctionElement(name.source, beginToken, endToken, 76 new PartialFunctionElement(name, beginToken, endToken,
62 kind, method.modifiers, enclosingElement); 77 kind, method.modifiers, enclosingElement);
63 enclosingElement.addMember(memberElement); 78 enclosingElement.addMember(memberElement);
64 } 79 }
65 80
66 void endFactoryMethod(Token factoryKeyword, Token periodBeforeName, 81 void endFactoryMethod(Token factoryKeyword, Token periodBeforeName,
67 Token endToken) { 82 Token endToken) {
68 super.endFactoryMethod(factoryKeyword, periodBeforeName, endToken); 83 super.endFactoryMethod(factoryKeyword, periodBeforeName, endToken);
69 FunctionExpression method = popNode(); 84 FunctionExpression method = popNode();
70 pushNode(null); 85 pushNode(null);
71 // TODO(ahe): Named constructors. 86 // TODO(ahe): Named constructors.
(...skipping 25 matching lines...) Expand all
97 void endInitializer(Token assignmentOperator) { 112 void endInitializer(Token assignmentOperator) {
98 pushNode(null); // Super expects an expression, but 113 pushNode(null); // Super expects an expression, but
99 // ClassElementParser just skips expressions. 114 // ClassElementParser just skips expressions.
100 super.endInitializer(assignmentOperator); 115 super.endInitializer(assignmentOperator);
101 } 116 }
102 117
103 void endInitializers(int count, Token beginToken, Token endToken) { 118 void endInitializers(int count, Token beginToken, Token endToken) {
104 pushNode(null); 119 pushNode(null);
105 } 120 }
106 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698