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

Side by Side Diff: pkg/compiler/lib/src/js/js.dart

Issue 915533002: Steps towards making dart2js JS AST templates an indepentent library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | pkg/compiler/lib/src/js/nodes.dart » ('j') | pkg/compiler/lib/src/js/printer.dart » ('J')
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 library js; 5 library js;
6 6
7 import 'precedence.dart'; 7 import 'precedence.dart';
8 import '../util/characters.dart' as charCodes; 8 import '../util/characters.dart' as charCodes; // TODO(sra): Local copy of us ed constants.
9 import '../util/util.dart'; 9 import '../io/code_output.dart' show CodeBuffer; // TODO(sra): Remove.
10 import '../io/code_output.dart' show CodeBuffer; 10 import '../io/source_information.dart' show SourceInformation; // TODO(sra): Rem ove.
11 import '../io/source_information.dart' show SourceInformation; 11 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER; // TODO(sra): Turn into an option.
12 import '../js_emitter/js_emitter.dart' show USE_NEW_EMITTER;
13 12
14 // TODO(floitsch): remove this dependency (currently necessary for the 13 // TODO(floitsch): remove this dependency (currently necessary for the
15 // CodeBuffer). 14 // CodeBuffer).
16 import '../dart2jslib.dart' as leg; 15 import '../dart2jslib.dart' as leg; // TODO(sra): Remove.
17 16
18 import '../dump_info.dart'; 17 import '../dump_info.dart' show DumpInfoTask; // TODO(sra): Remove.
19 18
20 part 'nodes.dart'; 19 part 'nodes.dart';
21 part 'builder.dart'; 20 part 'builder.dart';
22 part 'printer.dart'; 21 part 'printer.dart';
23 part 'template.dart'; 22 part 'template.dart';
23
24
25 // The following code will be moved out of this library into js_backend. When
26 // this happens, most of the imports can be removed.
27
28 CodeBuffer prettyPrint(Node node, leg.Compiler compiler,
29 {DumpInfoTask monitor,
30 bool allowVariableMinification: true}) {
31 JavaScriptPrintingOptions options = new JavaScriptPrintingOptions(
32 shouldCompressOutput: compiler.enableMinification,
33 minifyLocalVariables: allowVariableMinification);
34 Dart2JSJavaScriptPrintingContext context =
35 new Dart2JSJavaScriptPrintingContext(compiler, monitor);
36 Printer printer = new Printer(options, context);
37 printer.visit(node);
38 return context.outBuffer;
39 }
40
41 class Dart2JSJavaScriptPrintingContext extends JavaScriptPrintingContext {
42 final leg.Compiler compiler;
43 final DumpInfoTask monitor;
44 final CodeBuffer outBuffer = new CodeBuffer();
45
46 Dart2JSJavaScriptPrintingContext(leg.Compiler this.compiler,
47 DumpInfoTask this.monitor);
48
49 void error(String message) {
50 compiler.internalError(NO_LOCATION_SPANNABLE, message);
51 }
52
53 void emit(String string) {
54 outBuffer.add(string);
55 }
56
57 void enterNode(Node node) {
58 if (node.sourceInformation != null) {
59 node.sourceInformation.beginMapping(outBuffer);
60 }
61 if (monitor != null) monitor.enteringAst(node, outBuffer.length);
62 }
63
64 void exitNode(Node node) {
65 if (monitor != null) monitor.exitingAst(node, outBuffer.length);
66 if (node.sourceInformation != null) {
67 node.sourceInformation.endMapping(outBuffer);
68 }
69 }
70 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js/nodes.dart » ('j') | pkg/compiler/lib/src/js/printer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698