Browse Source

added :getter/:setter support for interfaces (fixed issue #887)

Nicolas Cannasse 13 years ago
parent
commit
6d21283839
2 changed files with 18 additions and 9 deletions
  1. 7 1
      genas3.ml
  2. 11 8
      genswf9.ml

+ 7 - 1
genas3.ml

@@ -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;

+ 11 - 8
genswf9.ml

@@ -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 =
@@ -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
@@ -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)