Skip to content

Commit

Permalink
Bugfix. --pretty typed requires expansion. Closes #691.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstansifer committed Aug 26, 2011
1 parent 5815f4f commit 230a586
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import std::getopts::optflagopt;
import std::getopts::opt_present;
import back::link::output_type;

tag pp_mode { ppm_normal; ppm_typed; ppm_identified; }
tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; }

fn default_configuration(sess: session::session, argv0: str, input: str) ->
ast::crate_cfg {
Expand Down Expand Up @@ -169,7 +169,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
}

fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
ppm: pp_mode, expand: bool) {
ppm: pp_mode) {
fn ann_paren_for_expr(node: &pprust::ann_node) {
alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
}
Expand Down Expand Up @@ -213,10 +213,14 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
let crate = crate_src.crate;
let src = crate_src.src;

if expand { crate = syntax::ext::expand::expand_crate(sess, crate); }
let ann;
alt ppm {
ppm_expanded. {
crate = syntax::ext::expand::expand_crate(sess, crate);
ann = pprust::no_ann();
}
ppm_typed. {
crate = syntax::ext::expand::expand_crate(sess, crate);
let amap = middle::ast_map::map_crate(*crate);
let {def_map: def_map, ext_map: ext_map} =
resolve::resolve_crate(sess, amap, crate);
Expand Down Expand Up @@ -254,7 +258,6 @@ options:
--lib compile a library crate
--static use or produce static libraries
--pretty [type] pretty-print the input instead of compiling
--expand [type] expand and pretty-print the input instead of compiling
--ls list the symbols defined by a crate file
-L <path> add a directory to the library search path
--noverify suppress LLVM verification step (slight speedup)
Expand Down Expand Up @@ -414,18 +417,20 @@ fn build_session(sopts: @session::options) -> session::session {
fn parse_pretty(sess: session::session, name: &str) -> pp_mode {
if str::eq(name, "normal") {
ret ppm_normal;
} else if str::eq(name, "expanded") {
ret ppm_expanded;
} else if str::eq(name, "typed") {
ret ppm_typed;
} else if str::eq(name, "identified") { ret ppm_identified; }
sess.fatal("argument to `pretty` or `expand` must be one of `normal`, " +
"`typed`, or `identified`");
sess.fatal("argument to `pretty` must be one of `normal`, `typed`, or "
+ "`identified`");
}

fn opts() -> [getopts::opt] {
ret [optflag("h"), optflag("help"), optflag("v"), optflag("version"),
optflag("glue"), optflag("emit-llvm"), optflagopt("pretty"),
optflagopt("expand"), optflag("ls"), optflag("parse-only"),
optflag("no-trans"), optflag("O"), optopt("OptLevel"), optmulti("L"),
optflag("ls"), optflag("parse-only"), optflag("no-trans"),
optflag("O"), optopt("OptLevel"), optmulti("L"),
optflag("S"), optflag("c"), optopt("o"), optflag("g"),
optflag("save-temps"), optopt("sysroot"), optflag("stats"),
optflag("time-passes"), optflag("time-llvm-passes"),
Expand Down Expand Up @@ -473,26 +478,14 @@ fn main(args: [str]) {
let ifile = match.free[0];
let saved_out_filename: str = "";
let cfg = build_configuration(sess, binary, ifile);
let expand =
option::map::<str,
pp_mode>(bind parse_pretty(sess, _),
getopts::opt_default(match, "expand",
"normal"));
alt expand {
some::<pp_mode>(ppm) {
pretty_print_input(sess, cfg, ifile, ppm, true);
ret;
}
none::<pp_mode>. {/* continue */ }
}
let pretty =
option::map::<str,
pp_mode>(bind parse_pretty(sess, _),
getopts::opt_default(match, "pretty",
"normal"));
alt pretty {
some::<pp_mode>(ppm) {
pretty_print_input(sess, cfg, ifile, ppm, false);
pretty_print_input(sess, cfg, ifile, ppm);
ret;
}
none::<pp_mode>. {/* continue */ }
Expand Down

0 comments on commit 230a586

Please sign in to comment.