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
This commit is contained in:
parent
28da4ecdaa
commit
7f2c399f3a
src
librustc/middle
libsyntax
@ -164,7 +164,7 @@ fn reserve_id_range(sess: Session,
|
||||
let to_id_min = sess.parse_sess.next_id;
|
||||
let to_id_max = sess.parse_sess.next_id + cnt;
|
||||
sess.parse_sess.next_id = to_id_max;
|
||||
return {min: to_id_min, max: to_id_min};
|
||||
ast_util::id_range { min: to_id_min, max: to_id_min }
|
||||
}
|
||||
|
||||
impl extended_decode_ctxt {
|
||||
|
@ -108,8 +108,12 @@ enum ast_node {
|
||||
}
|
||||
|
||||
type map = std::map::HashMap<node_id, ast_node>;
|
||||
type ctx = {map: map, mut path: path,
|
||||
mut local_id: uint, diag: span_handler};
|
||||
struct ctx {
|
||||
map: map,
|
||||
mut path: path,
|
||||
mut local_id: uint,
|
||||
diag: span_handler,
|
||||
}
|
||||
type vt = visit::vt<ctx>;
|
||||
|
||||
fn extend(cx: ctx, +elt: ident) -> @path {
|
||||
@ -131,12 +135,14 @@ fn mk_ast_map_visitor() -> vt {
|
||||
}
|
||||
|
||||
fn map_crate(diag: span_handler, c: crate) -> map {
|
||||
let cx = {map: std::map::HashMap(),
|
||||
mut path: ~[],
|
||||
mut local_id: 0u,
|
||||
diag: diag};
|
||||
let cx = ctx {
|
||||
map: std::map::HashMap(),
|
||||
mut path: ~[],
|
||||
mut local_id: 0u,
|
||||
diag: diag,
|
||||
};
|
||||
visit::visit_crate(c, cx, mk_ast_map_visitor());
|
||||
return cx.map;
|
||||
cx.map
|
||||
}
|
||||
|
||||
// Used for items loaded from external crate that are being inlined into this
|
||||
@ -150,10 +156,12 @@ fn map_decoded_item(diag: span_handler,
|
||||
// alias analysis, which we will not be running on the inlined items, and
|
||||
// even if we did I think it only needs an ordering between local
|
||||
// variables that are simultaneously in scope).
|
||||
let cx = {map: map,
|
||||
mut path: /* FIXME (#2543) */ copy path,
|
||||
mut local_id: 0u,
|
||||
diag: diag};
|
||||
let cx = ctx {
|
||||
map: map,
|
||||
mut path: /* FIXME (#2543) */ copy path,
|
||||
mut local_id: 0u,
|
||||
diag: diag,
|
||||
};
|
||||
let v = mk_ast_map_visitor();
|
||||
|
||||
// methods get added to the AST map when their impl is visited. Since we
|
||||
|
@ -455,7 +455,10 @@ fn dtor_dec() -> fn_decl {
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type id_range = {min: node_id, max: node_id};
|
||||
struct id_range {
|
||||
min: node_id,
|
||||
max: node_id,
|
||||
}
|
||||
|
||||
fn empty(range: id_range) -> bool {
|
||||
range.min >= range.max
|
||||
@ -596,7 +599,7 @@ fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
|
||||
*min = int::min(*min, id);
|
||||
*max = int::max(*max, id + 1);
|
||||
}
|
||||
return {min:*min, max:*max};
|
||||
id_range { min: *min, max: *max }
|
||||
}
|
||||
|
||||
fn compute_id_range_for_inlined_item(item: inlined_item) -> id_range {
|
||||
|
@ -57,15 +57,15 @@ trait handler {
|
||||
fn emit(cmsp: Option<(@codemap::CodeMap, span)>, msg: &str, lvl: level);
|
||||
}
|
||||
|
||||
type handler_t = @{
|
||||
struct handler_t {
|
||||
mut err_count: uint,
|
||||
emit: emitter
|
||||
};
|
||||
emit: emitter,
|
||||
}
|
||||
|
||||
type codemap_t = @{
|
||||
struct codemap_t {
|
||||
handler: handler,
|
||||
cm: @codemap::CodeMap
|
||||
};
|
||||
cm: @codemap::CodeMap,
|
||||
}
|
||||
|
||||
impl codemap_t: span_handler {
|
||||
fn span_fatal(sp: span, msg: &str) -> ! {
|
||||
@ -138,7 +138,7 @@ fn ice_msg(msg: &str) -> ~str {
|
||||
}
|
||||
|
||||
fn mk_span_handler(handler: handler, cm: @codemap::CodeMap) -> span_handler {
|
||||
@{ handler: handler, cm: cm } as span_handler
|
||||
@codemap_t { handler: handler, cm: cm } as span_handler
|
||||
}
|
||||
|
||||
fn mk_handler(emitter: Option<emitter>) -> handler {
|
||||
@ -154,12 +154,7 @@ fn mk_handler(emitter: Option<emitter>) -> handler {
|
||||
}
|
||||
};
|
||||
|
||||
let x: handler_t = @{
|
||||
mut err_count: 0,
|
||||
emit: emit
|
||||
};
|
||||
|
||||
x as handler
|
||||
@handler_t { mut err_count: 0, emit: emit } as handler
|
||||
}
|
||||
|
||||
enum level {
|
||||
|
@ -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)`
|
||||
|
@ -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",
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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 => {
|
||||
// -> !
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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>>(
|
||||
|
@ -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),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user