]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/doctree.rs
Improve some compiletest documentation
[rust.git] / src / librustdoc / doctree.rs
1 //! This module is used to store stuff from Rust's AST in a more convenient
2 //! manner (and with prettier names) before cleaning.
3 pub use self::StructType::*;
4
5 use syntax::ast;
6 use syntax::ast::{Name, NodeId};
7 use syntax::attr;
8 use syntax::ext::base::MacroKind;
9 use syntax::ptr::P;
10 use syntax::source_map::Spanned;
11 use syntax_pos::{self, Span};
12
13 use rustc::hir;
14 use rustc::hir::def_id::CrateNum;
15
16 pub struct Module {
17     pub name: Option<Name>,
18     pub attrs: hir::HirVec<ast::Attribute>,
19     pub where_outer: Span,
20     pub where_inner: Span,
21     pub extern_crates: Vec<ExternCrate>,
22     pub imports: Vec<Import>,
23     pub structs: Vec<Struct>,
24     pub unions: Vec<Union>,
25     pub enums: Vec<Enum>,
26     pub fns: Vec<Function>,
27     pub mods: Vec<Module>,
28     pub id: NodeId,
29     pub typedefs: Vec<Typedef>,
30     pub existentials: Vec<Existential>,
31     pub statics: Vec<Static>,
32     pub constants: Vec<Constant>,
33     pub traits: Vec<Trait>,
34     pub vis: hir::Visibility,
35     pub stab: Option<attr::Stability>,
36     pub depr: Option<attr::Deprecation>,
37     pub impls: Vec<Impl>,
38     pub foreigns: Vec<hir::ForeignMod>,
39     pub macros: Vec<Macro>,
40     pub proc_macros: Vec<ProcMacro>,
41     pub trait_aliases: Vec<TraitAlias>,
42     pub is_crate: bool,
43 }
44
45 impl Module {
46     pub fn new(name: Option<Name>) -> Module {
47         Module {
48             name       : name,
49             id: ast::CRATE_NODE_ID,
50             vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
51             stab: None,
52             depr: None,
53             where_outer: syntax_pos::DUMMY_SP,
54             where_inner: syntax_pos::DUMMY_SP,
55             attrs      : hir::HirVec::new(),
56             extern_crates: Vec::new(),
57             imports    :   Vec::new(),
58             structs    :   Vec::new(),
59             unions     :   Vec::new(),
60             enums      :   Vec::new(),
61             fns        :   Vec::new(),
62             mods       :   Vec::new(),
63             typedefs   :   Vec::new(),
64             existentials:  Vec::new(),
65             statics    :   Vec::new(),
66             constants  :   Vec::new(),
67             traits     :   Vec::new(),
68             impls      :   Vec::new(),
69             foreigns   :   Vec::new(),
70             macros     :   Vec::new(),
71             proc_macros:   Vec::new(),
72             trait_aliases: Vec::new(),
73             is_crate   : false,
74         }
75     }
76 }
77
78 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
79 pub enum StructType {
80     /// A braced struct
81     Plain,
82     /// A tuple struct
83     Tuple,
84     /// A unit struct
85     Unit,
86 }
87
88 pub struct Struct {
89     pub vis: hir::Visibility,
90     pub stab: Option<attr::Stability>,
91     pub depr: Option<attr::Deprecation>,
92     pub id: hir::HirId,
93     pub struct_type: StructType,
94     pub name: Name,
95     pub generics: hir::Generics,
96     pub attrs: hir::HirVec<ast::Attribute>,
97     pub fields: hir::HirVec<hir::StructField>,
98     pub whence: Span,
99 }
100
101 pub struct Union {
102     pub vis: hir::Visibility,
103     pub stab: Option<attr::Stability>,
104     pub depr: Option<attr::Deprecation>,
105     pub id: hir::HirId,
106     pub struct_type: StructType,
107     pub name: Name,
108     pub generics: hir::Generics,
109     pub attrs: hir::HirVec<ast::Attribute>,
110     pub fields: hir::HirVec<hir::StructField>,
111     pub whence: Span,
112 }
113
114 pub struct Enum {
115     pub vis: hir::Visibility,
116     pub stab: Option<attr::Stability>,
117     pub depr: Option<attr::Deprecation>,
118     pub variants: hir::HirVec<Variant>,
119     pub generics: hir::Generics,
120     pub attrs: hir::HirVec<ast::Attribute>,
121     pub id: hir::HirId,
122     pub whence: Span,
123     pub name: Name,
124 }
125
126 pub struct Variant {
127     pub name: Name,
128     pub attrs: hir::HirVec<ast::Attribute>,
129     pub def: hir::VariantData,
130     pub stab: Option<attr::Stability>,
131     pub depr: Option<attr::Deprecation>,
132     pub whence: Span,
133 }
134
135 pub struct Function {
136     pub decl: hir::FnDecl,
137     pub attrs: hir::HirVec<ast::Attribute>,
138     pub id: hir::HirId,
139     pub name: Name,
140     pub vis: hir::Visibility,
141     pub stab: Option<attr::Stability>,
142     pub depr: Option<attr::Deprecation>,
143     pub header: hir::FnHeader,
144     pub whence: Span,
145     pub generics: hir::Generics,
146     pub body: hir::BodyId,
147 }
148
149 pub struct Typedef {
150     pub ty: P<hir::Ty>,
151     pub gen: hir::Generics,
152     pub name: Name,
153     pub id: hir::HirId,
154     pub attrs: hir::HirVec<ast::Attribute>,
155     pub whence: Span,
156     pub vis: hir::Visibility,
157     pub stab: Option<attr::Stability>,
158     pub depr: Option<attr::Deprecation>,
159 }
160
161 pub struct Existential {
162     pub exist_ty: hir::ExistTy,
163     pub name: Name,
164     pub id: hir::HirId,
165     pub attrs: hir::HirVec<ast::Attribute>,
166     pub whence: Span,
167     pub vis: hir::Visibility,
168     pub stab: Option<attr::Stability>,
169     pub depr: Option<attr::Deprecation>,
170 }
171
172 #[derive(Debug)]
173 pub struct Static {
174     pub type_: P<hir::Ty>,
175     pub mutability: hir::Mutability,
176     pub expr: hir::BodyId,
177     pub name: Name,
178     pub attrs: hir::HirVec<ast::Attribute>,
179     pub vis: hir::Visibility,
180     pub stab: Option<attr::Stability>,
181     pub depr: Option<attr::Deprecation>,
182     pub id: hir::HirId,
183     pub whence: Span,
184 }
185
186 pub struct Constant {
187     pub type_: P<hir::Ty>,
188     pub expr: hir::BodyId,
189     pub name: Name,
190     pub attrs: hir::HirVec<ast::Attribute>,
191     pub vis: hir::Visibility,
192     pub stab: Option<attr::Stability>,
193     pub depr: Option<attr::Deprecation>,
194     pub id: hir::HirId,
195     pub whence: Span,
196 }
197
198 pub struct Trait {
199     pub is_auto: hir::IsAuto,
200     pub unsafety: hir::Unsafety,
201     pub name: Name,
202     pub items: hir::HirVec<hir::TraitItem>,
203     pub generics: hir::Generics,
204     pub bounds: hir::HirVec<hir::GenericBound>,
205     pub attrs: hir::HirVec<ast::Attribute>,
206     pub id: hir::HirId,
207     pub whence: Span,
208     pub vis: hir::Visibility,
209     pub stab: Option<attr::Stability>,
210     pub depr: Option<attr::Deprecation>,
211 }
212
213 pub struct TraitAlias {
214     pub name: Name,
215     pub generics: hir::Generics,
216     pub bounds: hir::HirVec<hir::GenericBound>,
217     pub attrs: hir::HirVec<ast::Attribute>,
218     pub id: hir::HirId,
219     pub whence: Span,
220     pub vis: hir::Visibility,
221     pub stab: Option<attr::Stability>,
222     pub depr: Option<attr::Deprecation>,
223 }
224
225 #[derive(Debug)]
226 pub struct Impl {
227     pub unsafety: hir::Unsafety,
228     pub polarity: hir::ImplPolarity,
229     pub defaultness: hir::Defaultness,
230     pub generics: hir::Generics,
231     pub trait_: Option<hir::TraitRef>,
232     pub for_: P<hir::Ty>,
233     pub items: hir::HirVec<hir::ImplItem>,
234     pub attrs: hir::HirVec<ast::Attribute>,
235     pub whence: Span,
236     pub vis: hir::Visibility,
237     pub stab: Option<attr::Stability>,
238     pub depr: Option<attr::Deprecation>,
239     pub id: hir::HirId,
240 }
241
242 // For Macro we store the DefId instead of the NodeId, since we also create
243 // these imported macro_rules (which only have a DUMMY_NODE_ID).
244 pub struct Macro {
245     pub name: Name,
246     pub def_id: hir::def_id::DefId,
247     pub attrs: hir::HirVec<ast::Attribute>,
248     pub whence: Span,
249     pub matchers: hir::HirVec<Span>,
250     pub stab: Option<attr::Stability>,
251     pub depr: Option<attr::Deprecation>,
252     pub imported_from: Option<Name>,
253 }
254
255 pub struct ExternCrate {
256     pub name: Name,
257     pub cnum: CrateNum,
258     pub path: Option<String>,
259     pub vis: hir::Visibility,
260     pub attrs: hir::HirVec<ast::Attribute>,
261     pub whence: Span,
262 }
263
264 pub struct Import {
265     pub name: Name,
266     pub id: hir::HirId,
267     pub vis: hir::Visibility,
268     pub attrs: hir::HirVec<ast::Attribute>,
269     pub path: hir::Path,
270     pub glob: bool,
271     pub whence: Span,
272 }
273
274 pub struct ProcMacro {
275     pub name: Name,
276     pub id: hir::HirId,
277     pub kind: MacroKind,
278     pub helpers: Vec<Name>,
279     pub attrs: hir::HirVec<ast::Attribute>,
280     pub whence: Span,
281     pub stab: Option<attr::Stability>,
282     pub depr: Option<attr::Deprecation>,
283 }
284
285 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
286     match *vdata {
287         hir::VariantData::Struct(..) => Plain,
288         hir::VariantData::Tuple(..) => Tuple,
289         hir::VariantData::Unit(..) => Unit,
290     }
291 }