]> git.proxmox.com Git - rustc.git/blob - src/librustdoc/doctree.rs
New upstream version 1.13.0+dfsg1
[rustc.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 pub use self::TypeBound::*;
15
16 use syntax::abi;
17 use syntax::ast;
18 use syntax::ast::{Name, NodeId};
19 use syntax::attr;
20 use syntax::ptr::P;
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 statics: Vec<Static>,
41 pub constants: Vec<Constant>,
42 pub traits: Vec<Trait>,
43 pub vis: hir::Visibility,
44 pub stab: Option<attr::Stability>,
45 pub depr: Option<attr::Deprecation>,
46 pub impls: Vec<Impl>,
47 pub def_traits: Vec<DefaultImpl>,
48 pub foreigns: Vec<hir::ForeignMod>,
49 pub macros: Vec<Macro>,
50 pub is_crate: bool,
51 }
52
53 impl Module {
54 pub fn new(name: Option<Name>) -> Module {
55 Module {
56 name : name,
57 id: ast::CRATE_NODE_ID,
58 vis: hir::Inherited,
59 stab: None,
60 depr: None,
61 where_outer: syntax_pos::DUMMY_SP,
62 where_inner: syntax_pos::DUMMY_SP,
63 attrs : hir::HirVec::new(),
64 extern_crates: Vec::new(),
65 imports : Vec::new(),
66 structs : Vec::new(),
67 unions : Vec::new(),
68 enums : Vec::new(),
69 fns : Vec::new(),
70 mods : Vec::new(),
71 typedefs : Vec::new(),
72 statics : Vec::new(),
73 constants : Vec::new(),
74 traits : Vec::new(),
75 impls : Vec::new(),
76 def_traits : Vec::new(),
77 foreigns : Vec::new(),
78 macros : Vec::new(),
79 is_crate : false,
80 }
81 }
82 }
83
84 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
85 pub enum StructType {
86 /// A braced struct
87 Plain,
88 /// A tuple struct
89 Tuple,
90 /// A unit struct
91 Unit,
92 }
93
94 pub enum TypeBound {
95 RegionBound,
96 TraitBound(hir::TraitRef)
97 }
98
99 pub struct Struct {
100 pub vis: hir::Visibility,
101 pub stab: Option<attr::Stability>,
102 pub depr: Option<attr::Deprecation>,
103 pub id: NodeId,
104 pub struct_type: StructType,
105 pub name: Name,
106 pub generics: hir::Generics,
107 pub attrs: hir::HirVec<ast::Attribute>,
108 pub fields: hir::HirVec<hir::StructField>,
109 pub whence: Span,
110 }
111
112 pub struct Union {
113 pub vis: hir::Visibility,
114 pub stab: Option<attr::Stability>,
115 pub depr: Option<attr::Deprecation>,
116 pub id: NodeId,
117 pub struct_type: StructType,
118 pub name: Name,
119 pub generics: hir::Generics,
120 pub attrs: hir::HirVec<ast::Attribute>,
121 pub fields: hir::HirVec<hir::StructField>,
122 pub whence: Span,
123 }
124
125 pub struct Enum {
126 pub vis: hir::Visibility,
127 pub stab: Option<attr::Stability>,
128 pub depr: Option<attr::Deprecation>,
129 pub variants: hir::HirVec<Variant>,
130 pub generics: hir::Generics,
131 pub attrs: hir::HirVec<ast::Attribute>,
132 pub id: NodeId,
133 pub whence: Span,
134 pub name: Name,
135 }
136
137 pub struct Variant {
138 pub name: Name,
139 pub attrs: hir::HirVec<ast::Attribute>,
140 pub def: hir::VariantData,
141 pub stab: Option<attr::Stability>,
142 pub depr: Option<attr::Deprecation>,
143 pub whence: Span,
144 }
145
146 pub struct Function {
147 pub decl: hir::FnDecl,
148 pub attrs: hir::HirVec<ast::Attribute>,
149 pub id: NodeId,
150 pub name: Name,
151 pub vis: hir::Visibility,
152 pub stab: Option<attr::Stability>,
153 pub depr: Option<attr::Deprecation>,
154 pub unsafety: hir::Unsafety,
155 pub constness: hir::Constness,
156 pub whence: Span,
157 pub generics: hir::Generics,
158 pub abi: abi::Abi,
159 }
160
161 pub struct Typedef {
162 pub ty: P<hir::Ty>,
163 pub gen: hir::Generics,
164 pub name: Name,
165 pub id: ast::NodeId,
166 pub attrs: hir::HirVec<ast::Attribute>,
167 pub whence: Span,
168 pub vis: hir::Visibility,
169 pub stab: Option<attr::Stability>,
170 pub depr: Option<attr::Deprecation>,
171 }
172
173 #[derive(Debug)]
174 pub struct Static {
175 pub type_: P<hir::Ty>,
176 pub mutability: hir::Mutability,
177 pub expr: P<hir::Expr>,
178 pub name: Name,
179 pub attrs: hir::HirVec<ast::Attribute>,
180 pub vis: hir::Visibility,
181 pub stab: Option<attr::Stability>,
182 pub depr: Option<attr::Deprecation>,
183 pub id: ast::NodeId,
184 pub whence: Span,
185 }
186
187 pub struct Constant {
188 pub type_: P<hir::Ty>,
189 pub expr: P<hir::Expr>,
190 pub name: Name,
191 pub attrs: hir::HirVec<ast::Attribute>,
192 pub vis: hir::Visibility,
193 pub stab: Option<attr::Stability>,
194 pub depr: Option<attr::Deprecation>,
195 pub id: ast::NodeId,
196 pub whence: Span,
197 }
198
199 pub struct Trait {
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::TyParamBound>,
205 pub attrs: hir::HirVec<ast::Attribute>,
206 pub id: ast::NodeId,
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 Impl {
214 pub unsafety: hir::Unsafety,
215 pub polarity: hir::ImplPolarity,
216 pub generics: hir::Generics,
217 pub trait_: Option<hir::TraitRef>,
218 pub for_: P<hir::Ty>,
219 pub items: hir::HirVec<hir::ImplItem>,
220 pub attrs: hir::HirVec<ast::Attribute>,
221 pub whence: Span,
222 pub vis: hir::Visibility,
223 pub stab: Option<attr::Stability>,
224 pub depr: Option<attr::Deprecation>,
225 pub id: ast::NodeId,
226 }
227
228 pub struct DefaultImpl {
229 pub unsafety: hir::Unsafety,
230 pub trait_: hir::TraitRef,
231 pub id: ast::NodeId,
232 pub attrs: hir::HirVec<ast::Attribute>,
233 pub whence: Span,
234 }
235
236 pub struct Macro {
237 pub name: Name,
238 pub id: ast::NodeId,
239 pub attrs: hir::HirVec<ast::Attribute>,
240 pub whence: Span,
241 pub matchers: hir::HirVec<Span>,
242 pub stab: Option<attr::Stability>,
243 pub depr: Option<attr::Deprecation>,
244 pub imported_from: Option<Name>,
245 }
246
247 pub struct ExternCrate {
248 pub name: Name,
249 pub cnum: CrateNum,
250 pub path: Option<String>,
251 pub vis: hir::Visibility,
252 pub attrs: hir::HirVec<ast::Attribute>,
253 pub whence: Span,
254 }
255
256 pub struct Import {
257 pub id: NodeId,
258 pub vis: hir::Visibility,
259 pub attrs: hir::HirVec<ast::Attribute>,
260 pub node: hir::ViewPath_,
261 pub whence: Span,
262 }
263
264 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
265 match *vdata {
266 hir::VariantData::Struct(..) => Plain,
267 hir::VariantData::Tuple(..) => Tuple,
268 hir::VariantData::Unit(..) => Unit,
269 }
270 }