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;
17 use syntax::ast::{Ident, NodeId};
21 attrs: Vec<ast::Attribute> ,
23 structs: Vec<Struct> ,
28 typedefs: Vec<Typedef> ,
29 statics: Vec<Static> ,
33 foreigns: Vec<ast::ForeignMod> ,
34 view_items: Vec<ast::ViewItem> ,
40 pub fn new(name: Option<Ident>) -> Module {
45 where: syntax::codemap::DUMMY_SP,
51 typedefs : Vec::new(),
55 view_items : Vec::new(),
56 foreigns : Vec::new(),
63 #[deriving(Show, Clone, Encodable, Decodable)]
69 /// A newtype struct (tuple struct with one element)
77 TraitBound(ast::TraitRef)
83 struct_type: StructType,
85 generics: ast::Generics,
86 attrs: Vec<ast::Attribute> ,
87 fields: Vec<ast::StructField> ,
93 variants: Vec<Variant> ,
94 generics: ast::Generics,
95 attrs: Vec<ast::Attribute> ,
103 attrs: Vec<ast::Attribute> ,
104 kind: ast::VariantKind,
106 vis: ast::Visibility,
110 pub struct Function {
112 attrs: Vec<ast::Attribute> ,
115 vis: ast::Visibility,
118 generics: ast::Generics,
126 attrs: Vec<ast::Attribute> ,
128 vis: ast::Visibility,
132 type_: ast::P<ast::Ty>,
133 mutability: ast::Mutability,
136 attrs: Vec<ast::Attribute> ,
137 vis: ast::Visibility,
144 methods: Vec<ast::TraitMethod> , //should be TraitMethod
145 generics: ast::Generics,
146 parents: Vec<ast::TraitRef> ,
147 attrs: Vec<ast::Attribute> ,
150 vis: ast::Visibility,
154 generics: ast::Generics,
155 trait_: Option<ast::TraitRef>,
156 for_: ast::P<ast::Ty>,
157 methods: Vec<@ast::Method> ,
158 attrs: Vec<ast::Attribute> ,
160 vis: ast::Visibility,
167 attrs: Vec<ast::Attribute> ,
171 pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
172 if sd.ctor_id.is_some() {
173 // We are in a tuple-struct
174 match sd.fields.len() {