// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. //! This module is used to store stuff from Rust's AST in a more convenient //! manner (and with prettier names) before cleaning. pub use self::StructType::*; pub use self::TypeBound::*; use syntax::abi; use syntax::ast; use syntax::ast::{Name, NodeId}; use syntax::attr; use syntax::ptr::P; use syntax_pos::{self, Span}; use rustc::hir; use rustc::hir::def_id::CrateNum; pub struct Module { pub name: Option, pub attrs: hir::HirVec, pub where_outer: Span, pub where_inner: Span, pub extern_crates: Vec, pub imports: Vec, pub structs: Vec, pub unions: Vec, pub enums: Vec, pub fns: Vec, pub mods: Vec, pub id: NodeId, pub typedefs: Vec, pub statics: Vec, pub constants: Vec, pub traits: Vec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub impls: Vec, pub def_traits: Vec, pub foreigns: Vec, pub macros: Vec, pub is_crate: bool, } impl Module { pub fn new(name: Option) -> Module { Module { name : name, id: ast::CRATE_NODE_ID, vis: hir::Inherited, stab: None, depr: None, where_outer: syntax_pos::DUMMY_SP, where_inner: syntax_pos::DUMMY_SP, attrs : hir::HirVec::new(), extern_crates: Vec::new(), imports : Vec::new(), structs : Vec::new(), unions : Vec::new(), enums : Vec::new(), fns : Vec::new(), mods : Vec::new(), typedefs : Vec::new(), statics : Vec::new(), constants : Vec::new(), traits : Vec::new(), impls : Vec::new(), def_traits : Vec::new(), foreigns : Vec::new(), macros : Vec::new(), is_crate : false, } } } #[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)] pub enum StructType { /// A braced struct Plain, /// A tuple struct Tuple, /// A unit struct Unit, } pub enum TypeBound { RegionBound, TraitBound(hir::TraitRef) } pub struct Struct { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub id: NodeId, pub struct_type: StructType, pub name: Name, pub generics: hir::Generics, pub attrs: hir::HirVec, pub fields: hir::HirVec, pub whence: Span, } pub struct Union { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub id: NodeId, pub struct_type: StructType, pub name: Name, pub generics: hir::Generics, pub attrs: hir::HirVec, pub fields: hir::HirVec, pub whence: Span, } pub struct Enum { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub variants: hir::HirVec, pub generics: hir::Generics, pub attrs: hir::HirVec, pub id: NodeId, pub whence: Span, pub name: Name, } pub struct Variant { pub name: Name, pub attrs: hir::HirVec, pub def: hir::VariantData, pub stab: Option, pub depr: Option, pub whence: Span, } pub struct Function { pub decl: hir::FnDecl, pub attrs: hir::HirVec, pub id: NodeId, pub name: Name, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub unsafety: hir::Unsafety, pub constness: hir::Constness, pub whence: Span, pub generics: hir::Generics, pub abi: abi::Abi, pub body: hir::BodyId, } pub struct Typedef { pub ty: P, pub gen: hir::Generics, pub name: Name, pub id: ast::NodeId, pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, } #[derive(Debug)] pub struct Static { pub type_: P, pub mutability: hir::Mutability, pub expr: hir::BodyId, pub name: Name, pub attrs: hir::HirVec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub id: ast::NodeId, pub whence: Span, } pub struct Constant { pub type_: P, pub expr: hir::BodyId, pub name: Name, pub attrs: hir::HirVec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub id: ast::NodeId, pub whence: Span, } pub struct Trait { pub unsafety: hir::Unsafety, pub name: Name, pub items: hir::HirVec, pub generics: hir::Generics, pub bounds: hir::HirVec, pub attrs: hir::HirVec, pub id: ast::NodeId, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, } pub struct Impl { pub unsafety: hir::Unsafety, pub polarity: hir::ImplPolarity, pub defaultness: hir::Defaultness, pub generics: hir::Generics, pub trait_: Option, pub for_: P, pub items: hir::HirVec, pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, pub id: ast::NodeId, } pub struct AutoImpl { pub unsafety: hir::Unsafety, pub trait_: hir::TraitRef, pub id: ast::NodeId, pub attrs: hir::HirVec, pub whence: Span, } // For Macro we store the DefId instead of the NodeId, since we also create // these imported macro_rules (which only have a DUMMY_NODE_ID). pub struct Macro { pub name: Name, pub def_id: hir::def_id::DefId, pub attrs: hir::HirVec, pub whence: Span, pub matchers: hir::HirVec, pub stab: Option, pub depr: Option, pub imported_from: Option, } pub struct ExternCrate { pub name: Name, pub cnum: CrateNum, pub path: Option, pub vis: hir::Visibility, pub attrs: hir::HirVec, pub whence: Span, } pub struct Import { pub name: Name, pub id: NodeId, pub vis: hir::Visibility, pub attrs: hir::HirVec, pub path: hir::Path, pub glob: bool, pub whence: Span, } pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType { match *vdata { hir::VariantData::Struct(..) => Plain, hir::VariantData::Tuple(..) => Tuple, hir::VariantData::Unit(..) => Unit, } }