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::codemap::Span;
20 use syntax::ast::{Ident, Name, NodeId};
26 pub name: Option<Name>,
27 pub attrs: Vec<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>,
34 pub fns: Vec<Function>,
35 pub mods: Vec<Module>,
37 pub typedefs: Vec<Typedef>,
38 pub statics: Vec<Static>,
39 pub constants: Vec<Constant>,
40 pub traits: Vec<Trait>,
41 pub vis: hir::Visibility,
42 pub stab: Option<attr::Stability>,
44 pub def_traits: Vec<DefaultImpl>,
45 pub foreigns: Vec<hir::ForeignMod>,
46 pub macros: Vec<Macro>,
51 pub fn new(name: Option<Name>) -> Module {
57 where_outer: syntax::codemap::DUMMY_SP,
58 where_inner: syntax::codemap::DUMMY_SP,
60 extern_crates: Vec::new(),
66 typedefs : Vec::new(),
68 constants : Vec::new(),
71 def_traits : Vec::new(),
72 foreigns : Vec::new(),
79 #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
85 /// A newtype struct (tuple struct with one element)
93 TraitBound(hir::TraitRef)
97 pub vis: hir::Visibility,
98 pub stab: Option<attr::Stability>,
100 pub struct_type: StructType,
102 pub generics: hir::Generics,
103 pub attrs: Vec<ast::Attribute>,
104 pub fields: Vec<hir::StructField>,
109 pub vis: hir::Visibility,
110 pub stab: Option<attr::Stability>,
111 pub variants: Vec<Variant>,
112 pub generics: hir::Generics,
113 pub attrs: Vec<ast::Attribute>,
121 pub attrs: Vec<ast::Attribute>,
122 pub kind: hir::VariantKind,
124 pub stab: Option<attr::Stability>,
128 pub struct Function {
129 pub decl: hir::FnDecl,
130 pub attrs: Vec<ast::Attribute>,
133 pub vis: hir::Visibility,
134 pub stab: Option<attr::Stability>,
135 pub unsafety: hir::Unsafety,
136 pub constness: hir::Constness,
138 pub generics: hir::Generics,
144 pub gen: hir::Generics,
147 pub attrs: Vec<ast::Attribute>,
149 pub vis: hir::Visibility,
150 pub stab: Option<attr::Stability>,
155 pub type_: P<hir::Ty>,
156 pub mutability: hir::Mutability,
157 pub expr: P<hir::Expr>,
159 pub attrs: Vec<ast::Attribute>,
160 pub vis: hir::Visibility,
161 pub stab: Option<attr::Stability>,
166 pub struct Constant {
167 pub type_: P<hir::Ty>,
168 pub expr: P<hir::Expr>,
170 pub attrs: Vec<ast::Attribute>,
171 pub vis: hir::Visibility,
172 pub stab: Option<attr::Stability>,
178 pub unsafety: hir::Unsafety,
180 pub items: Vec<P<hir::TraitItem>>, //should be TraitItem
181 pub generics: hir::Generics,
182 pub bounds: Vec<hir::TyParamBound>,
183 pub attrs: Vec<ast::Attribute>,
186 pub vis: hir::Visibility,
187 pub stab: Option<attr::Stability>,
191 pub unsafety: hir::Unsafety,
192 pub polarity: hir::ImplPolarity,
193 pub generics: hir::Generics,
194 pub trait_: Option<hir::TraitRef>,
195 pub for_: P<hir::Ty>,
196 pub items: Vec<P<hir::ImplItem>>,
197 pub attrs: Vec<ast::Attribute>,
199 pub vis: hir::Visibility,
200 pub stab: Option<attr::Stability>,
204 pub struct DefaultImpl {
205 pub unsafety: hir::Unsafety,
206 pub trait_: hir::TraitRef,
208 pub attrs: Vec<ast::Attribute>,
215 pub attrs: Vec<ast::Attribute>,
217 pub stab: Option<attr::Stability>,
218 pub imported_from: Option<Name>,
221 pub struct ExternCrate {
223 pub path: Option<String>,
224 pub vis: hir::Visibility,
225 pub attrs: Vec<ast::Attribute>,
231 pub vis: hir::Visibility,
232 pub attrs: Vec<ast::Attribute>,
233 pub node: hir::ViewPath_,
237 pub fn struct_type_from_def(sd: &hir::StructDef) -> StructType {
238 if sd.ctor_id.is_some() {
239 // We are in a tuple-struct
240 match sd.fields.len() {