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

Side by Side Diff: frog/leg/emitter.dart

Issue 9773026: Add a method on native classes for is checks. Reduces the code for generating is checks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | frog/leg/lib/native_helper.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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 buffer.add('$parametersString) {\n'); 158 buffer.add('$parametersString) {\n');
159 159
160 if (isNative) { 160 if (isNative) {
161 nativeEmitter.emitParameterStub( 161 nativeEmitter.emitParameterStub(
162 member, invocationName, parametersString, argumentsBuffer, 162 member, invocationName, parametersString, argumentsBuffer,
163 indexOfLastOptionalArgumentInParameters); 163 indexOfLastOptionalArgumentInParameters);
164 } else { 164 } else {
165 String arguments = Strings.join(argumentsBuffer, ","); 165 String arguments = Strings.join(argumentsBuffer, ",");
166 buffer.add(' return this.${namer.getName(member)}($arguments)'); 166 buffer.add(' return this.${namer.getName(member)}($arguments)');
167 } 167 }
168 buffer.add('\n}\n'); 168 buffer.add('\n};\n');
169 } 169 }
170 170
171 void addParameterStubs(FunctionElement member, 171 void addParameterStubs(FunctionElement member,
172 String attachTo(String invocationName), 172 String attachTo(String invocationName),
173 StringBuffer buffer, 173 StringBuffer buffer,
174 [bool isNative = false]) { 174 [bool isNative = false]) {
175 Set<Selector> selectors = compiler.universe.invokedNames[member.name]; 175 Set<Selector> selectors = compiler.universe.invokedNames[member.name];
176 if (selectors == null) return; 176 if (selectors == null) return;
177 FunctionParameters parameters = member.computeParameters(compiler); 177 FunctionParameters parameters = member.computeParameters(compiler);
178 for (Selector selector in selectors) { 178 for (Selector selector in selectors) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 if (member.isInstanceMember()) { 311 if (member.isInstanceMember()) {
312 addInstanceMember(member, attachTo, buffer); 312 addInstanceMember(member, attachTo, buffer);
313 } 313 }
314 } 314 }
315 for (Element member in classElement.backendMembers) { 315 for (Element member in classElement.backendMembers) {
316 if (member.isInstanceMember()) { 316 if (member.isInstanceMember()) {
317 addInstanceMember(member, attachTo, buffer); 317 addInstanceMember(member, attachTo, buffer);
318 } 318 }
319 } 319 }
320 generateTypeTests(classElement, (Element other) { 320 generateTypeTests(classElement, (Element other) {
321 buffer.add('${attachTo(namer.operatorIs(other))} = true;\n'); 321 buffer.add('${attachTo(namer.operatorIs(other))} = ');
322 if (nativeEmitter.requiresNativeIsCheck(other)) {
323 buffer.add('function() { return true; }');
324 } else {
325 buffer.add('true');
326 }
327 buffer.add(';\n');
322 }); 328 });
323 329
324 if (classElement === compiler.objectClass && compiler.enabledNoSuchMethod) { 330 if (classElement === compiler.objectClass && compiler.enabledNoSuchMethod) {
325 // Emit the noSuchMethods on the Object prototype now, so that 331 // Emit the noSuchMethods on the Object prototype now, so that
326 // the code in the dynamicMethod can find them. Note that the 332 // the code in the dynamicMethod can find them. Note that the
327 // code in dynamicMethod is invoked before analyzing the full JS 333 // code in dynamicMethod is invoked before analyzing the full JS
328 // script. 334 // script.
329 emitNoSuchMethodCalls(buffer); 335 emitNoSuchMethodCalls(buffer);
330 } 336 }
331 } 337 }
332 338
333 void generateTypeTests(ClassElement cls, 339 void generateTypeTests(ClassElement cls,
334 void generateTypeTest(ClassElement element)) { 340 void generateTypeTest(ClassElement element)) {
335 if (compiler.universe.isChecks.contains(cls)) { 341 if (compiler.universe.isChecks.contains(cls)) {
336 generateTypeTest(cls); 342 generateTypeTest(cls);
337 } 343 }
338 generateInterfacesIsTests(cls, generateTypeTest); 344 generateInterfacesIsTests(cls, generateTypeTest, new Set<Element>());
339 } 345 }
340 346
341 void generateInterfacesIsTests(ClassElement cls, 347 void generateInterfacesIsTests(ClassElement cls,
342 void generateTypeTest(ClassElement element)) { 348 void generateTypeTest(ClassElement element),
349 Set<Element> alreadyGenerated) {
343 for (Type interfaceType in cls.interfaces) { 350 for (Type interfaceType in cls.interfaces) {
344 Element element = interfaceType.element; 351 Element element = interfaceType.element;
345 if (compiler.universe.isChecks.contains(element)) { 352 if (!alreadyGenerated.contains(element) &&
353 compiler.universe.isChecks.contains(element)) {
354 alreadyGenerated.add(element);
346 generateTypeTest(element); 355 generateTypeTest(element);
347 } 356 }
348 generateInterfacesIsTests(element, generateTypeTest); 357 generateInterfacesIsTests(element, generateTypeTest, alreadyGenerated);
349 } 358 }
350 } 359 }
351 360
352 void emitClasses(StringBuffer buffer) { 361 void emitClasses(StringBuffer buffer) {
353 for (ClassElement element in compiler.universe.instantiatedClasses) { 362 for (ClassElement element in compiler.universe.instantiatedClasses) {
354 ensureGenerated(element, buffer); 363 ensureGenerated(element, buffer);
355 } 364 }
356 } 365 }
357 366
358 void emitStaticFunctionsWithNamer(StringBuffer buffer, 367 void emitStaticFunctionsWithNamer(StringBuffer buffer,
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 nativeEmitter.emitDynamicDispatchMetadata(); 715 nativeEmitter.emitDynamicDispatchMetadata();
707 mainBuffer.add( 716 mainBuffer.add(
708 'var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); 717 'var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n');
709 nativeEmitter.assembleCode(mainBuffer); 718 nativeEmitter.assembleCode(mainBuffer);
710 emitMain(mainBuffer); 719 emitMain(mainBuffer);
711 compiler.assembledCode = mainBuffer.toString(); 720 compiler.assembledCode = mainBuffer.toString();
712 }); 721 });
713 return compiler.assembledCode; 722 return compiler.assembledCode;
714 } 723 }
715 } 724 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/lib/native_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698