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, NodeId};
26 pub name: Option<Ident>,
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<Ident>) -> 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 vis: hir::Visibility,
125 pub stab: Option<attr::Stability>,
129 pub struct Function {
130 pub decl: hir::FnDecl,
131 pub attrs: Vec<ast::Attribute>,
134 pub vis: hir::Visibility,
135 pub stab: Option<attr::Stability>,
136 pub unsafety: hir::Unsafety,
137 pub constness: hir::Constness,
139 pub generics: hir::Generics,
145 pub gen: hir::Generics,
148 pub attrs: Vec<ast::Attribute>,
150 pub vis: hir::Visibility,
151 pub stab: Option<attr::Stability>,
156 pub type_: P<hir::Ty>,
157 pub mutability: hir::Mutability,
158 pub expr: P<hir::Expr>,
160 pub attrs: Vec<ast::Attribute>,
161 pub vis: hir::Visibility,
162 pub stab: Option<attr::Stability>,
167 pub struct Constant {
168 pub type_: P<hir::Ty>,
169 pub expr: P<hir::Expr>,
171 pub attrs: Vec<ast::Attribute>,
172 pub vis: hir::Visibility,
173 pub stab: Option<attr::Stability>,
179 pub unsafety: hir::Unsafety,
181 pub items: Vec<P<hir::TraitItem>>, //should be TraitItem
182 pub generics: hir::Generics,
183 pub bounds: Vec<hir::TyParamBound>,
184 pub attrs: Vec<ast::Attribute>,
187 pub vis: hir::Visibility,
188 pub stab: Option<attr::Stability>,
192 pub unsafety: hir::Unsafety,
193 pub polarity: hir::ImplPolarity,
194 pub generics: hir::Generics,
195 pub trait_: Option<hir::TraitRef>,
196 pub for_: P<hir::Ty>,
197 pub items: Vec<P<hir::ImplItem>>,
198 pub attrs: Vec<ast::Attribute>,
200 pub vis: hir::Visibility,
201 pub stab: Option<attr::Stability>,
205 pub struct DefaultImpl {
206 pub unsafety: hir::Unsafety,
207 pub trait_: hir::TraitRef,
209 pub attrs: Vec<ast::Attribute>,
216 pub attrs: Vec<ast::Attribute>,
218 pub stab: Option<attr::Stability>,
219 pub imported_from: Option<Ident>,
222 pub struct ExternCrate {
224 pub path: Option<String>,
225 pub vis: hir::Visibility,
226 pub attrs: Vec<ast::Attribute>,
232 pub vis: hir::Visibility,
233 pub attrs: Vec<ast::Attribute>,
234 pub node: hir::ViewPath_,
238 pub fn struct_type_from_def(sd: &hir::StructDef) -> StructType {
239 if sd.ctor_id.is_some() {
240 // We are in a tuple-struct
241 match sd.fields.len() {