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: ~[ast::Attribute],
33 foreigns: ~[ast::ForeignMod],
34 view_items: ~[ast::ViewItem],
40 pub fn new(name: Option<Ident>) -> Module {
45 where: syntax::codemap::DUMMY_SP,
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: ~[ast::Attribute],
87 fields: ~[ast::StructField],
94 generics: ast::Generics,
95 attrs: ~[ast::Attribute],
103 attrs: ~[ast::Attribute],
104 kind: ast::VariantKind,
106 vis: ast::Visibility,
110 pub struct Function {
112 attrs: ~[ast::Attribute],
115 vis: ast::Visibility,
118 generics: ast::Generics,
126 attrs: ~[ast::Attribute],
128 vis: ast::Visibility,
132 type_: ast::P<ast::Ty>,
133 mutability: ast::Mutability,
136 attrs: ~[ast::Attribute],
137 vis: ast::Visibility,
144 methods: ~[ast::TraitMethod], //should be TraitMethod
145 generics: ast::Generics,
146 parents: ~[ast::TraitRef],
147 attrs: ~[ast::Attribute],
150 vis: ast::Visibility,
154 generics: ast::Generics,
155 trait_: Option<ast::TraitRef>,
156 for_: ast::P<ast::Ty>,
157 methods: ~[@ast::Method],
158 attrs: ~[ast::Attribute],
160 vis: ast::Visibility,
167 attrs: ~[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() {