diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-01-17 08:55:28 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-01-20 14:08:18 -0800 |
| commit | 7f2c399f3a21400cc61d3ad235c433d610615237 (patch) | |
| tree | 9bf7b4a5ec6e549a7b1ddc1c29596f980c0a2770 /src/libsyntax/ext | |
| parent | 28da4ecdaab66244e6bb5155489de8e0aa0f30dd (diff) | |
| download | rust-7f2c399f3a21400cc61d3ad235c433d610615237.tar.gz rust-7f2c399f3a21400cc61d3ad235c433d610615237.zip | |
Convert many libsyntax records into structs
Specifically:
ast_map::ctx
ast_util::id_range
diagnostic::{handler_t,codemap_t}
auto_encode::field
ext::base::{macro_def,syntax_expander_tt,syntax_expander_tt_item}
ext::pipes::proto::next_state
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/check.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/parse_proto.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/pipec.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 9 |
8 files changed, 50 insertions, 26 deletions
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 9578a2f6317..1354b816a00 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -46,7 +46,7 @@ references other non-built-in types. A type definition like: #[auto_encode] #[auto_decode] - type spanned<T> = {node: T, span: span}; + struct spanned<T> {node: T, span: span} would yield functions like: @@ -810,11 +810,15 @@ fn mk_struct_deser_impl( // Records and structs don't have the same fields types, but they share enough // that if we extract the right subfields out we can share the code // generator code. -type field = { span: span, ident: ast::ident, mutbl: ast::mutability }; +struct field { + span: span, + ident: ast::ident, + mutbl: ast::mutability, +} fn mk_rec_fields(fields: ~[ast::ty_field]) -> ~[field] { do fields.map |field| { - { + field { span: field.span, ident: field.node.ident, mutbl: field.node.mt.mutbl, @@ -830,7 +834,7 @@ fn mk_struct_fields(fields: ~[@ast::struct_field]) -> ~[field] { unnamed fields", }; - { + field { span: field.span, ident: ident, mutbl: match mutbl { @@ -886,7 +890,7 @@ fn mk_ser_fields( fn mk_deser_fields( cx: ext_ctxt, span: span, - fields: ~[{ span: span, ident: ast::ident, mutbl: ast::mutability }] + fields: ~[field] ) -> ~[ast::field] { do fields.mapi |idx, field| { // ast for `|| std::serialize::decode(__d)` diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 7b69084a827..dab57dd0ad4 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -32,17 +32,27 @@ use std::map::HashMap; // is now probably a redundant AST node, can be merged with // ast::mac_invoc_tt. -type macro_def = {name: ~str, ext: syntax_extension}; +struct macro_def { + name: ~str, + ext: syntax_extension, +} type item_decorator = fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item]; -type syntax_expander_tt = {expander: syntax_expander_tt_, span: Option<span>}; +struct syntax_expander_tt { + expander: syntax_expander_tt_, + span: Option<span>, +} + type syntax_expander_tt_ = fn@(ext_ctxt, span, ~[ast::token_tree]) -> mac_result; -type syntax_expander_tt_item - = {expander: syntax_expander_tt_item_, span: Option<span>}; +struct syntax_expander_tt_item { + expander: syntax_expander_tt_item_, + span: Option<span>, +} + type syntax_expander_tt_item_ = fn@(ext_ctxt, span, ast::ident, ~[ast::token_tree]) -> mac_result; @@ -70,10 +80,10 @@ enum syntax_extension { // AST nodes into full ASTs fn syntax_expander_table() -> HashMap<~str, syntax_extension> { fn builtin_normal_tt(f: syntax_expander_tt_) -> syntax_extension { - normal_tt({expander: f, span: None}) + normal_tt(syntax_expander_tt {expander: f, span: None}) } fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension { - item_tt({expander: f, span: None}) + item_tt(syntax_expander_tt_item {expander: f, span: None}) } let syntax_expanders = HashMap(); syntax_expanders.insert(~"macro_rules", diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index eb571b99b4e..4b096f07b75 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -46,7 +46,9 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)) } - Some(normal_tt({expander: exp, span: exp_sp})) => { + Some(normal_tt( + syntax_expander_tt { expander: exp, span: exp_sp } + )) => { cx.bt_push(ExpandedFrom({call_site: s, callie: {name: *extname, span: exp_sp}})); @@ -231,7 +233,9 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt, None => cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)), - Some(normal_tt({expander: exp, span: exp_sp})) => { + Some(normal_tt( + syntax_expander_tt { expander: exp, span: exp_sp } + )) => { cx.bt_push(ExpandedFrom( {call_site: sp, callie: {name: *extname, span: exp_sp}})); let expanded = match exp(cx, mac.span, tts) { diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index f2ba413dd38..95d3308dd2f 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -52,9 +52,9 @@ impl ext_ctxt: proto::visitor<(), (), ()> { } fn visit_message(name: ~str, _span: span, _tys: &[@ast::Ty], - this: state, next: next_state) { + this: state, next: Option<next_state>) { match next { - Some({state: ref next, tys: next_tys}) => { + Some(next_state { state: ref next, tys: next_tys }) => { let proto = this.proto; if !proto.has_state((*next)) { // This should be a span fatal, but then we need to diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index 6a6e895bd40..e87a044fa01 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -88,7 +88,7 @@ impl parser::Parser: proto_parser { |p| p.parse_ty(false)) } else { ~[] }; - Some({state: name, tys: ntys}) + Some(next_state {state: name, tys: ntys}) } token::NOT => { // -> ! diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 306df24e79f..6c12736b7ea 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -49,7 +49,7 @@ impl message: gen_send { debug!("pipec: gen_send"); match self { message(ref _id, span, tys, this, - Some({state: ref next, tys: next_tys})) => { + Some(next_state {state: ref next, tys: next_tys})) => { debug!("pipec: next state exists"); let next = this.proto.get_state((*next)); assert next_tys.len() == next.ty_params.len(); @@ -217,7 +217,7 @@ impl state: to_type_decls { let message(name, span, tys, this, next) = *m; let tys = match next { - Some({state: ref next, tys: next_tys}) => { + Some(next_state { state: ref next, tys: next_tys }) => { let next = this.proto.get_state((*next)); let next_name = cx.str_of(next.data_name()); diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 9953b4de50d..26638cd8cd6 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -51,11 +51,14 @@ impl direction { } } -type next_state = Option<{state: ~str, tys: ~[@ast::Ty]}>; +struct next_state { + state: ~str, + tys: ~[@ast::Ty], +} enum message { // name, span, data, current state, next state - message(~str, span, ~[@ast::Ty], state, next_state) + message(~str, span, ~[@ast::Ty], state, Option<next_state>) } impl message { @@ -94,7 +97,7 @@ enum state { impl state { fn add_message(name: ~str, span: span, - +data: ~[@ast::Ty], next: next_state) { + +data: ~[@ast::Ty], next: Option<next_state>) { self.messages.push(message(name, span, data, self, next)); } @@ -119,7 +122,7 @@ impl state { fn reachable(f: fn(state) -> bool) { for self.messages.each |m| { match *m { - message(_, _, _, _, Some({state: ref id, _})) => { + message(_, _, _, _, Some(next_state { state: ref id, _ })) => { let state = self.proto.get_state((*id)); if !f(state) { break } } @@ -217,7 +220,7 @@ trait visitor<Tproto, Tstate, Tmessage> { fn visit_proto(proto: protocol, st: &[Tstate]) -> Tproto; fn visit_state(state: state, m: &[Tmessage]) -> Tstate; fn visit_message(name: ~str, spane: span, tys: &[@ast::Ty], - this: state, next: next_state) -> Tmessage; + this: state, next: Option<next_state>) -> Tmessage; } fn visit<Tproto, Tstate, Tmessage, V: visitor<Tproto, Tstate, Tmessage>>( diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index d68e5a34fbc..4ee9ddf48c8 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -139,8 +139,11 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, let exp: @fn(ext_ctxt, span, ~[ast::token_tree]) -> mac_result = |cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses); - return mr_def({ + mr_def(base::macro_def { name: *cx.parse_sess().interner.get(name), - ext: normal_tt({expander: exp, span: Some(sp)}) - }); + ext: normal_tt(base::syntax_expander_tt { + expander: exp, + span: Some(sp), + }) + }) } |
