Rollback breaking change.

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@188 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
johnlenz@google.com 2011-10-07 01:16:59 +00:00
parent b5b46da81c
commit 5d45b72a3a
10 changed files with 122 additions and 86 deletions

View file

@ -4,9 +4,9 @@
package com.google.dart.compiler;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.dart.runner.DartRunner;
import com.google.dart.runner.RunnerOptions;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
@ -42,19 +42,18 @@ public class CommandLineOptions {
usage = "Debugging: disable type optimizations")
private boolean disableTypeOptimizations = false;
@Option(name = "--documentation-lib", aliases = { "-documentation-lib" },
@Option(name = "-documentation-lib",
usage = "only generate documentation for the given library")
private String documentationLibrary = null;
@Option(name = "--documentation-out", aliases = { "-documentation-out" },
usage = "directory to receive documentation output")
@Option(name = "-documentation-out", usage = "directory to receive documentation output")
private String documentationOutputDirectory = null;
@Option(name = "--generate-documentation", aliases = { "-generate-documentation" },
@Option(name = "-generate-documentation",
usage = "generate documentation for the provided source files")
private boolean generateDocumentation = false;
@Option(name = "--generate-isolate-stubs", aliases = { "-generate-isolate-stubs" },
@Option(name = "-generate-isolate-stubs",
usage = "classes to generate stubs for, comma-separated")
private String generateIsolateStubs = null;
@ -65,63 +64,50 @@ public class CommandLineOptions {
@Option(name = "--ignore-unrecognized-flags", usage = "ignore unrecognized command line flags")
private boolean ignoreUnrecognizedFlags = false;
@Option(name = "--isolate-stub-out", aliases = { "-isolate-stub-out" },
usage = "file to receive generated stub output")
@Option(name = "-isolate-stub-out", usage = "file to receive generated stub output")
private String isolateStubOutputFile = null;
@Option(name = "--jvm-metrics-detail", usage = "summary or verbose (default is summary)")
@Option(name = "-jvm-metrics-detail", usage = "summary or verbose (default is summary)")
private String jvmMetricDetail = "summary";
@Option(name = "--jvm-metrics-format", usage = "tabular or pretty (default is tabular)")
@Option(name = "-jvm-metrics-format", usage = "tabular or pretty (default is tabular)")
private String jvmMetricFormat = "tabular";
@Option(name = "--jvm-metrics-type", usage = "comma-separated list, including:\n"
@Option(name = "-jvm-metrics-type", usage = "comma-separated list, including:\n"
+ " all: show all available stat types (default)\n"
+ " gc: show garbage collection stats\n"
+ " mem: show memory stats\n" + " jit: show jit stats")
private String jvmMetricType = "all";
@Option(name = "--noincremental", aliases = { "-noincremental" },
usage = "disable incremental compilation")
@Option(name = "-noincremental", usage = "disable incremental compilation")
private boolean noincremental = false;
// see shouldOptimize() below
private boolean optimize = false;
/**
* Enables optimization of the generated JavaScript.
*/
@Option(name = "--optimize", aliases = { "-optimize" }, usage = "produce optimized code")
public void setOptimize(boolean optimize) {
this.optimize = optimize;
}
@Option(name = "--out", usage = "write generated JavaScript to the specified file")
private File outputFilename = null;
// TODO(zundel): -out is for backward compatibility until scripts are updated
@Option(name = "--work", aliases = { "-out" }, usage = "directory to receive compiler output")
private File workDirectory = new File("out");
@Option(name = "--help", aliases = { "-?", "-help" }, usage = "prints this help message")
@Option(name = "-help", usage = "prints this help message")
private boolean showHelp = false;
@Option(name = "--jvm-metrics", usage = "print jvm metrics at end of compilation")
@Option(name = "-jvm-metrics", usage = "print jvm metrics at end of compilation")
private boolean showJvmMetrics = false;
@Option(name = "--metrics", usage = "print compilation metrics")
@Option(name = "-metrics", usage = "print compilation metrics")
private boolean showMetrics = false;
@Argument
private final List<String> sourceFiles = new ArrayList<String>();
@Option(name = "--fatal-type-errors", aliases = { "-fatal-type-errors" },
usage = "type errors are fatal errors (instead of warnings)")
private boolean typeErrorsAreFatal = false;
@Option(name = "--fatal-warnings", aliases = { "-Werror" },
usage = "warnings (excluding type warnings) are fatal errors")
@Option(name = "-Werror", usage = "warnings (excluding type warnings) are fatal errors")
private boolean warningsAreFatal = false;
@Argument
private final List<String> sourceFiles = new ArrayList<String>();
/**
* Returns whether the option -check-only is provided.
*/
@ -194,11 +180,11 @@ public class CommandLineOptions {
/**
* Returns whether the compiler should attempt to incrementally recompile.
*/
public boolean buildIncrementally() {
public boolean incremental() {
return !noincremental;
}
public boolean shouldBatch() {
public boolean isBatch() {
return batch;
}
@ -210,6 +196,17 @@ public class CommandLineOptions {
return generateHumanReadableOutput;
}
/**
* Enables optimization of the generated JavaScript.
*/
@Option(name = "-optimize", aliases = { "--optimize" }, usage = "produce optimized code")
public void optimize(boolean optimize) {
this.optimize = optimize;
}
@Option(name = "--out", usage = "write generated JavaScript to the specified file")
private File outputFilename = null;
/**
* @return the path to receive compiler output.
*/
@ -257,7 +254,7 @@ public class CommandLineOptions {
/**
* Command line options accepted by the {@link DartRunner} entry point.
*/
public static class DartRunnerOptions extends CompilerOptions implements RunnerOptions {
public static class DartRunnerOptions extends CompilerOptions {
@Option(name = "--compile-only", usage = "compile but do not execute")
private boolean compileOnly = false;
@ -265,19 +262,18 @@ public class CommandLineOptions {
@Option(name = "--expose_core_impl", usage = "automatic import of dart:coreimpl library")
private boolean exposeCoreImpl = false;
@Option(name = "--verbose", usage = "extra diagnostic output")
private boolean verbose = false;
@Option(name="--prof", usage = "enable profiling")
private boolean prof;
@Option(name = "--rhino", usage = "use rhino as the JavaScript interpreter")
private boolean rhino = false;
@Option(name = "--verbose", usage = "extra diagnostic output")
private boolean verbose = false;
/**
* @return <code>true</code> if the program should compile but not execute.
*/
@Override
public boolean shouldCompileOnly() {
return compileOnly;
}
@ -292,7 +288,6 @@ public class CommandLineOptions {
/**
* Returns <code>true</code> if profiling is enabled.
*/
@Override
public boolean shouldProfile() {
return prof;
}
@ -300,7 +295,6 @@ public class CommandLineOptions {
/**
* @return <code>true</code> if rhino should be used as the runtime (default is to invoke d8)
*/
@Override
public boolean useRhino() {
return rhino;
}
@ -308,7 +302,6 @@ public class CommandLineOptions {
/**
* @return <code>true</code> to enable diagnostic output
*/
@Override
public boolean verbose() {
return verbose;
}
@ -350,6 +343,7 @@ public class CommandLineOptions {
}
CmdLineParser cmdLineParser = new CmdLineParser(parsedOptions);
for (int i = 0, len = args.length; i < len; i++) {
System.out.println("Parsing: " + Joiner.on(" ").join(args));
try {
cmdLineParser.parseArgument(args);
} catch (CmdLineException e) {
@ -362,7 +356,8 @@ public class CommandLineOptions {
List<String> newArgs = Lists.newArrayList();
for (String arg : args) {
if (arg.equals(option)) {
System.out.println("(Ignoring unrecognized flag: " + arg + ")");
// TODO(zundel): remove diagnostic output
System.out.println("Ignoring unrecognized flag: " + arg);
continue;
}
newArgs.add(arg);

View file

@ -783,7 +783,7 @@ public class DartCompiler {
CompilerOptions topCompilerOptions = processCommandLineOptions(args);
boolean result = false;
try {
if (topCompilerOptions.shouldBatch()) {
if (topCompilerOptions.isBatch()) {
if (args.length > 1) {
System.err.println("(Extra arguments specified with -batch ignored.)");
}
@ -791,7 +791,7 @@ public class DartCompiler {
@Override
public boolean invoke(String[] args) throws Throwable {
CompilerOptions compilerOptions = processCommandLineOptions(args);
if (compilerOptions.shouldBatch()) {
if (compilerOptions.isBatch()) {
System.err.println("-batch ignored: Already in batch mode.");
}
return compilerMain(compilerOptions);

View file

@ -162,7 +162,7 @@ public class DefaultCompilerConfiguration implements CompilerConfiguration {
@Override
public boolean incremental() {
return compilerOptions.buildIncrementally();
return compilerOptions.incremental();
}
@Override

View file

@ -9,6 +9,7 @@ import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.dart.compiler.Backend;
import com.google.dart.compiler.CommandLineOptions;
import com.google.dart.compiler.CommandLineOptions.CompilerOptions;
import com.google.dart.compiler.CommandLineOptions.DartRunnerOptions;
import com.google.dart.compiler.CompilerConfiguration;
import com.google.dart.compiler.DartArtifactProvider;
@ -45,8 +46,10 @@ import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class DartRunner {
@ -99,6 +102,26 @@ public class DartRunner {
LibrarySource app = new UrlLibrarySource(new File(script));
// TODO(zundel): Replace RunnerFlag enum with DartRunnerOptions
final Set<RunnerFlag> flags = EnumSet.noneOf(RunnerFlag.class);
if (options.shouldOptimize()) {
flags.add(RunnerFlag.OPTIMIZE);
}
if (options.verbose()) {
flags.add(RunnerFlag.VERBOSE);
}
if (options.shouldProfile()) {
flags.add(RunnerFlag.PROFILE);
}
if (options.shouldCompileOnly()) {
flags.add(RunnerFlag.COMPILE_ONLY);
}
if (options.typeErrorsAreFatal()) {
flags.add(RunnerFlag.FATAL_TYPE_ERRORS);
}
if (options.useRhino()) {
flags.add(RunnerFlag.USE_RHINO);
}
if (options.shouldExposeCoreImpl()) {
imports = new ArrayList<LibrarySource>(imports);
// use a place-holder LibrarySource instance, to be replaced when embedded
@ -119,7 +142,7 @@ public class DartRunner {
};
CompilationResult compiled;
compiled = compileApp(app, imports, options, listener);
compiled = compileApp(app, imports, flags, listener);
if (listener.getProblemCount() != 0) {
throw new RunnerError("Compilation failed.");
@ -150,9 +173,8 @@ public class DartRunner {
}
}
if (!options.shouldCompileOnly()) {
runApp(compiled, app.getName(), options, scriptArguments.toArray(new String[0]),
stdout, stderr);
if (!flags.contains(RunnerFlag.COMPILE_ONLY)) {
runApp(compiled, app.getName(), flags, scriptArguments.toArray(new String[0]), stdout, stderr);
}
}
@ -269,7 +291,7 @@ public class DartRunner {
}
public static void compileAndRunApp(LibrarySource app,
DartRunnerOptions options,
Set<RunnerFlag> flags,
CompilerConfiguration config,
DartCompilerListener listener,
String[] dartArguments,
@ -278,21 +300,20 @@ public class DartRunner {
throws RunnerError {
CompilationResult compiled = compileApp(
app, Collections.<LibrarySource>emptyList(), config, listener);
runApp(compiled, app.getName(), options, dartArguments, stdout, stderr);
runApp(compiled, app.getName(), flags, dartArguments, stdout, stderr);
}
private static void runApp(CompilationResult compiled,
String sourceName,
DartRunnerOptions options,
Set<RunnerFlag> flags,
String[] scriptArguments,
PrintStream stdout,
PrintStream stderr)
throws RunnerError {
if (options.useRhino()) {
new RhinoLauncher().execute(compiled.js, sourceName, scriptArguments, options, stdout, stderr);
if (flags.contains(RunnerFlag.USE_RHINO)) {
new RhinoLauncher().execute(compiled.js, sourceName, scriptArguments, flags, stdout, stderr);
} else {
new V8Launcher(compiled.mapping).execute(compiled.js, sourceName, scriptArguments, options,
new V8Launcher(compiled.mapping).execute(compiled.js, sourceName, scriptArguments, flags,
stdout, stderr);
}
}
@ -307,15 +328,22 @@ public class DartRunner {
}
}
private static CompilationResult compileApp (LibrarySource app, List<LibrarySource> imports,
final DartRunnerOptions options, DartCompilerListener listener) throws RunnerError {
private static CompilationResult compileApp(LibrarySource app,
List<LibrarySource> imports,
final Set<RunnerFlag> flags,
DartCompilerListener listener)
throws RunnerError {
// TODO(johnlenz): create a "OptimizingCompilerConfiguration"
Backend backend;
if (options.shouldOptimize()) {
CompilerOptions defaultOptions = new CompilerOptions();
if (flags.contains(RunnerFlag.OPTIMIZE)) {
backend = new ClosureJsBackend();
defaultOptions.optimize(true);
} else {
backend = new JavascriptBackend();
}
CompilerConfiguration config = new DefaultCompilerConfiguration(backend, options) {
CompilerConfiguration config = new DefaultCompilerConfiguration(backend, defaultOptions) {
@Override
public boolean expectEntryPoint() {
return true;
@ -323,7 +351,7 @@ public class DartRunner {
@Override
public boolean typeErrorsAreFatal() {
return options.typeErrorsAreFatal();
return flags.contains(RunnerFlag.FATAL_TYPE_ERRORS);
}
};
return compileApp(app, imports, config, listener);

View file

@ -5,6 +5,7 @@
package com.google.dart.runner;
import java.io.PrintStream;
import java.util.Set;
/**
* @author floitsch@google.com (Florian Loitsch)
@ -12,7 +13,7 @@ import java.io.PrintStream;
*/
interface JavaScriptLauncher {
void execute(String jsScript, String sourceName, String[] args, RunnerOptions flags,
void execute(String jsScript, String sourceName, String[] args, Set<RunnerFlag> flags,
PrintStream stdout, PrintStream stderr)
throws RunnerError;

View file

@ -13,6 +13,7 @@ import org.mozilla.javascript.Undefined;
import java.io.PrintStream;
import java.lang.reflect.Member;
import java.util.Set;
/**
* @author floitsch@google.com (Florian Loitsch)
@ -177,7 +178,7 @@ public class RhinoLauncher implements JavaScriptLauncher {
}
@Override
public void execute(String jsScript, String sourceName, String[] args, RunnerOptions options,
public void execute(String jsScript, String sourceName, String[] args, Set<RunnerFlag> flags,
PrintStream stdout, PrintStream stderr)
throws RunnerError {
try {
@ -201,7 +202,7 @@ public class RhinoLauncher implements JavaScriptLauncher {
} catch (RhinoException e) {
// TODO(jgw): This is a hack to dump the translated source when something goes wrong. It can
// be removed as soon as we have a source map we can use to provide source-level errors.
if (options.verbose()) {
if (flags.contains(RunnerFlag.VERBOSE)) {
stdout.println(jsScript);
stdout.flush();
}

View file

@ -0,0 +1,17 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.google.dart.runner;
/**
* Flags that can be given to Runners and Launchers.
*/
public enum RunnerFlag {
VERBOSE,
PROFILE,
OPTIMIZE,
COMPILE_ONLY,
USE_RHINO,
FATAL_TYPE_ERRORS;
}

View file

@ -32,7 +32,7 @@ public class TestRunner {
try {
boolean runBatch = false;
TestRunnerOptions options = processCommandLineOptions(args);
if (options.shouldBatch()) {
if (options.isBatch()) {
runBatch = true;
if (args.length > 1) {
System.err.println("(Extra arguments specified with -batch ignored.)");

View file

@ -20,6 +20,7 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
* @author floitsch@google.com (Florian Loitsch)
@ -69,7 +70,7 @@ public class V8Launcher implements JavaScriptLauncher {
}
@Override
public void execute(String jsScript, String sourceName, String[] args, RunnerOptions options,
public void execute(String jsScript, String sourceName, String[] args, Set<RunnerFlag> flags,
PrintStream stdout, PrintStream stderr)
throws RunnerError {
if (!isConfigured()) {
@ -85,7 +86,7 @@ public class V8Launcher implements JavaScriptLauncher {
ArrayList<String> command = new ArrayList<String>();
command.add(v8Executable().getAbsolutePath());
command.add(sourceFile.getAbsolutePath());
if (options.shouldProfile()) {
if (flags.contains(RunnerFlag.PROFILE)) {
command.add("--prof");
}
command.add("--");
@ -132,7 +133,7 @@ public class V8Launcher implements JavaScriptLauncher {
if (exitValue != 0) {
StringWriter stringWriter = new StringWriter();
PrintWriter out = new PrintWriter(stringWriter);
if (options.verbose()) {
if (flags.contains(RunnerFlag.VERBOSE)) {
out.println(jsScript);
}
out.println("Execution failed.");

View file

@ -4,8 +4,6 @@
package com.google.dart.compiler.end2end;
import com.google.dart.compiler.CommandLineOptions;
import com.google.dart.compiler.CommandLineOptions.DartRunnerOptions;
import com.google.dart.compiler.CompilerConfiguration;
import com.google.dart.compiler.CompilerTestCase;
import com.google.dart.compiler.DartCompilerListener;
@ -19,9 +17,11 @@ import com.google.dart.compiler.backend.js.ClosureJsBackend;
import com.google.dart.compiler.backend.js.JavascriptBackend;
import com.google.dart.runner.DartRunner;
import com.google.dart.runner.RunnerError;
import com.google.dart.runner.RunnerFlag;
import org.mozilla.javascript.RhinoException;
import java.util.EnumSet;
import java.util.List;
/**
@ -71,16 +71,9 @@ public abstract class End2EndTestCase extends CompilerTestCase {
protected void runTest(LibrarySource app, OptimizationLevel opLevel,
DartCompilerListener listener) {
try {
final CompilerConfiguration config = getCompilerConfiguration(opLevel);
DartRunnerOptions verboseOptions = new CommandLineOptions.DartRunnerOptions() {
@Override
public boolean verbose() {
return true;
}
};
CompilerConfiguration config = getCompilerConfiguration(opLevel);
DartRunner.compileAndRunApp(app,
verboseOptions,
EnumSet.of(RunnerFlag.VERBOSE),
config,
listener,
new String[0],