]> git.proxmox.com Git - rustc.git/blob - src/librustdoc/doctree.rs
8fa92304d249cb9d3adcfdba00d3b77e6250992c
[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;
17 use syntax::codemap::Span;
18 use syntax::abi;
19 use syntax::ast;
20 use syntax::attr;
21 use syntax::ast::{Ident, NodeId};
22 use syntax::ptr::P;
23
24 pub struct Module {
25 pub name: Option<Ident>,
26 pub attrs: Vec<ast::Attribute>,
27 pub where_outer: Span,
28 pub where_inner: Span,
29 pub extern_crates: Vec<ExternCrate>,
30 pub imports: Vec<Import>,
31 pub structs: Vec<Struct>,
32 pub enums: Vec<Enum>,
33 pub fns: Vec<Function>,
34 pub mods: Vec<Module>,
35 pub id: NodeId,
36 pub typedefs: Vec<Typedef>,
37 pub statics: Vec<Static>,
38 pub constants: Vec<Constant>,
39 pub traits: Vec<Trait>,
40 pub vis: ast::Visibility,
41 pub stab: Option<attr::Stability>,
42 pub impls: Vec<Impl>,
43 pub def_traits: Vec<DefaultImpl>,
44 pub foreigns: Vec<ast::ForeignMod>,
45 pub macros: Vec<Macro>,
46 pub is_crate: bool,
47 }
48
49 impl Module {
50 pub fn new(name: Option<Ident>) -> Module {
51 Module {
52 name : name,
53 id: 0,
54 vis: ast::Inherited,
55 stab: None,
56 where_outer: syntax::codemap::DUMMY_SP,
57 where_inner: syntax::codemap::DUMMY_SP,
58 attrs : Vec::new(),
59 extern_crates: Vec::new(),
60 imports : Vec::new(),
61 structs : Vec::new(),
62 enums : Vec::new(),
63 fns : Vec::new(),
64 mods : Vec::new(),
65 typedefs : Vec::new(),
66 statics : Vec::new(),
67 constants : Vec::new(),
68 traits : Vec::new(),
69 impls : Vec::new(),
70 def_traits : Vec::new(),
71 foreigns : Vec::new(),
72 macros : Vec::new(),
73 is_crate : false,
74 }
75 }
76 }
77
78 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
79 pub enum StructType {
80 /// A normal struct
81 Plain,
82 /// A tuple struct
83 Tuple,
84 /// A newtype struct (tuple struct with one element)
85 Newtype,
86 /// A unit struct
87 Unit
88 }
89
90 pub enum TypeBound {
91 RegionBound,
92 TraitBound(ast::TraitRef)
93 }
94
95 pub struct Struct {
96 pub vis: ast::Visibility,
97 pub stab: Option<attr::Stability>,
98 pub id: NodeId,
99 pub struct_type: StructType,
100 pub name: Ident,
101 pub generics: ast::Generics,
102 pub attrs: Vec<ast::Attribute>,
103 pub fields: Vec<ast::StructField>,
104 pub whence: Span,
105 }
106
107 pub struct Enum {
108 pub vis: ast::Visibility,
109 pub stab: Option<attr::Stability>,
110 pub variants: Vec<Variant>,
111 pub generics: ast::Generics,
112 pub attrs: Vec<ast::Attribute>,
113 pub id: NodeId,
114 pub whence: Span,
115 pub name: Ident,
116 }
117
118 pub struct Variant {
119 pub name: Ident,
120 pub attrs: Vec<ast::Attribute>,
121 pub kind: ast::VariantKind,
122 pub id: ast::NodeId,
123 pub vis: ast::Visibility,
124 pub stab: Option<attr::Stability>,
125 pub whence: Span,
126 }
127
128 pub struct Function {
129 pub decl: ast::FnDecl,
130 pub attrs: Vec<ast::Attribute>,
131 pub id: NodeId,
132 pub name: Ident,
133 pub vis: ast::Visibility,
134 pub stab: Option<attr::Stability>,
135 pub unsafety: ast::Unsafety,
136 pub whence: Span,
137 pub generics: ast::Generics,
138 pub abi: abi::Abi,
139 }
140
141 pub struct Typedef {
142 pub ty: P<ast::Ty>,
143 pub gen: ast::Generics,
144 pub name: Ident,
145 pub id: ast::NodeId,
146 pub attrs: Vec<ast::Attribute>,
147 pub whence: Span,
148 pub vis: ast::Visibility,
149 pub stab: Option<attr::Stability>,
150 }
151
152 #[derive(Debug)]
153 pub struct Static {
154 pub type_: P<ast::Ty>,
155 pub mutability: ast::Mutability,
156 pub expr: P<ast::Expr>,
157 pub name: Ident,
158 pub attrs: Vec<ast::Attribute>,
159 pub vis: ast::Visibility,
160 pub stab: Option<attr::Stability>,
161 pub id: ast::NodeId,
162 pub whence: Span,
163 }
164
165 pub struct Constant {
166 pub type_: P<ast::Ty>,
167 pub expr: P<ast::Expr>,
168 pub name: Ident,
169 pub attrs: Vec<ast::Attribute>,
170 pub vis: ast::Visibility,
171 pub stab: Option<attr::Stability>,
172 pub id: ast::NodeId,
173 pub whence: Span,
174 }
175
176 pub struct Trait {
177 pub unsafety: ast::Unsafety,
178 pub name: Ident,
179 pub items: Vec<P<ast::TraitItem>>, //should be TraitItem
180 pub generics: ast::Generics,
181 pub bounds: Vec<ast::TyParamBound>,
182 pub attrs: Vec<ast::Attribute>,
183 pub id: ast::NodeId,
184 pub whence: Span,
185 pub vis: ast::Visibility,
186 pub stab: Option<attr::Stability>,
187 }
188
189 pub struct Impl {
190 pub unsafety: ast::Unsafety,
191 pub polarity: ast::ImplPolarity,
192 pub generics: ast::Generics,
193 pub trait_: Option<ast::TraitRef>,
194 pub for_: P<ast::Ty>,
195 pub items: Vec<P<ast::ImplItem>>,
196 pub attrs: Vec<ast::Attribute>,
197 pub whence: Span,
198 pub vis: ast::Visibility,
199 pub stab: Option<attr::Stability>,
200 pub id: ast::NodeId,
201 }
202
203 pub struct DefaultImpl {
204 pub unsafety: ast::Unsafety,
205 pub trait_: ast::TraitRef,
206 pub id: ast::NodeId,
207 pub attrs: Vec<ast::Attribute>,
208 pub whence: Span,
209 }
210
211 pub struct Macro {
212 pub name: Ident,
213 pub id: ast::NodeId,
214 pub attrs: Vec<ast::Attribute>,
215 pub whence: Span,
216 pub stab: Option<attr::Stability>,
217 pub imported_from: Option<Ident>,
218 }
219
220 pub struct ExternCrate {
221 pub name: Ident,
222 pub path: Option<String>,
223 pub vis: ast::Visibility,
224 pub attrs: Vec<ast::Attribute>,
225 pub whence: Span,
226 }
227
228 pub struct Import {
229 pub id: NodeId,
230 pub vis: ast::Visibility,
231 pub attrs: Vec<ast::Attribute>,
232 pub node: ast::ViewPath_,
233 pub whence: Span,
234 }
235
236 pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
237 if sd.ctor_id.is_some() {
238 // We are in a tuple-struct
239 match sd.fields.len() {
240 0 => Unit,
241 1 => Newtype,
242 _ => Tuple
243 }
244 } else {
245 Plain
246 }
247 }