(index<- ) ./librustdoc/doctree.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri May 9 13:02:28 2014
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::ast::{Ident, NodeId};
18
19 pub struct Module {
20 pub name: Option<Ident>,
21 pub attrs: Vec<ast::Attribute>,
22 pub where_outer: Span,
23 pub where_inner: Span,
24 pub structs: Vec<Struct>,
25 pub enums: Vec<Enum>,
26 pub fns: Vec<Function>,
27 pub mods: Vec<Module>,
28 pub id: NodeId,
29 pub typedefs: Vec<Typedef>,
30 pub statics: Vec<Static>,
31 pub traits: Vec<Trait>,
32 pub vis: ast::Visibility,
33 pub impls: Vec<Impl>,
34 pub foreigns: Vec<ast::ForeignMod>,
35 pub view_items: Vec<ast::ViewItem>,
36 pub macros: Vec<Macro>,
37 pub is_crate: bool,
38 }
39
40 impl Module {
41 pub fn new(name: Option<Ident>) -> Module {
42 Module {
43 name : name,
44 id: 0,
45 vis: ast::Inherited,
46 where_outer: syntax::codemap::DUMMY_SP,
47 where_inner: syntax::codemap::DUMMY_SP,
48 attrs : Vec::new(),
49 structs : Vec::new(),
50 enums : Vec::new(),
51 fns : Vec::new(),
52 mods : Vec::new(),
53 typedefs : Vec::new(),
54 statics : Vec::new(),
55 traits : Vec::new(),
56 impls : Vec::new(),
57 view_items : Vec::new(),
58 foreigns : Vec::new(),
59 macros : Vec::new(),
60 is_crate : false,
61 }
62 }
63 }
64
65 #[deriving(Show, Clone, Encodable, Decodable)]
66 pub enum StructType {
67 /// A normal struct
68 Plain,
69 /// A tuple struct
70 Tuple,
71 /// A newtype struct (tuple struct with one element)
72 Newtype,
73 /// A unit struct
74 Unit
75 }
76
77 pub enum TypeBound {
78 RegionBound,
79 TraitBound(ast::TraitRef)
80 }
81
82 pub struct Struct {
83 pub vis: ast::Visibility,
84 pub id: NodeId,
85 pub struct_type: StructType,
86 pub name: Ident,
87 pub generics: ast::Generics,
88 pub attrs: Vec<ast::Attribute>,
89 pub fields: Vec<ast::StructField>,
90 pub where: Span,
91 }
92
93 pub struct Enum {
94 pub vis: ast::Visibility,
95 pub variants: Vec<Variant>,
96 pub generics: ast::Generics,
97 pub attrs: Vec<ast::Attribute>,
98 pub id: NodeId,
99 pub where: Span,
100 pub name: Ident,
101 }
102
103 pub struct Variant {
104 pub name: Ident,
105 pub attrs: Vec<ast::Attribute>,
106 pub kind: ast::VariantKind,
107 pub id: ast::NodeId,
108 pub vis: ast::Visibility,
109 pub where: Span,
110 }
111
112 pub struct Function {
113 pub decl: ast::FnDecl,
114 pub attrs: Vec<ast::Attribute>,
115 pub id: NodeId,
116 pub name: Ident,
117 pub vis: ast::Visibility,
118 pub fn_style: ast::FnStyle,
119 pub where: Span,
120 pub generics: ast::Generics,
121 }
122
123 pub struct Typedef {
124 pub ty: ast::P<ast::Ty>,
125 pub gen: ast::Generics,
126 pub name: Ident,
127 pub id: ast::NodeId,
128 pub attrs: Vec<ast::Attribute>,
129 pub where: Span,
130 pub vis: ast::Visibility,
131 }
132
133 pub struct Static {
134 pub type_: ast::P<ast::Ty>,
135 pub mutability: ast::Mutability,
136 pub expr: @ast::Expr,
137 pub name: Ident,
138 pub attrs: Vec<ast::Attribute>,
139 pub vis: ast::Visibility,
140 pub id: ast::NodeId,
141 pub where: Span,
142 }
143
144 pub struct Trait {
145 pub name: Ident,
146 pub methods: Vec<ast::TraitMethod>, //should be TraitMethod
147 pub generics: ast::Generics,
148 pub parents: Vec<ast::TraitRef>,
149 pub attrs: Vec<ast::Attribute>,
150 pub id: ast::NodeId,
151 pub where: Span,
152 pub vis: ast::Visibility,
153 }
154
155 pub struct Impl {
156 pub generics: ast::Generics,
157 pub trait_: Option<ast::TraitRef>,
158 pub for_: ast::P<ast::Ty>,
159 pub methods: Vec<@ast::Method>,
160 pub attrs: Vec<ast::Attribute>,
161 pub where: Span,
162 pub vis: ast::Visibility,
163 pub id: ast::NodeId,
164 }
165
166 pub struct Macro {
167 pub name: Ident,
168 pub id: ast::NodeId,
169 pub attrs: Vec<ast::Attribute>,
170 pub where: Span,
171 }
172
173 pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
174 if sd.ctor_id.is_some() {
175 // We are in a tuple-struct
176 match sd.fields.len() {
177 0 => Unit,
178 1 => Newtype,
179 _ => Tuple
180 }
181 } else {
182 Plain
183 }
184 }
librustdoc/doctree.rs:111:1-111:1 -struct- definition:
pub struct Function {
pub decl: ast::FnDecl,
pub attrs: Vec<ast::Attribute>,
references:- 4librustdoc/visit_ast.rs:
101: debug!("Visiting fn");
102: Function {
103: id: item.id,
librustdoc/doctree.rs:
25: pub enums: Vec<Enum>,
26: pub fns: Vec<Function>,
27: pub mods: Vec<Module>,
librustdoc/clean.rs:
499: impl Clean<Item> for doctree::Function {
500: fn clean(&self) -> Item {
librustdoc/visit_ast.rs:
99: fn_style: &ast::FnStyle, _abi: &abi::Abi,
100: gen: &ast::Generics) -> Function {
101: debug!("Visiting fn");
librustdoc/doctree.rs:92:1-92:1 -struct- definition:
pub struct Enum {
pub vis: ast::Visibility,
pub variants: Vec<Variant>,
references:- 4librustdoc/visit_ast.rs:
86: }
87: Enum {
88: name: it.ident,
librustdoc/clean.rs:
841: impl Clean<Item> for doctree::Enum {
842: fn clean(&self) -> Item {
librustdoc/doctree.rs:
24: pub structs: Vec<Struct>,
25: pub enums: Vec<Enum>,
26: pub fns: Vec<Function>,
librustdoc/doctree.rs:18:1-18:1 -struct- definition:
pub struct Module {
pub name: Option<Ident>,
pub attrs: Vec<ast::Attribute>,
references:- 1141: pub fn new(name: Option<Ident>) -> Module {
42: Module {
43: name : name,
librustdoc/visit_ast.rs:
162: fn visit_view_path(&mut self, path: @ast::ViewPath,
163: om: &mut Module,
164: please_inline: bool) -> Option<@ast::ViewPath> {
--
230: pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
231: debug!("Visiting item {:?}", item);
librustdoc/clean.rs:
223: impl Clean<Item> for doctree::Module {
224: fn clean(&self) -> Item {
librustdoc/doctree.rs:81:1-81:1 -struct- definition:
pub struct Struct {
pub vis: ast::Visibility,
pub id: NodeId,
references:- 4librustdoc/visit_ast.rs:
60: let struct_type = struct_type_from_def(sd);
61: Struct {
62: id: item.id,
librustdoc/clean.rs:
796: impl Clean<Item> for doctree::Struct {
797: fn clean(&self) -> Item {
librustdoc/doctree.rs:
23: pub where_inner: Span,
24: pub structs: Vec<Struct>,
25: pub enums: Vec<Enum>,
librustdoc/doctree.rs:165:1-165:1 -struct- definition:
pub struct Macro {
pub name: Ident,
pub id: ast::NodeId,
references:- 3librustdoc/visit_ast.rs:
304: ast::ItemMac(ref _m) => {
305: om.macros.push(Macro {
306: id: item.id,
librustdoc/clean.rs:
1367: impl Clean<Item> for doctree::Macro {
1368: fn clean(&self) -> Item {
librustdoc/doctree.rs:
35: pub view_items: Vec<ast::ViewItem>,
36: pub macros: Vec<Macro>,
37: pub is_crate: bool,
librustdoc/doctree.rs:65:47-65:47 -enum- definition:
pub enum StructType {
/// A normal struct
Plain,
references:- 11173: pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
174: if sd.ctor_id.is_some() {
librustdoc/html/render.rs:
1484: g: Option<&clean::Generics>,
1485: ty: doctree::StructType,
1486: fields: &[clean::Item],
librustdoc/clean.rs:
818: pub struct VariantStruct {
819: pub struct_type: doctree::StructType,
820: pub fields: Vec<Item>,
librustdoc/doctree.rs:
66: pub enum StructType {
librustdoc/doctree.rs:122:1-122:1 -struct- definition:
pub struct Typedef {
pub ty: ast::P<ast::Ty>,
pub gen: ast::Generics,
references:- 3librustdoc/visit_ast.rs:
250: ast::ItemTy(ty, ref gen) => {
251: let t = Typedef {
252: ty: ty,
librustdoc/doctree.rs:
28: pub id: NodeId,
29: pub typedefs: Vec<Typedef>,
30: pub statics: Vec<Static>,
librustdoc/clean.rs:
986: impl Clean<Item> for doctree::Typedef {
987: fn clean(&self) -> Item {
librustdoc/doctree.rs:102:1-102:1 -struct- definition:
pub struct Variant {
pub name: Ident,
pub attrs: Vec<ast::Attribute>,
references:- 4librustdoc/visit_ast.rs:
77: for x in def.variants.iter() {
78: vars.push(Variant {
79: name: x.node.name,
librustdoc/doctree.rs:
94: pub vis: ast::Visibility,
95: pub variants: Vec<Variant>,
96: pub generics: ast::Generics,
librustdoc/clean.rs:
863: impl Clean<Item> for doctree::Variant {
864: fn clean(&self) -> Item {
librustdoc/visit_ast.rs:
75: debug!("Visiting enum");
76: let mut vars: Vec<Variant> = Vec::new();
77: for x in def.variants.iter() {
librustdoc/doctree.rs:154:1-154:1 -struct- definition:
pub struct Impl {
pub generics: ast::Generics,
pub trait_: Option<ast::TraitRef>,
references:- 3librustdoc/visit_ast.rs:
288: ast::ItemImpl(ref gen, ref tr, ty, ref meths) => {
289: let i = Impl {
290: generics: gen.clone(),
librustdoc/doctree.rs:
32: pub vis: ast::Visibility,
33: pub impls: Vec<Impl>,
34: pub foreigns: Vec<ast::ForeignMod>,
librustdoc/clean.rs:
1076: impl Clean<Item> for doctree::Impl {
1077: fn clean(&self) -> Item {
librustdoc/doctree.rs:132:1-132:1 -struct- definition:
pub struct Static {
pub type_: ast::P<ast::Ty>,
pub mutability: ast::Mutability,
references:- 329: pub typedefs: Vec<Typedef>,
30: pub statics: Vec<Static>,
31: pub traits: Vec<Trait>,
librustdoc/clean.rs:
1034: impl Clean<Item> for doctree::Static {
1035: fn clean(&self) -> Item {
librustdoc/visit_ast.rs:
262: ast::ItemStatic(ty, ref mut_, ref exp) => {
263: let s = Static {
264: type_: ty,
librustdoc/doctree.rs:172:1-172:1 -fn- definition:
pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
if sd.ctor_id.is_some() {
// We are in a tuple-struct
references:- 2librustdoc/clean.rs:
826: VariantStruct {
827: struct_type: doctree::struct_type_from_def(self),
828: fields: self.fields.clean().move_iter().collect(),
librustdoc/visit_ast.rs:
59: debug!("Visiting struct");
60: let struct_type = struct_type_from_def(sd);
61: Struct {
librustdoc/doctree.rs:143:1-143:1 -struct- definition:
pub struct Trait {
pub name: Ident,
pub methods: Vec<ast::TraitMethod>, //should be TraitMethod
references:- 3librustdoc/visit_ast.rs:
275: ast::ItemTrait(ref gen, _, ref tr, ref met) => {
276: let t = Trait {
277: name: item.ident,
librustdoc/clean.rs:
605: impl Clean<Item> for doctree::Trait {
606: fn clean(&self) -> Item {
librustdoc/doctree.rs:
30: pub statics: Vec<Static>,
31: pub traits: Vec<Trait>,
32: pub vis: ast::Visibility,