2012-01-26 17:20:29 -06:00
|
|
|
import driver::session::session;
|
|
|
|
import syntax::codemap;
|
2012-01-26 18:23:34 -06:00
|
|
|
import syntax::ast;
|
|
|
|
import front::attr;
|
2012-01-26 17:20:29 -06:00
|
|
|
|
|
|
|
export maybe_inject_libcore_ref;
|
|
|
|
|
|
|
|
fn maybe_inject_libcore_ref(sess: session,
|
|
|
|
crate: @ast::crate) -> @ast::crate {
|
2012-01-26 18:23:34 -06:00
|
|
|
if use_core(crate) {
|
2012-01-26 17:20:29 -06:00
|
|
|
inject_libcore_ref(sess, crate)
|
|
|
|
} else {
|
|
|
|
crate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 18:23:34 -06:00
|
|
|
fn use_core(crate: @ast::crate) -> bool {
|
|
|
|
!attr::attrs_contains_name(crate.node.attrs, "no_core")
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:20:29 -06:00
|
|
|
fn inject_libcore_ref(sess: session,
|
|
|
|
crate: @ast::crate) -> @ast::crate {
|
|
|
|
|
|
|
|
fn spanned<T: copy>(x: T) -> @ast::spanned<T> {
|
|
|
|
ret @{node: x,
|
|
|
|
span: {lo: 0u, hi: 0u,
|
2012-02-04 19:37:24 -06:00
|
|
|
expn_info: option::none}};
|
2012-01-26 17:20:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
let n1 = sess.next_node_id();
|
|
|
|
let n2 = sess.next_node_id();
|
|
|
|
|
|
|
|
let vi1 = spanned(ast::view_item_use("core", [], n1));
|
|
|
|
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
|
|
|
|
|
|
|
|
let vis = [vi1, vi2] + crate.node.module.view_items;
|
|
|
|
|
|
|
|
ret @{node: {module: { view_items: vis with crate.node.module }
|
|
|
|
with crate.node} with *crate }
|
|
|
|
}
|