diff options
Diffstat (limited to 'src/libsyntax/ast.rs')
| -rw-r--r-- | src/libsyntax/ast.rs | 174 |
1 files changed, 102 insertions, 72 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6cf38d5ae1d..38f0b2496cb 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -24,7 +24,7 @@ use extra::serialize::{Encodable, Decodable, Encoder, Decoder}; // table) and a SyntaxContext to track renaming and // macro expansion per Flatt et al., "Macros // That Work Together" -#[deriving(Eq,IterBytes)] +#[deriving(Clone, Eq, IterBytes)] pub struct ident { name: Name, ctxt: SyntaxContext } /// Construct an identifier with the given name and an empty context: @@ -93,7 +93,7 @@ impl<D:Decoder> Decodable<D> for ident { // Functions may or may not have names. pub type fn_ident = Option<ident>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct Lifetime { id: node_id, span: span, @@ -104,7 +104,7 @@ pub struct Lifetime { // for instance: core::cmp::Eq . It's represented // as a sequence of identifiers, along with a bunch // of supporting information. -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct Path { span: span, global: bool, @@ -117,7 +117,7 @@ pub type crate_num = int; pub type node_id = int; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct def_id { crate: crate_num, node: node_id, @@ -126,27 +126,27 @@ pub struct def_id { pub static local_crate: crate_num = 0; pub static crate_node_id: node_id = 0; -#[deriving(Eq, Encodable, Decodable,IterBytes)] // The AST represents all type param bounds as types. // typeck::collect::compute_bounds matches these against // the "special" built-in traits (see middle::lang_items) and // detects Copy, Send, Send, and Freeze. +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum TyParamBound { TraitTyParamBound(trait_ref), RegionTyParamBound } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct TyParam { ident: ident, id: node_id, bounds: OptVec<TyParamBound> } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct Generics { lifetimes: OptVec<Lifetime>, - ty_params: OptVec<TyParam> + ty_params: OptVec<TyParam>, } impl Generics { @@ -161,7 +161,7 @@ impl Generics { } } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum def { def_fn(def_id, purity), def_static_method(/* method */ def_id, @@ -199,7 +199,7 @@ pub type crate_cfg = ~[@meta_item]; pub type crate = spanned<crate_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct crate_ { module: _mod, attrs: ~[attribute], @@ -208,7 +208,7 @@ pub struct crate_ { pub type meta_item = spanned<meta_item_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum meta_item_ { meta_word(@str), meta_list(@str, ~[@meta_item]), @@ -217,7 +217,7 @@ pub enum meta_item_ { //pub type blk = spanned<blk_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] pub struct blk { view_items: ~[view_item], stmts: ~[@stmt], @@ -227,26 +227,26 @@ pub struct blk { span: span, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct pat { id: node_id, node: pat_, span: span, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct field_pat { ident: ident, pat: @pat, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum binding_mode { bind_by_ref(mutability), bind_infer } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum pat_ { pat_wild, // A pat_ident may either be a new bound variable, @@ -271,10 +271,10 @@ pub enum pat_ { pat_vec(~[@pat], Option<@pat>, ~[@pat]) } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum mutability { m_mutbl, m_imm, m_const, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum Sigil { BorrowedSigil, OwnedSigil, @@ -300,7 +300,7 @@ pub enum vstore { vstore_slice(Option<Lifetime>) // &'foo? [1,2,3,4] } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum expr_vstore { expr_vstore_uniq, // ~[1,2,3,4] expr_vstore_box, // @[1,2,3,4] @@ -309,7 +309,7 @@ pub enum expr_vstore { expr_vstore_mut_slice, // &mut [1,2,3,4] } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum binop { add, subtract, @@ -331,7 +331,7 @@ pub enum binop { gt, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum unop { box(mutability), uniq, @@ -342,7 +342,7 @@ pub enum unop { pub type stmt = spanned<stmt_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum stmt_ { // could be an item or a local (let) binding: stmt_decl(@decl, node_id), @@ -380,14 +380,14 @@ pub enum decl_ { decl_item(@item), } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct arm { pats: ~[@pat], guard: Option<@expr>, body: blk, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct field_ { ident: ident, expr: @expr, @@ -395,8 +395,11 @@ pub struct field_ { pub type field = spanned<field_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum blk_check_mode { default_blk, unsafe_blk, } +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] +pub enum blk_check_mode { + default_blk, + unsafe_blk, +} #[deriving(Eq, Encodable, Decodable,IterBytes)] pub struct expr { @@ -418,14 +421,14 @@ impl expr { } } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum CallSugar { NoSugar, DoSugar, ForSugar } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum expr_ { expr_vstore(@expr, expr_vstore), expr_vec(~[@expr], mutability), @@ -496,7 +499,7 @@ pub enum expr_ { // else knows what to do with them, so you'll probably get a syntax // error. // -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[doc="For macro invocations; parsing is delegated to the macro"] pub enum token_tree { // a single token @@ -569,7 +572,7 @@ pub enum token_tree { // pub type matcher = spanned<matcher_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum matcher_ { // match one token match_tok(::parse::token::Token), @@ -582,14 +585,14 @@ pub enum matcher_ { pub type mac = spanned<mac_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum mac_ { mac_invoc_tt(Path,~[token_tree]), // new macro-invocation } pub type lit = spanned<lit_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum lit_ { lit_str(@str), lit_int(i64, int_ty), @@ -603,7 +606,7 @@ pub enum lit_ { // NB: If you change this, you'll probably want to change the corresponding // type structure in middle/ty.rs as well. -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct mt { ty: ~Ty, mutbl: mutability, @@ -617,7 +620,7 @@ pub struct ty_field_ { pub type ty_field = spanned<ty_field_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct ty_method { ident: ident, attrs: ~[attribute], @@ -629,17 +632,24 @@ pub struct ty_method { span: span, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] // A trait method is either required (meaning it doesn't have an // implementation, just a signature) or provided (meaning it has a default // implementation). +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum trait_method { required(ty_method), provided(@method), } -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, } +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] +pub enum int_ty { + ty_i, + ty_char, + ty_i8, + ty_i16, + ty_i32, + ty_i64, +} impl ToStr for int_ty { fn to_str(&self) -> ~str { @@ -647,8 +657,14 @@ impl ToStr for int_ty { } } -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum uint_ty { ty_u, ty_u8, ty_u16, ty_u32, ty_u64, } +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] +pub enum uint_ty { + ty_u, + ty_u8, + ty_u16, + ty_u32, + ty_u64, +} impl ToStr for uint_ty { fn to_str(&self) -> ~str { @@ -656,8 +672,12 @@ impl ToStr for uint_ty { } } -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum float_ty { ty_f, ty_f32, ty_f64, } +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] +pub enum float_ty { + ty_f, + ty_f32, + ty_f64, +} impl ToStr for float_ty { fn to_str(&self) -> ~str { @@ -666,7 +686,7 @@ impl ToStr for float_ty { } // NB Eq method appears below. -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] pub struct Ty { id: node_id, node: ty_, @@ -674,7 +694,7 @@ pub struct Ty { } // Not represented directly in the AST, referred to by name through a ty_path. -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum prim_ty { ty_int(int_ty), ty_uint(uint_ty), @@ -683,7 +703,7 @@ pub enum prim_ty { ty_bool, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum Onceness { Once, Many @@ -722,7 +742,7 @@ pub struct TyBareFn { decl: fn_decl } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum ty_ { ty_nil, ty_bot, /* bottom type */ @@ -743,13 +763,13 @@ pub enum ty_ { ty_infer, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum asm_dialect { asm_att, asm_intel } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct inline_asm { asm: @str, clobbers: @str, @@ -760,7 +780,7 @@ pub struct inline_asm { dialect: asm_dialect } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct arg { is_mutbl: bool, ty: Ty, @@ -768,14 +788,14 @@ pub struct arg { id: node_id, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct fn_decl { inputs: ~[arg], output: Ty, cf: ret_style, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum purity { unsafe_fn, // declared with "unsafe fn" impure_fn, // declared with "fn" @@ -793,14 +813,14 @@ impl ToStr for purity { } } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum ret_style { noreturn, // functions with return type _|_ that always // raise an error or exit (i.e. never return to the caller) return_val, // everything else } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum explicit_self_ { sty_static, // no self sty_value, // `self` @@ -826,17 +846,20 @@ pub struct method { vis: visibility, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct _mod { view_items: ~[view_item], items: ~[@item], } // Foreign mods can be named or anonymous -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum foreign_mod_sort { named, anonymous } +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] +pub enum foreign_mod_sort { + named, + anonymous, +} -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] pub struct foreign_mod { sort: foreign_mod_sort, abis: AbiSet, @@ -844,24 +867,24 @@ pub struct foreign_mod { items: ~[@foreign_item], } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct variant_arg { ty: Ty, id: node_id, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum variant_kind { tuple_variant_kind(~[variant_arg]), struct_variant_kind(@struct_def), } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct enum_def { variants: ~[variant], } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct variant_ { name: ident, attrs: ~[attribute], @@ -873,7 +896,7 @@ pub struct variant_ { pub type variant = spanned<variant_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct path_list_ident_ { name: ident, id: node_id, @@ -883,7 +906,7 @@ pub type path_list_ident = spanned<path_list_ident_>; pub type view_path = spanned<view_path_>; -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Eq, Encodable, Decodable, IterBytes)] pub enum view_path_ { // quux = foo::bar::baz @@ -900,7 +923,7 @@ pub enum view_path_ { view_path_list(Path, ~[path_list_ident], node_id) } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct view_item { node: view_item_, attrs: ~[attribute], @@ -908,7 +931,7 @@ pub struct view_item { span: span, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum view_item_ { view_item_extern_mod(ident, ~[@meta_item], node_id), view_item_use(~[@view_path]), @@ -920,11 +943,14 @@ pub type attribute = spanned<attribute_>; // Distinguishes between attributes that decorate items and attributes that // are contained as statements within items. These two cases need to be // distinguished for pretty-printing. -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum attr_style { attr_outer, attr_inner, } +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] +pub enum attr_style { + attr_outer, + attr_inner, +} // doc-comments are promoted to attributes that have is_sugared_doc = true -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] pub struct attribute_ { style: attr_style, value: @meta_item, @@ -938,14 +964,18 @@ pub struct attribute_ { If this impl is an item_impl, the impl_id is redundant (it could be the same as the impl's node id). */ -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] pub struct trait_ref { path: Path, ref_id: node_id, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] -pub enum visibility { public, private, inherited } +#[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] +pub enum visibility { + public, + private, + inherited, +} impl visibility { pub fn inherit_from(&self, parent_visibility: visibility) -> visibility { @@ -984,7 +1014,7 @@ pub struct struct_def { FIXME (#3300): Should allow items to be anonymous. Right now we just use dummy names for anon items. */ -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct item { ident: ident, attrs: ~[attribute], @@ -994,7 +1024,7 @@ pub struct item { span: span, } -#[deriving(Eq, Encodable, Decodable,IterBytes)] +#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum item_ { item_static(Ty, mutability, @expr), item_fn(fn_decl, purity, AbiSet, Generics, blk), |
