rustdoc: fix fallout from using ptr::P.
This commit is contained in:
parent
b06212864f
commit
9295454ff5
5 changed files with 127 additions and 154 deletions
|
@ -20,6 +20,7 @@ use syntax::attr::{AttributeMethods, AttrMetaMethods};
|
||||||
use syntax::codemap::Pos;
|
use syntax::codemap::Pos;
|
||||||
use syntax::parse::token::InternedString;
|
use syntax::parse::token::InternedString;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use rustc::back::link;
|
use rustc::back::link;
|
||||||
use rustc::driver::driver;
|
use rustc::driver::driver;
|
||||||
|
@ -34,7 +35,6 @@ use rustc::middle::stability;
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
use std::gc::{Gc, GC};
|
|
||||||
|
|
||||||
use core::DocContext;
|
use core::DocContext;
|
||||||
use doctree;
|
use doctree;
|
||||||
|
@ -67,7 +67,7 @@ impl<T: Clean<U>, U> Clean<VecPerParamSpace<U>> for VecPerParamSpace<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static + Clean<U>, U> Clean<U> for Gc<T> {
|
impl<T: Clean<U>, U> Clean<U> for P<T> {
|
||||||
fn clean(&self, cx: &DocContext) -> U {
|
fn clean(&self, cx: &DocContext) -> U {
|
||||||
(**self).clean(cx)
|
(**self).clean(cx)
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,7 @@ impl Clean<Attribute> for ast::MetaItem {
|
||||||
|
|
||||||
impl Clean<Attribute> for ast::Attribute {
|
impl Clean<Attribute> for ast::Attribute {
|
||||||
fn clean(&self, cx: &DocContext) -> Attribute {
|
fn clean(&self, cx: &DocContext) -> Attribute {
|
||||||
self.desugar_doc().node.value.clean(cx)
|
self.with_desugared_doc(|a| a.node.value.clean(cx))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,12 +430,12 @@ impl attr::AttrMetaMethods for Attribute {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
|
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
|
||||||
}
|
}
|
||||||
impl<'a> attr::AttrMetaMethods for &'a Attribute {
|
impl<'a> attr::AttrMetaMethods for &'a Attribute {
|
||||||
fn name(&self) -> InternedString { (**self).name() }
|
fn name(&self) -> InternedString { (**self).name() }
|
||||||
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
|
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
|
||||||
fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
|
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
||||||
|
@ -758,10 +758,10 @@ impl Clean<SelfTy> for ast::ExplicitSelf_ {
|
||||||
match *self {
|
match *self {
|
||||||
ast::SelfStatic => SelfStatic,
|
ast::SelfStatic => SelfStatic,
|
||||||
ast::SelfValue(_) => SelfValue,
|
ast::SelfValue(_) => SelfValue,
|
||||||
ast::SelfRegion(lt, mt, _) => {
|
ast::SelfRegion(ref lt, ref mt, _) => {
|
||||||
SelfBorrowed(lt.clean(cx), mt.clean(cx))
|
SelfBorrowed(lt.clean(cx), mt.clean(cx))
|
||||||
}
|
}
|
||||||
ast::SelfExplicit(typ, _) => SelfExplicit(typ.clean(cx)),
|
ast::SelfExplicit(ref typ, _) => SelfExplicit(typ.clean(cx)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1189,11 +1189,11 @@ impl Clean<Type> for ast::Ty {
|
||||||
TyRptr(ref l, ref m) =>
|
TyRptr(ref l, ref m) =>
|
||||||
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
|
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
|
||||||
type_: box m.ty.clean(cx)},
|
type_: box m.ty.clean(cx)},
|
||||||
TyBox(ty) => Managed(box ty.clean(cx)),
|
TyBox(ref ty) => Managed(box ty.clean(cx)),
|
||||||
TyUniq(ty) => Unique(box ty.clean(cx)),
|
TyUniq(ref ty) => Unique(box ty.clean(cx)),
|
||||||
TyVec(ty) => Vector(box ty.clean(cx)),
|
TyVec(ref ty) => Vector(box ty.clean(cx)),
|
||||||
TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(cx),
|
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
|
||||||
e.span.to_src(cx)),
|
e.span.to_src(cx)),
|
||||||
TyTup(ref tys) => Tuple(tys.clean(cx)),
|
TyTup(ref tys) => Tuple(tys.clean(cx)),
|
||||||
TyPath(ref p, ref tpbs, id) => {
|
TyPath(ref p, ref tpbs, id) => {
|
||||||
resolve_type(cx, p.clean(cx), tpbs.clean(cx), id)
|
resolve_type(cx, p.clean(cx), tpbs.clean(cx), id)
|
||||||
|
@ -1799,7 +1799,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
|
||||||
remaining,
|
remaining,
|
||||||
b.clone());
|
b.clone());
|
||||||
let path = syntax::codemap::dummy_spanned(path);
|
let path = syntax::codemap::dummy_spanned(path);
|
||||||
ret.push(convert(&ast::ViewItemUse(box(GC) path)));
|
ret.push(convert(&ast::ViewItemUse(P(path))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast::ViewPathSimple(ident, _, id) => {
|
ast::ViewPathSimple(ident, _, id) => {
|
||||||
|
@ -1985,8 +1985,8 @@ fn name_from_pat(p: &ast::Pat) -> String {
|
||||||
},
|
},
|
||||||
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
|
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
|
||||||
.collect::<Vec<String>>().connect(", ")),
|
.collect::<Vec<String>>().connect(", ")),
|
||||||
PatBox(p) => name_from_pat(&*p),
|
PatBox(ref p) => name_from_pat(&**p),
|
||||||
PatRegion(p) => name_from_pat(&*p),
|
PatRegion(ref p) => name_from_pat(&**p),
|
||||||
PatLit(..) => {
|
PatLit(..) => {
|
||||||
warn!("tried to get argument name from PatLit, \
|
warn!("tried to get argument name from PatLit, \
|
||||||
which is silly in function arguments");
|
which is silly in function arguments");
|
||||||
|
|
|
@ -8,18 +8,16 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use rustc;
|
use rustc::driver::{config, driver, session};
|
||||||
use rustc::{driver, middle};
|
|
||||||
use rustc::middle::{privacy, ty};
|
use rustc::middle::{privacy, ty};
|
||||||
use rustc::lint;
|
use rustc::lint;
|
||||||
use rustc::back::link;
|
use rustc::back::link;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::{ast, ast_map, codemap, diagnostic};
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
use syntax;
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::gc::GC;
|
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use arena::TypedArena;
|
use arena::TypedArena;
|
||||||
|
@ -30,15 +28,15 @@ use clean::Clean;
|
||||||
|
|
||||||
/// Are we generating documentation (`Typed`) or tests (`NotTyped`)?
|
/// Are we generating documentation (`Typed`) or tests (`NotTyped`)?
|
||||||
pub enum MaybeTyped<'tcx> {
|
pub enum MaybeTyped<'tcx> {
|
||||||
Typed(middle::ty::ctxt<'tcx>),
|
Typed(ty::ctxt<'tcx>),
|
||||||
NotTyped(driver::session::Session)
|
NotTyped(session::Session)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ExternalPaths = RefCell<Option<HashMap<ast::DefId,
|
pub type ExternalPaths = RefCell<Option<HashMap<ast::DefId,
|
||||||
(Vec<String>, clean::TypeKind)>>>;
|
(Vec<String>, clean::TypeKind)>>>;
|
||||||
|
|
||||||
pub struct DocContext<'tcx> {
|
pub struct DocContext<'tcx> {
|
||||||
pub krate: ast::Crate,
|
pub krate: &'tcx ast::Crate,
|
||||||
pub maybe_typed: MaybeTyped<'tcx>,
|
pub maybe_typed: MaybeTyped<'tcx>,
|
||||||
pub src: Path,
|
pub src: Path,
|
||||||
pub external_paths: ExternalPaths,
|
pub external_paths: ExternalPaths,
|
||||||
|
@ -49,7 +47,7 @@ pub struct DocContext<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> DocContext<'tcx> {
|
impl<'tcx> DocContext<'tcx> {
|
||||||
pub fn sess<'a>(&'a self) -> &'a driver::session::Session {
|
pub fn sess<'a>(&'a self) -> &'a session::Session {
|
||||||
match self.maybe_typed {
|
match self.maybe_typed {
|
||||||
Typed(ref tcx) => &tcx.sess,
|
Typed(ref tcx) => &tcx.sess,
|
||||||
NotTyped(ref sess) => sess
|
NotTyped(ref sess) => sess
|
||||||
|
@ -80,64 +78,60 @@ pub struct CrateAnalysis {
|
||||||
|
|
||||||
pub type Externs = HashMap<String, Vec<String>>;
|
pub type Externs = HashMap<String, Vec<String>>;
|
||||||
|
|
||||||
/// Parses, resolves, and typechecks the given crate
|
pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
|
||||||
fn get_ast_and_resolve<'tcx>(cpath: &Path, libs: Vec<Path>, cfgs: Vec<String>,
|
cpath: &Path, triple: Option<String>)
|
||||||
externs: Externs, triple: Option<String>,
|
-> (clean::Crate, CrateAnalysis) {
|
||||||
type_arena: &'tcx TypedArena<ty::t_box_>)
|
|
||||||
-> (DocContext<'tcx>, CrateAnalysis) {
|
|
||||||
use syntax::codemap::dummy_spanned;
|
|
||||||
use rustc::driver::driver::{FileInput,
|
|
||||||
phase_1_parse_input,
|
|
||||||
phase_2_configure_and_expand,
|
|
||||||
phase_3_run_analysis_passes};
|
|
||||||
use rustc::driver::config::build_configuration;
|
|
||||||
|
|
||||||
let input = FileInput(cpath.clone());
|
// Parse, resolve, and typecheck the given crate.
|
||||||
|
|
||||||
|
let input = driver::FileInput(cpath.clone());
|
||||||
|
|
||||||
let warning_lint = lint::builtin::WARNINGS.name_lower();
|
let warning_lint = lint::builtin::WARNINGS.name_lower();
|
||||||
|
|
||||||
let sessopts = driver::config::Options {
|
let sessopts = config::Options {
|
||||||
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
|
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
|
||||||
addl_lib_search_paths: RefCell::new(libs),
|
addl_lib_search_paths: RefCell::new(libs),
|
||||||
crate_types: vec!(driver::config::CrateTypeRlib),
|
crate_types: vec!(config::CrateTypeRlib),
|
||||||
lint_opts: vec!((warning_lint, lint::Allow)),
|
lint_opts: vec!((warning_lint, lint::Allow)),
|
||||||
externs: externs,
|
externs: externs,
|
||||||
target_triple: triple.unwrap_or(driver::driver::host_triple().to_string()),
|
target_triple: triple.unwrap_or(driver::host_triple().to_string()),
|
||||||
..rustc::driver::config::basic_options().clone()
|
..config::basic_options().clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let codemap = syntax::codemap::CodeMap::new();
|
let codemap = codemap::CodeMap::new();
|
||||||
let diagnostic_handler = syntax::diagnostic::default_handler(syntax::diagnostic::Auto, None);
|
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None);
|
||||||
let span_diagnostic_handler =
|
let span_diagnostic_handler =
|
||||||
syntax::diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
||||||
|
|
||||||
let sess = driver::session::build_session_(sessopts,
|
let sess = session::build_session_(sessopts,
|
||||||
Some(cpath.clone()),
|
Some(cpath.clone()),
|
||||||
span_diagnostic_handler);
|
span_diagnostic_handler);
|
||||||
|
|
||||||
let mut cfg = build_configuration(&sess);
|
let mut cfg = config::build_configuration(&sess);
|
||||||
for cfg_ in cfgs.move_iter() {
|
for cfg_ in cfgs.move_iter() {
|
||||||
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
|
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
|
||||||
cfg.push(box(GC) dummy_spanned(ast::MetaWord(cfg_)));
|
cfg.push(P(codemap::dummy_spanned(ast::MetaWord(cfg_))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let krate = phase_1_parse_input(&sess, cfg, &input);
|
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
|
||||||
|
|
||||||
let name = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
|
let name = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
|
||||||
&input);
|
&input);
|
||||||
|
|
||||||
let (krate, ast_map)
|
let krate = driver::phase_2_configure_and_expand(&sess, krate, name.as_slice(), None)
|
||||||
= phase_2_configure_and_expand(&sess, krate, name.as_slice(), None)
|
.expect("phase_2_configure_and_expand aborted in rustdoc!");
|
||||||
.expect("phase_2_configure_and_expand aborted in rustdoc!");
|
|
||||||
|
|
||||||
let driver::driver::CrateAnalysis {
|
let mut forest = ast_map::Forest::new(krate);
|
||||||
|
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
|
||||||
|
|
||||||
|
let type_arena = TypedArena::new();
|
||||||
|
let driver::CrateAnalysis {
|
||||||
exported_items, public_items, ty_cx, ..
|
exported_items, public_items, ty_cx, ..
|
||||||
} = phase_3_run_analysis_passes(sess, &krate, ast_map, type_arena, name);
|
} = driver::phase_3_run_analysis_passes(sess, ast_map, &type_arena, name);
|
||||||
|
|
||||||
debug!("crate: {:?}", krate);
|
let ctxt = DocContext {
|
||||||
(DocContext {
|
krate: ty_cx.map.krate(),
|
||||||
krate: krate,
|
|
||||||
maybe_typed: Typed(ty_cx),
|
maybe_typed: Typed(ty_cx),
|
||||||
src: cpath.clone(),
|
src: cpath.clone(),
|
||||||
external_traits: RefCell::new(Some(HashMap::new())),
|
external_traits: RefCell::new(Some(HashMap::new())),
|
||||||
|
@ -145,26 +139,21 @@ fn get_ast_and_resolve<'tcx>(cpath: &Path, libs: Vec<Path>, cfgs: Vec<String>,
|
||||||
external_paths: RefCell::new(Some(HashMap::new())),
|
external_paths: RefCell::new(Some(HashMap::new())),
|
||||||
inlined: RefCell::new(Some(HashSet::new())),
|
inlined: RefCell::new(Some(HashSet::new())),
|
||||||
populated_crate_impls: RefCell::new(HashSet::new()),
|
populated_crate_impls: RefCell::new(HashSet::new()),
|
||||||
}, CrateAnalysis {
|
};
|
||||||
|
debug!("crate: {:?}", ctxt.krate);
|
||||||
|
|
||||||
|
let analysis = CrateAnalysis {
|
||||||
exported_items: exported_items,
|
exported_items: exported_items,
|
||||||
public_items: public_items,
|
public_items: public_items,
|
||||||
external_paths: RefCell::new(None),
|
external_paths: RefCell::new(None),
|
||||||
external_traits: RefCell::new(None),
|
external_traits: RefCell::new(None),
|
||||||
external_typarams: RefCell::new(None),
|
external_typarams: RefCell::new(None),
|
||||||
inlined: RefCell::new(None),
|
inlined: RefCell::new(None),
|
||||||
})
|
};
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
|
|
||||||
path: &Path, triple: Option<String>)
|
|
||||||
-> (clean::Crate, CrateAnalysis) {
|
|
||||||
let type_arena = TypedArena::new();
|
|
||||||
let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs, externs,
|
|
||||||
triple, &type_arena);
|
|
||||||
|
|
||||||
let krate = {
|
let krate = {
|
||||||
let mut v = RustdocVisitor::new(&ctxt, Some(&analysis));
|
let mut v = RustdocVisitor::new(&ctxt, Some(&analysis));
|
||||||
v.visit(&ctxt.krate);
|
v.visit(ctxt.krate);
|
||||||
v.clean(&ctxt)
|
v.clean(&ctxt)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ use syntax::codemap::Span;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::ast::{Ident, NodeId};
|
use syntax::ast::{Ident, NodeId};
|
||||||
|
use syntax::ptr::P;
|
||||||
use std::gc::Gc;
|
|
||||||
|
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
pub name: Option<Ident>,
|
pub name: Option<Ident>,
|
||||||
|
@ -130,7 +129,7 @@ pub struct Function {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Typedef {
|
pub struct Typedef {
|
||||||
pub ty: ast::P<ast::Ty>,
|
pub ty: P<ast::Ty>,
|
||||||
pub gen: ast::Generics,
|
pub gen: ast::Generics,
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub id: ast::NodeId,
|
pub id: ast::NodeId,
|
||||||
|
@ -141,9 +140,9 @@ pub struct Typedef {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Static {
|
pub struct Static {
|
||||||
pub type_: ast::P<ast::Ty>,
|
pub type_: P<ast::Ty>,
|
||||||
pub mutability: ast::Mutability,
|
pub mutability: ast::Mutability,
|
||||||
pub expr: Gc<ast::Expr>,
|
pub expr: P<ast::Expr>,
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub attrs: Vec<ast::Attribute>,
|
pub attrs: Vec<ast::Attribute>,
|
||||||
pub vis: ast::Visibility,
|
pub vis: ast::Visibility,
|
||||||
|
@ -167,7 +166,7 @@ pub struct Trait {
|
||||||
pub struct Impl {
|
pub struct Impl {
|
||||||
pub generics: ast::Generics,
|
pub generics: ast::Generics,
|
||||||
pub trait_: Option<ast::TraitRef>,
|
pub trait_: Option<ast::TraitRef>,
|
||||||
pub for_: ast::P<ast::Ty>,
|
pub for_: P<ast::Ty>,
|
||||||
pub items: Vec<ast::ImplItem>,
|
pub items: Vec<ast::ImplItem>,
|
||||||
pub attrs: Vec<ast::Attribute>,
|
pub attrs: Vec<ast::Attribute>,
|
||||||
pub whence: Span,
|
pub whence: Span,
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::dynamic_lib::DynamicLibrary;
|
use std::dynamic_lib::DynamicLibrary;
|
||||||
use std::gc::GC;
|
|
||||||
use std::io::{Command, TempDir};
|
use std::io::{Command, TempDir};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::os;
|
use std::os;
|
||||||
|
@ -28,6 +27,7 @@ use syntax::ast;
|
||||||
use syntax::codemap::{CodeMap, dummy_spanned};
|
use syntax::codemap::{CodeMap, dummy_spanned};
|
||||||
use syntax::diagnostic;
|
use syntax::diagnostic;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use core;
|
use core;
|
||||||
use clean;
|
use clean;
|
||||||
|
@ -67,15 +67,15 @@ pub fn run(input: &str,
|
||||||
let mut cfg = config::build_configuration(&sess);
|
let mut cfg = config::build_configuration(&sess);
|
||||||
cfg.extend(cfgs.move_iter().map(|cfg_| {
|
cfg.extend(cfgs.move_iter().map(|cfg_| {
|
||||||
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
|
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
|
||||||
box(GC) dummy_spanned(ast::MetaWord(cfg_))
|
P(dummy_spanned(ast::MetaWord(cfg_)))
|
||||||
}));
|
}));
|
||||||
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
|
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
|
||||||
let (krate, _) = driver::phase_2_configure_and_expand(&sess, krate,
|
let krate = driver::phase_2_configure_and_expand(&sess, krate,
|
||||||
"rustdoc-test", None)
|
"rustdoc-test", None)
|
||||||
.expect("phase_2_configure_and_expand aborted in rustdoc!");
|
.expect("phase_2_configure_and_expand aborted in rustdoc!");
|
||||||
|
|
||||||
let ctx = core::DocContext {
|
let ctx = core::DocContext {
|
||||||
krate: krate,
|
krate: &krate,
|
||||||
maybe_typed: core::NotTyped(sess),
|
maybe_typed: core::NotTyped(sess),
|
||||||
src: input_path,
|
src: input_path,
|
||||||
external_paths: RefCell::new(Some(HashMap::new())),
|
external_paths: RefCell::new(Some(HashMap::new())),
|
||||||
|
@ -86,7 +86,7 @@ pub fn run(input: &str,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut v = RustdocVisitor::new(&ctx, None);
|
let mut v = RustdocVisitor::new(&ctx, None);
|
||||||
v.visit(&ctx.krate);
|
v.visit(ctx.krate);
|
||||||
let mut krate = v.clean(&ctx);
|
let mut krate = v.clean(&ctx);
|
||||||
match crate_name {
|
match crate_name {
|
||||||
Some(name) => krate.name = name,
|
Some(name) => krate.name = name,
|
||||||
|
|
|
@ -18,11 +18,10 @@ use syntax::ast_map;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use rustc::middle::stability;
|
use rustc::middle::stability;
|
||||||
|
|
||||||
use std::gc::{Gc, GC};
|
|
||||||
|
|
||||||
use core;
|
use core;
|
||||||
use doctree::*;
|
use doctree::*;
|
||||||
|
|
||||||
|
@ -57,13 +56,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit(&mut self, krate: &ast::Crate) {
|
pub fn visit(&mut self, krate: &ast::Crate) {
|
||||||
self.attrs = krate.attrs.iter().map(|x| (*x).clone()).collect();
|
self.attrs = krate.attrs.clone();
|
||||||
|
|
||||||
self.module = self.visit_mod_contents(krate.span,
|
self.module = self.visit_mod_contents(krate.span,
|
||||||
krate.attrs
|
krate.attrs.clone(),
|
||||||
.iter()
|
|
||||||
.map(|x| *x)
|
|
||||||
.collect(),
|
|
||||||
ast::Public,
|
ast::Public,
|
||||||
ast::CRATE_NODE_ID,
|
ast::CRATE_NODE_ID,
|
||||||
&krate.module,
|
&krate.module,
|
||||||
|
@ -74,51 +70,50 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
self.module.is_crate = true;
|
self.module.is_crate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_struct_def(&mut self, item: &ast::Item, sd: Gc<ast::StructDef>,
|
pub fn visit_struct_def(&mut self, item: &ast::Item,
|
||||||
|
name: ast::Ident, sd: &ast::StructDef,
|
||||||
generics: &ast::Generics) -> Struct {
|
generics: &ast::Generics) -> Struct {
|
||||||
debug!("Visiting struct");
|
debug!("Visiting struct");
|
||||||
let struct_type = struct_type_from_def(&*sd);
|
let struct_type = struct_type_from_def(&*sd);
|
||||||
Struct {
|
Struct {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
struct_type: struct_type,
|
struct_type: struct_type,
|
||||||
name: item.ident,
|
name: name,
|
||||||
vis: item.vis,
|
vis: item.vis,
|
||||||
stab: self.stability(item.id),
|
stab: self.stability(item.id),
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
generics: generics.clone(),
|
generics: generics.clone(),
|
||||||
fields: sd.fields.iter().map(|x| (*x).clone()).collect(),
|
fields: sd.fields.clone(),
|
||||||
whence: item.span
|
whence: item.span
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef,
|
pub fn visit_enum_def(&mut self, it: &ast::Item,
|
||||||
|
name: ast::Ident, def: &ast::EnumDef,
|
||||||
params: &ast::Generics) -> Enum {
|
params: &ast::Generics) -> Enum {
|
||||||
debug!("Visiting enum");
|
debug!("Visiting enum");
|
||||||
let mut vars: Vec<Variant> = Vec::new();
|
|
||||||
for x in def.variants.iter() {
|
|
||||||
vars.push(Variant {
|
|
||||||
name: x.node.name,
|
|
||||||
attrs: x.node.attrs.iter().map(|x| *x).collect(),
|
|
||||||
vis: x.node.vis,
|
|
||||||
stab: self.stability(x.node.id),
|
|
||||||
id: x.node.id,
|
|
||||||
kind: x.node.kind.clone(),
|
|
||||||
whence: x.span,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Enum {
|
Enum {
|
||||||
name: it.ident,
|
name: name,
|
||||||
variants: vars,
|
variants: def.variants.iter().map(|v| Variant {
|
||||||
|
name: v.node.name,
|
||||||
|
attrs: v.node.attrs.clone(),
|
||||||
|
vis: v.node.vis,
|
||||||
|
stab: self.stability(v.node.id),
|
||||||
|
id: v.node.id,
|
||||||
|
kind: v.node.kind.clone(),
|
||||||
|
whence: v.span,
|
||||||
|
}).collect(),
|
||||||
vis: it.vis,
|
vis: it.vis,
|
||||||
stab: self.stability(it.id),
|
stab: self.stability(it.id),
|
||||||
generics: params.clone(),
|
generics: params.clone(),
|
||||||
attrs: it.attrs.iter().map(|x| *x).collect(),
|
attrs: it.attrs.clone(),
|
||||||
id: it.id,
|
id: it.id,
|
||||||
whence: it.span,
|
whence: it.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_fn(&mut self, item: &ast::Item, fd: &ast::FnDecl,
|
pub fn visit_fn(&mut self, item: &ast::Item,
|
||||||
|
name: ast::Ident, fd: &ast::FnDecl,
|
||||||
fn_style: &ast::FnStyle, _abi: &abi::Abi,
|
fn_style: &ast::FnStyle, _abi: &abi::Abi,
|
||||||
gen: &ast::Generics) -> Function {
|
gen: &ast::Generics) -> Function {
|
||||||
debug!("Visiting fn");
|
debug!("Visiting fn");
|
||||||
|
@ -126,9 +121,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
vis: item.vis,
|
vis: item.vis,
|
||||||
stab: self.stability(item.id),
|
stab: self.stability(item.id),
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
decl: fd.clone(),
|
decl: fd.clone(),
|
||||||
name: item.ident,
|
name: name,
|
||||||
whence: item.span,
|
whence: item.span,
|
||||||
generics: gen.clone(),
|
generics: gen.clone(),
|
||||||
fn_style: *fn_style,
|
fn_style: *fn_style,
|
||||||
|
@ -150,7 +145,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
om.stab = self.stability(id);
|
om.stab = self.stability(id);
|
||||||
om.id = id;
|
om.id = id;
|
||||||
for i in m.items.iter() {
|
for i in m.items.iter() {
|
||||||
self.visit_item(&**i, &mut om);
|
self.visit_item(&**i, None, &mut om);
|
||||||
}
|
}
|
||||||
om
|
om
|
||||||
}
|
}
|
||||||
|
@ -169,7 +164,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
let item = match item.node {
|
let item = match item.node {
|
||||||
ast::ViewItemUse(ref vpath) => {
|
ast::ViewItemUse(ref vpath) => {
|
||||||
match self.visit_view_path(*vpath, om, please_inline) {
|
match self.visit_view_path(&**vpath, om, please_inline) {
|
||||||
None => return,
|
None => return,
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
ast::ViewItem {
|
ast::ViewItem {
|
||||||
|
@ -184,9 +179,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
om.view_items.push(item);
|
om.view_items.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_view_path(&mut self, path: Gc<ast::ViewPath>,
|
fn visit_view_path(&mut self, path: &ast::ViewPath,
|
||||||
om: &mut Module,
|
om: &mut Module,
|
||||||
please_inline: bool) -> Option<Gc<ast::ViewPath>> {
|
please_inline: bool) -> Option<P<ast::ViewPath>> {
|
||||||
match path.node {
|
match path.node {
|
||||||
ast::ViewPathSimple(dst, _, id) => {
|
ast::ViewPathSimple(dst, _, id) => {
|
||||||
if self.resolve_id(id, Some(dst), false, om, please_inline) {
|
if self.resolve_id(id, Some(dst), false, om, please_inline) {
|
||||||
|
@ -203,10 +198,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if mine.len() == 0 { return None }
|
if mine.len() == 0 { return None }
|
||||||
return Some(box(GC) ::syntax::codemap::Spanned {
|
return Some(P(::syntax::codemap::Spanned {
|
||||||
node: ast::ViewPathList(p.clone(), mine, b.clone()),
|
node: ast::ViewPathList(p.clone(), mine, b.clone()),
|
||||||
span: path.span,
|
span: path.span,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are feature gated anyway
|
// these are feature gated anyway
|
||||||
|
@ -216,7 +211,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(path);
|
Some(P(path.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_id(&mut self, id: ast::NodeId, renamed: Option<ast::Ident>,
|
fn resolve_id(&mut self, id: ast::NodeId, renamed: Option<ast::Ident>,
|
||||||
|
@ -236,15 +231,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
|
|
||||||
match tcx.map.get(def.node) {
|
match tcx.map.get(def.node) {
|
||||||
ast_map::NodeItem(it) => {
|
ast_map::NodeItem(it) => {
|
||||||
let it = match renamed {
|
|
||||||
Some(ident) => {
|
|
||||||
box(GC) ast::Item {
|
|
||||||
ident: ident,
|
|
||||||
..(*it).clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => it,
|
|
||||||
};
|
|
||||||
if glob {
|
if glob {
|
||||||
match it.node {
|
match it.node {
|
||||||
ast::ItemMod(ref m) => {
|
ast::ItemMod(ref m) => {
|
||||||
|
@ -252,13 +238,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
self.visit_view_item(vi, om);
|
self.visit_view_item(vi, om);
|
||||||
}
|
}
|
||||||
for i in m.items.iter() {
|
for i in m.items.iter() {
|
||||||
self.visit_item(&**i, om);
|
self.visit_item(&**i, None, om);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => { fail!("glob not mapped to a module"); }
|
_ => { fail!("glob not mapped to a module"); }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.visit_item(&*it, om);
|
self.visit_item(it, renamed, om);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -266,47 +252,46 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
|
pub fn visit_item(&mut self, item: &ast::Item,
|
||||||
|
renamed: Option<ast::Ident>, om: &mut Module) {
|
||||||
debug!("Visiting item {:?}", item);
|
debug!("Visiting item {:?}", item);
|
||||||
|
let name = renamed.unwrap_or(item.ident);
|
||||||
match item.node {
|
match item.node {
|
||||||
ast::ItemMod(ref m) => {
|
ast::ItemMod(ref m) => {
|
||||||
om.mods.push(self.visit_mod_contents(item.span,
|
om.mods.push(self.visit_mod_contents(item.span,
|
||||||
item.attrs
|
item.attrs.clone(),
|
||||||
.iter()
|
|
||||||
.map(|x| *x)
|
|
||||||
.collect(),
|
|
||||||
item.vis,
|
item.vis,
|
||||||
item.id,
|
item.id,
|
||||||
m,
|
m,
|
||||||
Some(item.ident)));
|
Some(name)));
|
||||||
},
|
},
|
||||||
ast::ItemEnum(ref ed, ref gen) =>
|
ast::ItemEnum(ref ed, ref gen) =>
|
||||||
om.enums.push(self.visit_enum_def(item, ed, gen)),
|
om.enums.push(self.visit_enum_def(item, name, ed, gen)),
|
||||||
ast::ItemStruct(sd, ref gen) =>
|
ast::ItemStruct(ref sd, ref gen) =>
|
||||||
om.structs.push(self.visit_struct_def(item, sd, gen)),
|
om.structs.push(self.visit_struct_def(item, name, &**sd, gen)),
|
||||||
ast::ItemFn(ref fd, ref pur, ref abi, ref gen, _) =>
|
ast::ItemFn(ref fd, ref pur, ref abi, ref gen, _) =>
|
||||||
om.fns.push(self.visit_fn(item, &**fd, pur, abi, gen)),
|
om.fns.push(self.visit_fn(item, name, &**fd, pur, abi, gen)),
|
||||||
ast::ItemTy(ty, ref gen) => {
|
ast::ItemTy(ref ty, ref gen) => {
|
||||||
let t = Typedef {
|
let t = Typedef {
|
||||||
ty: ty,
|
ty: ty.clone(),
|
||||||
gen: gen.clone(),
|
gen: gen.clone(),
|
||||||
name: item.ident,
|
name: name,
|
||||||
id: item.id,
|
id: item.id,
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
whence: item.span,
|
whence: item.span,
|
||||||
vis: item.vis,
|
vis: item.vis,
|
||||||
stab: self.stability(item.id),
|
stab: self.stability(item.id),
|
||||||
};
|
};
|
||||||
om.typedefs.push(t);
|
om.typedefs.push(t);
|
||||||
},
|
},
|
||||||
ast::ItemStatic(ty, ref mut_, ref exp) => {
|
ast::ItemStatic(ref ty, ref mut_, ref exp) => {
|
||||||
let s = Static {
|
let s = Static {
|
||||||
type_: ty,
|
type_: ty.clone(),
|
||||||
mutability: mut_.clone(),
|
mutability: mut_.clone(),
|
||||||
expr: exp.clone(),
|
expr: exp.clone(),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.ident,
|
name: name,
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
whence: item.span,
|
whence: item.span,
|
||||||
vis: item.vis,
|
vis: item.vis,
|
||||||
stab: self.stability(item.id),
|
stab: self.stability(item.id),
|
||||||
|
@ -315,25 +300,25 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
},
|
},
|
||||||
ast::ItemTrait(ref gen, _, ref b, ref items) => {
|
ast::ItemTrait(ref gen, _, ref b, ref items) => {
|
||||||
let t = Trait {
|
let t = Trait {
|
||||||
name: item.ident,
|
name: name,
|
||||||
items: items.iter().map(|x| (*x).clone()).collect(),
|
items: items.clone(),
|
||||||
generics: gen.clone(),
|
generics: gen.clone(),
|
||||||
bounds: b.iter().map(|x| (*x).clone()).collect(),
|
bounds: b.iter().map(|x| (*x).clone()).collect(),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
whence: item.span,
|
whence: item.span,
|
||||||
vis: item.vis,
|
vis: item.vis,
|
||||||
stab: self.stability(item.id),
|
stab: self.stability(item.id),
|
||||||
};
|
};
|
||||||
om.traits.push(t);
|
om.traits.push(t);
|
||||||
},
|
},
|
||||||
ast::ItemImpl(ref gen, ref tr, ty, ref items) => {
|
ast::ItemImpl(ref gen, ref tr, ref ty, ref items) => {
|
||||||
let i = Impl {
|
let i = Impl {
|
||||||
generics: gen.clone(),
|
generics: gen.clone(),
|
||||||
trait_: tr.clone(),
|
trait_: tr.clone(),
|
||||||
for_: ty,
|
for_: ty.clone(),
|
||||||
items: items.iter().map(|x| *x).collect(),
|
items: items.clone(),
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
whence: item.span,
|
whence: item.span,
|
||||||
vis: item.vis,
|
vis: item.vis,
|
||||||
|
@ -354,7 +339,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
fn visit_macro(&self, item: &ast::Item) -> Macro {
|
fn visit_macro(&self, item: &ast::Item) -> Macro {
|
||||||
Macro {
|
Macro {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
attrs: item.attrs.iter().map(|x| *x).collect(),
|
attrs: item.attrs.clone(),
|
||||||
name: item.ident,
|
name: item.ident,
|
||||||
whence: item.span,
|
whence: item.span,
|
||||||
stab: self.stability(item.id),
|
stab: self.stability(item.id),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue