Browse Source

[cpp] Cripple native property usage by default. Closes #2852.

Hugh 10 years ago
parent
commit
9b27cc8e25
3 changed files with 19 additions and 9 deletions
  1. 1 0
      ast.ml
  2. 3 0
      common.ml
  3. 15 9
      gencpp.ml

+ 1 - 0
ast.ml

@@ -110,6 +110,7 @@ module Meta = struct
 		| NativeChildren
 		| NativeChildren
 		| NativeGen
 		| NativeGen
 		| NativeGeneric
 		| NativeGeneric
+		| NativeProperty
 		| NoCompletion
 		| NoCompletion
 		| NoDebug
 		| NoDebug
 		| NoDoc
 		| NoDoc

+ 3 - 0
common.ml

@@ -189,6 +189,7 @@ module Define = struct
 		| FileExtension
 		| FileExtension
 		| FlashStrict
 		| FlashStrict
 		| FlashUseStage
 		| FlashUseStage
+		| ForceNativeProperty
 		| FormatWarning
 		| FormatWarning
 		| GencommonDebug
 		| GencommonDebug
 		| HaxeBoot
 		| HaxeBoot
@@ -271,6 +272,7 @@ module Define = struct
 		| FileExtension -> ("file_extension","Output filename extension for cpp source code")
 		| FileExtension -> ("file_extension","Output filename extension for cpp source code")
 		| FlashStrict -> ("flash_strict","More strict typing for flash target")
 		| FlashStrict -> ("flash_strict","More strict typing for flash target")
 		| FlashUseStage -> ("flash_use_stage","Keep the SWF library initial stage")
 		| FlashUseStage -> ("flash_use_stage","Keep the SWF library initial stage")
+		| ForceNativeProperty -> ("force_native_property","Tag all properties with :nativeProperty metadata for 3.1 compatibility")
 		| FormatWarning -> ("format_warning","Print a warning for each formated string, for 2.x compatibility")
 		| FormatWarning -> ("format_warning","Print a warning for each formated string, for 2.x compatibility")
 		| GencommonDebug -> ("gencommon_debug","GenCommon internal")
 		| GencommonDebug -> ("gencommon_debug","GenCommon internal")
 		| HaxeBoot -> ("haxe_boot","Given the name 'haxe' to the flash boot class instead of a generated name")
 		| HaxeBoot -> ("haxe_boot","Given the name 'haxe' to the flash boot class instead of a generated name")
@@ -435,6 +437,7 @@ module MetaInfo = struct
 		| 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])
 		| 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]])
 		| 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])
 		| NativeGeneric -> ":nativeGeneric",("Used internally to annotate native generic classes",[Platform Cs; UsedOnEither[TClass;TEnum]; Internal])
+		| NativeProperty -> ":nativeProperty",("Use native properties which will execute even with dynamic usage",[Platform Cpp])
 		| NoCompletion -> ":noCompletion",("Prevents the compiler from suggesting completion on this field",[UsedOn TClassField])
 		| NoCompletion -> ":noCompletion",("Prevents the compiler from suggesting completion on this field",[UsedOn TClassField])
 		| NoDebug -> ":noDebug",("Does not generate debug information into the Swf even if -debug is set",[UsedOnEither [TClass;TClassField];Platform Flash])
 		| NoDebug -> ":noDebug",("Does not generate debug information into the Swf even if -debug is set",[UsedOnEither [TClass;TClassField];Platform Flash])
 		| NoDoc -> ":noDoc",("Prevents a type from being included in documentation generation",[])
 		| NoDoc -> ":noDoc",("Prevents a type from being included in documentation generation",[])

+ 15 - 9
gencpp.ml

@@ -3542,18 +3542,27 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
          end;
          end;
       in
       in
 
 
