mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Remove @muts from ExtCtxt
This commit is contained in:
parent
8143662836
commit
dc830345e8
@ -63,7 +63,7 @@ pub fn modify_for_testing(sess: session::Session,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct TestHarnessGenerator {
|
struct TestHarnessGenerator {
|
||||||
cx: @TestCtxt,
|
cx: TestCtxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fold::ast_fold for TestHarnessGenerator {
|
impl fold::ast_fold for TestHarnessGenerator {
|
||||||
@ -73,7 +73,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||||||
// Add a special __test module to the crate that will contain code
|
// Add a special __test module to the crate that will contain code
|
||||||
// generated for the test harness
|
// generated for the test harness
|
||||||
ast::Crate {
|
ast::Crate {
|
||||||
module: add_test_module(self.cx, &folded.module),
|
module: add_test_module(&self.cx, &folded.module),
|
||||||
.. folded
|
.. folded
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||||||
debug!("current path: {}",
|
debug!("current path: {}",
|
||||||
ast_util::path_name_i(self.cx.path.get()));
|
ast_util::path_name_i(self.cx.path.get()));
|
||||||
|
|
||||||
if is_test_fn(self.cx, i) || is_bench_fn(i) {
|
if is_test_fn(&self.cx, i) || is_bench_fn(i) {
|
||||||
match i.node {
|
match i.node {
|
||||||
ast::item_fn(_, purity, _, _, _)
|
ast::item_fn(_, purity, _, _, _)
|
||||||
if purity == ast::unsafe_fn => {
|
if purity == ast::unsafe_fn => {
|
||||||
@ -101,7 +101,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||||||
span: i.span,
|
span: i.span,
|
||||||
path: self.cx.path.get(),
|
path: self.cx.path.get(),
|
||||||
bench: is_bench_fn(i),
|
bench: is_bench_fn(i),
|
||||||
ignore: is_ignored(self.cx, i),
|
ignore: is_ignored(&self.cx, i),
|
||||||
should_fail: should_fail(i)
|
should_fail: should_fail(i)
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
@ -126,7 +126,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||||||
// Remove any #[main] from the AST so it doesn't clash with
|
// Remove any #[main] from the AST so it doesn't clash with
|
||||||
// the one we're going to add. Only if compiling an executable.
|
// the one we're going to add. Only if compiling an executable.
|
||||||
|
|
||||||
fn nomain(cx: @TestCtxt, item: @ast::item) -> @ast::item {
|
fn nomain(cx: &TestCtxt, item: @ast::item) -> @ast::item {
|
||||||
if !cx.sess.building_library.get() {
|
if !cx.sess.building_library.get() {
|
||||||
@ast::item {
|
@ast::item {
|
||||||
attrs: item.attrs.iter().filter_map(|attr| {
|
attrs: item.attrs.iter().filter_map(|attr| {
|
||||||
@ -145,7 +145,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||||||
|
|
||||||
let mod_nomain = ast::_mod {
|
let mod_nomain = ast::_mod {
|
||||||
view_items: m.view_items.clone(),
|
view_items: m.view_items.clone(),
|
||||||
items: m.items.iter().map(|i| nomain(self.cx, *i)).collect(),
|
items: m.items.iter().map(|i| nomain(&self.cx, *i)).collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
fold::noop_fold_mod(&mod_nomain, self)
|
fold::noop_fold_mod(&mod_nomain, self)
|
||||||
@ -154,7 +154,7 @@ impl fold::ast_fold for TestHarnessGenerator {
|
|||||||
|
|
||||||
fn generate_test_harness(sess: session::Session, crate: ast::Crate)
|
fn generate_test_harness(sess: session::Session, crate: ast::Crate)
|
||||||
-> ast::Crate {
|
-> ast::Crate {
|
||||||
let cx: @TestCtxt = @TestCtxt {
|
let mut cx: TestCtxt = TestCtxt {
|
||||||
sess: sess,
|
sess: sess,
|
||||||
ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()),
|
ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()),
|
||||||
path: RefCell::new(~[]),
|
path: RefCell::new(~[]),
|
||||||
@ -176,7 +176,7 @@ fn generate_test_harness(sess: session::Session, crate: ast::Crate)
|
|||||||
cx: cx
|
cx: cx
|
||||||
};
|
};
|
||||||
let res = fold.fold_crate(crate);
|
let res = fold.fold_crate(crate);
|
||||||
cx.ext_cx.bt_pop();
|
fold.cx.ext_cx.bt_pop();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ fn strip_test_functions(crate: ast::Crate) -> ast::Crate {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_test_fn(cx: @TestCtxt, i: @ast::item) -> bool {
|
fn is_test_fn(cx: &TestCtxt, i: @ast::item) -> bool {
|
||||||
let has_test_attr = attr::contains_name(i.attrs, "test");
|
let has_test_attr = attr::contains_name(i.attrs, "test");
|
||||||
|
|
||||||
fn has_test_signature(i: @ast::item) -> bool {
|
fn has_test_signature(i: @ast::item) -> bool {
|
||||||
@ -242,7 +242,7 @@ fn is_bench_fn(i: @ast::item) -> bool {
|
|||||||
return has_bench_attr && has_test_signature(i);
|
return has_bench_attr && has_test_signature(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ignored(cx: @TestCtxt, i: @ast::item) -> bool {
|
fn is_ignored(cx: &TestCtxt, i: @ast::item) -> bool {
|
||||||
i.attrs.iter().any(|attr| {
|
i.attrs.iter().any(|attr| {
|
||||||
// check ignore(cfg(foo, bar))
|
// check ignore(cfg(foo, bar))
|
||||||
"ignore" == attr.name() && match attr.meta_item_list() {
|
"ignore" == attr.name() && match attr.meta_item_list() {
|
||||||
|
@ -297,15 +297,15 @@ pub fn syntax_expander_table() -> SyntaxEnv {
|
|||||||
pub struct ExtCtxt {
|
pub struct ExtCtxt {
|
||||||
parse_sess: @mut parse::ParseSess,
|
parse_sess: @mut parse::ParseSess,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
backtrace: @mut Option<@ExpnInfo>,
|
backtrace: Option<@ExpnInfo>,
|
||||||
|
|
||||||
// These two @mut's should really not be here,
|
// These two @mut's should really not be here,
|
||||||
// but the self types for CtxtRepr are all wrong
|
// but the self types for CtxtRepr are all wrong
|
||||||
// and there are bugs in the code for object
|
// and there are bugs in the code for object
|
||||||
// types that make this hard to get right at the
|
// types that make this hard to get right at the
|
||||||
// moment. - nmatsakis
|
// moment. - nmatsakis
|
||||||
mod_path: @mut ~[ast::Ident],
|
mod_path: ~[ast::Ident],
|
||||||
trace_mac: @mut bool
|
trace_mac: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtCtxt {
|
impl ExtCtxt {
|
||||||
@ -314,9 +314,9 @@ impl ExtCtxt {
|
|||||||
ExtCtxt {
|
ExtCtxt {
|
||||||
parse_sess: parse_sess,
|
parse_sess: parse_sess,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
backtrace: @mut None,
|
backtrace: None,
|
||||||
mod_path: @mut ~[],
|
mod_path: ~[],
|
||||||
trace_mac: @mut false
|
trace_mac: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,32 +339,32 @@ impl ExtCtxt {
|
|||||||
pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
|
pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
|
||||||
pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
|
pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
|
||||||
pub fn call_site(&self) -> Span {
|
pub fn call_site(&self) -> Span {
|
||||||
match *self.backtrace {
|
match self.backtrace {
|
||||||
Some(@ExpnInfo {call_site: cs, ..}) => cs,
|
Some(@ExpnInfo {call_site: cs, ..}) => cs,
|
||||||
None => self.bug("missing top span")
|
None => self.bug("missing top span")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn print_backtrace(&self) { }
|
pub fn print_backtrace(&self) { }
|
||||||
pub fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
|
pub fn backtrace(&self) -> Option<@ExpnInfo> { self.backtrace }
|
||||||
pub fn mod_push(&self, i: ast::Ident) { self.mod_path.push(i); }
|
pub fn mod_push(&mut self, i: ast::Ident) { self.mod_path.push(i); }
|
||||||
pub fn mod_pop(&self) { self.mod_path.pop(); }
|
pub fn mod_pop(&mut self) { self.mod_path.pop(); }
|
||||||
pub fn mod_path(&self) -> ~[ast::Ident] { (*self.mod_path).clone() }
|
pub fn mod_path(&self) -> ~[ast::Ident] { self.mod_path.clone() }
|
||||||
pub fn bt_push(&self, ei: codemap::ExpnInfo) {
|
pub fn bt_push(&mut self, ei: codemap::ExpnInfo) {
|
||||||
match ei {
|
match ei {
|
||||||
ExpnInfo {call_site: cs, callee: ref callee} => {
|
ExpnInfo {call_site: cs, callee: ref callee} => {
|
||||||
*self.backtrace =
|
self.backtrace =
|
||||||
Some(@ExpnInfo {
|
Some(@ExpnInfo {
|
||||||
call_site: Span {lo: cs.lo, hi: cs.hi,
|
call_site: Span {lo: cs.lo, hi: cs.hi,
|
||||||
expn_info: *self.backtrace},
|
expn_info: self.backtrace},
|
||||||
callee: *callee});
|
callee: *callee});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn bt_pop(&self) {
|
pub fn bt_pop(&mut self) {
|
||||||
match *self.backtrace {
|
match self.backtrace {
|
||||||
Some(@ExpnInfo {
|
Some(@ExpnInfo {
|
||||||
call_site: Span {expn_info: prev, ..}, ..}) => {
|
call_site: Span {expn_info: prev, ..}, ..}) => {
|
||||||
*self.backtrace = prev
|
self.backtrace = prev
|
||||||
}
|
}
|
||||||
_ => self.bug("tried to pop without a push")
|
_ => self.bug("tried to pop without a push")
|
||||||
}
|
}
|
||||||
@ -394,10 +394,10 @@ impl ExtCtxt {
|
|||||||
self.parse_sess.span_diagnostic.handler().bug(msg);
|
self.parse_sess.span_diagnostic.handler().bug(msg);
|
||||||
}
|
}
|
||||||
pub fn trace_macros(&self) -> bool {
|
pub fn trace_macros(&self) -> bool {
|
||||||
*self.trace_mac
|
self.trace_mac
|
||||||
}
|
}
|
||||||
pub fn set_trace_macros(&self, x: bool) {
|
pub fn set_trace_macros(&mut self, x: bool) {
|
||||||
*self.trace_mac = x
|
self.trace_mac = x
|
||||||
}
|
}
|
||||||
pub fn str_of(&self, id: ast::Ident) -> @str {
|
pub fn str_of(&self, id: ast::Ident) -> @str {
|
||||||
ident_to_str(&id)
|
ident_to_str(&id)
|
||||||
|
Loading…
Reference in New Issue
Block a user