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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 1062913003: Extract CallStructure from Selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // TODO(ahe): Enable the next line when I can tell the difference between 330 // TODO(ahe): Enable the next line when I can tell the difference between
331 // an instance method and a global. They may have the same mangled name. 331 // an instance method and a global. They may have the same mangled name.
332 // if (recordedMangledNames.contains(mangledName)) return null; 332 // if (recordedMangledNames.contains(mangledName)) return null;
333 recordedMangledNames.add(mangledName); 333 recordedMangledNames.add(mangledName);
334 return getReflectionNameInternal(elementOrSelector, mangledName); 334 return getReflectionNameInternal(elementOrSelector, mangledName);
335 } 335 }
336 return null; 336 return null;
337 } 337 }
338 338
339 String getReflectionNameInternal(elementOrSelector, String mangledName) { 339 String getReflectionNameInternal(elementOrSelector, String mangledName) {
340 String name = 340 String name = namer.privateName(elementOrSelector.memberName);
341 namer.privateName(elementOrSelector.library, elementOrSelector.name);
342 if (elementOrSelector.isGetter) return name; 341 if (elementOrSelector.isGetter) return name;
343 if (elementOrSelector.isSetter) { 342 if (elementOrSelector.isSetter) {
344 if (!mangledName.startsWith(namer.setterPrefix)) return '$name='; 343 if (!mangledName.startsWith(namer.setterPrefix)) return '$name=';
345 String base = mangledName.substring(namer.setterPrefix.length); 344 String base = mangledName.substring(namer.setterPrefix.length);
346 String getter = '${namer.getterPrefix}$base'; 345 String getter = '${namer.getterPrefix}$base';
347 mangledFieldNames.putIfAbsent(getter, () => name); 346 mangledFieldNames.putIfAbsent(getter, () => name);
348 assert(mangledFieldNames[getter] == name); 347 assert(mangledFieldNames[getter] == name);
349 recordedMangledNames.add(getter); 348 recordedMangledNames.add(getter);
350 // TODO(karlklose,ahe): we do not actually need to store information 349 // TODO(karlklose,ahe): we do not actually need to store information
351 // about the name of this setter in the output, but it is needed for 350 // about the name of this setter in the output, but it is needed for
352 // marking the function as invokable by reflection. 351 // marking the function as invokable by reflection.
353 return '$name='; 352 return '$name=';
354 } 353 }
355 if (elementOrSelector is Element && elementOrSelector.isClosure) { 354 if (elementOrSelector is Element && elementOrSelector.isClosure) {
356 // Closures are synthesized and their name might conflict with existing 355 // Closures are synthesized and their name might conflict with existing
357 // globals. Assign an illegal name, and make sure they don't clash 356 // globals. Assign an illegal name, and make sure they don't clash
358 // with each other. 357 // with each other.
359 return " $mangledName"; 358 return " $mangledName";
360 } 359 }
361 if (elementOrSelector is Selector 360 if (elementOrSelector is Selector
362 || elementOrSelector.isFunction 361 || elementOrSelector.isFunction
363 || elementOrSelector.isConstructor) { 362 || elementOrSelector.isConstructor) {
364 int positionalParameterCount; 363 int positionalParameterCount;
365 String namedArguments = ''; 364 String namedArguments = '';
366 bool isConstructor = false; 365 bool isConstructor = false;
367 if (elementOrSelector is Selector) { 366 if (elementOrSelector is Selector) {
368 Selector selector = elementOrSelector; 367 CallStructure callStructure = elementOrSelector.callStructure;
369 positionalParameterCount = selector.positionalArgumentCount; 368 positionalParameterCount = callStructure.positionalArgumentCount;
370 namedArguments = namedParametersAsReflectionNames(selector); 369 namedArguments = namedParametersAsReflectionNames(callStructure);
371 } else { 370 } else {
372 FunctionElement function = elementOrSelector; 371 FunctionElement function = elementOrSelector;
373 if (function.isConstructor) { 372 if (function.isConstructor) {
374 isConstructor = true; 373 isConstructor = true;
375 name = Elements.reconstructConstructorName(function); 374 name = Elements.reconstructConstructorName(function);
376 } 375 }
377 FunctionSignature signature = function.functionSignature; 376 FunctionSignature signature = function.functionSignature;
378 positionalParameterCount = signature.requiredParameterCount; 377 positionalParameterCount = signature.requiredParameterCount;
379 if (signature.optionalParametersAreNamed) { 378 if (signature.optionalParametersAreNamed) {
380 var names = []; 379 var names = [];
381 for (Element e in signature.optionalParameters) { 380 for (Element e in signature.optionalParameters) {
382 names.add(e.name); 381 names.add(e.name);
383 } 382 }
384 Selector selector = new Selector.call( 383 CallStructure callStructure =
385 function.name, 384 new CallStructure(positionalParameterCount, names);
386 function.library, 385 namedArguments = namedParametersAsReflectionNames(callStructure);
387 positionalParameterCount,
388 names);
389 namedArguments = namedParametersAsReflectionNames(selector);
390 } else { 386 } else {
391 // Named parameters are handled differently by mirrors. For unnamed 387 // Named parameters are handled differently by mirrors. For unnamed
392 // parameters, they are actually required if invoked 388 // parameters, they are actually required if invoked
393 // reflectively. Also, if you have a method c(x) and c([x]) they both 389 // reflectively. Also, if you have a method c(x) and c([x]) they both
394 // get the same mangled name, so they must have the same reflection 390 // get the same mangled name, so they must have the same reflection
395 // name. 391 // name.
396 positionalParameterCount += signature.optionalParameterCount; 392 positionalParameterCount += signature.optionalParameterCount;
397 } 393 }
398 } 394 }
399 String suffix = '$name:$positionalParameterCount$namedArguments'; 395 String suffix = '$name:$positionalParameterCount$namedArguments';
400 return (isConstructor) ? 'new $suffix' : suffix; 396 return (isConstructor) ? 'new $suffix' : suffix;
401 } 397 }
402 Element element = elementOrSelector; 398 Element element = elementOrSelector;
403 if (element.isGenerativeConstructorBody) { 399 if (element.isGenerativeConstructorBody) {
404 return null; 400 return null;
405 } else if (element.isClass) { 401 } else if (element.isClass) {
406 ClassElement cls = element; 402 ClassElement cls = element;
407 if (cls.isUnnamedMixinApplication) return null; 403 if (cls.isUnnamedMixinApplication) return null;
408 return cls.name; 404 return cls.name;
409 } else if (element.isTypedef) { 405 } else if (element.isTypedef) {
410 return element.name; 406 return element.name;
411 } 407 }
412 throw compiler.internalError(element, 408 throw compiler.internalError(element,
413 'Do not know how to reflect on this $element.'); 409 'Do not know how to reflect on this $element.');
414 } 410 }
415 411
416 String namedParametersAsReflectionNames(Selector selector) { 412 String namedParametersAsReflectionNames(CallStructure structure) {
417 if (selector.getOrderedNamedArguments().isEmpty) return ''; 413 if (structure.isUnnamed) return '';
418 String names = selector.getOrderedNamedArguments().join(':'); 414 String names = structure.getOrderedNamedArguments().join(':');
419 return ':$names'; 415 return ':$names';
420 } 416 }
421 417
422 jsAst.Statement buildCspPrecompiledFunctionFor( 418 jsAst.Statement buildCspPrecompiledFunctionFor(
423 OutputUnit outputUnit) { 419 OutputUnit outputUnit) {
424 // TODO(ahe): Compute a hash code. 420 // TODO(ahe): Compute a hash code.
425 // TODO(sigurdm): Avoid this precompiled function. Generated 421 // TODO(sigurdm): Avoid this precompiled function. Generated
426 // constructor-functions and getter/setter functions can be stored in the 422 // constructor-functions and getter/setter functions can be stored in the
427 // library-description table. Setting properties on these can be moved to 423 // library-description table. Setting properties on these can be moved to
428 // finishClasses. 424 // finishClasses.
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 1856 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
1861 if (element.isInstanceMember) { 1857 if (element.isInstanceMember) {
1862 cachedClassBuilders.remove(element.enclosingClass); 1858 cachedClassBuilders.remove(element.enclosingClass);
1863 1859
1864 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 1860 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
1865 1861
1866 } 1862 }
1867 } 1863 }
1868 } 1864 }
1869 } 1865 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698