use syntax::ast::{IntTy, UintTy};
use syntax::attr;
use syntax::attr::AttrMetaMethods;
+use syntax::diagnostic::{ColorConfig, Auto, Always, Never};
use syntax::parse;
use syntax::parse::token::InternedString;
/// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name).
pub print_metas: (bool, bool, bool),
pub cg: CodegenOptions,
+ pub color: ColorConfig,
}
/// Some reasonable defaults
write_dependency_info: (false, None),
print_metas: (false, false, false),
cg: basic_codegen_options(),
+ color: Auto,
}
}
optopt( "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
optflag("", "parse-only", "Parse only; do not compile, assemble, or link"),
optflagopt("", "pretty",
- "Pretty-print the input instead of compiling;
- valid types are: normal (un-annotated source),
- expanded (crates expanded),
- typed (crates expanded, with type annotations),
- or identified (fully parenthesized,
- AST nodes and blocks with IDs)", "TYPE"),
+ "Pretty-print the input instead of compiling;
+ valid types are: `normal` (un-annotated source),
+ `expanded` (crates expanded),
+ `typed` (crates expanded, with type annotations),
+ `expanded,identified` (fully parenthesized, AST nodes with IDs), or
+ `flowgraph=<nodeid>` (graphviz formatted flowgraph for node)",
+ "TYPE"),
optflagopt("", "dep-info",
"Output dependency info to <filename> after compiling, \
in a format suitable for use by Makefiles", "FILENAME"),
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
optmulti("Z", "", "Set internal debugging options", "FLAG"),
- optflag( "v", "version", "Print version info and exit")
+ optflag("v", "version", "Print version info and exit"),
+ optopt("", "color", "Configure coloring of output:
+ auto = colorize, if output goes to a tty (default);
+ always = always colorize output;
+ never = never colorize output", "auto|always|never")
)
}
matches.opt_present("crate-file-name"));
let cg = build_codegen_options(matches);
+ let color = match matches.opt_str("color").as_ref().map(|s| s.as_slice()) {
+ Some("auto") => Auto,
+ Some("always") => Always,
+ Some("never") => Never,
+
+ None => Auto,
+
+ Some(arg) => early_error(format!(
+ "argument for --color must be auto, always or never (instead was `{}`)",
+ arg))
+ };
+
Options {
crate_types: crate_types,
gc: gc,
write_dependency_info: write_dependency_info,
print_metas: print_metas,
cg: cg,
+ color: color
}
}
PpmExpanded,
PpmTyped,
PpmIdentified,
- PpmExpandedIdentified
+ PpmExpandedIdentified,
+ PpmFlowGraph(ast::NodeId),
}
pub fn parse_pretty(sess: &Session, name: &str) -> PpMode {
- match name {
- "normal" => PpmNormal,
- "expanded" => PpmExpanded,
- "typed" => PpmTyped,
- "expanded,identified" => PpmExpandedIdentified,
- "identified" => PpmIdentified,
+ let mut split = name.splitn('=', 1);
+ let first = split.next().unwrap();
+ let opt_second = split.next();
+ match (opt_second, first) {
+ (None, "normal") => PpmNormal,
+ (None, "expanded") => PpmExpanded,
+ (None, "typed") => PpmTyped,
+ (None, "expanded,identified") => PpmExpandedIdentified,
+ (None, "identified") => PpmIdentified,
+ (Some(s), "flowgraph") => {
+ match from_str(s) {
+ Some(id) => PpmFlowGraph(id),
+ None => sess.fatal(format!("`pretty flowgraph=<nodeid>` needs \
+ an integer <nodeid>; got {}", s))
+ }
+ }
_ => {
- sess.fatal("argument to `pretty` must be one of `normal`, \
- `expanded`, `typed`, `identified`, \
- or `expanded,identified`");
+ sess.fatal(format!(
+ "argument to `pretty` must be one of `normal`, \
+ `expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
+ or `expanded,identified`; got {}", name));
}
}
}
}
pub fn early_error(msg: &str) -> ! {
- let mut emitter = diagnostic::EmitterWriter::stderr();
+ let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto);
emitter.emit(None, msg, diagnostic::Fatal);
fail!(diagnostic::FatalError);
}
Err(value) => {
// Task failed without emitting a fatal diagnostic
if !value.is::<diagnostic::FatalError>() {
- let mut emitter = diagnostic::EmitterWriter::stderr();
+ let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto);
// a .span_bug or .bug call has already printed what
// it wants to print.