Explorar o código

added post-process filter to promote abstract type parameters to their implementation fields

Simon Krajewski %!s(int64=12) %!d(string=hai) anos
pai
achega
aa972e7ee7
Modificáronse 3 ficheiros con 17 adicións e 1 borrados
  1. 15 0
      codegen.ml
  2. 1 0
      main.ml
  3. 1 1
      type.ml

+ 15 - 0
codegen.ml

@@ -790,6 +790,21 @@ let check_void_field ctx t = match t with
 	| _ ->
 		()
 
+(* Promotes type parameters of abstracts to their implementation fields *)
+let promote_abstract_parameters ctx t = match t with
+	| TClassDecl ({cl_kind = KAbstractImpl a} as c) when a.a_types <> [] ->
+		List.iter (fun f ->
+			List.iter (fun (n,t) -> match t with
+				| TInst({cl_kind = KTypeParameter _; cl_path=p,n} as cp,[]) when not (List.mem_assoc n f.cf_params) ->
+					let path = List.rev ((snd c.cl_path) :: List.rev (fst c.cl_path)),n in
+					f.cf_params <- (n,TInst({cp with cl_path = path},[])) :: f.cf_params
+				| _ ->
+					()
+			) a.a_types;
+		) c.cl_ordered_statics;
+	| _ ->
+		()
+
 (* -------------------------------------------------------------------------- *)
 (* LOCAL VARIABLES USAGE *)
 

+ 1 - 0
main.ml

@@ -1125,6 +1125,7 @@ try
 			Codegen.check_remove_metadata;
 			Codegen.check_void_field;
 		] in
+		let type_filters = if ctx.com.platform = Java then Codegen.promote_abstract_parameters :: type_filters else type_filters in
 		List.iter (fun t -> List.iter (fun f -> f tctx t) type_filters) com.types;
 		if ctx.has_error then raise Abort;
 		(match !xml_out with

+ 1 - 1
type.ml

@@ -145,7 +145,7 @@ and tclass_field = {
 	mutable cf_doc : Ast.documentation;
 	mutable cf_meta : metadata;
 	mutable cf_kind : field_kind;
-	cf_params : type_params;
+	mutable cf_params : type_params;
 	mutable cf_expr : texpr option;
 	mutable cf_overloads : tclass_field list;
 }