Handle built-in typenames in the resolve pass, rather than in parser
Closes #1728 Comments out a section of debuginfo.rs. This code was already broken (only being called when --xg was passed, and only working on trivial programs).
This commit is contained in:
parent
8673c4f195
commit
a08e589390
10 changed files with 188 additions and 168 deletions
|
@ -377,8 +377,9 @@ fn mk_test_wrapper(cx: test_ctxt,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_main(cx: test_ctxt) -> @ast::item {
|
fn mk_main(cx: test_ctxt) -> @ast::item {
|
||||||
|
let str_pt = @nospan({global: false, idents: ["str"], types: []});
|
||||||
let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};
|
let str_ty = @nospan(ast::ty_path(str_pt, cx.sess.next_node_id()));
|
||||||
|
let args_mt: ast::mt = {ty: str_ty, mut: ast::imm};
|
||||||
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
|
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
|
||||||
|
|
||||||
let args_arg: ast::arg =
|
let args_arg: ast::arg =
|
||||||
|
|
|
@ -230,8 +230,8 @@ fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
|
||||||
let cx = cx;
|
let cx = cx;
|
||||||
while option::is_none(cx.block_span) {
|
while option::is_none(cx.block_span) {
|
||||||
alt cx.parent {
|
alt cx.parent {
|
||||||
parent_none { fail "BAD"; /*break;*/ }
|
|
||||||
parent_some(b) { cx = b; }
|
parent_some(b) { cx = b; }
|
||||||
|
parent_none { fail; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sp = option::get(cx.block_span);
|
let sp = option::get(cx.block_span);
|
||||||
|
@ -275,7 +275,7 @@ fn size_and_align_of<T>() -> (int, int) {
|
||||||
(sys::size_of::<T>() as int, sys::align_of::<T>() as int)
|
(sys::size_of::<T>() as int, sys::align_of::<T>() as int)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
|
fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: ast::prim_ty, span: span)
|
||||||
-> @metadata<tydesc_md> {
|
-> @metadata<tydesc_md> {
|
||||||
let cache = get_cache(cx);
|
let cache = get_cache(cx);
|
||||||
let tg = BasicTypeDescriptorTag;
|
let tg = BasicTypeDescriptorTag;
|
||||||
|
@ -285,7 +285,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
|
||||||
option::none {}
|
option::none {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (name, (size, align), encoding) = alt ty.node {
|
let (name, (size, align), encoding) = alt ty {
|
||||||
ast::ty_bool {("bool", size_and_align_of::<bool>(), DW_ATE_boolean)}
|
ast::ty_bool {("bool", size_and_align_of::<bool>(), DW_ATE_boolean)}
|
||||||
ast::ty_int(m) { alt m {
|
ast::ty_int(m) { alt m {
|
||||||
ast::ty_char {("char", size_and_align_of::<char>(), DW_ATE_unsigned)}
|
ast::ty_char {("char", size_and_align_of::<char>(), DW_ATE_unsigned)}
|
||||||
|
@ -307,11 +307,10 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
|
||||||
ast::ty_f32 {("f32", size_and_align_of::<f32>(), DW_ATE_float)}
|
ast::ty_f32 {("f32", size_and_align_of::<f32>(), DW_ATE_float)}
|
||||||
ast::ty_f64 {("f64", size_and_align_of::<f64>(), DW_ATE_float)}
|
ast::ty_f64 {("f64", size_and_align_of::<f64>(), DW_ATE_float)}
|
||||||
}}
|
}}
|
||||||
_ { cx.tcx.sess.span_bug(ty.span,
|
_ { fail; }
|
||||||
"create_basic_type: unhandled type"); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let fname = filename_from_span(cx, ty.span);
|
let fname = filename_from_span(cx, span);
|
||||||
let file_node = create_file(cx, fname);
|
let file_node = create_file(cx, fname);
|
||||||
let cu_node = create_compile_unit(cx, fname);
|
let cu_node = create_compile_unit(cx, fname);
|
||||||
let lldata = [lltag(tg),
|
let lldata = [lltag(tg),
|
||||||
|
@ -415,7 +414,7 @@ fn create_record(cx: @crate_ctxt, t: ty::t, fields: [ast::ty_field],
|
||||||
for field in fields {
|
for field in fields {
|
||||||
let field_t = ty::get_field(ccx_tcx(cx), t, field.node.ident).mt.ty;
|
let field_t = ty::get_field(ccx_tcx(cx), t, field.node.ident).mt.ty;
|
||||||
let ty_md = create_ty(cx, field_t, field.node.mt.ty);
|
let ty_md = create_ty(cx, field_t, field.node.mt.ty);
|
||||||
let (size, align) = member_size_and_align(field.node.mt.ty);
|
let (size, align) = member_size_and_align(cx.tcx, field.node.mt.ty);
|
||||||
add_member(scx, field.node.ident,
|
add_member(scx, field.node.ident,
|
||||||
line_from_span(cx.sess.codemap, field.span) as int,
|
line_from_span(cx.sess.codemap, field.span) as int,
|
||||||
size as int, align as int, ty_md.node);
|
size as int, align as int, ty_md.node);
|
||||||
|
@ -439,8 +438,8 @@ fn create_boxed_type(cx: @crate_ctxt, outer: ty::t, _inner: ty::t,
|
||||||
//let cu_node = create_compile_unit_metadata(cx, fname);
|
//let cu_node = create_compile_unit_metadata(cx, fname);
|
||||||
let tcx = ccx_tcx(cx);
|
let tcx = ccx_tcx(cx);
|
||||||
let uint_t = ty::mk_uint(tcx);
|
let uint_t = ty::mk_uint(tcx);
|
||||||
let uint_ty = @{node: ast::ty_uint(ast::ty_u), span: span};
|
let refcount_type = create_basic_type(cx, uint_t,
|
||||||
let refcount_type = create_basic_type(cx, uint_t, uint_ty);
|
ast::ty_uint(ast::ty_u), span);
|
||||||
let scx = create_structure(file_node, ty_to_str(ccx_tcx(cx), outer), 0);
|
let scx = create_structure(file_node, ty_to_str(ccx_tcx(cx), outer), 0);
|
||||||
add_member(scx, "refcnt", 0, sys::size_of::<uint>() as int,
|
add_member(scx, "refcnt", 0, sys::size_of::<uint>() as int,
|
||||||
sys::align_of::<uint>() as int, refcount_type.node);
|
sys::align_of::<uint>() as int, refcount_type.node);
|
||||||
|
@ -492,14 +491,14 @@ fn create_vec(cx: @crate_ctxt, vec_t: ty::t, elem_t: ty::t,
|
||||||
let elem_ty_md = create_ty(cx, elem_t, elem_ty);
|
let elem_ty_md = create_ty(cx, elem_t, elem_ty);
|
||||||
let tcx = ccx_tcx(cx);
|
let tcx = ccx_tcx(cx);
|
||||||
let scx = create_structure(file_node, ty_to_str(tcx, vec_t), 0);
|
let scx = create_structure(file_node, ty_to_str(tcx, vec_t), 0);
|
||||||
let uint_ty = @{node: ast::ty_uint(ast::ty_u), span: vec_ty_span};
|
let size_t_type = create_basic_type(cx, ty::mk_uint(tcx),
|
||||||
let size_t_type = create_basic_type(cx, ty::mk_uint(tcx), uint_ty);
|
ast::ty_uint(ast::ty_u), vec_ty_span);
|
||||||
add_member(scx, "fill", 0, sys::size_of::<ctypes::size_t>() as int,
|
add_member(scx, "fill", 0, sys::size_of::<ctypes::size_t>() as int,
|
||||||
sys::align_of::<ctypes::size_t>() as int, size_t_type.node);
|
sys::align_of::<ctypes::size_t>() as int, size_t_type.node);
|
||||||
add_member(scx, "alloc", 0, sys::size_of::<ctypes::size_t>() as int,
|
add_member(scx, "alloc", 0, sys::size_of::<ctypes::size_t>() as int,
|
||||||
sys::align_of::<ctypes::size_t>() as int, size_t_type.node);
|
sys::align_of::<ctypes::size_t>() as int, size_t_type.node);
|
||||||
let subrange = llmdnode([lltag(SubrangeTag), lli64(0), lli64(0)]);
|
let subrange = llmdnode([lltag(SubrangeTag), lli64(0), lli64(0)]);
|
||||||
let (arr_size, arr_align) = member_size_and_align(elem_ty);
|
let (arr_size, arr_align) = member_size_and_align(tcx, elem_ty);
|
||||||
let data_ptr = create_composite_type(ArrayTypeTag, "", file_node.node, 0,
|
let data_ptr = create_composite_type(ArrayTypeTag, "", file_node.node, 0,
|
||||||
arr_size, arr_align, 0,
|
arr_size, arr_align, 0,
|
||||||
option::some(elem_ty_md.node),
|
option::some(elem_ty_md.node),
|
||||||
|
@ -510,36 +509,46 @@ fn create_vec(cx: @crate_ctxt, vec_t: ty::t, elem_t: ty::t,
|
||||||
ret @{node: llnode, data: {hash: ty::type_id(vec_t)}};
|
ret @{node: llnode, data: {hash: ty::type_id(vec_t)}};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn member_size_and_align(ty: @ast::ty) -> (int, int) {
|
fn member_size_and_align(tcx: ty::ctxt, ty: @ast::ty) -> (int, int) {
|
||||||
alt ty.node {
|
alt ty.node {
|
||||||
ast::ty_bool { size_and_align_of::<bool>() }
|
ast::ty_path(_, id) {
|
||||||
ast::ty_int(m) { alt m {
|
alt tcx.def_map.get(id) {
|
||||||
ast::ty_char { size_and_align_of::<char>() }
|
ast::def_prim_ty(nty) {
|
||||||
ast::ty_i { size_and_align_of::<int>() }
|
alt nty {
|
||||||
ast::ty_i8 { size_and_align_of::<i8>() }
|
ast::ty_bool { size_and_align_of::<bool>() }
|
||||||
ast::ty_i16 { size_and_align_of::<i16>() }
|
ast::ty_int(m) { alt m {
|
||||||
ast::ty_i32 { size_and_align_of::<i32>() }
|
ast::ty_char { size_and_align_of::<char>() }
|
||||||
ast::ty_i64 { size_and_align_of::<i64>() }
|
ast::ty_i { size_and_align_of::<int>() }
|
||||||
}}
|
ast::ty_i8 { size_and_align_of::<i8>() }
|
||||||
ast::ty_uint(m) { alt m {
|
ast::ty_i16 { size_and_align_of::<i16>() }
|
||||||
ast::ty_u { size_and_align_of::<uint>() }
|
ast::ty_i32 { size_and_align_of::<i32>() }
|
||||||
ast::ty_u8 { size_and_align_of::<i8>() }
|
ast::ty_i64 { size_and_align_of::<i64>() }
|
||||||
ast::ty_u16 { size_and_align_of::<u16>() }
|
}}
|
||||||
ast::ty_u32 { size_and_align_of::<u32>() }
|
ast::ty_uint(m) { alt m {
|
||||||
ast::ty_u64 { size_and_align_of::<u64>() }
|
ast::ty_u { size_and_align_of::<uint>() }
|
||||||
}}
|
ast::ty_u8 { size_and_align_of::<i8>() }
|
||||||
ast::ty_float(m) { alt m {
|
ast::ty_u16 { size_and_align_of::<u16>() }
|
||||||
ast::ty_f { size_and_align_of::<float>() }
|
ast::ty_u32 { size_and_align_of::<u32>() }
|
||||||
ast::ty_f32 { size_and_align_of::<f32>() }
|
ast::ty_u64 { size_and_align_of::<u64>() }
|
||||||
ast::ty_f64 { size_and_align_of::<f64>() }
|
}}
|
||||||
}}
|
ast::ty_float(m) { alt m {
|
||||||
|
ast::ty_f { size_and_align_of::<float>() }
|
||||||
|
ast::ty_f32 { size_and_align_of::<f32>() }
|
||||||
|
ast::ty_f64 { size_and_align_of::<f64>() }
|
||||||
|
}}
|
||||||
|
_ { fail; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ { fail; }
|
||||||
|
}
|
||||||
|
}
|
||||||
ast::ty_box(_) | ast::ty_uniq(_) {
|
ast::ty_box(_) | ast::ty_uniq(_) {
|
||||||
size_and_align_of::<ctypes::uintptr_t>()
|
size_and_align_of::<ctypes::uintptr_t>()
|
||||||
}
|
}
|
||||||
ast::ty_rec(fields) {
|
ast::ty_rec(fields) {
|
||||||
let total_size = 0;
|
let total_size = 0;
|
||||||
for field in fields {
|
for field in fields {
|
||||||
let (size, _) = member_size_and_align(field.node.mt.ty);
|
let (size, _) = member_size_and_align(tcx, field.node.mt.ty);
|
||||||
total_size += size;
|
total_size += size;
|
||||||
}
|
}
|
||||||
(total_size, 64) //XXX different align for other arches?
|
(total_size, 64) //XXX different align for other arches?
|
||||||
|
@ -551,7 +560,7 @@ fn member_size_and_align(ty: @ast::ty) -> (int, int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_ty(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
|
fn create_ty(_cx: @crate_ctxt, _t: ty::t, _ty: @ast::ty)
|
||||||
-> @metadata<tydesc_md> {
|
-> @metadata<tydesc_md> {
|
||||||
/*let cache = get_cache(cx);
|
/*let cache = get_cache(cx);
|
||||||
alt cached_metadata::<@metadata<tydesc_md>>(
|
alt cached_metadata::<@metadata<tydesc_md>>(
|
||||||
|
@ -560,6 +569,19 @@ fn create_ty(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
|
||||||
option::none {}
|
option::none {}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
/* FIXME I am disabling this code as part of the patch that moves
|
||||||
|
* recognition of named builtin types into resolve. I tried to fix
|
||||||
|
* it, but it seems to already be broken -- it's only called when
|
||||||
|
* --xg is given, and compiling with --xg fails on trivial programs.
|
||||||
|
*
|
||||||
|
* Generating an ast::ty from a ty::t seems like it should not be
|
||||||
|
* needed. It is only done to track spans, but you will not get the
|
||||||
|
* right spans anyway -- types tend to refer to stuff defined
|
||||||
|
* elsewhere, not be self-contained.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fail;
|
||||||
|
/*
|
||||||
fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: span) -> @ast::ty {
|
fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: span) -> @ast::ty {
|
||||||
let ty = alt ty::get(t).struct {
|
let ty = alt ty::get(t).struct {
|
||||||
ty::ty_nil { ast::ty_nil }
|
ty::ty_nil { ast::ty_nil }
|
||||||
|
@ -628,8 +650,18 @@ fn create_ty(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
|
||||||
ret create_pointer_type(cx, t, ty.span, v);
|
ret create_pointer_type(cx, t, ty.span, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ { ret create_basic_type(cx, t, ty); }
|
ast::ty_path(_, id) {
|
||||||
|
alt ccx_tcx(cx).def_map.get(id) {
|
||||||
|
ast::def_prim_ty(pty) {
|
||||||
|
ret create_basic_type(cx, t, pty, ty.span);
|
||||||
|
}
|
||||||
|
_ {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ {}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
|
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
|
||||||
|
|
|
@ -99,17 +99,22 @@ fn check_ctypes(tcx: ty::ctxt, crate: @ast::crate) {
|
||||||
let tys = vec::map(decl.inputs) {|a| a.ty };
|
let tys = vec::map(decl.inputs) {|a| a.ty };
|
||||||
for ty in (tys + [decl.output]) {
|
for ty in (tys + [decl.output]) {
|
||||||
alt ty.node {
|
alt ty.node {
|
||||||
ast::ty_int(ast::ty_i) {
|
ast::ty_path(_, id) {
|
||||||
tcx.sess.span_warn(
|
alt tcx.def_map.get(id) {
|
||||||
ty.span,
|
ast::def_prim_ty(ast::ty_int(ast::ty_i)) {
|
||||||
"found rust type `int` in native module, while \
|
tcx.sess.span_warn(
|
||||||
ctypes::c_int or ctypes::long should be used");
|
ty.span,
|
||||||
}
|
"found rust type `int` in native module, while \
|
||||||
ast::ty_uint(ast::ty_u) {
|
ctypes::c_int or ctypes::long should be used");
|
||||||
tcx.sess.span_warn(
|
}
|
||||||
ty.span,
|
ast::def_prim_ty(ast::ty_uint(ast::ty_u)) {
|
||||||
"found rust type `uint` in native module, while \
|
tcx.sess.span_warn(
|
||||||
ctypes::c_uint or ctypes::ulong should be used");
|
ty.span,
|
||||||
|
"found rust type `uint` in native module, while \
|
||||||
|
ctypes::c_uint or ctypes::ulong should be used");
|
||||||
|
}
|
||||||
|
_ { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ { }
|
_ { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ export _impl, iscopes, method_info;
|
||||||
// them, storing the resulting def in the AST nodes.
|
// them, storing the resulting def in the AST nodes.
|
||||||
|
|
||||||
enum scope {
|
enum scope {
|
||||||
|
scope_toplevel,
|
||||||
scope_crate,
|
scope_crate,
|
||||||
scope_item(@ast::item),
|
scope_item(@ast::item),
|
||||||
scope_bare_fn(ast::fn_decl, node_id, [ast::ty_param]),
|
scope_bare_fn(ast::fn_decl, node_id, [ast::ty_param]),
|
||||||
|
@ -44,6 +45,10 @@ enum scope {
|
||||||
|
|
||||||
type scopes = list<scope>;
|
type scopes = list<scope>;
|
||||||
|
|
||||||
|
fn top_scope() -> scopes {
|
||||||
|
cons(scope_crate, @cons(scope_toplevel, @nil))
|
||||||
|
}
|
||||||
|
|
||||||
enum import_state {
|
enum import_state {
|
||||||
todo(ast::node_id, ast::ident, @[ast::ident], span, scopes),
|
todo(ast::node_id, ast::ident, @[ast::ident], span, scopes),
|
||||||
is_glob(@[ast::ident], scopes, span),
|
is_glob(@[ast::ident], scopes, span),
|
||||||
|
@ -190,7 +195,7 @@ fn map_crate(e: @env, c: @ast::crate) {
|
||||||
visit_item: bind index_i(e, _, _, _),
|
visit_item: bind index_i(e, _, _, _),
|
||||||
visit_block: visit_block_with_scope
|
visit_block: visit_block_with_scope
|
||||||
with *visit::default_visitor::<scopes>()};
|
with *visit::default_visitor::<scopes>()};
|
||||||
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v_map_mod));
|
visit::visit_crate(*c, top_scope(), visit::mk_vt(v_map_mod));
|
||||||
|
|
||||||
// Register the top-level mod
|
// Register the top-level mod
|
||||||
e.mod_map.insert(ast::crate_node_id,
|
e.mod_map.insert(ast::crate_node_id,
|
||||||
|
@ -257,8 +262,7 @@ fn map_crate(e: @env, c: @ast::crate) {
|
||||||
visit_block: visit_block_with_scope,
|
visit_block: visit_block_with_scope,
|
||||||
visit_item: bind visit_item_with_scope(e, _, _, _)
|
visit_item: bind visit_item_with_scope(e, _, _, _)
|
||||||
with *visit::default_visitor::<scopes>()};
|
with *visit::default_visitor::<scopes>()};
|
||||||
visit::visit_crate(*c, cons(scope_crate, @nil),
|
visit::visit_crate(*c, top_scope(), visit::mk_vt(v_link_glob));
|
||||||
visit::mk_vt(v_link_glob));
|
|
||||||
fn link_glob(e: @env, vi: @ast::view_item, sc: scopes, _v: vt<scopes>) {
|
fn link_glob(e: @env, vi: @ast::view_item, sc: scopes, _v: vt<scopes>) {
|
||||||
alt vi.node {
|
alt vi.node {
|
||||||
//if it really is a glob import, that is
|
//if it really is a glob import, that is
|
||||||
|
@ -344,7 +348,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
|
||||||
visit_constr: bind walk_constr(e, _, _, _, _, _),
|
visit_constr: bind walk_constr(e, _, _, _, _, _),
|
||||||
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
|
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
|
||||||
with *visit::default_visitor()};
|
with *visit::default_visitor()};
|
||||||
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
|
visit::visit_crate(*c, top_scope(), visit::mk_vt(v));
|
||||||
e.used_imports.track = false;
|
e.used_imports.track = false;
|
||||||
e.sess.abort_if_errors();
|
e.sess.abort_if_errors();
|
||||||
|
|
||||||
|
@ -808,10 +812,7 @@ fn lookup_path_strict(e: env, sc: scopes, sp: span, pth: ast::path_,
|
||||||
let n_idents = vec::len(pth.idents);
|
let n_idents = vec::len(pth.idents);
|
||||||
let headns = if n_idents == 1u { ns } else { ns_module };
|
let headns = if n_idents == 1u { ns } else { ns_module };
|
||||||
|
|
||||||
let first_scope;
|
let first_scope = if pth.global { top_scope() } else { sc };
|
||||||
if pth.global {
|
|
||||||
first_scope = list::cons(scope_crate, @list::nil);
|
|
||||||
} else { first_scope = sc; }
|
|
||||||
|
|
||||||
let dcur =
|
let dcur =
|
||||||
lookup_in_scope_strict(e, first_scope, sp, pth.idents[0], headns);
|
lookup_in_scope_strict(e, first_scope, sp, pth.idents[0], headns);
|
||||||
|
@ -879,6 +880,29 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
|
||||||
fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
|
fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
|
||||||
option<def> {
|
option<def> {
|
||||||
alt s {
|
alt s {
|
||||||
|
scope_toplevel {
|
||||||
|
if ns == ns_type {
|
||||||
|
ret some(ast::def_prim_ty(alt name {
|
||||||
|
"bool" { ast::ty_bool }
|
||||||
|
"int" { ast::ty_int(ast::ty_i) }
|
||||||
|
"uint" { ast::ty_uint(ast::ty_u) }
|
||||||
|
"float" { ast::ty_float(ast::ty_f) }
|
||||||
|
"str" { ast::ty_str }
|
||||||
|
"char" { ast::ty_int(ast::ty_char) }
|
||||||
|
"i8" { ast::ty_int(ast::ty_i8) }
|
||||||
|
"i16" { ast::ty_int(ast::ty_i16) }
|
||||||
|
"i32" { ast::ty_int(ast::ty_i32) }
|
||||||
|
"i64" { ast::ty_int(ast::ty_i64) }
|
||||||
|
"u8" { ast::ty_uint(ast::ty_u8) }
|
||||||
|
"u16" { ast::ty_uint(ast::ty_u16) }
|
||||||
|
"u32" { ast::ty_uint(ast::ty_u32) }
|
||||||
|
"u64" { ast::ty_uint(ast::ty_u64) }
|
||||||
|
"f32" { ast::ty_float(ast::ty_f32) }
|
||||||
|
"f64" { ast::ty_float(ast::ty_f64) }
|
||||||
|
_ { ret none; }
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
scope_crate {
|
scope_crate {
|
||||||
ret lookup_in_local_mod(e, ast::crate_node_id, sp,
|
ret lookup_in_local_mod(e, ast::crate_node_id, sp,
|
||||||
name, ns, inside);
|
name, ns, inside);
|
||||||
|
@ -950,7 +974,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret none::<def>;
|
ret none;
|
||||||
}
|
}
|
||||||
let left_fn = false;
|
let left_fn = false;
|
||||||
let closing = [];
|
let closing = [];
|
||||||
|
@ -959,7 +983,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
|
||||||
let sc = sc;
|
let sc = sc;
|
||||||
while true {
|
while true {
|
||||||
alt copy sc {
|
alt copy sc {
|
||||||
nil { ret none::<def>; }
|
nil { ret none; }
|
||||||
cons(hd, tl) {
|
cons(hd, tl) {
|
||||||
let fnd = in_scope(e, sp, name, hd, ns);
|
let fnd = in_scope(e, sp, name, hd, ns);
|
||||||
if !is_none(fnd) {
|
if !is_none(fnd) {
|
||||||
|
@ -1019,7 +1043,7 @@ fn lookup_in_ty_params(e: env, name: ident, ty_params: [ast::ty_param])
|
||||||
} { ret some(ast::def_ty_param(local_def(tp.id), n)); }
|
} { ret some(ast::def_ty_param(local_def(tp.id), n)); }
|
||||||
n += 1u;
|
n += 1u;
|
||||||
}
|
}
|
||||||
ret none::<def>;
|
ret none;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_in_pat(e: env, name: ident, pat: @ast::pat) -> option<def_id> {
|
fn lookup_in_pat(e: env, name: ident, pat: @ast::pat) -> option<def_id> {
|
||||||
|
@ -1043,10 +1067,10 @@ fn lookup_in_fn(e: env, name: ident, decl: ast::fn_decl,
|
||||||
ret some(ast::def_arg(local_def(a.id), a.mode));
|
ret some(ast::def_arg(local_def(a.id), a.mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret none::<def>;
|
ret none;
|
||||||
}
|
}
|
||||||
ns_type { ret lookup_in_ty_params(e, name, ty_params); }
|
ns_type { ret lookup_in_ty_params(e, name, ty_params); }
|
||||||
_ { ret none::<def>; }
|
_ { ret none; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1261,7 +1285,7 @@ fn lookup_in_local_mod(e: env, node_id: node_id, sp: span, id: ident,
|
||||||
let info = e.mod_map.get(node_id);
|
let info = e.mod_map.get(node_id);
|
||||||
if dr == outside && !is_exported(e, id, option::get(info.m)) {
|
if dr == outside && !is_exported(e, id, option::get(info.m)) {
|
||||||
// if we're in a native mod, then dr==inside, so info.m is some _mod
|
// if we're in a native mod, then dr==inside, so info.m is some _mod
|
||||||
ret none::<def>; // name is not visible
|
ret none; // name is not visible
|
||||||
}
|
}
|
||||||
alt info.index.find(id) {
|
alt info.index.find(id) {
|
||||||
none { }
|
none { }
|
||||||
|
@ -1334,7 +1358,7 @@ fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident,
|
||||||
}
|
}
|
||||||
alt info.glob_imported_names.get(id) {
|
alt info.glob_imported_names.get(id) {
|
||||||
glob_resolving(sp) {
|
glob_resolving(sp) {
|
||||||
ret none::<def>;
|
ret none;
|
||||||
}
|
}
|
||||||
glob_resolved(val, typ, md) {
|
glob_resolved(val, typ, md) {
|
||||||
ret alt wanted_ns {
|
ret alt wanted_ns {
|
||||||
|
@ -1361,7 +1385,7 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
|
||||||
ret some(ast::def_variant(local_def(parent_id),
|
ret some(ast::def_variant(local_def(parent_id),
|
||||||
local_def(vid)));
|
local_def(vid)));
|
||||||
}
|
}
|
||||||
_ { ret none::<def>; }
|
_ { ret none; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mie_native_item(native_item) {
|
mie_native_item(native_item) {
|
||||||
|
@ -1375,7 +1399,7 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret none::<def>;
|
ret none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1473,7 +1497,7 @@ fn ns_for_def(d: def) -> namespace {
|
||||||
ast::def_upvar(_, _, _) | ast::def_self(_) { ns_val(ns_any_value) }
|
ast::def_upvar(_, _, _) | ast::def_self(_) { ns_val(ns_any_value) }
|
||||||
ast::def_mod(_) | ast::def_native_mod(_) { ns_module }
|
ast::def_mod(_) | ast::def_native_mod(_) { ns_module }
|
||||||
ast::def_ty(_) | ast::def_binding(_) | ast::def_use(_) |
|
ast::def_ty(_) | ast::def_binding(_) | ast::def_use(_) |
|
||||||
ast::def_ty_param(_, _) { ns_type }
|
ast::def_ty_param(_, _) | ast::def_prim_ty(_) { ns_type }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1497,7 +1521,7 @@ fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) ->
|
||||||
e.ext_map.insert(def_id_of_def(d), ids);
|
e.ext_map.insert(def_id_of_def(d), ids);
|
||||||
if ns_ok(ns, ns_for_def(d)) { ret some(d); }
|
if ns_ok(ns, ns_for_def(d)) { ret some(d); }
|
||||||
}
|
}
|
||||||
ret none::<def>;
|
ret none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
|
||||||
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
|
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, id.node));
|
||||||
ret {bounds: @[], ty: typ};
|
ret {bounds: @[], ty: typ};
|
||||||
}
|
}
|
||||||
ast::def_ty(_) {
|
ast::def_ty(_) | ast::def_prim_ty(_) {
|
||||||
fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found type");
|
fcx.ccx.tcx.sess.span_fatal(sp, "expected value but found type");
|
||||||
}
|
}
|
||||||
ast::def_upvar(_, inner, _) {
|
ast::def_upvar(_, inner, _) {
|
||||||
|
@ -273,30 +273,24 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
|
||||||
ty_param_bounds_and_ty.ty);
|
ty_param_bounds_and_ty.ty);
|
||||||
ret typ;
|
ret typ;
|
||||||
}
|
}
|
||||||
let typ;
|
let typ = alt ast_ty.node {
|
||||||
alt ast_ty.node {
|
ast::ty_nil { ty::mk_nil(tcx) }
|
||||||
ast::ty_nil { typ = ty::mk_nil(tcx); }
|
ast::ty_bot { ty::mk_bot(tcx) }
|
||||||
ast::ty_bot { typ = ty::mk_bot(tcx); }
|
|
||||||
ast::ty_bool { typ = ty::mk_bool(tcx); }
|
|
||||||
ast::ty_int(it) { typ = ty::mk_mach_int(tcx, it); }
|
|
||||||
ast::ty_uint(uit) { typ = ty::mk_mach_uint(tcx, uit); }
|
|
||||||
ast::ty_float(ft) { typ = ty::mk_mach_float(tcx, ft); }
|
|
||||||
ast::ty_str { typ = ty::mk_str(tcx); }
|
|
||||||
ast::ty_box(mt) {
|
ast::ty_box(mt) {
|
||||||
typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, mode, mt));
|
ty::mk_box(tcx, ast_mt_to_mt(tcx, mode, mt))
|
||||||
}
|
}
|
||||||
ast::ty_uniq(mt) {
|
ast::ty_uniq(mt) {
|
||||||
typ = ty::mk_uniq(tcx, ast_mt_to_mt(tcx, mode, mt));
|
ty::mk_uniq(tcx, ast_mt_to_mt(tcx, mode, mt))
|
||||||
}
|
}
|
||||||
ast::ty_vec(mt) {
|
ast::ty_vec(mt) {
|
||||||
typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, mode, mt));
|
ty::mk_vec(tcx, ast_mt_to_mt(tcx, mode, mt))
|
||||||
}
|
}
|
||||||
ast::ty_ptr(mt) {
|
ast::ty_ptr(mt) {
|
||||||
typ = ty::mk_ptr(tcx, ast_mt_to_mt(tcx, mode, mt));
|
ty::mk_ptr(tcx, ast_mt_to_mt(tcx, mode, mt))
|
||||||
}
|
}
|
||||||
ast::ty_tup(fields) {
|
ast::ty_tup(fields) {
|
||||||
let flds = vec::map(fields, bind ast_ty_to_ty(tcx, mode, _));
|
let flds = vec::map(fields, bind ast_ty_to_ty(tcx, mode, _));
|
||||||
typ = ty::mk_tup(tcx, flds);
|
ty::mk_tup(tcx, flds)
|
||||||
}
|
}
|
||||||
ast::ty_rec(fields) {
|
ast::ty_rec(fields) {
|
||||||
let flds: [field] = [];
|
let flds: [field] = [];
|
||||||
|
@ -304,22 +298,31 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
|
||||||
let tm = ast_mt_to_mt(tcx, mode, f.node.mt);
|
let tm = ast_mt_to_mt(tcx, mode, f.node.mt);
|
||||||
flds += [{ident: f.node.ident, mt: tm}];
|
flds += [{ident: f.node.ident, mt: tm}];
|
||||||
}
|
}
|
||||||
typ = ty::mk_rec(tcx, flds);
|
ty::mk_rec(tcx, flds)
|
||||||
}
|
}
|
||||||
ast::ty_fn(proto, decl) {
|
ast::ty_fn(proto, decl) {
|
||||||
typ = ty::mk_fn(tcx, ty_of_fn_decl(tcx, mode, proto, decl));
|
ty::mk_fn(tcx, ty_of_fn_decl(tcx, mode, proto, decl))
|
||||||
}
|
}
|
||||||
ast::ty_path(path, id) {
|
ast::ty_path(path, id) {
|
||||||
alt tcx.def_map.get(id) {
|
alt tcx.def_map.get(id) {
|
||||||
ast::def_ty(id) {
|
ast::def_ty(id) {
|
||||||
typ = instantiate(tcx, ast_ty.span, mode, id, path.node.types);
|
instantiate(tcx, ast_ty.span, mode, id, path.node.types)
|
||||||
|
}
|
||||||
|
ast::def_prim_ty(nty) {
|
||||||
|
alt nty {
|
||||||
|
ast::ty_bool { ty::mk_bool(tcx) }
|
||||||
|
ast::ty_int(it) { ty::mk_mach_int(tcx, it) }
|
||||||
|
ast::ty_uint(uit) { ty::mk_mach_uint(tcx, uit) }
|
||||||
|
ast::ty_float(ft) { ty::mk_mach_float(tcx, ft) }
|
||||||
|
ast::ty_str { ty::mk_str(tcx) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast::def_ty_param(id, n) {
|
ast::def_ty_param(id, n) {
|
||||||
if vec::len(path.node.types) > 0u {
|
if vec::len(path.node.types) > 0u {
|
||||||
tcx.sess.span_err(ast_ty.span, "provided type parameters to \
|
tcx.sess.span_err(ast_ty.span, "provided type parameters to \
|
||||||
a type parameter");
|
a type parameter");
|
||||||
}
|
}
|
||||||
typ = ty::mk_param(tcx, n, id);
|
ty::mk_param(tcx, n, id)
|
||||||
}
|
}
|
||||||
ast::def_self(iface_id) {
|
ast::def_self(iface_id) {
|
||||||
alt tcx.items.get(iface_id.node) {
|
alt tcx.items.get(iface_id.node) {
|
||||||
|
@ -328,9 +331,9 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
|
||||||
tcx.sess.span_err(ast_ty.span, "incorrect number of type \
|
tcx.sess.span_err(ast_ty.span, "incorrect number of type \
|
||||||
parameter to self type");
|
parameter to self type");
|
||||||
}
|
}
|
||||||
typ = ty::mk_self(tcx, vec::map(path.node.types, {|ast_ty|
|
ty::mk_self(tcx, vec::map(path.node.types, {|ast_ty|
|
||||||
ast_ty_to_ty(tcx, mode, ast_ty)
|
ast_ty_to_ty(tcx, mode, ast_ty)
|
||||||
}));
|
}))
|
||||||
}
|
}
|
||||||
_ { fail; }
|
_ { fail; }
|
||||||
}
|
}
|
||||||
|
@ -346,7 +349,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
|
||||||
for constr: @ast::ty_constr in cs {
|
for constr: @ast::ty_constr in cs {
|
||||||
out_cs += [ty::ast_constr_to_constr(tcx, constr)];
|
out_cs += [ty::ast_constr_to_constr(tcx, constr)];
|
||||||
}
|
}
|
||||||
typ = ty::mk_constr(tcx, ast_ty_to_ty(tcx, mode, t), out_cs);
|
ty::mk_constr(tcx, ast_ty_to_ty(tcx, mode, t), out_cs)
|
||||||
}
|
}
|
||||||
ast::ty_infer {
|
ast::ty_infer {
|
||||||
alt mode {
|
alt mode {
|
||||||
|
@ -359,7 +362,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
|
||||||
tcx.sess.span_bug(ast_ty.span,
|
tcx.sess.span_bug(ast_ty.span,
|
||||||
"found `ty_mac` in unexpected place");
|
"found `ty_mac` in unexpected place");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ));
|
tcx.ast_ty_to_ty_cache.insert(ast_ty, some(typ));
|
||||||
ret typ;
|
ret typ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ enum def {
|
||||||
def_local(def_id, let_style),
|
def_local(def_id, let_style),
|
||||||
def_variant(def_id /* enum */, def_id /* variant */),
|
def_variant(def_id /* enum */, def_id /* variant */),
|
||||||
def_ty(def_id),
|
def_ty(def_id),
|
||||||
|
def_prim_ty(prim_ty),
|
||||||
def_ty_param(def_id, uint),
|
def_ty_param(def_id, uint),
|
||||||
def_binding(def_id),
|
def_binding(def_id),
|
||||||
def_use(def_id),
|
def_use(def_id),
|
||||||
|
@ -327,20 +328,18 @@ enum float_ty { ty_f, ty_f32, ty_f64, }
|
||||||
|
|
||||||
type ty = spanned<ty_>;
|
type ty = spanned<ty_>;
|
||||||
|
|
||||||
enum ty_ {
|
// Not represented directly in the AST, referred to by name through a ty_path.
|
||||||
ty_nil,
|
enum prim_ty {
|
||||||
ty_bot, /* return type of ! functions and type of
|
|
||||||
ret/fail/break/cont. there is no syntax
|
|
||||||
for this type. */
|
|
||||||
|
|
||||||
/* bot represents the value of functions that don't return a value
|
|
||||||
locally to their context. in contrast, things like log that do
|
|
||||||
return, but don't return a meaningful value, have result type nil. */
|
|
||||||
ty_bool,
|
|
||||||
ty_int(int_ty),
|
ty_int(int_ty),
|
||||||
ty_uint(uint_ty),
|
ty_uint(uint_ty),
|
||||||
ty_float(float_ty),
|
ty_float(float_ty),
|
||||||
ty_str,
|
ty_str,
|
||||||
|
ty_bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ty_ {
|
||||||
|
ty_nil,
|
||||||
|
ty_bot, /* bottom type */
|
||||||
ty_box(mt),
|
ty_box(mt),
|
||||||
ty_uniq(mt),
|
ty_uniq(mt),
|
||||||
ty_vec(mt),
|
ty_vec(mt),
|
||||||
|
|
|
@ -31,6 +31,7 @@ fn def_id_of_def(d: def) -> def_id {
|
||||||
def_native_mod(id) | def_const(id) | def_arg(id, _) | def_local(id, _) |
|
def_native_mod(id) | def_const(id) | def_arg(id, _) | def_local(id, _) |
|
||||||
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
|
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
|
||||||
def_binding(id) | def_use(id) | def_upvar(id, _, _) { id }
|
def_binding(id) | def_use(id) | def_upvar(id, _, _) { id }
|
||||||
|
def_prim_ty(_) { fail; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -446,8 +446,7 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
|
||||||
span: fld.new_span(f.span)}
|
span: fld.new_span(f.span)}
|
||||||
}
|
}
|
||||||
alt t {
|
alt t {
|
||||||
ty_nil | ty_bot | ty_bool | ty_str {t}
|
ty_nil | ty_bot {t}
|
||||||
ty_int(_) | ty_uint(_) | ty_float(_) {t}
|
|
||||||
ty_box(mt) {ty_box(fold_mt(mt, fld))}
|
ty_box(mt) {ty_box(fold_mt(mt, fld))}
|
||||||
ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
|
ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
|
||||||
ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
|
ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
|
||||||
|
|
|
@ -152,7 +152,6 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
|
||||||
"assert", "claim", "native", "fn", "pure",
|
"assert", "claim", "native", "fn", "pure",
|
||||||
"unsafe", "import", "export", "let", "const",
|
"unsafe", "import", "export", "let", "const",
|
||||||
"log", "copy", "impl", "iface", "enum",
|
"log", "copy", "impl", "iface", "enum",
|
||||||
"m32", "m64", "m128", "f80", "f16", "f128",
|
|
||||||
"class", "trait"] {
|
"class", "trait"] {
|
||||||
words.insert(word, ());
|
words.insert(word, ());
|
||||||
}
|
}
|
||||||
|
@ -427,96 +426,62 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
|
||||||
none {}
|
none {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let t: ast::ty_;
|
let t = if p.token == token::LPAREN {
|
||||||
// FIXME: do something with this
|
|
||||||
|
|
||||||
if eat_word(p, "bool") {
|
|
||||||
t = ast::ty_bool;
|
|
||||||
} else if eat_word(p, "int") {
|
|
||||||
t = ast::ty_int(ast::ty_i);
|
|
||||||
} else if eat_word(p, "uint") {
|
|
||||||
t = ast::ty_uint(ast::ty_u);
|
|
||||||
} else if eat_word(p, "float") {
|
|
||||||
t = ast::ty_float(ast::ty_f);
|
|
||||||
} else if eat_word(p, "str") {
|
|
||||||
t = ast::ty_str;
|
|
||||||
} else if eat_word(p, "char") {
|
|
||||||
t = ast::ty_int(ast::ty_char);
|
|
||||||
} else if eat_word(p, "i8") {
|
|
||||||
t = ast::ty_int(ast::ty_i8);
|
|
||||||
} else if eat_word(p, "i16") {
|
|
||||||
t = ast::ty_int(ast::ty_i16);
|
|
||||||
} else if eat_word(p, "i32") {
|
|
||||||
t = ast::ty_int(ast::ty_i32);
|
|
||||||
} else if eat_word(p, "i64") {
|
|
||||||
t = ast::ty_int(ast::ty_i64);
|
|
||||||
} else if eat_word(p, "u8") {
|
|
||||||
t = ast::ty_uint(ast::ty_u8);
|
|
||||||
} else if eat_word(p, "u16") {
|
|
||||||
t = ast::ty_uint(ast::ty_u16);
|
|
||||||
} else if eat_word(p, "u32") {
|
|
||||||
t = ast::ty_uint(ast::ty_u32);
|
|
||||||
} else if eat_word(p, "u64") {
|
|
||||||
t = ast::ty_uint(ast::ty_u64);
|
|
||||||
} else if eat_word(p, "f32") {
|
|
||||||
t = ast::ty_float(ast::ty_f32);
|
|
||||||
} else if eat_word(p, "f64") {
|
|
||||||
t = ast::ty_float(ast::ty_f64);
|
|
||||||
} else if p.token == token::LPAREN {
|
|
||||||
p.bump();
|
p.bump();
|
||||||
if p.token == token::RPAREN {
|
if p.token == token::RPAREN {
|
||||||
p.bump();
|
p.bump();
|
||||||
t = ast::ty_nil;
|
ast::ty_nil
|
||||||
} else {
|
} else {
|
||||||
let ts = [parse_ty(p, false)];
|
let ts = [parse_ty(p, false)];
|
||||||
while p.token == token::COMMA {
|
while p.token == token::COMMA {
|
||||||
p.bump();
|
p.bump();
|
||||||
ts += [parse_ty(p, false)];
|
ts += [parse_ty(p, false)];
|
||||||
}
|
}
|
||||||
if vec::len(ts) == 1u {
|
let t = if vec::len(ts) == 1u { ts[0].node }
|
||||||
t = ts[0].node;
|
else { ast::ty_tup(ts) };
|
||||||
} else { t = ast::ty_tup(ts); }
|
|
||||||
expect(p, token::RPAREN);
|
expect(p, token::RPAREN);
|
||||||
|
t
|
||||||
}
|
}
|
||||||
} else if p.token == token::AT {
|
} else if p.token == token::AT {
|
||||||
p.bump();
|
p.bump();
|
||||||
t = ast::ty_box(parse_mt(p));
|
ast::ty_box(parse_mt(p))
|
||||||
} else if p.token == token::TILDE {
|
} else if p.token == token::TILDE {
|
||||||
p.bump();
|
p.bump();
|
||||||
t = ast::ty_uniq(parse_mt(p));
|
ast::ty_uniq(parse_mt(p))
|
||||||
} else if p.token == token::BINOP(token::STAR) {
|
} else if p.token == token::BINOP(token::STAR) {
|
||||||
p.bump();
|
p.bump();
|
||||||
t = ast::ty_ptr(parse_mt(p));
|
ast::ty_ptr(parse_mt(p))
|
||||||
} else if p.token == token::LBRACE {
|
} else if p.token == token::LBRACE {
|
||||||
let elems =
|
let elems =
|
||||||
parse_seq(token::LBRACE, token::RBRACE, seq_sep_opt(token::COMMA),
|
parse_seq(token::LBRACE, token::RBRACE, seq_sep_opt(token::COMMA),
|
||||||
parse_ty_field, p);
|
parse_ty_field, p);
|
||||||
if vec::len(elems.node) == 0u { unexpected(p, token::RBRACE); }
|
if vec::len(elems.node) == 0u { unexpected(p, token::RBRACE); }
|
||||||
let hi = elems.span.hi;
|
let hi = elems.span.hi;
|
||||||
t = ast::ty_rec(elems.node);
|
|
||||||
|
let t = ast::ty_rec(elems.node);
|
||||||
if p.token == token::COLON {
|
if p.token == token::COLON {
|
||||||
p.bump();
|
p.bump();
|
||||||
t = ast::ty_constr(@spanned(lo, hi, t),
|
ast::ty_constr(@spanned(lo, hi, t), parse_type_constraints(p))
|
||||||
parse_type_constraints(p));
|
} else { t }
|
||||||
}
|
|
||||||
} else if p.token == token::LBRACKET {
|
} else if p.token == token::LBRACKET {
|
||||||
expect(p, token::LBRACKET);
|
expect(p, token::LBRACKET);
|
||||||
t = ast::ty_vec(parse_mt(p));
|
let t = ast::ty_vec(parse_mt(p));
|
||||||
expect(p, token::RBRACKET);
|
expect(p, token::RBRACKET);
|
||||||
|
t
|
||||||
} else if eat_word(p, "fn") {
|
} else if eat_word(p, "fn") {
|
||||||
let proto = parse_fn_ty_proto(p);
|
let proto = parse_fn_ty_proto(p);
|
||||||
alt proto {
|
alt proto {
|
||||||
ast::proto_bare { p.warn("fn is deprecated, use native fn"); }
|
ast::proto_bare { p.warn("fn is deprecated, use native fn"); }
|
||||||
_ { /* fallthrough */ }
|
_ { /* fallthrough */ }
|
||||||
}
|
}
|
||||||
t = ast::ty_fn(proto, parse_ty_fn(p));
|
ast::ty_fn(proto, parse_ty_fn(p))
|
||||||
} else if eat_word(p, "native") {
|
} else if eat_word(p, "native") {
|
||||||
expect_word(p, "fn");
|
expect_word(p, "fn");
|
||||||
t = ast::ty_fn(ast::proto_bare, parse_ty_fn(p));
|
ast::ty_fn(ast::proto_bare, parse_ty_fn(p))
|
||||||
} else if p.token == token::MOD_SEP || is_ident(p.token) {
|
} else if p.token == token::MOD_SEP || is_ident(p.token) {
|
||||||
let path = parse_path(p);
|
let path = parse_path(p);
|
||||||
t = ast::ty_path(path, p.get_id());
|
ast::ty_path(path, p.get_id())
|
||||||
} else { p.fatal("expecting type"); }
|
} else { p.fatal("expecting type"); };
|
||||||
ret parse_ty_postfix(t, p, colons_before_params, lo);
|
ret parse_ty_postfix(t, p, colons_before_params, lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ fn test_res_to_str() {
|
||||||
let decl: ast::fn_decl = {
|
let decl: ast::fn_decl = {
|
||||||
inputs: [{
|
inputs: [{
|
||||||
mode: ast::expl(ast::by_val),
|
mode: ast::expl(ast::by_val),
|
||||||
ty: @ast_util::respan(ast_util::dummy_sp(), ast::ty_bool),
|
ty: @ast_util::respan(ast_util::dummy_sp(), ast::ty_nil),
|
||||||
ident: "b",
|
ident: "b",
|
||||||
id: 0
|
id: 0
|
||||||
}],
|
}],
|
||||||
|
@ -146,7 +146,7 @@ fn test_res_to_str() {
|
||||||
cf: ast::return_val,
|
cf: ast::return_val,
|
||||||
constraints: []
|
constraints: []
|
||||||
};
|
};
|
||||||
assert res_to_str(decl, "a", []) == "resource a(b: bool)";
|
assert res_to_str(decl, "a", []) == "resource a(b: ())";
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_to_str(blk: ast::blk) -> str {
|
fn block_to_str(blk: ast::blk) -> str {
|
||||||
|
@ -317,16 +317,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
|
||||||
ibox(s, 0u);
|
ibox(s, 0u);
|
||||||
alt ty.node {
|
alt ty.node {
|
||||||
ast::ty_nil { word(s.s, "()"); }
|
ast::ty_nil { word(s.s, "()"); }
|
||||||
ast::ty_bool { word(s.s, "bool"); }
|
|
||||||
ast::ty_bot { word(s.s, "!"); }
|
ast::ty_bot { word(s.s, "!"); }
|
||||||
ast::ty_int(ast::ty_i) { word(s.s, "int"); }
|
|
||||||
ast::ty_int(ast::ty_char) { word(s.s, "char"); }
|
|
||||||
ast::ty_int(t) { word(s.s, ast_util::int_ty_to_str(t)); }
|
|
||||||
ast::ty_uint(ast::ty_u) { word(s.s, "uint"); }
|
|
||||||
ast::ty_uint(t) { word(s.s, ast_util::uint_ty_to_str(t)); }
|
|
||||||
ast::ty_float(ast::ty_f) { word(s.s, "float"); }
|
|
||||||
ast::ty_float(t) { word(s.s, ast_util::float_ty_to_str(t)); }
|
|
||||||
ast::ty_str { word(s.s, "str"); }
|
|
||||||
ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); }
|
ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); }
|
||||||
ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); }
|
ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); }
|
||||||
ast::ty_vec(mt) {
|
ast::ty_vec(mt) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue