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