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::{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 def: hir::VariantData,
123 pub stab: Option<attr::Stability>,
127 pub struct Function {
128 pub decl: hir::FnDecl,
129 pub attrs: Vec<ast::Attribute>,
132 pub vis: hir::Visibility,
133 pub stab: Option<attr::Stability>,
134 pub unsafety: hir::Unsafety,
135 pub constness: hir::Constness,
137 pub generics: hir::Generics,
143 pub gen: hir::Generics,
146 pub attrs: Vec<ast::Attribute>,
148 pub vis: hir::Visibility,
149 pub stab: Option<attr::Stability>,
154 pub type_: P<hir::Ty>,
155 pub mutability: hir::Mutability,
156 pub expr: P<hir::Expr>,
158 pub attrs: Vec<ast::Attribute>,
159 pub vis: hir::Visibility,
160 pub stab: Option<attr::Stability>,
165 pub struct Constant {
166 pub type_: P<hir::Ty>,
167 pub expr: P<hir::Expr>,
169 pub attrs: Vec<ast::Attribute>,
170 pub vis: hir::Visibility,
171 pub stab: Option<attr::Stability>,
177 pub unsafety: hir::Unsafety,
179 pub items: Vec<hir::TraitItem>,
180 pub generics: hir::Generics,
181 pub bounds: Vec<hir::TyParamBound>,
182 pub attrs: Vec<ast::Attribute>,
185 pub vis: hir::Visibility,
186 pub stab: Option<attr::Stability>,
190 pub unsafety: hir::Unsafety,
191 pub polarity: hir::ImplPolarity,
192 pub generics: hir::Generics,
193 pub trait_: Option<hir::TraitRef>,
194 pub for_: P<hir::Ty>,
195 pub items: Vec<hir::ImplItem>,
196 pub attrs: Vec<ast::Attribute>,
198 pub vis: hir::Visibility,
199 pub stab: Option<attr::Stability>,
203 pub struct DefaultImpl {
204 pub unsafety: hir::Unsafety,
205 pub trait_: hir::TraitRef,
207 pub attrs: Vec<ast::Attribute>,
214 pub attrs: Vec<ast::Attribute>,
216 pub matchers: Vec<Span>,
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::VariantData) -> StructType {
239 // We are in a tuple-struct
240 match sd.fields().len() {