Skip to content

Commit

Permalink
auto merge of #16419 : huonw/rust/pretty-expanded-hygiene, r=pnkfelix
Browse files Browse the repository at this point in the history
Different Identifiers and Names can have identical textual representations, but different internal representations, due to the macro hygiene machinery (syntax contexts and gensyms). This provides a way to see these internals by compiling with `--pretty expanded,hygiene`.

This is useful for debugging & hacking on macros (e.g. diagnosing #15750 likely would've been faster with this functionality).

E.g. 

```rust
#![feature(macro_rules)]
// minimal junk
#![no_std]

macro_rules! foo {
    ($x: ident) => { y + $x }
}

fn bar() {
    foo!(x)
}
```
```rust
#![feature(macro_rules)]
// minimal junk
#![no_std]


fn bar /* 61#0 */() { y /* 60#2 */ + x /* 58#3 */ }
```
  • Loading branch information
bors committed Aug 30, 2014
2 parents 43c26e6 + 32e4371 commit d398eb7
Show file tree
Hide file tree
Showing 8 changed files with 685 additions and 558 deletions.
517 changes: 1 addition & 516 deletions src/librustc/driver/driver.rs

Large diffs are not rendered by default.

42 changes: 3 additions & 39 deletions src/librustc/driver/mod.rs
Expand Up @@ -33,6 +33,7 @@ use getopts;
pub mod driver;
pub mod session;
pub mod config;
pub mod pretty;


pub fn main_args(args: &[String]) -> int {
Expand Down Expand Up @@ -96,11 +97,11 @@ fn run_compiler(args: &[String]) {
let ofile = matches.opt_str("o").map(|o| Path::new(o));

let pretty = matches.opt_default("pretty", "normal").map(|a| {
parse_pretty(&sess, a.as_slice())
pretty::parse_pretty(&sess, a.as_slice())
});
match pretty {
Some((ppm, opt_uii)) => {
driver::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
return;
}
None => {/* continue */ }
Expand Down Expand Up @@ -384,43 +385,6 @@ fn print_crate_info(sess: &Session,
}
}

#[deriving(PartialEq, Show)]
pub enum PpSourceMode {
PpmNormal,
PpmExpanded,
PpmTyped,
PpmIdentified,
PpmExpandedIdentified,
}

#[deriving(PartialEq, Show)]
pub enum PpMode {
PpmSource(PpSourceMode),
PpmFlowGraph,
}

fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<driver::UserIdentifiedItem>) {
let mut split = name.splitn(1, '=');
let first = split.next().unwrap();
let opt_second = split.next();
let first = match first {
"normal" => PpmSource(PpmNormal),
"expanded" => PpmSource(PpmExpanded),
"typed" => PpmSource(PpmTyped),
"expanded,identified" => PpmSource(PpmExpandedIdentified),
"identified" => PpmSource(PpmIdentified),
"flowgraph" => PpmFlowGraph,
_ => {
sess.fatal(format!(
"argument to `pretty` must be one of `normal`, \
`expanded`, `flowgraph=<nodeid>`, `typed`, `identified`, \
or `expanded,identified`; got {}", name).as_slice());
}
};
let opt_second = opt_second.and_then::<driver::UserIdentifiedItem>(from_str);
(first, opt_second)
}

fn parse_crate_attrs(sess: &Session, input: &Input) ->
Vec<ast::Attribute> {
let result = match *input {
Expand Down

0 comments on commit d398eb7

Please sign in to comment.