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::*;
16 use syntax::ast::{Name, NodeId};
18 use syntax::ext::base::MacroKind;
20 use syntax::source_map::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 existentials: Vec<Existential>,
41 pub statics: Vec<Static>,
42 pub constants: Vec<Constant>,
43 pub traits: Vec<Trait>,
44 pub vis: hir::Visibility,
45 pub stab: Option<attr::Stability>,
46 pub depr: Option<attr::Deprecation>,
48 pub foreigns: Vec<hir::ForeignMod>,
49 pub macros: Vec<Macro>,
50 pub proc_macros: Vec<ProcMacro>,
55 pub fn new(name: Option<Name>) -> Module {
58 id: ast::CRATE_NODE_ID,
59 vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
62 where_outer: syntax_pos::DUMMY_SP,
63 where_inner: syntax_pos::DUMMY_SP,
64 attrs : hir::HirVec::new(),
65 extern_crates: Vec::new(),
72 typedefs : Vec::new(),
73 existentials: Vec::new(),
75 constants : Vec::new(),
78 foreigns : Vec::new(),
80 proc_macros: Vec::new(),
86 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
97 pub vis: hir::Visibility,
98 pub stab: Option<attr::Stability>,
99 pub depr: Option<attr::Deprecation>,
101 pub struct_type: StructType,
103 pub generics: hir::Generics,
104 pub attrs: hir::HirVec<ast::Attribute>,
105 pub fields: hir::HirVec<hir::StructField>,
110 pub vis: hir::Visibility,
111 pub stab: Option<attr::Stability>,
112 pub depr: Option<attr::Deprecation>,
114 pub struct_type: StructType,
116 pub generics: hir::Generics,
117 pub attrs: hir::HirVec<ast::Attribute>,
118 pub fields: hir::HirVec<hir::StructField>,
123 pub vis: hir::Visibility,
124 pub stab: Option<attr::Stability>,
125 pub depr: Option<attr::Deprecation>,
126 pub variants: hir::HirVec<Variant>,
127 pub generics: hir::Generics,
128 pub attrs: hir::HirVec<ast::Attribute>,
136 pub attrs: hir::HirVec<ast::Attribute>,
137 pub def: hir::VariantData,
138 pub stab: Option<attr::Stability>,
139 pub depr: Option<attr::Deprecation>,
143 pub struct Function {
144 pub decl: hir::FnDecl,
145 pub attrs: hir::HirVec<ast::Attribute>,
148 pub vis: hir::Visibility,
149 pub stab: Option<attr::Stability>,
150 pub depr: Option<attr::Deprecation>,
151 pub header: hir::FnHeader,
153 pub generics: hir::Generics,
154 pub body: hir::BodyId,
159 pub gen: hir::Generics,
162 pub attrs: hir::HirVec<ast::Attribute>,
164 pub vis: hir::Visibility,
165 pub stab: Option<attr::Stability>,
166 pub depr: Option<attr::Deprecation>,
169 pub struct Existential {
170 pub exist_ty: hir::ExistTy,
173 pub attrs: hir::HirVec<ast::Attribute>,
175 pub vis: hir::Visibility,
176 pub stab: Option<attr::Stability>,
177 pub depr: Option<attr::Deprecation>,
182 pub type_: P<hir::Ty>,
183 pub mutability: hir::Mutability,
184 pub expr: hir::BodyId,
186 pub attrs: hir::HirVec<ast::Attribute>,
187 pub vis: hir::Visibility,
188 pub stab: Option<attr::Stability>,
189 pub depr: Option<attr::Deprecation>,
194 pub struct Constant {
195 pub type_: P<hir::Ty>,
196 pub expr: hir::BodyId,
198 pub attrs: hir::HirVec<ast::Attribute>,
199 pub vis: hir::Visibility,
200 pub stab: Option<attr::Stability>,
201 pub depr: Option<attr::Deprecation>,
207 pub is_auto: hir::IsAuto,
208 pub unsafety: hir::Unsafety,
210 pub items: hir::HirVec<hir::TraitItem>,
211 pub generics: hir::Generics,
212 pub bounds: hir::HirVec<hir::GenericBound>,
213 pub attrs: hir::HirVec<ast::Attribute>,
216 pub vis: hir::Visibility,
217 pub stab: Option<attr::Stability>,
218 pub depr: Option<attr::Deprecation>,
223 pub unsafety: hir::Unsafety,
224 pub polarity: hir::ImplPolarity,
225 pub defaultness: hir::Defaultness,
226 pub generics: hir::Generics,
227 pub trait_: Option<hir::TraitRef>,
228 pub for_: P<hir::Ty>,
229 pub items: hir::HirVec<hir::ImplItem>,
230 pub attrs: hir::HirVec<ast::Attribute>,
232 pub vis: hir::Visibility,
233 pub stab: Option<attr::Stability>,
234 pub depr: Option<attr::Deprecation>,
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 struct ProcMacro {
274 pub helpers: Vec<Name>,
275 pub attrs: hir::HirVec<ast::Attribute>,
277 pub stab: Option<attr::Stability>,
278 pub depr: Option<attr::Deprecation>,
281 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
283 hir::VariantData::Struct(..) => Plain,
284 hir::VariantData::Tuple(..) => Tuple,
285 hir::VariantData::Unit(..) => Unit,