Skip to content

Trace macros flag #24430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"Force overflow checks on or off"),
force_dropflag_checks: Option<bool> = (None, parse_opt_bool,
"Force drop flag checks on or off"),
trace_macros: bool = (false, parse_bool,
"For every macro invocation, print its name and arguments"),
}

pub fn default_lib_output() -> CrateType {
Expand Down Expand Up @@ -667,7 +669,7 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
Ok(t) => t,
Err(e) => {
sp.handler().fatal(&format!("Error loading target specification: {}", e));
}
}
};

let (int_type, uint_type) = match &target.target_pointer_width[..] {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
crate_name: crate_name.to_string(),
features: Some(&features),
recursion_limit: sess.recursion_limit.get(),
trace_mac: sess.opts.debugging_opts.trace_macros,
};
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
cfg,
Expand Down
6 changes: 2 additions & 4 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ pub struct ExtCtxt<'a> {
pub use_std: bool,

pub mod_path: Vec<ast::Ident> ,
pub trace_mac: bool,
pub exported_macros: Vec<ast::MacroDef>,

pub syntax_env: SyntaxEnv,
Expand All @@ -572,7 +571,6 @@ impl<'a> ExtCtxt<'a> {
mod_path: Vec::new(),
ecfg: ecfg,
use_std: true,
trace_mac: false,
exported_macros: Vec::new(),
syntax_env: env,
recursion_count: 0,
Expand Down Expand Up @@ -732,10 +730,10 @@ impl<'a> ExtCtxt<'a> {
self.parse_sess.span_diagnostic.handler().bug(msg);
}
pub fn trace_macros(&self) -> bool {
self.trace_mac
self.ecfg.trace_mac
}
pub fn set_trace_macros(&mut self, x: bool) {
self.trace_mac = x
self.ecfg.trace_mac = x
}
pub fn ident_of(&self, st: &str) -> ast::Ident {
str_to_ident(st)
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ pub struct ExpansionConfig<'feat> {
pub crate_name: String,
pub features: Option<&'feat Features>,
pub recursion_limit: usize,
pub trace_mac: bool,
}

macro_rules! feature_tests {
Expand All @@ -1427,6 +1428,7 @@ impl<'feat> ExpansionConfig<'feat> {
crate_name: crate_name,
features: None,
recursion_limit: 64,
trace_mac: false,
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/run-make/trace-macros-flag/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This test verifies that "-Z trace-macros" works as it should. The traditional
# "hello world" program provides a small example of this as not only println! is
# listed, but also print! (since println! expands to this)

-include ../tools.mk

all:
$(RUSTC) -Z trace-macros hello.rs > $(TMPDIR)/hello.out
diff -u $(TMPDIR)/hello.out hello.trace
13 changes: 13 additions & 0 deletions src/test/run-make/trace-macros-flag/hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
println!("Hello, World!");
}
2 changes: 2 additions & 0 deletions src/test/run-make/trace-macros-flag/hello.trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
println! { "Hello, World!" }
print! { concat ! ( "Hello, World!" , "\n" ) }