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

Unified Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 1212613009: dart2js: Implement frequency based naming. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Reserve reserved names :) Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
index f34051c1445732921a6a866c33733d1c86869a7c..f8d369589eabcc76ce8fe19cabca17410b9b8b61 100644
--- a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
@@ -33,47 +33,6 @@ import 'package:js_runtime/shared/embedded_names.dart' show
import '../js_emitter.dart' show NativeGenerator, buildTearOffCode;
import '../model.dart';
-/// Represents the LiteralString resulting from unparsing [expression]. The
-/// actual unparsing is done on demand when requesting the [value] of this
-/// node.
-class _UnparsedNode extends js.DeferredString
- implements AstContainer {
- @override
- final js.Node ast;
- final Compiler _compiler;
- final bool _protectForEval;
- js.LiteralString _cachedLiteral;
-
- /// A [js.Literal] that represents the string result of unparsing [ast].
- ///
- /// When its string [value] is requested, the node pretty-prints the given
- /// [ast] and, if [protectForEval] is true, wraps the resulting
- /// string in parenthesis. The result is also escaped.
- _UnparsedNode(this.ast, this._compiler, this._protectForEval);
-
- js.LiteralString get _literal {
- if (_cachedLiteral == null) {
- String text = js.prettyPrint(ast, _compiler).getText();
- if (_protectForEval) {
- if (ast is js.Fun) text = '($text)';
- if (ast is js.LiteralExpression) {
- js.LiteralExpression literalExpression = ast;
- String template = literalExpression.template;
- if (template.startsWith("function ") ||
- template.startsWith("{")) {
- text = '($text)';
- }
- }
- }
- _cachedLiteral = js.js.escapedString(text);
- }
- return _cachedLiteral;
- }
-
- @override
- String get value => _literal.value;
-}
-
class ModelEmitter {
final Compiler compiler;
final Namer namer;
@@ -185,9 +144,11 @@ class ModelEmitter {
js.Statement mainAst = emitMainFragment(program);
- fragmentsCode.forEach(program.metadataFinalizer.countTokensInAst);
- program.metadataFinalizer.countTokensInAst(mainAst);
- program.metadataFinalizer.finalizeTokens();
+ js.TokenCounter counter = new js.TokenCounter();
+ fragmentsCode.forEach(counter.countTokens);
+ counter.countTokens(mainAst);
+
+ program.finalizers.forEach((js.TokenFinalizer f) => f.finalizeTokens());
for (int i = 0; i < fragmentsCode.length; ++i) {
String code = js.prettyPrint(fragmentsCode[i], compiler).getText();
@@ -217,7 +178,7 @@ class ModelEmitter {
/// See [_UnparsedNode] for details.
js.Literal unparse(Compiler compiler, js.Node value,
{bool protectForEval: true}) {
- return new _UnparsedNode(value, compiler, protectForEval);
+ return new js.UnparsedNode(value, compiler, protectForEval);
}
String buildGeneratedBy(compiler) {
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/model.dart ('k') | pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698