rust/src/librustdoc/doctree.rs

277 lines
7.4 KiB
Rust
Raw Normal View History

// Copyright 2012-2013 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.
2013-08-15 15:28:54 -05:00
//! This module is used to store stuff from Rust's AST in a more convenient
//! manner (and with prettier names) before cleaning.
pub use self::StructType::*;
pub use self::TypeBound::*;
2013-08-15 15:28:54 -05:00
use syntax::abi;
2013-08-15 15:28:54 -05:00
use syntax::ast;
use syntax::ast::{Name, NodeId};
use syntax::attr;
use syntax::ptr::P;
use syntax_pos::{self, Span};
2016-03-29 00:50:44 -05:00
use rustc::hir;
use rustc::hir::def_id::CrateNum;
2014-05-16 12:15:33 -05:00
2013-08-15 15:28:54 -05:00
pub struct Module {
2015-09-19 20:50:30 -05:00
pub name: Option<Name>,
pub attrs: hir::HirVec<ast::Attribute>,
pub where_outer: Span,
pub where_inner: Span,
pub extern_crates: Vec<ExternCrate>,
pub imports: Vec<Import>,
pub structs: Vec<Struct>,
2016-08-10 13:00:17 -05:00
pub unions: Vec<Union>,
pub enums: Vec<Enum>,
pub fns: Vec<Function>,
pub mods: Vec<Module>,
pub id: NodeId,
pub typedefs: Vec<Typedef>,
pub statics: Vec<Static>,
pub constants: Vec<Constant>,
pub traits: Vec<Trait>,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub impls: Vec<Impl>,
pub def_traits: Vec<AutoImpl>,
2015-07-31 02:04:06 -05:00
pub foreigns: Vec<hir::ForeignMod>,
pub macros: Vec<Macro>,
pub is_crate: bool,
2013-08-15 15:28:54 -05:00
}
impl Module {
2015-09-19 20:50:30 -05:00
pub fn new(name: Option<Name>) -> Module {
2013-08-15 15:28:54 -05:00
Module {
name : name,
id: ast::CRATE_NODE_ID,
2015-07-31 02:04:06 -05:00
vis: hir::Inherited,
stab: None,
2015-12-12 14:01:27 -06:00
depr: None,
where_outer: syntax_pos::DUMMY_SP,
where_inner: syntax_pos::DUMMY_SP,
attrs : hir::HirVec::new(),
extern_crates: Vec::new(),
imports : Vec::new(),
structs : Vec::new(),
2016-08-10 13:00:17 -05:00
unions : Vec::new(),
enums : Vec::new(),
fns : Vec::new(),
mods : Vec::new(),
typedefs : Vec::new(),
statics : Vec::new(),
constants : Vec::new(),
traits : Vec::new(),
impls : Vec::new(),
2015-01-26 17:35:03 -06:00
def_traits : Vec::new(),
foreigns : Vec::new(),
macros : Vec::new(),
is_crate : false,
2013-08-15 15:28:54 -05:00
}
}
}
2015-01-28 07:34:18 -06:00
#[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
2013-08-15 15:28:54 -05:00
pub enum StructType {
/// A braced struct
2013-08-15 15:28:54 -05:00
Plain,
/// A tuple struct
Tuple,
/// A unit struct
Unit,
2013-08-15 15:28:54 -05:00
}
pub enum TypeBound {
RegionBound,
2015-07-31 02:04:06 -05:00
TraitBound(hir::TraitRef)
2013-08-15 15:28:54 -05:00
}
pub struct Struct {
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2016-08-10 13:00:17 -05:00
pub depr: Option<attr::Deprecation>,
pub id: NodeId,
pub struct_type: StructType,
pub name: Name,
pub generics: hir::Generics,
pub attrs: hir::HirVec<ast::Attribute>,
pub fields: hir::HirVec<hir::StructField>,
pub whence: Span,
}
pub struct Union {
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub id: NodeId,
pub struct_type: StructType,
2015-09-19 20:50:30 -05:00
pub name: Name,
2015-07-31 02:04:06 -05:00
pub generics: hir::Generics,
pub attrs: hir::HirVec<ast::Attribute>,
pub fields: hir::HirVec<hir::StructField>,
pub whence: Span,
2013-08-15 15:28:54 -05:00
}
pub struct Enum {
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub variants: hir::HirVec<Variant>,
2015-07-31 02:04:06 -05:00
pub generics: hir::Generics,
pub attrs: hir::HirVec<ast::Attribute>,
pub id: NodeId,
pub whence: Span,
2015-09-19 20:50:30 -05:00
pub name: Name,
2013-08-15 15:28:54 -05:00
}
pub struct Variant {
pub name: Name,
pub attrs: hir::HirVec<ast::Attribute>,
pub def: hir::VariantData,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub whence: Span,
2013-08-15 15:28:54 -05:00
}
pub struct Function {
2015-07-31 02:04:06 -05:00
pub decl: hir::FnDecl,
pub attrs: hir::HirVec<ast::Attribute>,
pub id: NodeId,
2015-09-19 20:50:30 -05:00
pub name: Name,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
2015-07-31 02:04:06 -05:00
pub unsafety: hir::Unsafety,
pub constness: hir::Constness,
pub whence: Span,
2015-07-31 02:04:06 -05:00
pub generics: hir::Generics,
pub abi: abi::Abi,
pub body: hir::BodyId,
2013-08-15 15:28:54 -05:00
}
pub struct Typedef {
2015-07-31 02:04:06 -05:00
pub ty: P<hir::Ty>,
pub gen: hir::Generics,
2015-09-19 20:50:30 -05:00
pub name: Name,
pub id: ast::NodeId,
pub attrs: hir::HirVec<ast::Attribute>,
pub whence: Span,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
2013-08-15 15:28:54 -05:00
}
2015-01-28 07:34:18 -06:00
#[derive(Debug)]
2013-08-15 15:28:54 -05:00
pub struct Static {
2015-07-31 02:04:06 -05:00
pub type_: P<hir::Ty>,
pub mutability: hir::Mutability,
pub expr: hir::BodyId,
2015-09-19 20:50:30 -05:00
pub name: Name,
pub attrs: hir::HirVec<ast::Attribute>,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub id: ast::NodeId,
pub whence: Span,
2013-08-15 15:28:54 -05:00
}
pub struct Constant {
2015-07-31 02:04:06 -05:00
pub type_: P<hir::Ty>,
pub expr: hir::BodyId,
2015-09-19 20:50:30 -05:00
pub name: Name,
pub attrs: hir::HirVec<ast::Attribute>,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub id: ast::NodeId,
pub whence: Span,
}
2013-08-15 15:28:54 -05:00
pub struct Trait {
2015-07-31 02:04:06 -05:00
pub unsafety: hir::Unsafety,
2015-09-19 20:50:30 -05:00
pub name: Name,
pub items: hir::HirVec<hir::TraitItem>,
2015-07-31 02:04:06 -05:00
pub generics: hir::Generics,
pub bounds: hir::HirVec<hir::TyParamBound>,
pub attrs: hir::HirVec<ast::Attribute>,
pub id: ast::NodeId,
pub whence: Span,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
2013-08-15 15:28:54 -05:00
}
pub struct Impl {
2015-07-31 02:04:06 -05:00
pub unsafety: hir::Unsafety,
pub polarity: hir::ImplPolarity,
pub defaultness: hir::Defaultness,
2015-07-31 02:04:06 -05:00
pub generics: hir::Generics,
pub trait_: Option<hir::TraitRef>,
pub for_: P<hir::Ty>,
pub items: hir::HirVec<hir::ImplItem>,
pub attrs: hir::HirVec<ast::Attribute>,
pub whence: Span,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub id: ast::NodeId,
2013-08-15 15:28:54 -05:00
}
pub struct AutoImpl {
2015-07-31 02:04:06 -05:00
pub unsafety: hir::Unsafety,
pub trait_: hir::TraitRef,
2015-01-26 17:35:03 -06:00
pub id: ast::NodeId,
pub attrs: hir::HirVec<ast::Attribute>,
pub whence: Span,
2015-01-26 17:35:03 -06:00
}
// For Macro we store the DefId instead of the NodeId, since we also create
// these imported macro_rules (which only have a DUMMY_NODE_ID).
pub struct Macro {
pub name: Name,
pub def_id: hir::def_id::DefId,
pub attrs: hir::HirVec<ast::Attribute>,
pub whence: Span,
pub matchers: hir::HirVec<Span>,
pub stab: Option<attr::Stability>,
2015-12-12 14:01:27 -06:00
pub depr: Option<attr::Deprecation>,
pub imported_from: Option<Name>,
}
pub struct ExternCrate {
2015-09-19 20:50:30 -05:00
pub name: Name,
pub cnum: CrateNum,
pub path: Option<String>,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub attrs: hir::HirVec<ast::Attribute>,
pub whence: Span,
}
pub struct Import {
pub name: Name,
pub id: NodeId,
2015-07-31 02:04:06 -05:00
pub vis: hir::Visibility,
pub attrs: hir::HirVec<ast::Attribute>,
pub path: hir::Path,
pub glob: bool,
pub whence: Span,
}
pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
match *vdata {
hir::VariantData::Struct(..) => Plain,
hir::VariantData::Tuple(..) => Tuple,
hir::VariantData::Unit(..) => Unit,
2013-08-15 15:28:54 -05:00
}
}