aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-12-16 15:55:28 -0800
committerGraydon Hoare <[email protected]>2010-12-16 15:55:28 -0800
commit31f0642da3519985e69235be6cc30fc3f574ba95 (patch)
tree4e986e1ae96b64325d501b134d2ad55362c3400f /src/comp/middle
parentrustc: Add a type fold mechanism to the typechecker (diff)
downloadrust-31f0642da3519985e69235be6cc30fc3f574ba95.tar.xz
rust-31f0642da3519985e69235be6cc30fc3f574ba95.zip
Stub out translation of obj ctors (no vtbl or body built).
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/trans.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 747a7c67..b074e6d6 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -2253,6 +2253,15 @@ fn arg_tys_of_fn(ast.ann ann) -> vec[typeck.arg] {
fail;
}
+fn ret_ty_of_fn(ast.ann ann) -> @typeck.ty {
+ alt (typeck.ann_to_type(ann).struct) {
+ case (typeck.ty_fn(_, ?ret_ty)) {
+ ret ret_ty;
+ }
+ }
+ fail;
+}
+
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
&ast.ann ann) {
@@ -2274,6 +2283,33 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
}
}
+fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
+ &ast.ann ann) {
+
+ auto llctor_decl = cx.item_ids.get(oid);
+ cx.item_names.insert(cx.path, llctor_decl);
+
+ // Translate obj ctor fields to function arguments.
+ let vec[ast.arg] fn_args = vec();
+ for (ast.obj_field f in ob.fields) {
+ fn_args += vec(rec(mode=ast.alias,
+ ty=f.ty,
+ ident=f.ident,
+ id=f.id));
+ }
+
+ auto fcx = new_fn_ctxt(cx, cx.path, llctor_decl);
+ create_llargs_for_fn_args(fcx, fn_args);
+
+ auto bcx = new_top_block_ctxt(fcx);
+
+ copy_args_to_allocas(bcx, fn_args, arg_tys_of_fn(ann));
+
+ auto pair = bcx.build.Alloca(type_of(cx, ret_ty_of_fn(ann)));
+
+ bcx.build.Ret(pair);
+}
+
fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
&ast.variant variant, int index) {
if (_vec.len[ast.variant_arg](variant.args) == 0u) {
@@ -2351,6 +2387,10 @@ impure fn trans_item(@crate_ctxt cx, &ast.item item) {
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
trans_fn(sub_cx, f, fid, ann);
}
+ case (ast.item_obj(?name, ?ob, _, ?oid, ?ann)) {
+ auto sub_cx = @rec(path=cx.path + "." + name with *cx);
+ trans_obj(sub_cx, ob, oid, ann);
+ }
case (ast.item_mod(?name, ?m, _)) {
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
trans_mod(sub_cx, m);