diff options
| author | Patrick Walton <[email protected]> | 2011-03-30 17:23:25 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-30 17:28:06 -0700 |
| commit | cc59cea8b055cd94279c167e99b1176751702d36 (patch) | |
| tree | 9a7c33168ac8845f81e62c43a6a1ae8ee46ace87 /src/comp/front | |
| parent | Um, that'd be, align the word *before* retpc. Addresses point to the low part... (diff) | |
| download | rust-cc59cea8b055cd94279c167e99b1176751702d36.tar.xz rust-cc59cea8b055cd94279c167e99b1176751702d36.zip | |
rustc: Thread an item-to-type mapping throughout the typechecking and translation phases
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 4 | ||||
| -rw-r--r-- | src/comp/front/creader.rs | 34 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 4 |
3 files changed, 35 insertions, 7 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 9e7c3cc1..95a5cceb 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -395,6 +395,8 @@ tag view_item_ { view_item_export(ident); } +type obj_def_ids = rec(def_id ty, def_id ctor); + type item = spanned[item_]; tag item_ { item_const(ident, @ty, @expr, def_id, ann); @@ -403,7 +405,7 @@ tag item_ { item_native_mod(ident, native_mod, def_id); item_ty(ident, @ty, vec[ty_param], def_id, ann); item_tag(ident, vec[variant], vec[ty_param], def_id); - item_obj(ident, _obj, vec[ty_param], def_id, ann); + item_obj(ident, _obj, vec[ty_param], obj_def_ids, ann); } type native_item = spanned[native_item_]; diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs index f79d6160..ea6581e0 100644 --- a/src/comp/front/creader.rs +++ b/src/comp/front/creader.rs @@ -544,6 +544,23 @@ fn read_crates(session.session sess, } +fn kind_has_type_params(u8 kind_ch) -> bool { + // FIXME: It'd be great if we had u8 char literals. + if (kind_ch == ('c' as u8)) { ret false; } + else if (kind_ch == ('f' as u8)) { ret true; } + else if (kind_ch == ('o' as u8)) { ret true; } + else if (kind_ch == ('t' as u8)) { ret true; } + else if (kind_ch == ('m' as u8)) { ret false; } + else if (kind_ch == ('n' as u8)) { ret false; } + else if (kind_ch == ('v' as u8)) { ret true; } + else { + log #fmt("kind_has_type_params(): unknown kind char: %d", + kind_ch as int); + fail; + } +} + + // Crate metadata queries fn lookup_def(session.session sess, int cnum, vec[ast.ident] path) @@ -567,7 +584,6 @@ fn lookup_def(session.session sess, int cnum, vec[ast.ident] path) auto def; if (kind_ch == ('c' as u8)) { def = ast.def_const(did); } else if (kind_ch == ('f' as u8)) { def = ast.def_fn(did); } - else if (kind_ch == ('y' as u8)) { def = ast.def_ty(did); } else if (kind_ch == ('o' as u8)) { def = ast.def_obj(did); } else if (kind_ch == ('t' as u8)) { def = ast.def_ty(did); } else if (kind_ch == ('m' as u8)) { def = ast.def_mod(did); } @@ -584,13 +600,23 @@ fn lookup_def(session.session sess, int cnum, vec[ast.ident] path) ret some[ast.def](def); } -fn get_type(session.session sess, ast.def_id def) -> ty.ty_params_and_ty { +fn get_type(session.session sess, ast.def_id def) -> ty.ty_params_opt_and_ty { auto external_crate_id = def._0; auto data = sess.get_external_crate(external_crate_id); auto ebml_r = lookup_item(def._1, data); auto t = get_item_type(ebml_r, external_crate_id); - auto tps = get_item_ty_params(ebml_r, external_crate_id); - ret tup(tps, t); + + auto tps_opt; + auto kind_ch = get_item_kind(ebml_r); + auto has_ty_params = kind_has_type_params(kind_ch); + if (has_ty_params) { + auto tps = get_item_ty_params(ebml_r, external_crate_id); + tps_opt = some[vec[ast.def_id]](tps); + } else { + tps_opt = none[vec[ast.def_id]]; + } + + ret tup(tps_opt, t); } fn get_symbol(session.session sess, ast.def_id def) -> str { diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 25c9f4a5..a247c824 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1876,8 +1876,8 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item { methods=meths, dtor=dtor); - auto item = ast.item_obj(ident, ob, ty_params, - p.next_def_id(), ast.ann_none); + auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id()); + auto item = ast.item_obj(ident, ob, ty_params, odid, ast.ann_none); ret @spanned(lo, hi, item); } |