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