diff options
| author | Graydon Hoare <[email protected]> | 2010-12-17 17:52:18 -0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-12-17 17:52:25 -0800 |
| commit | b00abd04e26ee26a4f37d9f94dc1e28424a970d0 (patch) | |
| tree | a9eb6ccafe3235b8c65b4e08a4983c925d5a5624 /src/comp/middle | |
| parent | rustc: Zero out slots after dropping them (diff) | |
| download | rust-b00abd04e26ee26a4f37d9f94dc1e28424a970d0.tar.xz rust-b00abd04e26ee26a4f37d9f94dc1e28424a970d0.zip | |
Record type annotations for methods.
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/typeck.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index b318ce33..1ce7862c 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -621,13 +621,51 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) { ret @fold.respan[ast.item_](sp, item); } + fn get_ctor_obj_methods(@ty t) -> vec[method] { + alt (t.struct) { + case (ty_fn(_,?tobj)) { + alt (tobj.struct) { + case (ty_obj(?tm)) { + ret tm; + } + case (_) { + let vec[method] tm = vec(); + ret tm; + } + } + } + case (_) { + let vec[method] tm = vec(); + ret tm; + } + } + } + + fn fold_item_obj(&@env e, &span sp, ast.ident i, &ast._obj ob, vec[ast.ty_param] ty_params, ast.def_id id, ast.ann a) -> @ast.item { check (e.item_to_ty.contains_key(id)); auto ty = e.item_to_ty.get(id); - auto item = ast.item_obj(i, ob, ty_params, id, - ast.ann_type(ty)); + let vec[method] meth_tys = get_ctor_obj_methods(ty); + let vec[@ast.method] methods = vec(); + + let uint n = 0u; + for (method meth_ty in meth_tys) { + let @ast.method meth = ob.methods.(n); + let ast.method_ m_; + let @ast.method m; + auto meth_tfn = plain_ty(ty_fn(meth_ty.inputs, + meth_ty.output)); + m_ = rec(ann=ast.ann_type(meth_tfn) with meth.node); + m = @rec(node=m_ with *meth); + append[@ast.method](methods, m); + n += 1u; + } + + auto ob_ = rec(methods = methods with ob); + auto item = ast.item_obj(i, ob_, ty_params, id, + ast.ann_type(ty)); ret @fold.respan[ast.item_](sp, item); } |