|
@@ -37,25 +37,15 @@ let transform_abstract_field com this_t a_t a f =
|
|
|
| FFun fu when f.cff_name = "new" && not stat ->
|
|
|
let init p = (EVars ["this",Some this_t,None],p) in
|
|
|
let cast e = (ECast(e,None)),pos e in
|
|
|
- let check_type e ct = (ECheckType(e,ct)),pos e in
|
|
|
let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
|
|
|
if Meta.has Meta.MultiType a.a_meta then begin
|
|
|
if List.mem AInline f.cff_access then error "MultiType constructors cannot be inline" f.cff_pos;
|
|
|
if fu.f_expr <> None then error "MultiType constructors cannot have a body" f.cff_pos;
|
|
|
end;
|
|
|
- let has_call e =
|
|
|
- let rec loop e = match fst e with
|
|
|
- | ECall _ -> raise Exit
|
|
|
- | _ -> Ast.map_expr loop e
|
|
|
- in
|
|
|
- try ignore(loop e); false with Exit -> true
|
|
|
- in
|
|
|
let fu = {
|
|
|
fu with
|
|
|
f_expr = (match fu.f_expr with
|
|
|
| None -> if Meta.has Meta.MultiType a.a_meta then Some (EConst (Ident "null"),p) else None
|
|
|
- | Some (EBlock [EBinop (OpAssign,(EConst (Ident "this"),_),e),_],_ | EBinop (OpAssign,(EConst (Ident "this"),_),e),_) when not (has_call e) ->
|
|
|
- Some (EReturn (Some (cast (check_type e this_t))), pos e)
|
|
|
| Some (EBlock el,p) -> Some (EBlock (init p :: el @ [ret p]),p)
|
|
|
| Some e -> Some (EBlock [init p;e;ret p],p)
|
|
|
);
|