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.
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.
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::*;
17 use syntax::ast::{Name, NodeId};
20 use syntax::codemap::Spanned;
21 use syntax_pos::{self, Span};
24 use rustc::hir::def_id::CrateNum;
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>,
36 pub fns: Vec<Function>,
37 pub mods: Vec<Module>,
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>,
47 pub foreigns: Vec<hir::ForeignMod>,
48 pub macros: Vec<Macro>,
53 pub fn new(name: Option<Name>) -> Module {
56 id: ast::CRATE_NODE_ID,
57 vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityInherited },
60 where_outer: syntax_pos::DUMMY_SP,
61 where_inner: syntax_pos::DUMMY_SP,
62 attrs : hir::HirVec::new(),
63 extern_crates: Vec::new(),
70 typedefs : Vec::new(),
72 constants : Vec::new(),
75 foreigns : Vec::new(),
82 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
94 TraitBound(hir::TraitRef)
98 pub vis: hir::Visibility,
99 pub stab: Option<attr::Stability>,
100 pub depr: Option<attr::Deprecation>,
102 pub struct_type: StructType,
104 pub generics: hir::Generics,
105 pub attrs: hir::HirVec<ast::Attribute>,
106 pub fields: hir::HirVec<hir::StructField>,
111 pub vis: hir::Visibility,
112 pub stab: Option<attr::Stability>,
113 pub depr: Option<attr::Deprecation>,
115 pub struct_type: StructType,
117 pub generics: hir::Generics,
118 pub attrs: hir::HirVec<ast::Attribute>,
119 pub fields: hir::HirVec<hir::StructField>,
124 pub vis: hir::Visibility,
125 pub stab: Option<attr::Stability>,
126 pub depr: Option<attr::Deprecation>,
127 pub variants: hir::HirVec<Variant>,
128 pub generics: hir::Generics,
129 pub attrs: hir::HirVec<ast::Attribute>,
137 pub attrs: hir::HirVec<ast::Attribute>,
138 pub def: hir::VariantData,
139 pub stab: Option<attr::Stability>,
140 pub depr: Option<attr::Deprecation>,
144 pub struct Function {
145 pub decl: hir::FnDecl,
146 pub attrs: hir::HirVec<ast::Attribute>,
149 pub vis: hir::Visibility,
150 pub stab: Option<attr::Stability>,
151 pub depr: Option<attr::Deprecation>,
152 pub header: hir::FnHeader,
154 pub generics: hir::Generics,
155 pub body: hir::BodyId,
160 pub gen: hir::Generics,
163 pub attrs: hir::HirVec<ast::Attribute>,
165 pub vis: hir::Visibility,
166 pub stab: Option<attr::Stability>,
167 pub depr: Option<attr::Deprecation>,
172 pub type_: P<hir::Ty>,
173 pub mutability: hir::Mutability,
174 pub expr: hir::BodyId,
176 pub attrs: hir::HirVec<ast::Attribute>,
177 pub vis: hir::Visibility,
178 pub stab: Option<attr::Stability>,
179 pub depr: Option<attr::Deprecation>,
184 pub struct Constant {
185 pub type_: P<hir::Ty>,
186 pub expr: hir::BodyId,
188 pub attrs: hir::HirVec<ast::Attribute>,
189 pub vis: hir::Visibility,
190 pub stab: Option<attr::Stability>,
191 pub depr: Option<attr::Deprecation>,
197 pub is_auto: hir::IsAuto,
198 pub unsafety: hir::Unsafety,
200 pub items: hir::HirVec<hir::TraitItem>,
201 pub generics: hir::Generics,
202 pub bounds: hir::HirVec<hir::GenericBound>,
203 pub attrs: hir::HirVec<ast::Attribute>,
206 pub vis: hir::Visibility,
207 pub stab: Option<attr::Stability>,
208 pub depr: Option<attr::Deprecation>,
213 pub unsafety: hir::Unsafety,
214 pub polarity: hir::ImplPolarity,
215 pub defaultness: hir::Defaultness,
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>,
222 pub vis: hir::Visibility,
223 pub stab: Option<attr::Stability>,
224 pub depr: Option<attr::Deprecation>,
228 // For Macro we store the DefId instead of the NodeId, since we also create
229 // these imported macro_rules (which only have a DUMMY_NODE_ID).
232 pub def_id: hir::def_id::DefId,
233 pub attrs: hir::HirVec<ast::Attribute>,
235 pub matchers: hir::HirVec<Span>,
236 pub stab: Option<attr::Stability>,
237 pub depr: Option<attr::Deprecation>,
238 pub imported_from: Option<Name>,
241 pub struct ExternCrate {
244 pub path: Option<String>,
245 pub vis: hir::Visibility,
246 pub attrs: hir::HirVec<ast::Attribute>,
253 pub vis: hir::Visibility,
254 pub attrs: hir::HirVec<ast::Attribute>,
260 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
262 hir::VariantData::Struct(..) => Plain,
263 hir::VariantData::Tuple(..) => Tuple,
264 hir::VariantData::Unit(..) => Unit,