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,
163 pub gen: hir::Generics,
166 pub attrs: hir::HirVec<ast::Attribute>,
168 pub vis: hir::Visibility,
169 pub stab: Option<attr::Stability>,
170 pub depr: Option<attr::Deprecation>,
175 pub type_: P<hir::Ty>,
176 pub mutability: hir::Mutability,
177 pub expr: P<hir::Expr>,
179 pub attrs: hir::HirVec<ast::Attribute>,
180 pub vis: hir::Visibility,
181 pub stab: Option<attr::Stability>,
182 pub depr: Option<attr::Deprecation>,
187 pub struct Constant {
188 pub type_: P<hir::Ty>,
189 pub expr: P<hir::Expr>,
191 pub attrs: hir::HirVec<ast::Attribute>,
192 pub vis: hir::Visibility,
193 pub stab: Option<attr::Stability>,
194 pub depr: Option<attr::Deprecation>,
200 pub unsafety: hir::Unsafety,
202 pub items: hir::HirVec<hir::TraitItem>,
203 pub generics: hir::Generics,
204 pub bounds: hir::HirVec<hir::TyParamBound>,
205 pub attrs: hir::HirVec<ast::Attribute>,
208 pub vis: hir::Visibility,
209 pub stab: Option<attr::Stability>,
210 pub depr: Option<attr::Deprecation>,
214 pub unsafety: hir::Unsafety,
215 pub polarity: hir::ImplPolarity,
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 pub struct DefaultImpl {
229 pub unsafety: hir::Unsafety,
230 pub trait_: hir::TraitRef,
232 pub attrs: hir::HirVec<ast::Attribute>,
239 pub attrs: hir::HirVec<ast::Attribute>,
241 pub matchers: hir::HirVec<Span>,
242 pub stab: Option<attr::Stability>,
243 pub depr: Option<attr::Deprecation>,
244 pub imported_from: Option<Name>,
247 pub struct ExternCrate {
250 pub path: Option<String>,
251 pub vis: hir::Visibility,
252 pub attrs: hir::HirVec<ast::Attribute>,
258 pub vis: hir::Visibility,
259 pub attrs: hir::HirVec<ast::Attribute>,
260 pub node: hir::ViewPath_,
264 pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
266 hir::VariantData::Struct(..) => Plain,
267 hir::VariantData::Tuple(..) => Tuple,
268 hir::VariantData::Unit(..) => Unit,