فهرست منبع

use Meta.HlNative instead of Meta.Custom ":hlNative"

Dan Korostelev 7 سال پیش
والد
کامیت
eba0fd3818
3فایلهای تغییر یافته به همراه12 افزوده شده و 10 حذف شده
  1. 2 0
      src/core/meta.ml
  2. 9 9
      src/generators/genhl.ml
  3. 1 1
      src/optimization/analyzerTexpr.ml

+ 2 - 0
src/core/meta.ml

@@ -69,6 +69,7 @@ type strict_meta =
 	| HeaderCode
 	| HeaderInclude
 	| HeaderNamespaceCode
+	| HlNative
 	| HxGen
 	| IfFeature
 	| Impl
@@ -266,6 +267,7 @@ let get_info = function
 	| HeaderCode -> ":headerCode",("Code to be injected into the generated header file",[Platform Cpp])
 	| HeaderInclude -> ":headerInclude",("File to be included in generated header file",[Platform Cpp])
 	| HeaderNamespaceCode -> ":headerNamespaceCode",("",[Platform Cpp])
+	| HlNative -> ":hlNative",("Specifies hdll name and function prefix for native functions",[UsedOnEither [TClass;TClassField];Platform Hl])
 	| HxGen -> ":hxGen",("Annotates that an extern class was generated by Haxe",[Platforms [Java;Cs]; UsedOnEither [TClass;TEnum]])
 	| IfFeature -> ":ifFeature",("Causes a field to be kept by DCE if the given feature is part of the compilation",[HasParam "Feature name";UsedOn TClassField])
 	| Impl -> ":impl",("Used internally to mark abstract implementation fields",[UsedOn TAbstractField; UsedInternally])

+ 9 - 9
src/generators/genhl.ml

@@ -135,7 +135,7 @@ let is_to_string t =
 	| _ -> false
 
 let is_extern_field f =
-	not (Type.is_physical_field f) || (match f.cf_kind with Method MethNormal -> List.exists (fun (m,_,_) -> m = Meta.Custom ":hlNative") f.cf_meta | _ -> false) || Meta.has Meta.Extern f.cf_meta
+	not (Type.is_physical_field f) || (match f.cf_kind with Method MethNormal -> List.exists (fun (m,_,_) -> m = Meta.HlNative) f.cf_meta | _ -> false) || Meta.has Meta.Extern f.cf_meta
 
 let is_array_class name =
 	match name with
@@ -3122,13 +3122,13 @@ let generate_static ctx c f =
 			));
 		in
 		let rec loop = function
-			| (Meta.Custom ":hlNative",[(EConst(String(lib)),_);(EConst(String(name)),_)] ,_ ) :: _ ->
+			| (Meta.HlNative,[(EConst(String(lib)),_);(EConst(String(name)),_)] ,_ ) :: _ ->
 				add_native lib name
-			| (Meta.Custom ":hlNative",[(EConst(String(lib)),_)] ,_ ) :: _ ->
+			| (Meta.HlNative,[(EConst(String(lib)),_)] ,_ ) :: _ ->
 				add_native lib f.cf_name
-			| (Meta.Custom ":hlNative",[] ,_ ) :: _ ->
+			| (Meta.HlNative,[] ,_ ) :: _ ->
 				add_native "std" f.cf_name
-			| (Meta.Custom ":hlNative",_ ,p) :: _ ->
+			| (Meta.HlNative,_ ,p) :: _ ->
 				abort "Invalid @:hlNative decl" p
 			| [] ->
 				ignore(make_fun ctx (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) None None)
@@ -3184,7 +3184,7 @@ let generate_type ctx t =
 		List.iter (fun f ->
 			List.iter (fun (name,args,pos) ->
 				match name with
-				| Meta.Custom ":hlNative" -> generate_static ctx c f
+				| Meta.HlNative -> generate_static ctx c f
 				| _ -> ()
 			) f.cf_meta
 		) c.cl_ordered_statics
@@ -3771,7 +3771,7 @@ let add_types ctx types =
 			in
 			if not ctx.is_macro then List.iter (fun f -> ignore(loop c.cl_super f)) c.cl_overrides;
 			List.iter (fun (m,args,p) ->
-				if m = Meta.Custom ":hlNative" then
+				if m = Meta.HlNative then
 					let lib, prefix = (match args with
 					| [(EConst (String lib),_)] -> lib, ""
 					| [(EConst (String lib),_);(EConst (String p),_)] -> lib, p
@@ -3780,11 +3780,11 @@ let add_types ctx types =
 					(* adds :hlNative for all empty methods *)
 					List.iter (fun f ->
 						match f.cf_kind with
-						| Method MethNormal when not (List.exists (fun (m,_,_) -> m = Meta.Custom ":hlNative") f.cf_meta) ->
+						| Method MethNormal when not (List.exists (fun (m,_,_) -> m = Meta.HlNative) f.cf_meta) ->
 							(match f.cf_expr with
 							| Some { eexpr = TFunction { tf_expr = { eexpr = TBlock ([] | [{ eexpr = TReturn (Some { eexpr = TConst _ })}]) } } } | None ->
 								let name = prefix ^ String.lowercase (Str.global_replace (Str.regexp "[A-Z]+") "_\\0" f.cf_name) in
-								f.cf_meta <- (Meta.Custom ":hlNative", [(EConst (String lib),p);(EConst (String name),p)], p) :: f.cf_meta;
+								f.cf_meta <- (Meta.HlNative, [(EConst (String lib),p);(EConst (String name),p)], p) :: f.cf_meta;
 							| _ -> ())
 						| _ -> ()
 					) c.cl_ordered_statics

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -1237,7 +1237,7 @@ module Purity = struct
 				| None ->
 					if not (is_pure c cf) then taint node
 				(* TODO: The function code check shouldn't be here I guess. *)
-				| Some _ when (Meta.has Meta.Extern cf.cf_meta || Meta.has Meta.FunctionCode cf.cf_meta || Meta.has (Meta.Custom ":hlNative") cf.cf_meta || Meta.has (Meta.Custom ":hlNative") c.cl_meta) ->
+				| Some _ when (Meta.has Meta.Extern cf.cf_meta || Meta.has Meta.FunctionCode cf.cf_meta || Meta.has (Meta.HlNative) cf.cf_meta || Meta.has (Meta.HlNative) c.cl_meta) ->
 					if not (is_pure c cf) then taint node
 				| Some e ->
 					try