OLD | NEW |
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 14 matching lines...) Expand all Loading... |
25 assert(state <= STATE_DONE); | 25 assert(state <= STATE_DONE); |
26 super.supertypeLoadState = state; | 26 super.supertypeLoadState = state; |
27 } | 27 } |
28 | 28 |
29 void set resolutionState(int state) { | 29 void set resolutionState(int state) { |
30 assert(state == resolutionState + 1); | 30 assert(state == resolutionState + 1); |
31 assert(state <= STATE_DONE); | 31 assert(state <= STATE_DONE); |
32 super.resolutionState = state; | 32 super.resolutionState = state; |
33 } | 33 } |
34 | 34 |
35 ClassNode parseNode(DiagnosticListener diagnosticListener) { | 35 ClassNode parseNode(Compiler compiler) { |
36 if (cachedNode != null) return cachedNode; | 36 if (cachedNode != null) return cachedNode; |
37 // TODO(ahe): Measure these tasks. | 37 compiler.withCurrentElement(this, () { |
38 MemberListener listener = new MemberListener(diagnosticListener, this); | 38 compiler.parser.measure(() { |
39 Parser parser = new ClassElementParser(listener); | 39 MemberListener listener = new MemberListener(compiler, this); |
40 Token token = parser.parseTopLevelDeclaration(beginToken); | 40 Parser parser = new ClassElementParser(listener); |
41 assert(token === endToken.next); | 41 Token token = parser.parseTopLevelDeclaration(beginToken); |
42 cachedNode = listener.popNode(); | 42 assert(token === endToken.next); |
43 assert(listener.nodes.isEmpty()); | 43 cachedNode = listener.popNode(); |
44 if (isPatched) { | 44 assert(listener.nodes.isEmpty()); |
45 // TODO(lrn): Perhaps extract functionality so it doesn't need compiler. | 45 }); |
46 Compiler compiler = diagnosticListener; | 46 compiler.patchParser.measure(() { |
47 ClassNode patchNode = compiler.patchParser.parsePatchClassNode(patch); | 47 if (isPatched) { |
48 Link<Element> patches = patch.localMembers; | 48 // TODO(lrn): Perhaps extract functionality so it doesn't |
49 compiler.applyContainerPatch(this, patches); | 49 // need compiler. |
50 } | 50 ClassNode patchNode = compiler.patchParser.parsePatchClassNode(patch); |
| 51 Link<Element> patches = patch.localMembers; |
| 52 compiler.applyContainerPatch(this, patches); |
| 53 } |
| 54 }); |
| 55 }); |
51 return cachedNode; | 56 return cachedNode; |
52 } | 57 } |
53 | 58 |
54 Token position() => beginToken; | 59 Token position() => beginToken; |
55 | 60 |
56 bool isInterface() => beginToken.stringValue === "interface"; | 61 bool isInterface() => beginToken.stringValue === "interface"; |
57 | 62 |
58 PartialClassElement cloneTo(Element enclosing, DiagnosticListener listener) { | 63 PartialClassElement cloneTo(Element enclosing, DiagnosticListener listener) { |
59 parseNode(listener); | 64 parseNode(listener); |
60 // TODO(lrn): Is copying id acceptable? | 65 // TODO(lrn): Is copying id acceptable? |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 name = send.receiver.asIdentifier().source; | 112 name = send.receiver.asIdentifier().source; |
108 } | 113 } |
109 return enclosingElement.name == name; | 114 return enclosingElement.name == name; |
110 } | 115 } |
111 | 116 |
112 SourceString getMethodNameHack(Node methodName) { | 117 SourceString getMethodNameHack(Node methodName) { |
113 Send send = methodName.asSend(); | 118 Send send = methodName.asSend(); |
114 if (send === null) return methodName.asIdentifier().source; | 119 if (send === null) return methodName.asIdentifier().source; |
115 Identifier receiver = send.receiver.asIdentifier(); | 120 Identifier receiver = send.receiver.asIdentifier(); |
116 Identifier selector = send.selector.asIdentifier(); | 121 Identifier selector = send.selector.asIdentifier(); |
117 if (selector.asOperator() !== null) { | 122 Operator operator = selector.asOperator(); |
118 return Elements.constructOperatorName(receiver.source, selector.source); | 123 if (operator !== null) { |
| 124 assert(receiver.source.stringValue === 'operator'); |
| 125 // TODO(ahe): It is a hack to compare to ')', but it beats |
| 126 // parsing the node. |
| 127 bool isUnary = operator.token.next.next.stringValue === ')'; |
| 128 return Elements.constructOperatorName(operator.source, isUnary); |
119 } else { | 129 } else { |
120 return Elements.constructConstructorName(receiver.source, | 130 return Elements.constructConstructorName(receiver.source, |
121 selector.source); | 131 selector.source); |
122 } | 132 } |
123 } | 133 } |
124 | 134 |
125 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 135 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
126 super.endMethod(getOrSet, beginToken, endToken); | 136 super.endMethod(getOrSet, beginToken, endToken); |
127 FunctionExpression method = popNode(); | 137 FunctionExpression method = popNode(); |
128 pushNode(null); | 138 pushNode(null); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 193 } |
184 | 194 |
185 void addMember(Element memberElement) { | 195 void addMember(Element memberElement) { |
186 for (Link link = metadata; !link.isEmpty(); link = link.tail) { | 196 for (Link link = metadata; !link.isEmpty(); link = link.tail) { |
187 memberElement.addMetadata(link.head); | 197 memberElement.addMetadata(link.head); |
188 } | 198 } |
189 metadata = const EmptyLink<MetadataAnnotation>(); | 199 metadata = const EmptyLink<MetadataAnnotation>(); |
190 enclosingElement.addMember(memberElement, listener); | 200 enclosingElement.addMember(memberElement, listener); |
191 } | 201 } |
192 } | 202 } |
OLD | NEW |