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