+      let checkPropCall field = if ( (has_meta_key class_def.cl_meta Meta.NativeProperty) ||
+                                     (has_meta_key field.cf_meta Meta.NativeProperty) ||
+                                     (Common.defined common_ctx Define.ForceNativeProperty) )
+         then
+            "inCallProp != hx::paccNever"
+         else
+            "inCallProp == hx::paccAlways"
+      in
+
+
 
 
       if (has_get_field class_def) then begin
       if (has_get_field class_def) then begin
-         let checkPropCall field = "inCallProp != hx::paccNever" in
          (* Dynamic "Get" Field function - string version *)
          (* Dynamic "Get" Field function - string version *)
          output_cpp ("Dynamic " ^ class_name ^ "::__Field(const ::String &inName,hx::PropertyAccess inCallProp)\n{\n");
          output_cpp ("Dynamic " ^ class_name ^ "::__Field(const ::String &inName,hx::PropertyAccess inCallProp)\n{\n");
          let get_field_dat = List.map (fun f ->
          let get_field_dat = List.map (fun f ->
-            (f.cf_name, String.length f.cf_name, "return " ^
+            (f.cf_name, String.length f.cf_name, 
                (match f.cf_kind with
                (match f.cf_kind with
-               | Var { v_read = AccCall } when is_extern_field f -> (keyword_remap ("get_" ^ f.cf_name)) ^ "()"
-               | Var { v_read = AccCall } -> (checkPropCall f) ^ " ? " ^ (keyword_remap ("get_" ^ f.cf_name)) ^ "() : " ^
+               | Var { v_read = AccCall } when is_extern_field f -> "if (" ^ (checkPropCall f) ^ ") return " ^(keyword_remap ("get_" ^ f.cf_name)) ^ "()"
+               | Var { v_read = AccCall } -> "return " ^ (checkPropCall f) ^ " ? " ^ (keyword_remap ("get_" ^ f.cf_name)) ^ "() : " ^
                      ((keyword_remap f.cf_name) ^ if (variable_field f) then "" else "_dyn()")
                      ((keyword_remap f.cf_name) ^ if (variable_field f) then "" else "_dyn()")
-               | _ -> ((keyword_remap f.cf_name) ^ if (variable_field f) then "" else "_dyn()")
+               | _ -> "return " ^ ((keyword_remap f.cf_name) ^ if (variable_field f) then "" else "_dyn()")
                ) ^ ";"
                ) ^ ";"
             ) )
             ) )
          in
          in
@@ -3595,10 +3604,8 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
          end;
          end;
       end;
       end;
 
 
-
       (* Dynamic "Set" Field function *)
       (* Dynamic "Set" Field function *)
       if (has_set_field class_def) then begin
       if (has_set_field class_def) then begin
-         let checkPropCall field = "inCallProp != hx::paccNever" in
 
 
          output_cpp ("Dynamic " ^ class_name ^ "::__SetField(const ::String &inName,const Dynamic &inValue,hx::PropertyAccess inCallProp)\n{\n");
          output_cpp ("Dynamic " ^ class_name ^ "::__SetField(const ::String &inName,const Dynamic &inValue,hx::PropertyAccess inCallProp)\n{\n");
 
 
@@ -3608,9 +3615,8 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
                   " return inValue;" in
                   " return inValue;" in
             (f.cf_name, String.length f.cf_name,
             (f.cf_name, String.length f.cf_name,
                (match f.cf_kind with
                (match f.cf_kind with
-               | Var { v_write = AccCall } when is_extern_field f -> "return " ^ (keyword_remap ("set_" ^ f.cf_name)) ^ "(inValue);"
                | Var { v_write = AccCall } -> "if (" ^ (checkPropCall f) ^ ") return " ^ (keyword_remap ("set_" ^ f.cf_name)) ^ "(inValue);"
                | Var { v_write = AccCall } -> "if (" ^ (checkPropCall f) ^ ") return " ^ (keyword_remap ("set_" ^ f.cf_name)) ^ "(inValue);"
-                  ^ default_action
+                  ^ ( if is_extern_field f then "" else default_action )
                | _ -> default_action
                | _ -> default_action
                )
                )
             )
             )