Skip to content

Commit 5491527

Browse files
Added support for dumping AST to console, text file or dot file
Review URL: http://codereview.chromium.org//8566019 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1587 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 8eb81c4 commit 5491527

File tree

7 files changed

+936
-0
lines changed

7 files changed

+936
-0
lines changed

compiler/java/com/google/dart/compiler/CommandLineOptions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public static class CompilerOptions {
7272
@Option(name = "--generate_source_maps",
7373
usage = "Generate source maps")
7474
private boolean generateSourceMaps = false;
75+
76+
@Option(name = "--dump-ast-format", aliases={"-dump-ast-format"},
77+
usage = "Dump parse tree. Supported formats include console, text or dot")
78+
private String dumpAST = "";
79+
80+
@Option(name = "--coverage-instrumenter", aliases={"-coverage-instrumentor"},
81+
usage = "Add coverage instrumentation probes")
82+
private boolean coverage = false;
7583

7684
@Option(name = "--human-readable-output",
7785
usage = "Write human readable javascript")
@@ -246,6 +254,14 @@ public boolean generateSourceMaps() {
246254
public boolean generateHumanReadableOutput() {
247255
return generateHumanReadableOutput;
248256
}
257+
258+
public String dumpAST(){
259+
return dumpAST;
260+
}
261+
262+
public boolean instrument4Coverage(){
263+
return coverage;
264+
}
249265

250266
/**
251267
* @return the path to receive compiler output.

compiler/java/com/google/dart/compiler/DartCompiler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.google.dart.compiler.ast.LibraryNode;
1919
import com.google.dart.compiler.ast.LibraryUnit;
2020
import com.google.dart.compiler.ast.Modifiers;
21+
import com.google.dart.compiler.ast.viz.ASTWriterFactory;
22+
import com.google.dart.compiler.ast.viz.BaseASTWriter;
2123
import com.google.dart.compiler.common.SourceInfo;
2224
import com.google.dart.compiler.metrics.CompilerMetrics;
2325
import com.google.dart.compiler.metrics.DartEventType;
@@ -664,13 +666,21 @@ private void compileLibraries() throws IOException {
664666
try {
665667
// Set entry point
666668
setEntryPoint();
669+
670+
// Dump the compiler parse tree if dump format is set in arguments
671+
BaseASTWriter astWriter = ASTWriterFactory.create(config);
667672

668673
// The two following for loops can be parallelized.
669674
for (LibraryUnit lib : libraries.values()) {
670675
boolean persist = false;
671676

672677
// Compile all the units in this library.
673678
for (DartUnit unit : lib.getUnits()) {
679+
680+
if(astWriter != null) {
681+
astWriter.process(unit);
682+
}
683+
674684
// Don't compile api-only units.
675685
if (unit.isDiet()) {
676686
continue;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
package com.google.dart.compiler.ast.viz;
6+
7+
import com.google.dart.compiler.CompilerConfiguration;
8+
import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
9+
10+
public class ASTWriterFactory {
11+
public static BaseASTWriter create(CompilerConfiguration config) {
12+
String astFormat = config.getCompilerOptions().dumpAST();
13+
CompilerOptions compilerOptions = config.getCompilerOptions();
14+
String outDir = compilerOptions.getWorkDirectory().getAbsolutePath();
15+
if ("console".equals(astFormat)) {
16+
return new ConsoleWriter(outDir);
17+
} else if ("text".equals(astFormat)) {
18+
return new TextWriter(outDir);
19+
} else if ("dot".equals(astFormat)) {
20+
return new DotWriter(outDir);
21+
}
22+
return null;
23+
}
24+
}

0 commit comments

Comments
 (0)