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

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

Issue 9027002: Support factory methods. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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 30 matching lines...) Expand all
41 enclosingElement.kind == ElementKind.CLASS && 41 enclosingElement.kind == ElementKind.CLASS &&
42 enclosingElement.name == name.source; 42 enclosingElement.name == name.source;
43 } 43 }
44 44
45 void endMethod(Token beginToken, Token period, Token endToken) { 45 void endMethod(Token beginToken, Token period, Token endToken) {
46 super.endMethod(beginToken, period, endToken); 46 super.endMethod(beginToken, period, endToken);
47 FunctionExpression method = popNode(); 47 FunctionExpression method = popNode();
48 pushNode(null); 48 pushNode(null);
49 Identifier name = method.name; // TODO(ahe): Named constructors. 49 Identifier name = method.name; // TODO(ahe): Named constructors.
50 ElementKind kind = isConstructor(name) ? 50 ElementKind kind = isConstructor(name) ?
51 ElementKind.CONSTRUCTOR : 51 ElementKind.GENERATIVE_CONSTRUCTOR :
52 ElementKind.FUNCTION; 52 ElementKind.FUNCTION;
53 Element memberElement = 53 Element memberElement =
54 new PartialFunctionElement(name.source, beginToken, endToken, 54 new PartialFunctionElement(name.source, beginToken, endToken,
55 kind, method.modifiers, enclosingElement); 55 kind, method.modifiers, enclosingElement);
56 enclosingElement.addMember(memberElement); 56 enclosingElement.addMember(memberElement);
57 } 57 }
58 58
59 void endFactoryMethod(Token factoryKeyword, Token periodBeforeName,
60 Token endToken) {
61 super.endFactoryMethod(factoryKeyword, periodBeforeName, endToken);
62 FunctionExpression method = popNode();
63 pushNode(null);
64 // TODO(ahe): Named constructors.
65 Identifier name = method.returnType.typeName;
ahe 2011/12/22 13:32:39 You need to change this now. The return type is al
ngeoffray 2011/12/22 13:50:23 Done.
66 ElementKind kind = ElementKind.FUNCTION;
67 Element memberElement =
68 new PartialFunctionElement(name.source, factoryKeyword, endToken, kind,
69 method.modifiers, enclosingElement);
70 enclosingElement.addMember(memberElement);
71 }
72
59 void endFields(int count, Token beginToken, Token endToken) { 73 void endFields(int count, Token beginToken, Token endToken) {
60 super.endFields(count, beginToken, endToken); 74 super.endFields(count, beginToken, endToken);
61 VariableDefinitions variableDefinitions = popNode(); 75 VariableDefinitions variableDefinitions = popNode();
62 Modifiers modifiers = variableDefinitions.modifiers; 76 Modifiers modifiers = variableDefinitions.modifiers;
63 pushNode(null); 77 pushNode(null);
64 void buildFieldElement(SourceString name, Element fields) { 78 void buildFieldElement(SourceString name, Element fields) {
65 Element element = new VariableElement(name, fields, ElementKind.FIELD, 79 Element element = new VariableElement(name, fields, ElementKind.FIELD,
66 enclosingElement); 80 enclosingElement);
67 enclosingElement.addMember(element); 81 enclosingElement.addMember(element);
68 } 82 }
69 buildFieldElements(modifiers, variableDefinitions.definitions, 83 buildFieldElements(modifiers, variableDefinitions.definitions,
70 buildFieldElement, beginToken, endToken); 84 buildFieldElement, beginToken, endToken);
71 } 85 }
72 86
73 void endInitializer(Token assignmentOperator) { 87 void endInitializer(Token assignmentOperator) {
74 canceler.cancel("field initializers are not implemented", 88 canceler.cancel("field initializers are not implemented",
75 token: assignmentOperator); 89 token: assignmentOperator);
76 } 90 }
77 91
78 void endInitializers(int count, Token beginToken, Token endToken) { 92 void endInitializers(int count, Token beginToken, Token endToken) {
79 pushNode(null); 93 pushNode(null);
80 } 94 }
81 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698