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

Unified Diff: lib/compiler/implementation/patch_parser.dart

Issue 10696147: Patch methods in classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Small type/typo fixes Created 8 years, 5 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: lib/compiler/implementation/patch_parser.dart
diff --git a/lib/compiler/implementation/patch_parser.dart b/lib/compiler/implementation/patch_parser.dart
index 26fc5ae90119688bf5d0ee9b0644a3bf3e58b978..d336a9eec02f7eb0a8f6f191c6570459f7aa47b2 100644
--- a/lib/compiler/implementation/patch_parser.dart
+++ b/lib/compiler/implementation/patch_parser.dart
@@ -12,6 +12,7 @@
#import("elements/elements.dart");
#import('native_handler.dart', prefix: 'native');
+
class PatchParserTask extends leg.CompilerTask {
PatchParserTask(leg.Compiler compiler): super(compiler);
final String name = "Patching Parser";
@@ -47,6 +48,20 @@ class PatchParserTask extends leg.CompilerTask {
new PatchParser(patchListener).parseUnit(tokens);
});
}
+
+ tree.ClassNode parsePatchClassNode(PartialClassElement element) {
+ // Parse [PartialClassElement] using a "patch"-aware parser instead
+ // of calling its [parseNode] method.
+ if (element.cachedNode != null) return element.cachedNode;
+ PatchMemberListener listener =
+ new PatchMemberListener(compiler, element);
+ Parser parser = new PatchClassElementParser(listener);
+ Token token = parser.parseTopLevelDeclaration(element.beginToken);
+ assert(token === element.endToken.next);
+ element.cachedNode = listener.popNode();
+ assert(listener.nodes.isEmpty());
+ return element.cachedNode;
+ }
}
/**
@@ -93,7 +108,7 @@ class PatchParser extends PartialParser {
return listener.unexpected(patch);
}
patchListener.beginPatch(patch);
- token = super.parseTopLevelDeclaration(token.next);
+ token = super.parseTopLevelDeclaration(token);
patchListener.endPatch(patch);
return token;
}
@@ -164,3 +179,39 @@ class PatchElementListener extends ElementListener implements PatchListener {
super.pushElement(element);
}
}
+
+
+/**
+ * Extension of [MemberListener] for parsing patch class bodies.
+ */
+class PatchMemberListener extends MemberListener implements PatchListener {
+ bool isMemberPatch = false;
+ bool isClassPatch = false;
+ PatchMemberListener(leg.DiagnosticListener listener,
+ Element enclosingElement)
+ : super(listener, enclosingElement);
+
+ void beginPatch(Token token) {
+ if (token.next.stringValue === "class") {
+ isClassPatch = true;
+ } else {
+ isMemberPatch = true;
+ }
+ handleIdentifier(token);
+ }
+
+ void endPatch(Token token) {
+ if (token.next.stringValue === "class") {
+ isClassPatch = false;
+ } else {
+ isMemberPatch = false;
+ }
+ }
+
+ void addMember(Element element) {
+ if (isMemberPatch || (isClassPatch && element is ClassElement)) {
+ element.addMetadata(popNode());
+ }
+ super.addMember(element);
+ }
+}
« no previous file with comments | « lib/compiler/implementation/library_map.dart ('k') | lib/compiler/implementation/scanner/class_element_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698