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

Unified 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: Move constructor name creation to lookup function. 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 side-by-side diff with in-line comments
Download patch
Index: frog/leg/scanner/class_element_parser.dart
diff --git a/frog/leg/scanner/class_element_parser.dart b/frog/leg/scanner/class_element_parser.dart
index 256a48e48f03b9d3acab05153177a4c701e6842c..0594270ad69185fd5ac92706aa5e4ad625f7fc26 100644
--- a/frog/leg/scanner/class_element_parser.dart
+++ b/frog/leg/scanner/class_element_parser.dart
@@ -39,26 +39,42 @@ class MemberListener extends NodeListener {
[Element this.enclosingElement = null])
: super(canceler, logger);
- bool isConstructor(Identifier name) {
- return enclosingElement !== null &&
- enclosingElement.kind == ElementKind.CLASS &&
- enclosingElement.name == name.source;
+ bool isConstructorName(Node nameNode) {
+ if (enclosingElement === null ||
+ enclosingElement.kind != ElementKind.CLASS) {
+ return false;
+ }
+ SourceString name;
+ if (nameNode.asIdentifier() != null) {
+ name = nameNode.asIdentifier().source;
+ } else {
+ Send send = nameNode.asSend();
+ name = send.receiver.asIdentifier().source;
+ }
+ return enclosingElement.name == name;
}
void endMethod(Token beginToken, Token endToken) {
super.endMethod(beginToken, endToken);
FunctionExpression method = popNode();
pushNode(null);
- Expression qualified = method.name;
- Identifier name = qualified.asIdentifier();
- if (name === null) {
- canceler.cancel('qualified names are not implemented', node: qualified);
+ bool isConstructor = isConstructorName(method.name);
+ SourceString name;
+ if (method.name.asSend() != null) {
ngeoffray 2012/01/20 13:54:17 I would put method.name in a variable (also used l
karlklose 2012/01/20 14:11:36 Done.
+ // TODO(karlklose): find a better place for the construction of the name.
+ Identifier receiver = method.name.asSend().receiver.asIdentifier();
+ Identifier selector = method.name.asSend().selector.asIdentifier();
+ SourceString className = receiver.source;
+ SourceString constructorName = selector.source;
+ name = new SourceString('$className.$constructorName');
ahe 2012/02/15 07:31:15 The scanner and parser generally takes care to avo
ahe 2012/02/15 09:25:00 I made some additional instrumentation and I can c
+ } else {
+ name = method.name.asIdentifier().source;
}
- ElementKind kind = isConstructor(name) ?
+ ElementKind kind = isConstructor ?
ElementKind.GENERATIVE_CONSTRUCTOR :
ElementKind.FUNCTION;
Element memberElement =
- new PartialFunctionElement(name.source, beginToken, endToken,
+ new PartialFunctionElement(name, beginToken, endToken,
kind, method.modifiers, enclosingElement);
enclosingElement.addMember(memberElement);
}

Powered by Google App Engine
This is Rietveld 408576698