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

Side by Side Diff: lib/compiler/implementation/scanner/class_element_parser.dart

Issue 10703188: Allow patch files to add top-level declarations to the patched library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix errors caught by editor. 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 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
11 class PartialClassElement extends ClassElement { 11 class PartialClassElement extends ClassElement {
12 final Token beginToken; 12 final Token beginToken;
13 final Token endToken; 13 final Token endToken;
14 Node cachedNode; 14 Node cachedNode;
15 15
16 PartialClassElement(SourceString name, 16 PartialClassElement(SourceString name,
17 Token this.beginToken, 17 Token this.beginToken,
18 Token this.endToken, 18 Token this.endToken,
19 CompilationUnitElement enclosing, 19 CompilationUnitElement enclosing,
20 int id) 20 int id)
21 : super(name, enclosing, id); 21 : super(name, enclosing, id);
22 22
23 ClassNode parseNode(DiagnosticListener diagnosticListener) { 23 ClassNode parseNode(DiagnosticListener diagnosticListener) {
24 if (cachedNode != null) return cachedNode; 24 if (cachedNode != null) return cachedNode;
25 MemberListener listener = new MemberListener(diagnosticListener, this); 25 MemberListener listener = new MemberListener(diagnosticListener, this);
26 Parser parser = new ClassElementParser(listener); 26 Parser parser = new ClassElementParser(listener);
27 Token token = parser.parseTopLevelDeclaration(beginToken); 27 Token token = parser.parseTopLevelDeclaration(beginToken);
28 assert(token === endToken.next); 28 assert(token === endToken.next);
29 cachedNode = listener.popNode(); 29 cachedNode = listener.popNode();
30 assert(listener.nodes.isEmpty()); 30 assert(listener.nodes.isEmpty());
31 return cachedNode; 31 return cachedNode;
32 } 32 }
33 33
34 Token position() => beginToken; 34 Token position() => beginToken;
35 35
36 bool isInterface() => beginToken.stringValue === "interface"; 36 bool isInterface() => beginToken.stringValue === "interface";
37
38 PartialClassElement cloneTo(CompilationUnitElement enclosing,
39 DiagnosticListener listener) {
40 parseNode(listener);
41 PartialClassElement result =
42 new PartialClassElement(name, beginToken, endToken, enclosing, id);
43 cloneMembersTo(result, listener);
44 result.cachedNode = cachedNode;
45 result.scriptOverride = getScript();
46 return result;
47 }
37 } 48 }
38 49
39 class MemberListener extends NodeListener { 50 class MemberListener extends NodeListener {
40 final ClassElement enclosingElement; 51 final ClassElement enclosingElement;
41 52
42 MemberListener(DiagnosticListener listener, 53 MemberListener(DiagnosticListener listener,
43 Element enclosingElement) 54 Element enclosingElement)
44 : this.enclosingElement = enclosingElement, 55 : this.enclosingElement = enclosingElement,
45 super(listener, enclosingElement.getCompilationUnit()); 56 super(listener, enclosingElement.getCompilationUnit());
46 57
47 bool isConstructorName(Node nameNode) { 58 bool isConstructorName(Node nameNode) {
48 if (enclosingElement === null || 59 if (enclosingElement === null ||
49 enclosingElement.kind != ElementKind.CLASS) { 60 enclosingElement.kind != ElementKind.CLASS) {
50 return false; 61 return false;
51 } 62 }
52 SourceString name; 63 SourceString name;
53 if (nameNode.asIdentifier() !== null) { 64 if (nameNode.asIdentifier() !== null) {
54 name = nameNode.asIdentifier().source; 65 name = nameNode.asIdentifier().source;
55 } else { 66 } else {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 140 }
130 141
131 void endInitializers(int count, Token beginToken, Token endToken) { 142 void endInitializers(int count, Token beginToken, Token endToken) {
132 pushNode(null); 143 pushNode(null);
133 } 144 }
134 145
135 void addMember(Element memberElement) { 146 void addMember(Element memberElement) {
136 enclosingElement.addMember(memberElement, listener); 147 enclosingElement.addMember(memberElement, listener);
137 } 148 }
138 } 149 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/scanner/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698