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.
15 use syntax::codemap::Span;
18 use syntax::ast::{Ident, NodeId};
23 pub name: Option<Ident>,
24 pub attrs: Vec<ast::Attribute>,
25 pub where_outer: Span,
26 pub where_inner: Span,
27 pub structs: Vec<Struct>,
29 pub fns: Vec<Function>,
30 pub mods: Vec<Module>,
32 pub typedefs: Vec<Typedef>,
33 pub statics: Vec<Static>,
34 pub traits: Vec<Trait>,
35 pub vis: ast::Visibility,
36 pub stab: Option<attr::Stability>,
38 pub foreigns: Vec<ast::ForeignMod>,
39 pub view_items: Vec<ast::ViewItem>,
40 pub macros: Vec<Macro>,
45 pub fn new(name: Option<Ident>) -> Module {
51 where_outer: syntax::codemap::DUMMY_SP,
52 where_inner: syntax::codemap::DUMMY_SP,
58 typedefs : Vec::new(),
62 view_items : Vec::new(),
63 foreigns : Vec::new(),
70 #[deriving(Show, Clone, Encodable, Decodable)]
76 /// A newtype struct (tuple struct with one element)
84 TraitBound(ast::TraitRef)
88 pub vis: ast::Visibility,
89 pub stab: Option<attr::Stability>,
91 pub struct_type: StructType,
93 pub generics: ast::Generics,
94 pub attrs: Vec<ast::Attribute>,
95 pub fields: Vec<ast::StructField>,
100 pub vis: ast::Visibility,
101 pub stab: Option<attr::Stability>,
102 pub variants: Vec<Variant>,
103 pub generics: ast::Generics,
104 pub attrs: Vec<ast::Attribute>,
112 pub attrs: Vec<ast::Attribute>,
113 pub kind: ast::VariantKind,
115 pub vis: ast::Visibility,
116 pub stab: Option<attr::Stability>,
120 pub struct Function {
121 pub decl: ast::FnDecl,
122 pub attrs: Vec<ast::Attribute>,
125 pub vis: ast::Visibility,
126 pub stab: Option<attr::Stability>,
127 pub fn_style: ast::FnStyle,
129 pub generics: ast::Generics,
133 pub ty: ast::P<ast::Ty>,
134 pub gen: ast::Generics,
137 pub attrs: Vec<ast::Attribute>,
139 pub vis: ast::Visibility,
140 pub stab: Option<attr::Stability>,
144 pub type_: ast::P<ast::Ty>,
145 pub mutability: ast::Mutability,
146 pub expr: Gc<ast::Expr>,
148 pub attrs: Vec<ast::Attribute>,
149 pub vis: ast::Visibility,
150 pub stab: Option<attr::Stability>,
157 pub methods: Vec<ast::TraitMethod>, //should be TraitMethod
158 pub generics: ast::Generics,
159 pub parents: Vec<ast::TraitRef>,
160 pub attrs: Vec<ast::Attribute>,
163 pub vis: ast::Visibility,
164 pub stab: Option<attr::Stability>,
168 pub generics: ast::Generics,
169 pub trait_: Option<ast::TraitRef>,
170 pub for_: ast::P<ast::Ty>,
171 pub methods: Vec<Gc<ast::Method>>,
172 pub attrs: Vec<ast::Attribute>,
174 pub vis: ast::Visibility,
175 pub stab: Option<attr::Stability>,
182 pub attrs: Vec<ast::Attribute>,
184 pub stab: Option<attr::Stability>,
187 pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
188 if sd.ctor_id.is_some() {
189 // We are in a tuple-struct
190 match sd.fields.len() {