Skip to content

Commit

Permalink
added :getter/:setter support for interfaces (fixed issue HaxeFoundat…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Jun 6, 2012
1 parent 60c4391 commit 6d21283
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 7 additions & 1 deletion genas3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,13 @@ let generate_field ctx static f =
if ctx.curclass.cl_interface then
match follow f.cf_type with
| TFun (args,r) ->
print ctx "function %s(" f.cf_name;
let rec loop = function
| [] -> f.cf_name
| (":getter",[Ast.EConst (Ast.String name),_],_) :: _ -> "get " ^ name
| (":setter",[Ast.EConst (Ast.String name),_],_) :: _ -> "set " ^ name
| _ :: l -> loop l
in
print ctx "function %s(" (loop f.cf_meta);
concat ctx "," (fun (arg,o,t) ->
let tstr = type_str ctx t p in
print ctx "%s : %s" arg tstr;
Expand Down
19 changes: 11 additions & 8 deletions genswf9.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,15 @@ let extract_meta meta =
| l -> Some (Array.of_list l)

let generate_field_kind ctx f c stat =
let method_kind() =
let rec loop = function
| [] -> f.cf_name, MK3Normal
| (":getter",[EConst (Ident f),_],_) :: _ -> f, MK3Getter
| (":setter",[EConst (Ident f),_],_) :: _ -> f, MK3Setter
| _ :: l -> loop l
in
loop f.cf_meta
in
match f.cf_expr with
| Some { eexpr = TFunction fdata } ->
let rec loop c name =
Expand All @@ -1908,13 +1917,7 @@ let generate_field_kind ctx f c stat =
hlv_const = false;
})
| _ ->
let rec lookup_kind = function
| [] -> f.cf_name, MK3Normal
| (":getter",[EConst (Ident f),_],_) :: _ -> f, MK3Getter
| (":setter",[EConst (Ident f),_],_) :: _ -> f, MK3Setter
| _ :: l -> lookup_kind l
in
let name, kind = lookup_kind f.cf_meta in
let name, kind = method_kind() in
let old = ctx.debug in
ctx.debug <- (old || has_meta ":debug" f.cf_meta) && not (has_meta ":nodebug" f.cf_meta);
let m = generate_method ctx fdata stat in
Expand All @@ -1940,7 +1943,7 @@ let generate_field_kind ctx f c stat =
hlm_type = end_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t, (if opt then Some TNull else None)) args) dparams tret;
hlm_final = false;
hlm_override = false;
hlm_kind = MK3Normal;
hlm_kind = snd (method_kind());
})
| _ ->
None)
Expand Down

0 comments on commit 6d21283

Please sign in to comment.