Skip to content

Commit

Permalink
use Meta.HlNative instead of Meta.Custom ":hlNative"
Browse files Browse the repository at this point in the history
  • Loading branch information
nadako committed Feb 5, 2018
1 parent 3db1a89 commit eba0fd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/core/meta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type strict_meta =
| HeaderCode
| HeaderInclude
| HeaderNamespaceCode
| HlNative
| HxGen
| IfFeature
| Impl
Expand Down Expand Up @@ -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])
Expand Down
18 changes: 9 additions & 9 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/optimization/analyzerTexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eba0fd3

Please sign in to comment.