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

Side by Side Diff: dart/lib/compiler/implementation/emitter.dart

Issue 10511008: Support overriding fields with fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 6 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 | « no previous file | dart/lib/compiler/implementation/namer.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * A function element that represents a closure call. The signature is copied 6 * A function element that represents a closure call. The signature is copied
7 * from the given element. 7 * from the given element.
8 */ 8 */
9 class ClosureInvocationElement extends FunctionElement { 9 class ClosureInvocationElement extends FunctionElement {
10 ClosureInvocationElement(SourceString name, 10 ClosureInvocationElement(SourceString name,
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 defineInstanceMember(namer.getName(member), codeBlock); 391 defineInstanceMember(namer.getName(member), codeBlock);
392 codeBlock = compiler.codegenWorld.generatedBailoutCode[member]; 392 codeBlock = compiler.codegenWorld.generatedBailoutCode[member];
393 if (codeBlock !== null) { 393 if (codeBlock !== null) {
394 defineInstanceMember(compiler.namer.getBailoutName(member), codeBlock); 394 defineInstanceMember(compiler.namer.getBailoutName(member), codeBlock);
395 } 395 }
396 FunctionElement function = member; 396 FunctionElement function = member;
397 FunctionSignature parameters = function.computeSignature(compiler); 397 FunctionSignature parameters = function.computeSignature(compiler);
398 if (!parameters.optionalParameters.isEmpty()) { 398 if (!parameters.optionalParameters.isEmpty()) {
399 addParameterStubs(member, defineInstanceMember); 399 addParameterStubs(member, defineInstanceMember);
400 } 400 }
401 } else if (member.kind !== ElementKind.FIELD) { 401 } else if (member.kind === ElementKind.FIELD) {
402 SourceString name = member.name;
403 ClassElement cls = member.getEnclosingClass();
404 if (cls.lookupSuperMember(name) !== null) {
405 String fieldName = namer.instanceFieldName(cls, name);
406 defineInstanceMember(namer.getterName(cls.getLibrary(), name),
407 'function() {\n return this.$fieldName;\n }');
408 defineInstanceMember(namer.setterName(cls.getLibrary(), name),
409 'function(x) {\n this.$fieldName = x;\n }');
410 }
411 } else {
402 compiler.internalError('unexpected kind: "${member.kind}"', 412 compiler.internalError('unexpected kind: "${member.kind}"',
403 element: member); 413 element: member);
404 } 414 }
405 emitExtraAccessors(member, defineInstanceMember); 415 emitExtraAccessors(member, defineInstanceMember);
406 } 416 }
407 417
408 Set<Element> emitClassFields(ClassElement classElement, StringBuffer buffer) { 418 Set<Element> emitClassFields(ClassElement classElement, StringBuffer buffer) {
409 // If the class is never instantiated we still need to set it up for 419 // If the class is never instantiated we still need to set it up for
410 // inheritance purposes, but we can simplify its JavaScript constructor. 420 // inheritance purposes, but we can simplify its JavaScript constructor.
411 bool isInstantiated = 421 bool isInstantiated =
(...skipping 14 matching lines...) Expand all
426 } 436 }
427 437
428 if ((isInstantiated && !enclosingClass.isNative()) 438 if ((isInstantiated && !enclosingClass.isNative())
429 || needsDynamicGetter 439 || needsDynamicGetter
430 || needsDynamicSetter) { 440 || needsDynamicSetter) {
431 if (isFirstField) { 441 if (isFirstField) {
432 isFirstField = false; 442 isFirstField = false;
433 } else { 443 } else {
434 buffer.add(", "); 444 buffer.add(", ");
435 } 445 }
436 LibraryElement library = member.getLibrary();
437 SourceString name = member.name; 446 SourceString name = member.name;
438 String fieldName = namer.instanceFieldName(library, name); 447 String fieldName = namer.instanceFieldName(member.getEnclosingClass(),
448 name);
439 // Getters and setters with suffixes will be generated dynamically. 449 // Getters and setters with suffixes will be generated dynamically.
440 buffer.add('"$fieldName'); 450 buffer.add('"$fieldName');
441 if (needsDynamicGetter || needsDynamicSetter) { 451 if (needsDynamicGetter || needsDynamicSetter) {
442 if (needsDynamicGetter && needsDynamicSetter) { 452 if (needsDynamicGetter && needsDynamicSetter) {
443 buffer.add(GETTER_SETTER_SUFFIX); 453 buffer.add(GETTER_SETTER_SUFFIX);
444 } else if (needsDynamicGetter) { 454 } else if (needsDynamicGetter) {
445 buffer.add(GETTER_SUFFIX); 455 buffer.add(GETTER_SUFFIX);
446 } else { 456 } else {
447 buffer.add(SETTER_SUFFIX); 457 buffer.add(SETTER_SUFFIX);
448 } 458 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 720 }
711 721
712 void emitCallStubForGetter(Element member, 722 void emitCallStubForGetter(Element member,
713 Set<Selector> selectors, 723 Set<Selector> selectors,
714 void defineInstanceMember(String invocationName, 724 void defineInstanceMember(String invocationName,
715 String definition)) { 725 String definition)) {
716 String getter; 726 String getter;
717 if (member.kind == ElementKind.GETTER) { 727 if (member.kind == ElementKind.GETTER) {
718 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()"; 728 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()";
719 } else { 729 } else {
720 getter = 730 String name = namer.instanceFieldName(member.getEnclosingClass(),
721 "this.${namer.instanceFieldName(member.getLibrary(), member.name)}"; 731 member.name);
732 getter = "this.$name";
722 } 733 }
723 for (Selector selector in selectors) { 734 for (Selector selector in selectors) {
724 if (selector.applies(member, compiler)) { 735 if (selector.applies(member, compiler)) {
725 String invocationName = 736 String invocationName =
726 namer.instanceMethodInvocationName(member.getLibrary(), member.name, 737 namer.instanceMethodInvocationName(member.getLibrary(), member.name,
727 selector); 738 selector);
728 SourceString callName = Namer.CLOSURE_INVOCATION_NAME; 739 SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
729 String closureCallName = 740 String closureCallName =
730 namer.instanceMethodInvocationName(member.getLibrary(), callName, 741 namer.instanceMethodInvocationName(member.getLibrary(), callName,
731 selector); 742 selector);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 mainBuffer.add('function init() {\n'); 1000 mainBuffer.add('function init() {\n');
990 mainBuffer.add(' $isolateProperties = {};\n'); 1001 mainBuffer.add(' $isolateProperties = {};\n');
991 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); 1002 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer);
992 emitFinishIsolateConstructor(mainBuffer); 1003 emitFinishIsolateConstructor(mainBuffer);
993 mainBuffer.add('}\n'); 1004 mainBuffer.add('}\n');
994 compiler.assembledCode = mainBuffer.toString(); 1005 compiler.assembledCode = mainBuffer.toString();
995 }); 1006 });
996 return compiler.assembledCode; 1007 return compiler.assembledCode;
997 } 1008 }
998 } 1009 }
OLDNEW
« no previous file with comments | « no previous file | dart/lib/compiler/implementation/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698