De-@ Session usage.

This commit is contained in:
Eduard Burtescu 2014-03-05 16:36:01 +02:00
parent eb68beec4b
commit 4fae06824c
48 changed files with 510 additions and 548 deletions

View file

@ -26,6 +26,7 @@ use rustc::metadata::decoder;
use std;
use core;
use doctree;
use visit_ast;
use std::local_data;
@ -84,7 +85,7 @@ impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
let cx = local_data::get(super::ctxtkey, |x| *x.unwrap());
let mut externs = ~[];
cx.sess.cstore.iter_crate_data(|n, meta| {
cx.sess().cstore.iter_crate_data(|n, meta| {
externs.push((n, meta.clean()));
});
@ -683,7 +684,7 @@ impl Clean<Type> for ast::Ty {
fn clean(&self) -> Type {
use syntax::ast::*;
debug!("cleaning type `{:?}`", self);
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess.codemap;
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
debug!("span corresponds to `{}`", codemap.span_to_str(self.span));
match self.node {
TyNil => Unit,
@ -865,7 +866,7 @@ pub struct Span {
impl Clean<Span> for syntax::codemap::Span {
fn clean(&self) -> Span {
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess.codemap;
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
let filename = cm.span_to_filename(*self);
let lo = cm.lookup_char_pos(self.lo);
let hi = cm.lookup_char_pos(self.hi);
@ -1179,7 +1180,7 @@ trait ToSource {
impl ToSource for syntax::codemap::Span {
fn to_src(&self) -> ~str {
debug!("converting span {:?} to snippet", self.clean());
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess.codemap.clone();
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap.clone();
let sn = match cm.span_to_snippet(*self) {
Some(x) => x,
None => ~""
@ -1234,10 +1235,10 @@ fn name_from_pat(p: &ast::Pat) -> ~str {
fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>,
id: ast::NodeId) -> Type {
let cx = local_data::get(super::ctxtkey, |x| *x.unwrap());
let tycx = match cx.tycx {
Some(tycx) => tycx,
let tycx = match cx.maybe_typed {
core::Typed(ref tycx) => tycx,
// If we're extracting tests, this return value doesn't matter.
None => return Bool
core::NotTyped(_) => return Bool
};
debug!("searching for {:?} in defmap", id);
let def_map = tycx.def_map.borrow();
@ -1289,12 +1290,12 @@ fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource {
fn resolve_def(id: ast::NodeId) -> Option<ast::DefId> {
let cx = local_data::get(super::ctxtkey, |x| *x.unwrap());
match cx.tycx {
Some(tcx) => {
match cx.maybe_typed {
core::Typed(ref tcx) => {
let def_map = tcx.def_map.borrow();
def_map.get().find(&id).map(|&d| ast_util::def_id_of_def(d))
}
None => None
core::NotTyped(_) => None
}
}

View file

@ -27,10 +27,23 @@ use visit_ast::RustdocVisitor;
use clean;
use clean::Clean;
pub enum MaybeTyped {
Typed(middle::ty::ctxt),
NotTyped(driver::session::Session)
}
pub struct DocContext {
krate: ast::Crate,
tycx: Option<middle::ty::ctxt>,
sess: driver::session::Session
maybe_typed: MaybeTyped
}
impl DocContext {
pub fn sess<'a>(&'a self) -> &'a driver::session::Session {
match self.maybe_typed {
Typed(ref tcx) => &tcx.sess,
NotTyped(ref sess) => sess
}
}
}
pub struct CrateAnalysis {
@ -67,27 +80,27 @@ fn get_ast_and_resolve(cpath: &Path,
parsesess.cm,
span_diagnostic_handler);
let mut cfg = build_configuration(sess);
let mut cfg = build_configuration(&sess);
for cfg_ in cfgs.move_iter() {
let cfg_ = token::intern_and_get_ident(cfg_);
cfg.push(@dummy_spanned(ast::MetaWord(cfg_)));
}
let krate = phase_1_parse_input(sess, cfg, &input);
let loader = &mut Loader::new(sess);
let id = from_str("rustdoc").unwrap();
let (krate, ast_map) = phase_2_configure_and_expand(sess, loader,
krate, &id);
let krate = phase_1_parse_input(&sess, cfg, &input);
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(sess),
krate, &from_str("rustdoc").unwrap());
let driver::driver::CrateAnalysis {
exported_items, public_items, ty_cx, ..
} = phase_3_run_analysis_passes(sess, &krate, ast_map);
debug!("crate: {:?}", krate);
return (DocContext { krate: krate, tycx: Some(ty_cx), sess: sess },
CrateAnalysis {
exported_items: exported_items,
public_items: public_items,
});
(DocContext {
krate: krate,
maybe_typed: Typed(ty_cx)
}, CrateAnalysis {
exported_items: exported_items,
public_items: public_items,
})
}
pub fn run_core (libs: HashSet<Path>, cfgs: ~[~str], path: &Path) -> (clean::Crate, CrateAnalysis) {

View file

@ -58,17 +58,14 @@ pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -
parsesess.cm,
span_diagnostic_handler);
let cfg = driver::build_configuration(sess);
let krate = driver::phase_1_parse_input(sess, cfg, &input);
let loader = &mut Loader::new(sess);
let id = from_str("rustdoc-test").unwrap();
let (krate, _) = driver::phase_2_configure_and_expand(sess, loader, krate,
&id);
let cfg = driver::build_configuration(&sess);
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let (krate, _) = driver::phase_2_configure_and_expand(sess, &mut Loader::new(sess), krate,
&from_str("rustdoc-test").unwrap());
let ctx = @core::DocContext {
krate: krate,
tycx: None,
sess: sess,
maybe_typed: core::NotTyped(sess),
};
local_data::set(super::ctxtkey, ctx);
@ -140,7 +137,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");
let out = Some(outdir.path().clone());
let cfg = driver::build_configuration(sess);
let cfg = driver::build_configuration(&sess);
driver::compile_input(sess, cfg, &input, &out, &None);
if no_run { return }

View file

@ -183,21 +183,18 @@ impl<'a> RustdocVisitor<'a> {
fn resolve_id(&mut self, id: ast::NodeId, glob: bool,
om: &mut Module) -> bool {
let def = {
let dm = match self.cx.tycx {
Some(tcx) => tcx.def_map.borrow(),
None => return false,
};
ast_util::def_id_of_def(*dm.get().get(&id))
let tcx = match self.cx.maybe_typed {
core::Typed(ref tcx) => tcx,
core::NotTyped(_) => return false
};
let def = ast_util::def_id_of_def(*tcx.def_map.borrow().get().get(&id));
if !ast_util::is_local(def) { return false }
let analysis = match self.analysis {
Some(analysis) => analysis, None => return false
};
if analysis.public_items.contains(&def.node) { return false }
let item = self.cx.tycx.unwrap().map.get(def.node);
match item {
match tcx.map.get(def.node) {
ast_map::NodeItem(it) => {
if glob {
match it.node {