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

Side by Side Diff: frog/leg/ssa/builder.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: Address comments. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « frog/leg/scanner/listener.dart ('k') | frog/leg/typechecker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 191
192 HGraph buildFactory(ClassElement classElement, 192 HGraph buildFactory(ClassElement classElement,
193 ConstructorBodyElement bodyElement, 193 ConstructorBodyElement bodyElement,
194 FunctionElement functionElement) { 194 FunctionElement functionElement) {
195 openFunction(functionElement); 195 openFunction(functionElement);
196 196
197 FunctionExpression function = functionElement.parseNode(compiler, compiler); 197 FunctionExpression function = functionElement.parseNode(compiler, compiler);
198 NodeList initializers = function.initializers; 198 NodeList initializers = function.initializers;
199 NodeList parameters = function.parameters; 199 NodeList parameters = function.parameters;
200 Send redirectConstructor;
201 Send superConstructor;
ngeoffray 2012/01/19 14:36:33 Why adding these?
karlklose 2012/01/19 16:06:26 Removed.
200 // Run through the initializers. 202 // Run through the initializers.
201 if (initializers !== null) { 203 if (initializers !== null) {
202 for (Link<Node> link = initializers.nodes; 204 for (Link<Node> link = initializers.nodes;
203 !link.isEmpty(); 205 !link.isEmpty();
204 link = link.tail) { 206 link = link.tail) {
205 assert(link.head is Send); 207 assert(link.head is Send);
206 if (link.head is !SendSet) { 208 if (link.head is !SendSet) {
207 compiler.unimplemented('SsaBuilder.buildFactory super-init'); 209 compiler.unimplemented('SsaBuilder.buildFactory super-init');
210 } else {
211 SendSet init = link.head;
212 Link<Node> arguments = init.arguments;
213 assert(!arguments.isEmpty() && arguments.tail.isEmpty());
214 visit(arguments.head);
215 HInstruction value = pop();
216 updateDefinition(init, value);
208 } 217 }
209 SendSet init = link.head;
210 Link<Node> arguments = init.arguments;
211 assert(!arguments.isEmpty() && arguments.tail.isEmpty());
212 visit(arguments.head);
213 HInstruction value = pop();
214 updateDefinition(init, value);
215 } 218 }
216 } 219 }
217 220
218 // Call the JavaScript constructor with the fields as argument. 221 // Call the JavaScript constructor with the fields as argument.
219 // TODO(floitsch): allow super calls. 222 // TODO(floitsch): allow super calls.
220 // TODO(floitsch): allow inits at field declarations. 223 // TODO(floitsch): allow inits at field declarations.
221 List<HInstruction> fieldValues = <HInstruction>[]; 224 List<HInstruction> fieldValues = <HInstruction>[];
222 for (Element member in classElement.members) { 225 for (Element member in classElement.members) {
223 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { 226 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) {
224 HInstruction value = definitions[member]; 227 HInstruction value = definitions[member];
225 if (value === null) { 228 if (value === null) {
226 value = new HLiteral(null, HType.UNKNOWN); 229 value = new HLiteral(null, HType.UNKNOWN);
227 add(value); 230 add(value);
228 } 231 }
229 fieldValues.add(value); 232 fieldValues.add(value);
230 } 233 }
231 } 234 }
232 HForeignNew newObject = new HForeignNew(classElement, fieldValues); 235 HForeignNew newObject = new HForeignNew(classElement, fieldValues);
233 add(newObject); 236 add(newObject);
234 237
235 // Call the method body. 238 // Call the method body.
236 String methodName = compiler.namer.getName(bodyElement); 239 String methodName = compiler.namer.getName(bodyElement);
237 List bodyCallInputs = <HInstruction>[]; 240 List bodyCallInputs = <HInstruction>[];
238 bodyCallInputs.add(newObject); 241 bodyCallInputs.add(newObject);
239 for (Link link = parameters.nodes; !link.isEmpty(); link = link.tail) { 242 for (Link link = parameters.nodes; !link.isEmpty(); link = link.tail) {
240 Link<Node> identifierLink = link.head.definitions.nodes; 243 Link<Node> identifierLink = link.head.definitions.nodes;
241 // We expect exactly one identifier. 244 // We expect exactly one identifier.
242 assert(!identifierLink.isEmpty() && identifierLink.tail.isEmpty()); 245 assert(!identifierLink.isEmpty() && identifierLink.tail.isEmpty());
243 if (identifierLink.head is !Identifier) { 246 if (identifierLink.head is !Identifier) {
244 compiler.unimplemented( 247 compiler.unimplemented("SsaBuilder.buildFactory non-identifier");
245 "SsaBuilder.buildFactory non-identifier");
246 } 248 }
247 Identifier name = identifierLink.head; 249 Identifier name = identifierLink.head;
248 Element parameterElement = elements[name]; 250 Element parameterElement = elements[name];
249 HInstruction currentValue = definitions[parameterElement]; 251 HInstruction currentValue = definitions[parameterElement];
250 bodyCallInputs.add(currentValue); 252 bodyCallInputs.add(currentValue);
251 } 253 }
252 add(new HInvokeDynamicMethod(methodName, bodyCallInputs)); 254 add(new HInvokeDynamicMethod(methodName, bodyCallInputs));
253 close(new HReturn(newObject)).addSuccessor(graph.exit); 255 close(new HReturn(newObject)).addSuccessor(graph.exit);
254 return closeFunction(); 256 return closeFunction();
255 } 257 }
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 } 800 }
799 801
800 void generateGetter(Send send, Element element) { 802 void generateGetter(Send send, Element element) {
801 if (Elements.isStaticOrTopLevelField(element)) { 803 if (Elements.isStaticOrTopLevelField(element)) {
802 push(new HStatic(element)); 804 push(new HStatic(element));
803 } else if (element === null || Elements.isInstanceField(element)) { 805 } else if (element === null || Elements.isInstanceField(element)) {
804 HInstruction receiver; 806 HInstruction receiver;
805 if (send.receiver == null) { 807 if (send.receiver == null) {
806 receiver = thisDefinition; 808 receiver = thisDefinition;
807 if (receiver === null) { 809 if (receiver === null) {
808 compiler.unimplemented("Ssa.generateGetter.", node: send); 810 compiler.unimplemented("SsaBuilder.generateGetter.", node: send);
809 } 811 }
810 } else { 812 } else {
811 visit(send.receiver); 813 visit(send.receiver);
812 receiver = pop(); 814 receiver = pop();
813 } 815 }
814 SourceString getterName = send.selector.asIdentifier().source; 816 SourceString getterName = send.selector.asIdentifier().source;
815 Element staticInterceptor = null; 817 Element staticInterceptor = null;
816 if (methodInterceptionEnabled) { 818 if (methodInterceptionEnabled) {
817 staticInterceptor = interceptors.getStaticGetInterceptor(getterName); 819 staticInterceptor = interceptors.getStaticGetInterceptor(getterName);
818 } 820 }
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 } 1419 }
1418 1420
1419 visitCatchBlock(CatchBlock node) { 1421 visitCatchBlock(CatchBlock node) {
1420 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node); 1422 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node);
1421 } 1423 }
1422 1424
1423 visitTypedef(Typedef node) { 1425 visitTypedef(Typedef node) {
1424 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 1426 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
1425 } 1427 }
1426 } 1428 }
OLDNEW
« no previous file with comments | « frog/leg/scanner/listener.dart ('k') | frog/leg/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698