diff options
| author | bors <bors@rust-lang.org> | 2013-05-01 09:18:59 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-01 09:18:59 -0700 |
| commit | 55fbc47af15bb1a8d930a7623737903c54b58349 (patch) | |
| tree | 5b2f63c6b21287b5e42932ee9ca8b5b9659bdfb1 /src/libsyntax/parse | |
| parent | f67239fac3cc521fedaf14faf5357beab78caea8 (diff) | |
| parent | 7c9d089ee732c2930898574d9ecedbb01efe0eb9 (diff) | |
| download | rust-55fbc47af15bb1a8d930a7623737903c54b58349.tar.gz rust-55fbc47af15bb1a8d930a7623737903c54b58349.zip | |
auto merge of #6148 : erickt/rust/remove-drop, r=pcwalton
The drop block has been deprecated for quite some time. This patch series removes support for parsing it and all the related machinery that made drop work. As a side feature of all this, I also added the ability to annote fields in structs. This allows comments to be properly associated with an individual field. However, I didn't update `rustdoc` to integrate these comment blocks into the documentation it generates.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 110 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 145 |
4 files changed, 99 insertions, 164 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 7e7931bbb60..5d51a54d770 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -24,7 +24,7 @@ use parse::token::{ident_interner, mk_ident_interner}; use core::io; use core::option::{None, Option, Some}; use core::path::Path; -use core::result::{Err, Ok, Result}; +use core::result::{Err, Ok}; pub mod lexer; pub mod parser; diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index ce21e0f672d..c1afc53def0 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -18,7 +18,7 @@ removed. */ -use ast::{expr, expr_lit, lit_nil}; +use ast::{expr, expr_lit, lit_nil, attribute}; use ast; use codemap::{span, respan}; use parse::parser::Parser; @@ -282,13 +282,13 @@ pub impl Parser { } } - fn try_parse_obsolete_priv_section(&self) -> bool { + fn try_parse_obsolete_priv_section(&self, attrs: ~[attribute]) -> bool { if self.is_keyword(&~"priv") && self.look_ahead(1) == token::LBRACE { self.obsolete(copy *self.span, ObsoletePrivSection); self.eat_keyword(&~"priv"); self.bump(); while *self.token != token::RBRACE { - self.parse_single_struct_field(ast::private); + self.parse_single_struct_field(ast::private, attrs); } self.bump(); true diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 42c6fad6463..a582748edb3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -102,11 +102,6 @@ enum restriction { RESTRICT_NO_BAR_OR_DOUBLEBAR_OP, } -// So that we can distinguish a class dtor from other class members - -enum class_contents { dtor_decl(blk, ~[attribute], codemap::span), - members(~[@struct_field]) } - type arg_or_capture_item = Either<arg, ()>; type item_info = (ident, item_, Option<~[attribute]>); @@ -2525,7 +2520,9 @@ pub impl Parser { } // parse a structure field - fn parse_name_and_ty(&self, pr: visibility) -> @struct_field { + fn parse_name_and_ty(&self, + pr: visibility, + attrs: ~[attribute]) -> @struct_field { let mut is_mutbl = struct_immutable; let lo = self.span.lo; if self.eat_keyword(&~"mut") { @@ -2540,7 +2537,8 @@ pub impl Parser { @spanned(lo, self.last_span.hi, ast::struct_field_ { kind: named_field(name, is_mutbl, pr), id: self.get_id(), - ty: ty + ty: ty, + attrs: attrs, }) } @@ -3299,7 +3297,6 @@ pub impl Parser { } let mut fields: ~[@struct_field]; - let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None; let is_tuple_like; if self.eat(&token::LBRACE) { @@ -3307,26 +3304,8 @@ pub impl Parser { is_tuple_like = false; fields = ~[]; while *self.token != token::RBRACE { - match self.parse_struct_decl_field() { - dtor_decl(ref blk, ref attrs, s) => { - match the_dtor { - Some((_, _, s_first)) => { - self.span_note(s, fmt!("Duplicate destructor \ - declaration for class %s", - *self.interner.get(class_name))); - self.span_fatal(copy s_first, ~"First destructor \ - declared here"); - } - None => { - the_dtor = Some((copy *blk, copy *attrs, s)); - } - } - } - members(mms) => { - for mms.each |struct_field| { - fields.push(*struct_field) - } - } + for self.parse_struct_decl_field().each |struct_field| { + fields.push(*struct_field) } } if fields.len() == 0 { @@ -3342,11 +3321,13 @@ pub impl Parser { &token::RPAREN, seq_sep_trailing_allowed(token::COMMA) ) |p| { + let attrs = self.parse_outer_attributes(); let lo = p.span.lo; let struct_field_ = ast::struct_field_ { kind: unnamed_field, id: self.get_id(), - ty: p.parse_ty(false) + ty: p.parse_ty(false), + attrs: attrs, }; @spanned(lo, p.span.hi, struct_field_) }; @@ -3365,19 +3346,11 @@ pub impl Parser { ); } - let actual_dtor = do the_dtor.map |dtor| { - let (d_body, d_attrs, d_s) = copy *dtor; - codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(), - attrs: d_attrs, - self_id: self.get_id(), - body: d_body}, - span: d_s}}; let _ = self.get_id(); // XXX: Workaround for crazy bug. let new_id = self.get_id(); (class_name, item_struct(@ast::struct_def { fields: fields, - dtor: actual_dtor, ctor_id: if is_tuple_like { Some(new_id) } else { None } }, generics), None) @@ -3391,12 +3364,14 @@ pub impl Parser { } // parse a structure field declaration - fn parse_single_struct_field(&self, vis: visibility) -> @struct_field { + fn parse_single_struct_field(&self, + vis: visibility, + attrs: ~[attribute]) -> @struct_field { if self.eat_obsolete_ident("let") { self.obsolete(*self.last_span, ObsoleteLet); } - let a_var = self.parse_name_and_ty(vis); + let a_var = self.parse_name_and_ty(vis, attrs); match *self.token { token::SEMI => { self.obsolete(copy *self.span, ObsoleteFieldTerminator); @@ -3420,34 +3395,27 @@ pub impl Parser { } // parse an element of a struct definition - fn parse_struct_decl_field(&self) -> class_contents { - - if self.try_parse_obsolete_priv_section() { - return members(~[]); - } + fn parse_struct_decl_field(&self) -> ~[@struct_field] { let attrs = self.parse_outer_attributes(); + if self.try_parse_obsolete_priv_section(attrs) { + return ~[]; + } + if self.eat_keyword(&~"priv") { - return members(~[self.parse_single_struct_field(private)]) + return ~[self.parse_single_struct_field(private, attrs)] } if self.eat_keyword(&~"pub") { - return members(~[self.parse_single_struct_field(public)]); + return ~[self.parse_single_struct_field(public, attrs)]; } if self.try_parse_obsolete_struct_ctor() { - return members(~[]); + return ~[]; } - if self.eat_keyword(&~"drop") { - let lo = self.last_span.lo; - let body = self.parse_block(); - return dtor_decl(body, attrs, mk_sp(lo, self.last_span.hi)) - } - else { - return members(~[self.parse_single_struct_field(inherited)]); - } + return ~[self.parse_single_struct_field(inherited, attrs)]; } // parse visiility: PUB, PRIV, or nothing @@ -3830,44 +3798,16 @@ pub impl Parser { // parse a structure-like enum variant definition // this should probably be renamed or refactored... fn parse_struct_def(&self) -> @struct_def { - let mut the_dtor: Option<(blk, ~[attribute], codemap::span)> = None; let mut fields: ~[@struct_field] = ~[]; while *self.token != token::RBRACE { - match self.parse_struct_decl_field() { - dtor_decl(ref blk, ref attrs, s) => { - match the_dtor { - Some((_, _, s_first)) => { - self.span_note(s, ~"duplicate destructor \ - declaration"); - self.span_fatal(copy s_first, - ~"first destructor \ - declared here"); - } - None => { - the_dtor = Some((copy *blk, copy *attrs, s)); - } - } - } - members(mms) => { - for mms.each |struct_field| { - fields.push(*struct_field); - } - } + for self.parse_struct_decl_field().each |struct_field| { + fields.push(*struct_field); } } self.bump(); - let actual_dtor = do the_dtor.map |dtor| { - let (d_body, d_attrs, d_s) = copy *dtor; - codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(), - attrs: d_attrs, - self_id: self.get_id(), - body: d_body }, - span: d_s } - }; return @ast::struct_def { fields: fields, - dtor: actual_dtor, ctor_id: None }; } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 9426e9abab3..338b7c99d97 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -305,50 +305,47 @@ pub fn is_bar(t: &Token) -> bool { pub mod special_idents { use ast::ident; - pub static underscore : ident = ident { repr: 0u, ctxt: 0}; - pub static anon : ident = ident { repr: 1u, ctxt: 0}; - pub static dtor : ident = ident { repr: 2u, ctxt: 0}; // 'drop', but that's - // reserved - pub static invalid : ident = ident { repr: 3u, ctxt: 0}; // '' - pub static unary : ident = ident { repr: 4u, ctxt: 0}; - pub static not_fn : ident = ident { repr: 5u, ctxt: 0}; - pub static idx_fn : ident = ident { repr: 6u, ctxt: 0}; - pub static unary_minus_fn : ident = ident { repr: 7u, ctxt: 0}; - pub static clownshoes_extensions : ident = ident { repr: 8u, ctxt: 0}; - - pub static self_ : ident = ident { repr: 9u, ctxt: 0}; // 'self' + pub static underscore : ident = ident { repr: 0, ctxt: 0}; + pub static anon : ident = ident { repr: 1, ctxt: 0}; + pub static invalid : ident = ident { repr: 2, ctxt: 0}; // '' + pub static unary : ident = ident { repr: 3, ctxt: 0}; + pub static not_fn : ident = ident { repr: 4, ctxt: 0}; + pub static idx_fn : ident = ident { repr: 5, ctxt: 0}; + pub static unary_minus_fn : ident = ident { repr: 6, ctxt: 0}; + pub static clownshoes_extensions : ident = ident { repr: 7, ctxt: 0}; + + pub static self_ : ident = ident { repr: 8, ctxt: 0}; // 'self' /* for matcher NTs */ - pub static item : ident = ident { repr: 10u, ctxt: 0}; - pub static block : ident = ident { repr: 11u, ctxt: 0}; - pub static stmt : ident = ident { repr: 12u, ctxt: 0}; - pub static pat : ident = ident { repr: 13u, ctxt: 0}; - pub static expr : ident = ident { repr: 14u, ctxt: 0}; - pub static ty : ident = ident { repr: 15u, ctxt: 0}; - pub static ident : ident = ident { repr: 16u, ctxt: 0}; - pub static path : ident = ident { repr: 17u, ctxt: 0}; - pub static tt : ident = ident { repr: 18u, ctxt: 0}; - pub static matchers : ident = ident { repr: 19u, ctxt: 0}; - - pub static str : ident = ident { repr: 20u, ctxt: 0}; // for the type + pub static item : ident = ident { repr: 9, ctxt: 0}; + pub static block : ident = ident { repr: 10, ctxt: 0}; + pub static stmt : ident = ident { repr: 11, ctxt: 0}; + pub static pat : ident = ident { repr: 12, ctxt: 0}; + pub static expr : ident = ident { repr: 13, ctxt: 0}; + pub static ty : ident = ident { repr: 14, ctxt: 0}; + pub static ident : ident = ident { repr: 15, ctxt: 0}; + pub static path : ident = ident { repr: 16, ctxt: 0}; + pub static tt : ident = ident { repr: 17, ctxt: 0}; + pub static matchers : ident = ident { repr: 18, ctxt: 0}; + + pub static str : ident = ident { repr: 19, ctxt: 0}; // for the type /* outside of libsyntax */ - pub static ty_visitor : ident = ident { repr: 21u, ctxt: 0}; - pub static arg : ident = ident { repr: 22u, ctxt: 0}; - pub static descrim : ident = ident { repr: 23u, ctxt: 0}; - pub static clownshoe_abi : ident = ident { repr: 24u, ctxt: 0}; - pub static clownshoe_stack_shim : ident = ident { repr: 25u, ctxt: 0}; - pub static tydesc : ident = ident { repr: 26u, ctxt: 0}; - pub static literally_dtor : ident = ident { repr: 27u, ctxt: 0}; - pub static main : ident = ident { repr: 28u, ctxt: 0}; - pub static opaque : ident = ident { repr: 29u, ctxt: 0}; - pub static blk : ident = ident { repr: 30u, ctxt: 0}; - pub static static : ident = ident { repr: 31u, ctxt: 0}; - pub static intrinsic : ident = ident { repr: 32u, ctxt: 0}; - pub static clownshoes_foreign_mod: ident = ident { repr: 33u, ctxt: 0}; - pub static unnamed_field: ident = ident { repr: 34u, ctxt: 0}; - pub static c_abi: ident = ident { repr: 35u, ctxt: 0}; - pub static type_self: ident = ident { repr: 36u, ctxt: 0}; // `Self` + pub static ty_visitor : ident = ident { repr: 20, ctxt: 0}; + pub static arg : ident = ident { repr: 21, ctxt: 0}; + pub static descrim : ident = ident { repr: 22, ctxt: 0}; + pub static clownshoe_abi : ident = ident { repr: 23, ctxt: 0}; + pub static clownshoe_stack_shim : ident = ident { repr: 24, ctxt: 0}; + pub static tydesc : ident = ident { repr: 25, ctxt: 0}; + pub static main : ident = ident { repr: 26, ctxt: 0}; + pub static opaque : ident = ident { repr: 27, ctxt: 0}; + pub static blk : ident = ident { repr: 28, ctxt: 0}; + pub static static : ident = ident { repr: 29, ctxt: 0}; + pub static intrinsic : ident = ident { repr: 30, ctxt: 0}; + pub static clownshoes_foreign_mod: ident = ident { repr: 31, ctxt: 0}; + pub static unnamed_field: ident = ident { repr: 32, ctxt: 0}; + pub static c_abi: ident = ident { repr: 33, ctxt: 0}; + pub static type_self: ident = ident { repr: 34, ctxt: 0}; // `Self` } pub struct StringRef<'self>(&'self str); @@ -426,41 +423,39 @@ pub fn mk_fresh_ident_interner() -> @ident_interner { let init_vec = ~[ @~"_", // 0 @~"anon", // 1 - @~"drop", // 2 - @~"", // 3 - @~"unary", // 4 - @~"!", // 5 - @~"[]", // 6 - @~"unary-", // 7 - @~"__extensions__", // 8 - @~"self", // 9 - @~"item", // 10 - @~"block", // 11 - @~"stmt", // 12 - @~"pat", // 13 - @~"expr", // 14 - @~"ty", // 15 - @~"ident", // 16 - @~"path", // 17 - @~"tt", // 18 - @~"matchers", // 19 - @~"str", // 20 - @~"TyVisitor", // 21 - @~"arg", // 22 - @~"descrim", // 23 - @~"__rust_abi", // 24 - @~"__rust_stack_shim", // 25 - @~"TyDesc", // 26 - @~"dtor", // 27 - @~"main", // 28 - @~"<opaque>", // 29 - @~"blk", // 30 - @~"static", // 31 - @~"intrinsic", // 32 - @~"__foreign_mod__", // 33 - @~"__field__", // 34 - @~"C", // 35 - @~"Self", // 36 + @~"", // 2 + @~"unary", // 3 + @~"!", // 4 + @~"[]", // 5 + @~"unary-", // 6 + @~"__extensions__", // 7 + @~"self", // 8 + @~"item", // 9 + @~"block", // 10 + @~"stmt", // 11 + @~"pat", // 12 + @~"expr", // 13 + @~"ty", // 14 + @~"ident", // 15 + @~"path", // 16 + @~"tt", // 17 + @~"matchers", // 18 + @~"str", // 19 + @~"TyVisitor", // 20 + @~"arg", // 21 + @~"descrim", // 22 + @~"__rust_abi", // 23 + @~"__rust_stack_shim", // 24 + @~"TyDesc", // 25 + @~"main", // 26 + @~"<opaque>", // 27 + @~"blk", // 28 + @~"static", // 29 + @~"intrinsic", // 30 + @~"__foreign_mod__", // 31 + @~"__field__", // 32 + @~"C", // 33 + @~"Self", // 34 ]; let rv = @ident_interner { |
