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

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

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

Powered by Google App Engine
This is Rietveld 408576698