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

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: 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 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 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 NodeList initializers = function.initializers; 198 NodeList initializers = function.initializers;
199 NodeList parameters = function.parameters; 199 NodeList parameters = function.parameters;
200 // Run through the initializers. 200 // Run through the initializers.
201 if (initializers !== null) { 201 if (initializers !== null) {
202 for (Link<Node> link = initializers.nodes; 202 for (Link<Node> link = initializers.nodes;
203 !link.isEmpty(); 203 !link.isEmpty();
204 link = link.tail) { 204 link = link.tail) {
205 assert(link.head is Send); 205 assert(link.head is Send);
206 if (link.head is !SendSet) { 206 if (link.head is !SendSet) {
207 compiler.unimplemented('SsaBuilder.buildFactory super-init'); 207 compiler.unimplemented('SsaBuilder.buildFactory super-init');
208 } else {
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);
208 } 215 }
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 } 216 }
216 } 217 }
217 218
218 // Call the JavaScript constructor with the fields as argument. 219 // Call the JavaScript constructor with the fields as argument.
219 // TODO(floitsch): allow super calls. 220 // TODO(floitsch): allow super calls.
220 // TODO(floitsch): allow inits at field declarations. 221 // TODO(floitsch): allow inits at field declarations.
221 List<HInstruction> fieldValues = <HInstruction>[]; 222 List<HInstruction> fieldValues = <HInstruction>[];
222 for (Element member in classElement.members) { 223 for (Element member in classElement.members) {
223 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { 224 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) {
224 HInstruction value = definitions[member]; 225 HInstruction value = definitions[member];
225 if (value === null) { 226 if (value === null) {
226 value = new HLiteral(null, HType.UNKNOWN); 227 value = new HLiteral(null, HType.UNKNOWN);
227 add(value); 228 add(value);
228 } 229 }
229 fieldValues.add(value); 230 fieldValues.add(value);
230 } 231 }
231 } 232 }
232 HForeignNew newObject = new HForeignNew(classElement, fieldValues); 233 HForeignNew newObject = new HForeignNew(classElement, fieldValues);
233 add(newObject); 234 add(newObject);
234 235
235 // Call the method body. 236 // Call the method body.
236 String methodName = compiler.namer.getName(bodyElement); 237 String methodName = compiler.namer.getName(bodyElement);
237 List bodyCallInputs = <HInstruction>[]; 238 List bodyCallInputs = <HInstruction>[];
238 bodyCallInputs.add(newObject); 239 bodyCallInputs.add(newObject);
239 for (Link link = parameters.nodes; !link.isEmpty(); link = link.tail) { 240 for (Link link = parameters.nodes; !link.isEmpty(); link = link.tail) {
240 Link<Node> identifierLink = link.head.definitions.nodes; 241 Link<Node> identifierLink = link.head.definitions.nodes;
241 // We expect exactly one identifier. 242 // We expect exactly one identifier.
242 assert(!identifierLink.isEmpty() && identifierLink.tail.isEmpty()); 243 assert(!identifierLink.isEmpty() && identifierLink.tail.isEmpty());
243 if (identifierLink.head is !Identifier) { 244 if (identifierLink.head is !Identifier) {
244 compiler.unimplemented( 245 compiler.unimplemented("SsaBuilder.buildFactory non-identifier");
245 "SsaBuilder.buildFactory non-identifier");
246 } 246 }
247 Identifier name = identifierLink.head; 247 Identifier name = identifierLink.head;
248 Element parameterElement = elements[name]; 248 Element parameterElement = elements[name];
249 HInstruction currentValue = definitions[parameterElement]; 249 HInstruction currentValue = definitions[parameterElement];
250 bodyCallInputs.add(currentValue); 250 bodyCallInputs.add(currentValue);
251 } 251 }
252 add(new HInvokeDynamicMethod(methodName, bodyCallInputs)); 252 add(new HInvokeDynamicMethod(methodName, bodyCallInputs));
253 close(new HReturn(newObject)).addSuccessor(graph.exit); 253 close(new HReturn(newObject)).addSuccessor(graph.exit);
254 return closeFunction(); 254 return closeFunction();
255 } 255 }
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 } 798 }
799 799
800 void generateGetter(Send send, Element element) { 800 void generateGetter(Send send, Element element) {
801 if (Elements.isStaticOrTopLevelField(element)) { 801 if (Elements.isStaticOrTopLevelField(element)) {
802 push(new HStatic(element)); 802 push(new HStatic(element));
803 } else if (element === null || Elements.isInstanceField(element)) { 803 } else if (element === null || Elements.isInstanceField(element)) {
804 HInstruction receiver; 804 HInstruction receiver;
805 if (send.receiver == null) { 805 if (send.receiver == null) {
806 receiver = thisDefinition; 806 receiver = thisDefinition;
807 if (receiver === null) { 807 if (receiver === null) {
808 compiler.unimplemented("Ssa.generateGetter.", node: send); 808 compiler.unimplemented("SsaBuilder.generateGetter.", node: send);
809 } 809 }
810 } else { 810 } else {
811 visit(send.receiver); 811 visit(send.receiver);
812 receiver = pop(); 812 receiver = pop();
813 } 813 }
814 SourceString getterName = send.selector.asIdentifier().source; 814 SourceString getterName = send.selector.asIdentifier().source;
815 Element staticInterceptor = null; 815 Element staticInterceptor = null;
816 if (methodInterceptionEnabled) { 816 if (methodInterceptionEnabled) {
817 staticInterceptor = interceptors.getStaticGetInterceptor(getterName); 817 staticInterceptor = interceptors.getStaticGetInterceptor(getterName);
818 } 818 }
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 } 1417 }
1418 1418
1419 visitCatchBlock(CatchBlock node) { 1419 visitCatchBlock(CatchBlock node) {
1420 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node); 1420 compiler.unimplemented('SsaBuilder.visitCatchBlock', node: node);
1421 } 1421 }
1422 1422
1423 visitTypedef(Typedef node) { 1423 visitTypedef(Typedef node) {
1424 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 1424 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
1425 } 1425 }
1426 } 1426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698