Remove some needlessly repetetive casts in metadata code
This commit is contained in:
parent
6c9d95a9a0
commit
72591496b0
@ -79,9 +79,9 @@ fn lookup_item(item_id: int, data: @[u8]) -> ebml::doc {
|
||||
ret find_item(item_id, items);
|
||||
}
|
||||
|
||||
fn item_family(item: ebml::doc) -> u8 {
|
||||
fn item_family(item: ebml::doc) -> char {
|
||||
let fam = ebml::get_doc(item, tag_items_data_item_family);
|
||||
ret ebml::doc_as_u8(fam);
|
||||
ebml::doc_as_u8(fam) as char
|
||||
}
|
||||
|
||||
fn item_symbol(item: ebml::doc) -> str {
|
||||
@ -218,24 +218,22 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
|
||||
let fam_ch = item_family(item);
|
||||
let did = {crate: cnum, node: did_.node};
|
||||
// We treat references to enums as references to types.
|
||||
let def =
|
||||
alt fam_ch as char {
|
||||
'c' { ast::def_const(did) }
|
||||
'u' { ast::def_fn(did, ast::unsafe_fn) }
|
||||
'f' { ast::def_fn(did, ast::impure_fn) }
|
||||
'p' { ast::def_fn(did, ast::pure_fn) }
|
||||
'y' { ast::def_ty(did) }
|
||||
't' { ast::def_ty(did) }
|
||||
'm' { ast::def_mod(did) }
|
||||
'n' { ast::def_native_mod(did) }
|
||||
'v' {
|
||||
let tid = variant_enum_id(item);
|
||||
tid = {crate: cnum, node: tid.node};
|
||||
ast::def_variant(tid, did)
|
||||
}
|
||||
'I' { ast::def_ty(did) }
|
||||
};
|
||||
ret def;
|
||||
alt fam_ch {
|
||||
'c' { ast::def_const(did) }
|
||||
'u' { ast::def_fn(did, ast::unsafe_fn) }
|
||||
'f' { ast::def_fn(did, ast::impure_fn) }
|
||||
'p' { ast::def_fn(did, ast::pure_fn) }
|
||||
'y' { ast::def_ty(did) }
|
||||
't' { ast::def_ty(did) }
|
||||
'm' { ast::def_mod(did) }
|
||||
'n' { ast::def_native_mod(did) }
|
||||
'v' {
|
||||
let tid = variant_enum_id(item);
|
||||
tid = {crate: cnum, node: tid.node};
|
||||
ast::def_variant(tid, did)
|
||||
}
|
||||
'I' { ast::def_ty(did) }
|
||||
}
|
||||
}
|
||||
|
||||
fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
||||
@ -338,7 +336,7 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
||||
_ { tcx.sess.bug("get_iface_methods: id has non-function type");
|
||||
} };
|
||||
result += [{ident: name, tps: bounds, fty: fty,
|
||||
purity: alt item_family(mth) as char {
|
||||
purity: alt item_family(mth) {
|
||||
'u' { ast::unsafe_fn }
|
||||
'f' { ast::impure_fn }
|
||||
'p' { ast::pure_fn }
|
||||
@ -347,15 +345,15 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
|
||||
@result
|
||||
}
|
||||
|
||||
fn family_has_type_params(fam_ch: u8) -> bool {
|
||||
alt fam_ch as char {
|
||||
fn family_has_type_params(fam_ch: char) -> bool {
|
||||
alt fam_ch {
|
||||
'c' | 'T' | 'm' | 'n' { false }
|
||||
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' { true }
|
||||
}
|
||||
}
|
||||
|
||||
fn family_names_type(fam_ch: u8) -> bool {
|
||||
alt fam_ch as char { 'y' | 't' | 'I' { true } _ { false } }
|
||||
fn family_names_type(fam_ch: char) -> bool {
|
||||
alt fam_ch { 'y' | 't' | 'I' { true } _ { false } }
|
||||
}
|
||||
|
||||
fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
|
||||
@ -371,8 +369,8 @@ fn describe_def(items: ebml::doc, id: ast::def_id) -> str {
|
||||
ret item_family_to_str(item_family(find_item(id.node, items)));
|
||||
}
|
||||
|
||||
fn item_family_to_str(fam: u8) -> str {
|
||||
alt fam as char {
|
||||
fn item_family_to_str(fam: char) -> str {
|
||||
alt fam {
|
||||
'c' { ret "const"; }
|
||||
'f' { ret "fn"; }
|
||||
'u' { ret "unsafe fn"; }
|
||||
|
@ -168,9 +168,9 @@ fn encode_reexport_paths(ebml_w: ebml::writer,
|
||||
|
||||
|
||||
// Item info table encoding
|
||||
fn encode_family(ebml_w: ebml::writer, c: u8) {
|
||||
fn encode_family(ebml_w: ebml::writer, c: char) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_family);
|
||||
ebml_w.writer.write([c]);
|
||||
ebml_w.writer.write([c as u8]);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
||||
index += [{val: variant.node.id, pos: ebml_w.writer.tell()}];
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(variant.node.id));
|
||||
encode_family(ebml_w, 'v' as u8);
|
||||
encode_family(ebml_w, 'v');
|
||||
encode_name(ebml_w, variant.node.name);
|
||||
encode_enum_id(ebml_w, local_def(id));
|
||||
encode_type(ecx, ebml_w,
|
||||
@ -292,7 +292,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
|
||||
id: node_id, path: ast_map::path, name: ident) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
encode_family(ebml_w, 'm' as u8);
|
||||
encode_family(ebml_w, 'm');
|
||||
encode_name(ebml_w, name);
|
||||
alt ecx.ccx.impl_map.get(id) {
|
||||
list::cons(impls, @list::nil) {
|
||||
@ -322,7 +322,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_const(_, _) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, 'c' as u8);
|
||||
encode_family(ebml_w, 'c');
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
||||
encode_symbol(ecx, ebml_w, item.id);
|
||||
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
||||
@ -331,7 +331,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_fn(decl, tps, _) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, purity_fn_family(decl.purity) as u8);
|
||||
encode_family(ebml_w, purity_fn_family(decl.purity));
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
||||
encode_symbol(ecx, ebml_w, item.id);
|
||||
@ -344,7 +344,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_native_mod(_) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, 'n' as u8);
|
||||
encode_family(ebml_w, 'n');
|
||||
encode_name(ebml_w, item.ident);
|
||||
encode_path(ebml_w, path, ast_map::path_name(item.ident));
|
||||
ebml::end_tag(ebml_w);
|
||||
@ -352,7 +352,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_ty(_, tps) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, 'y' as u8);
|
||||
encode_family(ebml_w, 'y');
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
||||
encode_name(ebml_w, item.ident);
|
||||
@ -362,7 +362,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_enum(variants, tps) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, 't' as u8);
|
||||
encode_family(ebml_w, 't');
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
||||
encode_name(ebml_w, item.ident);
|
||||
@ -382,7 +382,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
encode_family(ebml_w, 'y' as u8);
|
||||
encode_family(ebml_w, 'y');
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, ty::ty_fn_ret(fn_ty));
|
||||
encode_name(ebml_w, item.ident);
|
||||
@ -393,7 +393,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
index += [{val: ctor_id, pos: ebml_w.writer.tell()}];
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
encode_family(ebml_w, 'f' as u8);
|
||||
encode_family(ebml_w, 'f');
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, fn_ty);
|
||||
encode_symbol(ecx, ebml_w, ctor_id);
|
||||
@ -403,7 +403,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_impl(tps, ifce, _, methods) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, 'i' as u8);
|
||||
encode_family(ebml_w, 'i');
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
||||
encode_name(ebml_w, item.ident);
|
||||
@ -430,7 +430,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
index += [{val: m.id, pos: ebml_w.writer.tell()}];
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(m.id));
|
||||
encode_family(ebml_w, purity_fn_family(m.decl.purity) as u8);
|
||||
encode_family(ebml_w, purity_fn_family(m.decl.purity));
|
||||
encode_type_param_bounds(ebml_w, ecx, tps + m.tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, m.id));
|
||||
encode_name(ebml_w, m.ident);
|
||||
@ -442,7 +442,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
item_iface(tps, ms) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_family(ebml_w, 'I' as u8);
|
||||
encode_family(ebml_w, 'I');
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
|
||||
encode_name(ebml_w, item.ident);
|
||||
@ -452,7 +452,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||
encode_name(ebml_w, mty.ident);
|
||||
encode_type_param_bounds(ebml_w, ecx, ms[i].tps);
|
||||
encode_type(ecx, ebml_w, ty::mk_fn(tcx, mty.fty));
|
||||
encode_family(ebml_w, purity_fn_family(mty.purity) as u8);
|
||||
encode_family(ebml_w, purity_fn_family(mty.purity));
|
||||
ebml::end_tag(ebml_w);
|
||||
i += 1u;
|
||||
}
|
||||
@ -467,13 +467,8 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
alt nitem.node {
|
||||
native_item_fn(fn_decl, tps) {
|
||||
let letter = alt fn_decl.purity {
|
||||
unsafe_fn { 'u' }
|
||||
pure_fn { 'p' } // this is currently impossible, but hey.
|
||||
impure_fn { 'f' }
|
||||
} as u8;
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_family(ebml_w, letter);
|
||||
encode_family(ebml_w, purity_fn_family(fn_decl.purity));
|
||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_type(ecx.ccx.tcx, nitem.id));
|
||||
encode_symbol(ecx, ebml_w, nitem.id);
|
||||
|
@ -18,16 +18,22 @@
|
||||
|
||||
type pstate = {data: @[u8], crate: int, mutable pos: uint, tcx: ty::ctxt};
|
||||
|
||||
fn peek(st: @pstate) -> u8 {
|
||||
st.data[st.pos]
|
||||
fn peek(st: @pstate) -> char {
|
||||
st.data[st.pos] as char
|
||||
}
|
||||
|
||||
fn next(st: @pstate) -> u8 {
|
||||
let ch = st.data[st.pos];
|
||||
fn next(st: @pstate) -> char {
|
||||
let ch = st.data[st.pos] as char;
|
||||
st.pos = st.pos + 1u;
|
||||
ret ch;
|
||||
}
|
||||
|
||||
fn next_byte(st: @pstate) -> u8 {
|
||||
let b = st.data[st.pos];
|
||||
st.pos = st.pos + 1u;
|
||||
ret b;
|
||||
}
|
||||
|
||||
fn parse_ident(st: @pstate, last: char) -> ast::ident {
|
||||
fn is_last(b: char, c: char) -> bool { ret c == b; }
|
||||
ret parse_ident_(st, bind is_last(last, _));
|
||||
@ -36,8 +42,8 @@ fn parse_ident(st: @pstate, last: char) -> ast::ident {
|
||||
fn parse_ident_(st: @pstate, is_last: fn@(char) -> bool) ->
|
||||
ast::ident {
|
||||
let rslt = "";
|
||||
while !is_last(peek(st) as char) {
|
||||
rslt += str::from_byte(next(st));
|
||||
while !is_last(peek(st)) {
|
||||
rslt += str::from_byte(next_byte(st));
|
||||
}
|
||||
ret rslt;
|
||||
}
|
||||
@ -50,7 +56,7 @@ fn parse_ty_data(data: @[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
|
||||
}
|
||||
|
||||
fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) {
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
'!' { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) }
|
||||
_ { (ast::return_val, parse_ty(st, conv)) }
|
||||
}
|
||||
@ -58,12 +64,12 @@ fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) {
|
||||
|
||||
fn parse_constrs(st: @pstate, conv: conv_did) -> [@ty::constr] {
|
||||
let rslt: [@ty::constr] = [];
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
':' {
|
||||
do {
|
||||
next(st);
|
||||
rslt += [parse_constr(st, conv, parse_constr_arg)];
|
||||
} while peek(st) as char == ';'
|
||||
} while peek(st) == ';'
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
@ -73,12 +79,12 @@ fn parse_constrs(st: @pstate, conv: conv_did) -> [@ty::constr] {
|
||||
// FIXME less copy-and-paste
|
||||
fn parse_ty_constrs(st: @pstate, conv: conv_did) -> [@ty::type_constr] {
|
||||
let rslt: [@ty::type_constr] = [];
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
':' {
|
||||
do {
|
||||
next(st);
|
||||
rslt += [parse_constr(st, conv, parse_ty_constr_arg)];
|
||||
} while peek(st) as char == ';'
|
||||
} while peek(st) == ';'
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
@ -90,7 +96,7 @@ fn parse_path(st: @pstate) -> @ast::path {
|
||||
fn is_last(c: char) -> bool { ret c == '(' || c == ':'; }
|
||||
idents += [parse_ident_(st, is_last)];
|
||||
while true {
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
':' { next(st); next(st); }
|
||||
c {
|
||||
if c == '(' {
|
||||
@ -104,7 +110,7 @@ fn parse_path(st: @pstate) -> @ast::path {
|
||||
}
|
||||
|
||||
fn parse_constr_arg(st: @pstate) -> ast::fn_constr_arg {
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
'*' { st.pos += 1u; ret ast::carg_base; }
|
||||
c {
|
||||
|
||||
@ -129,7 +135,7 @@ fn parse_constr_arg(st: @pstate) -> ast::fn_constr_arg {
|
||||
}
|
||||
|
||||
fn parse_ty_constr_arg(st: @pstate) -> ast::constr_arg_general_<@path> {
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
'*' { st.pos += 1u; ret ast::carg_base; }
|
||||
c { ret ast::carg_ident(parse_path(st)); }
|
||||
}
|
||||
@ -141,7 +147,7 @@ fn parse_constr<T: copy>(st: @pstate, conv: conv_did,
|
||||
let sp = ast_util::dummy_sp(); // FIXME: use a real span
|
||||
let args: [@sp_constr_arg<T>] = [];
|
||||
let pth = parse_path(st);
|
||||
let ignore: char = next(st) as char;
|
||||
let ignore: char = next(st);
|
||||
assert (ignore == '(');
|
||||
let def = parse_def(st, conv);
|
||||
let an_arg: constr_arg_general_<T>;
|
||||
@ -149,7 +155,7 @@ fn parse_constr<T: copy>(st: @pstate, conv: conv_did,
|
||||
an_arg = pser(st);
|
||||
// FIXME use a real span
|
||||
args += [@respan(sp, an_arg)];
|
||||
ignore = next(st) as char;
|
||||
ignore = next(st);
|
||||
} while ignore == ';'
|
||||
assert (ignore == ')');
|
||||
ret @respan(sp, {path: pth, args: args, id: def});
|
||||
@ -171,7 +177,7 @@ fn parse_proto(c: char) -> ast::proto {
|
||||
}
|
||||
|
||||
fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
alt next(st) as char {
|
||||
alt next(st) {
|
||||
'n' { ret ty::mk_nil(st.tcx); }
|
||||
'z' { ret ty::mk_bot(st.tcx); }
|
||||
'b' { ret ty::mk_bool(st.tcx); }
|
||||
@ -179,7 +185,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
'u' { ret ty::mk_uint(st.tcx); }
|
||||
'l' { ret ty::mk_float(st.tcx); }
|
||||
'M' {
|
||||
alt next(st) as char {
|
||||
alt next(st) {
|
||||
'b' { ret ty::mk_mach_uint(st.tcx, ast::ty_u8); }
|
||||
'w' { ret ty::mk_mach_uint(st.tcx, ast::ty_u16); }
|
||||
'l' { ret ty::mk_mach_uint(st.tcx, ast::ty_u32); }
|
||||
@ -195,18 +201,18 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
'c' { ret ty::mk_char(st.tcx); }
|
||||
'S' { ret ty::mk_str(st.tcx); }
|
||||
't' {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let def = parse_def(st, conv);
|
||||
let params: [ty::t] = [];
|
||||
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
|
||||
while peek(st) != ']' { params += [parse_ty(st, conv)]; }
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty::mk_enum(st.tcx, def, params);
|
||||
}
|
||||
'x' {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let def = parse_def(st, conv);
|
||||
let params: [ty::t] = [];
|
||||
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
|
||||
while peek(st) != ']' { params += [parse_ty(st, conv)]; }
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty::mk_iface(st.tcx, def, params);
|
||||
}
|
||||
@ -215,9 +221,9 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
ret ty::mk_param(st.tcx, parse_int(st) as uint, did);
|
||||
}
|
||||
's' {
|
||||
assert next(st) as char == '[';
|
||||
assert next(st) == '[';
|
||||
let params = [];
|
||||
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
|
||||
while peek(st) != ']' { params += [parse_ty(st, conv)]; }
|
||||
st.pos += 1u;
|
||||
ret ty::mk_self(st.tcx, params);
|
||||
}
|
||||
@ -226,12 +232,12 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
'*' { ret ty::mk_ptr(st.tcx, parse_mt(st, conv)); }
|
||||
'I' { ret ty::mk_vec(st.tcx, parse_mt(st, conv)); }
|
||||
'R' {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let fields: [ty::field] = [];
|
||||
while peek(st) as char != ']' {
|
||||
while peek(st) != ']' {
|
||||
let name = "";
|
||||
while peek(st) as char != '=' {
|
||||
name += str::from_byte(next(st));
|
||||
while peek(st) != '=' {
|
||||
name += str::from_byte(next_byte(st));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
fields += [{ident: name, mt: parse_mt(st, conv)}];
|
||||
@ -240,22 +246,22 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
ret ty::mk_rec(st.tcx, fields);
|
||||
}
|
||||
'T' {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let params = [];
|
||||
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
|
||||
while peek(st) != ']' { params += [parse_ty(st, conv)]; }
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty::mk_tup(st.tcx, params);
|
||||
}
|
||||
'f' {
|
||||
let proto = parse_proto(next(st) as char);
|
||||
let proto = parse_proto(next(st));
|
||||
parse_ty_rust_fn(st, conv, proto)
|
||||
}
|
||||
'r' {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let def = parse_def(st, conv);
|
||||
let inner = parse_ty(st, conv);
|
||||
let params: [ty::t] = [];
|
||||
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
|
||||
while peek(st) != ']' { params += [parse_ty(st, conv)]; }
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty::mk_res(st.tcx, def, inner, params);
|
||||
}
|
||||
@ -263,7 +269,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
'Y' { ret ty::mk_type(st.tcx); }
|
||||
'y' { ret ty::mk_send_type(st.tcx); }
|
||||
'C' {
|
||||
let ck = alt next(st) as char {
|
||||
let ck = alt next(st) {
|
||||
'&' { ty::ck_block }
|
||||
'@' { ty::ck_box }
|
||||
'~' { ty::ck_uniq }
|
||||
@ -272,9 +278,9 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
}
|
||||
'#' {
|
||||
let pos = parse_hex(st);
|
||||
assert (next(st) as char == ':');
|
||||
assert (next(st) == ':');
|
||||
let len = parse_hex(st);
|
||||
assert (next(st) as char == '#');
|
||||
assert (next(st) == '#');
|
||||
alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
|
||||
some(tt) { ret tt; }
|
||||
none {
|
||||
@ -286,10 +292,10 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
}
|
||||
}
|
||||
'A' {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let tt = parse_ty(st, conv);
|
||||
let tcs = parse_ty_constrs(st, conv);
|
||||
assert (next(st) as char == ']');
|
||||
assert (next(st) == ']');
|
||||
ret ty::mk_constr(st.tcx, tt, tcs);
|
||||
}
|
||||
'"' {
|
||||
@ -304,7 +310,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
|
||||
|
||||
fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
|
||||
let m;
|
||||
alt peek(st) as char {
|
||||
alt peek(st) {
|
||||
'm' { next(st); m = ast::mut; }
|
||||
'?' { next(st); m = ast::maybe_mut; }
|
||||
_ { m = ast::imm; }
|
||||
@ -314,7 +320,7 @@ fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
|
||||
|
||||
fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id {
|
||||
let def = [];
|
||||
while peek(st) as char != '|' { def += [next(st)]; }
|
||||
while peek(st) != '|' { def += [next_byte(st)]; }
|
||||
st.pos = st.pos + 1u;
|
||||
ret conv(parse_def_id(def));
|
||||
}
|
||||
@ -322,7 +328,7 @@ fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id {
|
||||
fn parse_int(st: @pstate) -> int {
|
||||
let n = 0;
|
||||
while true {
|
||||
let cur = peek(st) as char;
|
||||
let cur = peek(st);
|
||||
if cur < '0' || cur > '9' { break; }
|
||||
st.pos = st.pos + 1u;
|
||||
n *= 10;
|
||||
@ -334,7 +340,7 @@ fn parse_int(st: @pstate) -> int {
|
||||
fn parse_hex(st: @pstate) -> uint {
|
||||
let n = 0u;
|
||||
while true {
|
||||
let cur = peek(st) as char;
|
||||
let cur = peek(st);
|
||||
if (cur < '0' || cur > '9') && (cur < 'a' || cur > 'f') { break; }
|
||||
st.pos = st.pos + 1u;
|
||||
n *= 16u;
|
||||
@ -346,10 +352,10 @@ fn parse_hex(st: @pstate) -> uint {
|
||||
}
|
||||
|
||||
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
|
||||
assert (next(st) as char == '[');
|
||||
assert (next(st) == '[');
|
||||
let inputs: [ty::arg] = [];
|
||||
while peek(st) as char != ']' {
|
||||
let mode = alt peek(st) as char {
|
||||
while peek(st) != ']' {
|
||||
let mode = alt peek(st) {
|
||||
'&' { ast::by_mut_ref }
|
||||
'-' { ast::by_move }
|
||||
'+' { ast::by_copy }
|
||||
@ -399,7 +405,7 @@ fn parse_bounds_data(data: @[u8], start: uint,
|
||||
fn parse_bounds(st: @pstate, conv: conv_did) -> @[ty::param_bound] {
|
||||
let bounds = [];
|
||||
while true {
|
||||
bounds += [alt next(st) as char {
|
||||
bounds += [alt next(st) {
|
||||
'S' { ty::bound_send }
|
||||
'C' { ty::bound_copy }
|
||||
'I' { ty::bound_iface(parse_ty(st, conv)) }
|
||||
|
Loading…
Reference in New Issue
Block a user