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};
19 use syntax::codemap::Spanned;
20 use syntax_pos::{self, Span};
23 use rustc::hir::def_id::CrateNum;
26 pub name: Option<Name>,
27 pub attrs: hir::HirVec<ast::Attribute>,
28 pub where_outer: Span,
29 pub where_inner: Span,
30 pub extern_crates: Vec<ExternCrate>,
31 pub imports: Vec<Import>,
32 pub structs: Vec<Struct>,
33 pub unions: Vec<Union>,
35 pub fns: Vec<Function>,
36 pub mods: Vec<Module>,
38 pub typedefs: Vec<Typedef>,
39 pub existentials: Vec<Existential>,
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::VisibilityKind::Inherited },
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(),
71 existentials: Vec::new(),
73 constants : Vec::new(),
76 foreigns : Vec::new(),
83 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
94 pub vis: hir::Visibility,
95 pub stab: Option<attr::Stability>,
96 pub depr: Option<attr::Deprecation>,
98 pub struct_type: StructType,
100 pub generics: hir::Generics,
101 pub attrs: hir::HirVec<ast::Attribute>,
102 pub fields: hir::HirVec<hir::StructField>,
107 pub vis: hir::Visibility,
108 pub stab: Option<attr::Stability>,
109 pub depr: Option<attr::Deprecation>,
111 pub struct_type: StructType,
113 pub generics: hir::Generics,
114 pub attrs: hir::HirVec<ast::Attribute>,
115 pub fields: hir::HirVec<hir::StructField>,
120 pub vis: hir::Visibility,
121 pub stab: Option<attr::Stability>,
122 pub depr: Option<attr::Deprecation>,
123 pub variants: hir::HirVec<Variant>,
124 pub generics: hir::Generics,
125 pub attrs: hir::HirVec<ast::Attribute>,
133 pub attrs: hir::HirVec<ast::Attribute>,
134 pub def: hir::VariantData,
135 pub stab: Option<attr::Stability>,
136 pub depr: Option<attr::Deprecation>,
140 pub struct Function {
141 pub decl: hir::FnDecl,
142 pub attrs: hir::HirVec<ast::Attribute>,
145 pub vis: hir::Visibility,
146 pub stab: Option<attr::Stability>,
147 pub depr: Option<attr::Deprecation>,
148 pub header: hir::FnHeader,
150 pub generics: hir::Generics,
151 pub body: hir::BodyId,
156 pub gen: hir::Generics,
159 pub attrs: hir::HirVec<ast::Attribute>,
161 pub vis: hir::Visibility,
162 pub stab: Option<attr::Stability>,
163 pub depr: Option<attr::Deprecation>,
166 pub struct Existential {
167 pub exist_ty: hir::ExistTy,
170 pub attrs: hir::HirVec<ast::Attribute>,
172 pub vis: hir::Visibility,
173 pub stab: Option<attr::Stability>,
174 pub depr: Option<attr::Deprecation>,
179 pub type_: P<hir::Ty>,
180 pub mutability: hir::Mutability,
181 pub expr: hir::BodyId,
183 pub attrs: hir::HirVec<ast::Attribute>,
184 pub vis: hir::Visibility,
185 pub stab: Option<attr::Stability>,
186 pub depr: Option<attr::Deprecation>,
191 pub struct Constant {
192 pub type_: P<hir::Ty>,
193 pub expr: hir::BodyId,
195 pub attrs: hir::HirVec<ast::Attribute>,
196 pub vis: hir::Visibility,
197 pub stab: Option<attr::Stability>,
198 pub depr: Option<attr::Deprecation>,
204 pub is_auto: hir::IsAuto,
205 pub unsafety: hir::Unsafety,
207 pub items: hir::HirVec<hir::TraitItem>,
208 pub generics: hir::Generics,
209 pub bounds: hir::HirVec<hir::GenericBound>,
210 pub attrs: hir::HirVec<ast::Attribute>,
213 pub vis: hir::Visibility,
214 pub stab: Option<attr::Stability>,
215 pub depr: Option<attr::Deprecation>,
220 pub unsafety: hir::Unsafety,
221 pub polarity: hir::ImplPolarity,
222 pub defaultness: hir::Defaultness,
223 pub generics: hir::Generics,
224 pub trait_: Option<hir::TraitRef>,
225 pub for_: P<hir::Ty>,
226 pub items: hir::HirVec<hir::ImplItem>,
227 pub attrs: hir::HirVec<ast::Attribute>,
229 pub vis: hir::Visibility,
230 pub stab: Option<attr::Stability>,
231 pub depr: Option<attr::Deprecation>,
235 // For Macro we store the DefId instead of the NodeId, since we also create
236 // these imported macro_rules (which only have a DUMMY_NODE_ID).
239 pub def_id: hir::def_id::DefId,
240 pub attrs: hir::HirVec<ast::Attribute>,
242 pub matchers: hir::HirVec<Span>,
243 pub stab: Option<attr::Stability>,
244 pub depr: Option<attr::Deprecation>,
245 pub imported_from: Option<Name>,
248 pub struct ExternCrate {
251 pub path: Option<String>,
252 pub vis: hir::Visibility,
253 pub attrs: hir::HirVec<ast::Attribute>,
260 pub vis: hir::Visibility,
261 pub attrs: hir::HirVec<ast::Attribute>,
267 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
269 hir::VariantData::Struct(..) => Plain,
270 hir::VariantData::Tuple(..) => Tuple,
271 hir::VariantData::Unit(..) => Unit,