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::*;
18 use syntax::ast::{Name, NodeId};
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 def_traits: Vec<DefaultImpl>,
48 pub foreigns: Vec<hir::ForeignMod>,
49 pub macros: Vec<Macro>,
54 pub fn new(name: Option<Name>) -> Module {
57 id: ast::CRATE_NODE_ID,
61 where_outer: syntax_pos::DUMMY_SP,
62 where_inner: syntax_pos::DUMMY_SP,
63 attrs : hir::HirVec::new(),
64 extern_crates: Vec::new(),
71 typedefs : Vec::new(),
73 constants : Vec::new(),
76 def_traits : Vec::new(),
77 foreigns : Vec::new(),
84 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
96 TraitBound(hir::TraitRef)
100 pub vis: hir::Visibility,
101 pub stab: Option<attr::Stability>,
102 pub depr: Option<attr::Deprecation>,
104 pub struct_type: StructType,
106 pub generics: hir::Generics,
107 pub attrs: hir::HirVec<ast::Attribute>,
108 pub fields: hir::HirVec<hir::StructField>,
113 pub vis: hir::Visibility,
114 pub stab: Option<attr::Stability>,
115 pub depr: Option<attr::Deprecation>,
117 pub struct_type: StructType,
119 pub generics: hir::Generics,
120 pub attrs: hir::HirVec<ast::Attribute>,
121 pub fields: hir::HirVec<hir::StructField>,
126 pub vis: hir::Visibility,
127 pub stab: Option<attr::Stability>,
128 pub depr: Option<attr::Deprecation>,
129 pub variants: hir::HirVec<Variant>,
130 pub generics: hir::Generics,
131 pub attrs: hir::HirVec<ast::Attribute>,
139 pub attrs: hir::HirVec<ast::Attribute>,
140 pub def: hir::VariantData,
141 pub stab: Option<attr::Stability>,
142 pub depr: Option<attr::Deprecation>,
146 pub struct Function {
147 pub decl: hir::FnDecl,
148 pub attrs: hir::HirVec<ast::Attribute>,
151 pub vis: hir::Visibility,
152 pub stab: Option<attr::Stability>,
153 pub depr: Option<attr::Deprecation>,
154 pub unsafety: hir::Unsafety,
155 pub constness: hir::Constness,
157 pub generics: hir::Generics,
159 pub body: hir::BodyId,
164 pub gen: hir::Generics,
167 pub attrs: hir::HirVec<ast::Attribute>,
169 pub vis: hir::Visibility,
170 pub stab: Option<attr::Stability>,
171 pub depr: Option<attr::Deprecation>,
176 pub type_: P<hir::Ty>,
177 pub mutability: hir::Mutability,
178 pub expr: hir::BodyId,
180 pub attrs: hir::HirVec<ast::Attribute>,
181 pub vis: hir::Visibility,
182 pub stab: Option<attr::Stability>,
183 pub depr: Option<attr::Deprecation>,
188 pub struct Constant {
189 pub type_: P<hir::Ty>,
190 pub expr: hir::BodyId,
192 pub attrs: hir::HirVec<ast::Attribute>,
193 pub vis: hir::Visibility,
194 pub stab: Option<attr::Stability>,
195 pub depr: Option<attr::Deprecation>,
201 pub unsafety: hir::Unsafety,
203 pub items: hir::HirVec<hir::TraitItem>,
204 pub generics: hir::Generics,
205 pub bounds: hir::HirVec<hir::TyParamBound>,
206 pub attrs: hir::HirVec<ast::Attribute>,
209 pub vis: hir::Visibility,
210 pub stab: Option<attr::Stability>,
211 pub depr: Option<attr::Deprecation>,
215 pub unsafety: hir::Unsafety,
216 pub polarity: hir::ImplPolarity,
217 pub defaultness: hir::Defaultness,
218 pub generics: hir::Generics,
219 pub trait_: Option<hir::TraitRef>,
220 pub for_: P<hir::Ty>,
221 pub items: hir::HirVec<hir::ImplItem>,
222 pub attrs: hir::HirVec<ast::Attribute>,
224 pub vis: hir::Visibility,
225 pub stab: Option<attr::Stability>,
226 pub depr: Option<attr::Deprecation>,
230 pub struct DefaultImpl {
231 pub unsafety: hir::Unsafety,
232 pub trait_: hir::TraitRef,
234 pub attrs: hir::HirVec<ast::Attribute>,
238 // For Macro we store the DefId instead of the NodeId, since we also create
239 // these imported macro_rules (which only have a DUMMY_NODE_ID).
242 pub def_id: hir::def_id::DefId,
243 pub attrs: hir::HirVec<ast::Attribute>,
245 pub matchers: hir::HirVec<Span>,
246 pub stab: Option<attr::Stability>,
247 pub depr: Option<attr::Deprecation>,
248 pub imported_from: Option<Name>,
251 pub struct ExternCrate {
254 pub path: Option<String>,
255 pub vis: hir::Visibility,
256 pub attrs: hir::HirVec<ast::Attribute>,
263 pub vis: hir::Visibility,
264 pub attrs: hir::HirVec<ast::Attribute>,
270 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
272 hir::VariantData::Struct(..) => Plain,
273 hir::VariantData::Tuple(..) => Tuple,
274 hir::VariantData::Unit(..) => Unit,