OLD | NEW |
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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 669 |
670 bool isForeign(Element element) => element.library == foreignLibrary; | 670 bool isForeign(Element element) => element.library == foreignLibrary; |
671 | 671 |
672 bool isBackendLibrary(LibraryElement library) { | 672 bool isBackendLibrary(LibraryElement library) { |
673 return library == interceptorsLibrary || | 673 return library == interceptorsLibrary || |
674 library == jsHelperLibrary; | 674 library == jsHelperLibrary; |
675 } | 675 } |
676 | 676 |
677 static Namer determineNamer(Compiler compiler) { | 677 static Namer determineNamer(Compiler compiler) { |
678 return compiler.enableMinification ? | 678 return compiler.enableMinification ? |
679 new MinifyNamer(compiler) : | 679 compiler.useFrequencyNamer ? |
| 680 new FrequencyBasedNamer(compiler) : |
| 681 new MinifyNamer(compiler) : |
680 new Namer(compiler); | 682 new Namer(compiler); |
681 } | 683 } |
682 | 684 |
683 bool usedByBackend(Element element) { | 685 bool usedByBackend(Element element) { |
684 if (element.isParameter | 686 if (element.isParameter |
685 || element.isInitializingFormal | 687 || element.isInitializingFormal |
686 || element.isField) { | 688 || element.isField) { |
687 if (usedByBackend(element.enclosingElement)) return true; | 689 if (usedByBackend(element.enclosingElement)) return true; |
688 } | 690 } |
689 return helpersUsed.contains(element.declaration); | 691 return helpersUsed.contains(element.declaration); |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1455 return element.isNative ? jsInterceptorClass : compiler.objectClass; | 1457 return element.isNative ? jsInterceptorClass : compiler.objectClass; |
1456 } | 1458 } |
1457 | 1459 |
1458 /** | 1460 /** |
1459 * Unit test hook that returns code of an element as a String. | 1461 * Unit test hook that returns code of an element as a String. |
1460 * | 1462 * |
1461 * Invariant: [element] must be a declaration element. | 1463 * Invariant: [element] must be a declaration element. |
1462 */ | 1464 */ |
1463 String assembleCode(Element element) { | 1465 String assembleCode(Element element) { |
1464 assert(invariant(element, element.isDeclaration)); | 1466 assert(invariant(element, element.isDeclaration)); |
| 1467 var code = generatedCode[element]; |
| 1468 if (namer is jsAst.TokenFinalizer) { |
| 1469 jsAst.TokenCounter counter = new jsAst.TokenCounter(); |
| 1470 counter.countTokens(code); |
| 1471 namer.finalizeTokens(); |
| 1472 } |
1465 return jsAst.prettyPrint(generatedCode[element], compiler).getText(); | 1473 return jsAst.prettyPrint(generatedCode[element], compiler).getText(); |
1466 } | 1474 } |
1467 | 1475 |
1468 int assembleProgram() { | 1476 int assembleProgram() { |
1469 int programSize = emitter.assembleProgram(); | 1477 int programSize = emitter.assembleProgram(); |
1470 noSuchMethodRegistry.emitDiagnostic(); | 1478 noSuchMethodRegistry.emitDiagnostic(); |
1471 int totalMethodCount = generatedCode.length; | 1479 int totalMethodCount = generatedCode.length; |
1472 if (totalMethodCount != preMirrorsMethodCount) { | 1480 if (totalMethodCount != preMirrorsMethodCount) { |
1473 int mirrorCount = totalMethodCount - preMirrorsMethodCount; | 1481 int mirrorCount = totalMethodCount - preMirrorsMethodCount; |
1474 double percentage = (mirrorCount / totalMethodCount) * 100; | 1482 double percentage = (mirrorCount / totalMethodCount) * 100; |
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2988 } | 2996 } |
2989 } | 2997 } |
2990 | 2998 |
2991 /// Records that [constant] is used by the element behind [registry]. | 2999 /// Records that [constant] is used by the element behind [registry]. |
2992 class Dependency { | 3000 class Dependency { |
2993 final ConstantValue constant; | 3001 final ConstantValue constant; |
2994 final Element annotatedElement; | 3002 final Element annotatedElement; |
2995 | 3003 |
2996 const Dependency(this.constant, this.annotatedElement); | 3004 const Dependency(this.constant, this.annotatedElement); |
2997 } | 3005 } |
OLD | NEW |