2
0
Эх сурвалжийг харах

[java/cs] Added @:nativeChildren

Cauê Waneck 11 жил өмнө
parent
commit
ebd83a86a7
3 өөрчлөгдсөн 25 нэмэгдсэн , 9 устгасан
  1. 1 0
      ast.ml
  2. 1 0
      common.ml
  3. 23 9
      gencommon.ml

+ 1 - 0
ast.ml

@@ -99,6 +99,7 @@ module Meta = struct
 		| MergeBlock
 		| MultiType
 		| Native
+		| NativeChildren
 		| NativeGen
 		| NativeGeneric
 		| NoCompletion

+ 1 - 0
common.ml

@@ -403,6 +403,7 @@ module MetaInfo = struct
 		| MergeBlock -> ":mergeBlock",("Internally used by typer to mark block that should be merged into the outer scope",[Internal])
 		| MultiType -> ":multiType",("Specifies that an abstract chooses its this-type from its @:to functions",[UsedOn TAbstract; HasParam "Relevant type parameters"])
 		| Native -> ":native",("Rewrites the path of a class or enum during generation",[HasParam "Output type path";UsedOnEither [TClass;TEnum]])
+		| NativeChildren -> ":nativeChildren",("Annotates that all children from a type should be treated as if it were an extern definition - platform native",[Platforms [Java;Cs]; UsedOn TClass])
 		| NativeGen -> ":nativeGen",("Annotates that a type should be treated as if it were an extern definition - platform native",[Platforms [Java;Cs;Python]; UsedOnEither[TClass;TEnum]])
 		| NativeGeneric -> ":nativeGeneric",("Used internally to annotate native generic classes",[Platform Cs; UsedOnEither[TClass;TEnum]; Internal])
 		| NoCompletion -> ":noCompletion",("Prevents the compiler from suggesting completion on this field",[UsedOn TClassField])

+ 23 - 9
gencommon.ml

@@ -1500,15 +1500,28 @@ struct
 	let default_hxgen_func md =
 		match md with
 			| TClassDecl cl ->
-				let rec is_hxgen_class c =
+				let rec is_hxgen_class (c,_) =
 					if c.cl_extern then begin
-						if Meta.has Meta.HxGen c.cl_meta then true else Option.map_default (fun (c,_) -> is_hxgen_class c) false c.cl_super
+						if Meta.has Meta.HxGen c.cl_meta then true else Option.map_default (is_hxgen_class) false c.cl_super
 					end else begin
-						if Meta.has Meta.NativeGen c.cl_meta then Option.map_default (fun (c, _) -> is_hxgen_class c) false c.cl_super else true
+						if Meta.has Meta.NativeChildren c.cl_meta || Meta.has Meta.NativeGen c.cl_meta then
+							Option.map_default (is_hxgen_class) false c.cl_super
+						else
+							let rec has_nativec (c,p) =
+								if is_hxgen_class (c,p) then
+									false
+								else
+									(Meta.has Meta.NativeChildren c.cl_meta && not (Option.map_default is_hxgen_class false c.cl_super))
+									|| Option.map_default has_nativec false c.cl_super
+							in
+							if Option.map_default has_nativec false c.cl_super then
+								false
+							else
+								true
 					end
 				in
 
-				is_hxgen_class cl
+				is_hxgen_class (cl,[])
 			| TEnumDecl e -> if e.e_extern then Meta.has Meta.HxGen e.e_meta else not (Meta.has Meta.NativeGen e.e_meta)
 			| TAbstractDecl a -> not (Meta.has Meta.NativeGen a.a_meta)
 			| TTypeDecl t -> (* TODO see when would we use this *)
@@ -1520,12 +1533,13 @@ struct
 	*)
 	let run_filter gen is_hxgen_func =
 		let filter md =
-			if is_hxgen_func md then begin
+			let meta = if is_hxgen_func md then Meta.HxGen else Meta.NativeGen in
+			begin
 				match md with
-					| TClassDecl cl -> cl.cl_meta <- (Meta.HxGen, [], cl.cl_pos) :: cl.cl_meta
-					| TEnumDecl e -> e.e_meta <- (Meta.HxGen, [], e.e_pos) :: e.e_meta
-					| TTypeDecl t -> t.t_meta <- (Meta.HxGen, [], t.t_pos) :: t.t_meta
-					| TAbstractDecl a -> a.a_meta <- (Meta.HxGen, [], a.a_pos) :: a.a_meta
+					| TClassDecl cl -> cl.cl_meta <- (meta, [], cl.cl_pos) :: cl.cl_meta
+					| TEnumDecl e -> e.e_meta <- (meta, [], e.e_pos) :: e.e_meta
+					| TTypeDecl t -> t.t_meta <- (meta, [], t.t_pos) :: t.t_meta
+					| TAbstractDecl a -> a.a_meta <- (meta, [], a.a_pos) :: a.a_meta
 			end
 		in
 		List.iter filter gen.gcon.types