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

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

Issue 9873012: Move member-iterating code into ClassElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 8 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) 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 compiler.internalError('unexpected kind: "${member.kind}"', 228 compiler.internalError('unexpected kind: "${member.kind}"',
229 element: member); 229 element: member);
230 } 230 }
231 emitExtraAccessors(member, attachTo, buffer); 231 emitExtraAccessors(member, attachTo, buffer);
232 } 232 }
233 233
234 bool generateFieldInits(ClassElement classElement, 234 bool generateFieldInits(ClassElement classElement,
235 StringBuffer argumentsBuffer, 235 StringBuffer argumentsBuffer,
236 StringBuffer bodyBuffer) { 236 StringBuffer bodyBuffer) {
237 bool isFirst = true; 237 bool isFirst = true;
238 do { 238 void generateFieldInit(ClassElement enclosingClass, Element member) {
239 // TODO(floitsch): make sure there are no name clashes. 239 // TODO(floitsch): make sure there are no name clashes.
240 String className = namer.getName(classElement); 240 String className = namer.getName(enclosingClass);
241 if (!isFirst) argumentsBuffer.add(', ');
242 isFirst = false;
243 String memberName = namer.instanceFieldName(member.getLibrary(),
244 member.name);
245 argumentsBuffer.add('${className}_$memberName');
246 bodyBuffer.add(' this.$memberName = ${className}_$memberName;\n');
247 }
241 248
242 void generateFieldInit(Element member) { 249 classElement.forEachInstanceField(generateFieldInit,
243 if (member.isInstanceMember() && member.kind == ElementKind.FIELD) { 250 includeBackendMembers: true,
244 if (!isFirst) argumentsBuffer.add(', '); 251 includeSuperMembers: true);
245 isFirst = false;
246 String memberName = namer.instanceFieldName(member.getLibrary(),
247 member.name);
248 argumentsBuffer.add('${className}_$memberName');
249 bodyBuffer.add(' this.$memberName = ${className}_$memberName;\n');
250 }
251 }
252
253 for (Element element in classElement.members) {
254 generateFieldInit(element);
255 }
256 for (Element element in classElement.backendMembers) {
257 generateFieldInit(element);
258 }
259
260 classElement = classElement.superclass;
261 } while(classElement !== null);
262 } 252 }
263 253
264 void emitInherits(ClassElement cls, StringBuffer buffer) { 254 void emitInherits(ClassElement cls, StringBuffer buffer) {
265 ClassElement superclass = cls.superclass; 255 ClassElement superclass = cls.superclass;
266 if (superclass !== null) { 256 if (superclass !== null) {
267 addInheritFunctionIfNecessary(); 257 addInheritFunctionIfNecessary();
268 String className = namer.isolatePropertyAccess(cls); 258 String className = namer.isolatePropertyAccess(cls);
269 String superName = namer.isolatePropertyAccess(superclass); 259 String superName = namer.isolatePropertyAccess(superclass);
270 buffer.add('${inheritsName}($className, $superName);\n'); 260 buffer.add('${inheritsName}($className, $superName);\n');
271 } 261 }
(...skipping 28 matching lines...) Expand all
300 if (compiler.universe.instantiatedClasses.contains(classElement)) { 290 if (compiler.universe.instantiatedClasses.contains(classElement)) {
301 generateFieldInits(classElement, buffer, bodyBuffer); 291 generateFieldInits(classElement, buffer, bodyBuffer);
302 } 292 }
303 buffer.add(') {\n'); 293 buffer.add(') {\n');
304 buffer.add(bodyBuffer); 294 buffer.add(bodyBuffer);
305 buffer.add('};\n'); 295 buffer.add('};\n');
306 296
307 emitInherits(classElement, buffer); 297 emitInherits(classElement, buffer);
308 298
309 String attachTo(String name) => '$className.prototype.$name'; 299 String attachTo(String name) => '$className.prototype.$name';
310 for (Element member in classElement.members) { 300
301 classElement.forEachMember(includeBackendMembers: true,
302 f: (ClassElement enclosing, Element member) {
311 if (member.isInstanceMember()) { 303 if (member.isInstanceMember()) {
312 addInstanceMember(member, attachTo, buffer); 304 addInstanceMember(member, attachTo, buffer);
313 } 305 }
314 } 306 });
315 for (Element member in classElement.backendMembers) { 307
316 if (member.isInstanceMember()) {
317 addInstanceMember(member, attachTo, buffer);
318 }
319 }
320 generateTypeTests(classElement, (Element other) { 308 generateTypeTests(classElement, (Element other) {
321 buffer.add('${attachTo(namer.operatorIs(other))} = '); 309 buffer.add('${attachTo(namer.operatorIs(other))} = ');
322 if (nativeEmitter.requiresNativeIsCheck(other)) { 310 if (nativeEmitter.requiresNativeIsCheck(other)) {
323 buffer.add('function() { return true; }'); 311 buffer.add('function() { return true; }');
324 } else { 312 } else {
325 buffer.add('true'); 313 buffer.add('true');
326 } 314 }
327 buffer.add(';\n'); 315 buffer.add(';\n');
328 }); 316 });
329 317
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 nativeEmitter.emitDynamicDispatchMetadata(); 721 nativeEmitter.emitDynamicDispatchMetadata();
734 mainBuffer.add( 722 mainBuffer.add(
735 'var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 723 'var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
736 nativeEmitter.assembleCode(mainBuffer); 724 nativeEmitter.assembleCode(mainBuffer);
737 emitMain(mainBuffer); 725 emitMain(mainBuffer);
738 compiler.assembledCode = mainBuffer.toString(); 726 compiler.assembledCode = mainBuffer.toString();
739 }); 727 });
740 return compiler.assembledCode; 728 return compiler.assembledCode;
741 } 729 }
742 } 730 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698