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};
24 pub name: Option<Ident>,
25 pub attrs: Vec<ast::Attribute>,
26 pub where_outer: Span,
27 pub where_inner: Span,
28 pub structs: Vec<Struct>,
30 pub fns: Vec<Function>,
31 pub mods: Vec<Module>,
33 pub typedefs: Vec<Typedef>,
34 pub statics: Vec<Static>,
35 pub constants: Vec<Constant>,
36 pub traits: Vec<Trait>,
37 pub vis: ast::Visibility,
38 pub stab: Option<attr::Stability>,
40 pub foreigns: Vec<ast::ForeignMod>,
41 pub view_items: Vec<ast::ViewItem>,
42 pub macros: Vec<Macro>,
47 pub fn new(name: Option<Ident>) -> Module {
53 where_outer: syntax::codemap::DUMMY_SP,
54 where_inner: syntax::codemap::DUMMY_SP,
60 typedefs : Vec::new(),
62 constants : Vec::new(),
65 view_items : Vec::new(),
66 foreigns : Vec::new(),
73 #[deriving(Show, Clone, RustcEncodable, RustcDecodable, Copy)]
79 /// A newtype struct (tuple struct with one element)
87 TraitBound(ast::TraitRef)
91 pub vis: ast::Visibility,
92 pub stab: Option<attr::Stability>,
94 pub struct_type: StructType,
96 pub generics: ast::Generics,
97 pub attrs: Vec<ast::Attribute>,
98 pub fields: Vec<ast::StructField>,
103 pub vis: ast::Visibility,
104 pub stab: Option<attr::Stability>,
105 pub variants: Vec<Variant>,
106 pub generics: ast::Generics,
107 pub attrs: Vec<ast::Attribute>,
115 pub attrs: Vec<ast::Attribute>,
116 pub kind: ast::VariantKind,
118 pub vis: ast::Visibility,
119 pub stab: Option<attr::Stability>,
123 pub struct Function {
124 pub decl: ast::FnDecl,
125 pub attrs: Vec<ast::Attribute>,
128 pub vis: ast::Visibility,
129 pub stab: Option<attr::Stability>,
130 pub unsafety: ast::Unsafety,
132 pub generics: ast::Generics,
137 pub gen: ast::Generics,
140 pub attrs: Vec<ast::Attribute>,
142 pub vis: ast::Visibility,
143 pub stab: Option<attr::Stability>,
148 pub type_: P<ast::Ty>,
149 pub mutability: ast::Mutability,
150 pub expr: P<ast::Expr>,
152 pub attrs: Vec<ast::Attribute>,
153 pub vis: ast::Visibility,
154 pub stab: Option<attr::Stability>,
159 pub struct Constant {
160 pub type_: P<ast::Ty>,
161 pub expr: P<ast::Expr>,
163 pub attrs: Vec<ast::Attribute>,
164 pub vis: ast::Visibility,
165 pub stab: Option<attr::Stability>,
171 pub unsafety: ast::Unsafety,
173 pub items: Vec<ast::TraitItem>, //should be TraitItem
174 pub generics: ast::Generics,
175 pub bounds: Vec<ast::TyParamBound>,
176 pub attrs: Vec<ast::Attribute>,
179 pub vis: ast::Visibility,
180 pub stab: Option<attr::Stability>,
184 pub unsafety: ast::Unsafety,
185 pub generics: ast::Generics,
186 pub trait_: Option<ast::TraitRef>,
187 pub for_: P<ast::Ty>,
188 pub items: Vec<ast::ImplItem>,
189 pub attrs: Vec<ast::Attribute>,
191 pub vis: ast::Visibility,
192 pub stab: Option<attr::Stability>,
199 pub attrs: Vec<ast::Attribute>,
201 pub stab: Option<attr::Stability>,
204 pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
205 if sd.ctor_id.is_some() {
206 // We are in a tuple-struct
207 match sd.fields.len() {