Skip to content

Commit

Permalink
Prepare haxe_api_level 313 for nativeProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Jan 15, 2015
1 parent 3536be0 commit 6975ff6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
21 changes: 12 additions & 9 deletions gencpp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ and gen_expression ctx retval expression =
if assigning then
output ( "->__FieldRef(" ^ (str member) ^ ")" )
else
output ( "->__Field(" ^ (str member) ^ ",true)" );
output ( "->__Field(" ^ (str member) ^ ", hx::paccDynamic )" );
already_dynamic := true;
end else begin
if (isString) then
Expand Down Expand Up @@ -3003,7 +3003,7 @@ let generate_enum_files common_ctx enum_def super_deps meta file_info =
output_cpp ("}\n\n");

(* Dynamic "Get" Field function - string version *)
output_cpp ("Dynamic " ^ class_name ^ "::__Field(const ::String &inName,bool inCallProp)\n{\n");
output_cpp ("Dynamic " ^ class_name ^ "::__Field(const ::String &inName,hx::PropertyAccess inCallProp)\n{\n");
let dump_constructor_test _ constr =
output_cpp ("\tif (inName==" ^ (str constr.ef_name) ^ ") return " ^
(keyword_remap constr.ef_name) );
Expand Down Expand Up @@ -3508,13 +3508,14 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla


if (has_get_field class_def) then begin
let checkPropCall field = "inCallProp != hx::paccNever" in
(* Dynamic "Get" Field function - string version *)
output_cpp ("Dynamic " ^ class_name ^ "::__Field(const ::String &inName,bool 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 ->
(f.cf_name, String.length f.cf_name, "return " ^
(match f.cf_kind with
| Var { v_read = AccCall } when is_extern_field f -> (keyword_remap ("get_" ^ f.cf_name)) ^ "()"
| Var { v_read = AccCall } -> "inCallProp ? " ^ (keyword_remap ("get_" ^ f.cf_name)) ^ "() : " ^
| Var { v_read = AccCall } -> (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()")
) ^ ";"
Expand Down Expand Up @@ -3561,7 +3562,9 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla

(* Dynamic "Set" Field function *)
if (has_set_field class_def) then begin
output_cpp ("Dynamic " ^ class_name ^ "::__SetField(const ::String &inName,const Dynamic &inValue,bool inCallProp)\n{\n");
let checkPropCall field = "inCallProp != hx::paccNever" in

output_cpp ("Dynamic " ^ class_name ^ "::__SetField(const ::String &inName,const Dynamic &inValue,hx::PropertyAccess inCallProp)\n{\n");

let set_field_dat = List.map (fun f ->
let default_action =
Expand All @@ -3570,7 +3573,7 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
(f.cf_name, String.length f.cf_name,
(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 (inCallProp) 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
| _ -> default_action
)
Expand Down Expand Up @@ -3740,7 +3743,7 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
output_cpp ("\t} else " ^ ret );

if (class_def.cl_interface) then begin
output_cpp (" mDelegate->__Field(HX_CSTRING(\"" ^ field.cf_name ^ "\"),false)");
output_cpp (" mDelegate->__Field(HX_CSTRING(\"" ^ field.cf_name ^ "\"), hx::paccNever)");
if (List.length names <= 5) then
output_cpp ("->__run(" ^ (String.concat "," names) ^ ");")
else
Expand Down Expand Up @@ -3915,9 +3918,9 @@ let generate_class_files common_ctx member_types super_deps constructor_deps cla
output_h ("\t\t//~" ^ class_name ^ "();\n\n");
output_h ("\t\tHX_DO_RTTI_ALL;\n");
if (has_get_field class_def) then
output_h ("Dynamic __Field(const ::String &inString, bool inCallProp);\n");
output_h ("Dynamic __Field(const ::String &inString, hx::PropertyAccess inCallProp);\n");
if (has_set_field class_def) then
output_h ("Dynamic __SetField(const ::String &inString,const Dynamic &inValue, bool inCallProp);\n");
output_h ("Dynamic __SetField(const ::String &inString,const Dynamic &inValue, hx::PropertyAccess inCallProp);\n");
if (has_get_fields class_def) then
output_h ("void __GetFields(Array< ::String> &outFields);\n");

Expand Down
2 changes: 1 addition & 1 deletion main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ try
let swf_version = ref false in
let evals = ref [] in
Common.define_value com Define.HaxeVer (float_repres (float_of_int version /. 1000.));
Common.define_value com Define.HxcppApiLevel "312";
Common.define_value com Define.HxcppApiLevel "313";
Common.raw_define com "haxe3";
Common.define_value com Define.Dce "std";
com.warning <- (fun msg p -> message ctx ("Warning : " ^ msg) p);
Expand Down
33 changes: 24 additions & 9 deletions std/cpp/_std/Reflect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,60 @@
*/
@:coreApi class Reflect {

@:analyzer(ignore)
public static function hasField( o : Dynamic, field : String ) : Bool untyped {
return o!=null && o.__HasField(field);
}

@:analyzer(ignore)
public static function field( o : Dynamic, field : String ) : Dynamic untyped {
return (o==null) ? null : o.__Field(field,false);
return (o==null) ? null : o.__Field(field,untyped __cpp__("hx::paccNever") );
}

public inline static function setField( o : Dynamic, field : String, value : Dynamic ) : Void untyped {
@:analyzer(ignore)
public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void untyped {
if (o!=null)
o.__SetField(field,value,false);
o.__SetField(field,value,untyped __cpp__("hx::paccNever") );
}

public static inline function getProperty( o : Dynamic, field : String ) : Dynamic {
return (o==null) ? null : o.__Field(field,true);
@:analyzer(ignore)
public static function getProperty( o : Dynamic, field : String ) : Dynamic {
return (o==null) ? null : o.__Field(field,untyped __cpp__("hx::paccAlways") );
}

public static inline function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void {
@:analyzer(ignore)
public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void {
if (o!=null)
o.__SetField(field,value,true);
o.__SetField(field,value,untyped __cpp__("hx::paccAlways") );
}

@:analyzer(ignore)
public static function callMethod( o : Dynamic, func : haxe.Constraints.Function, args : Array<Dynamic> ) : Dynamic untyped {
if (func!=null && func.__GetType()==__global__.vtString)
func = o.__Field(func,true);
func = o.__Field(func,untyped __cpp__("hx::paccDynamic"));
untyped func.__SetThis(o);
return untyped func.__Run(args);
}

@:analyzer(ignore)
public static function fields( o : Dynamic ) : Array<String> untyped {
if( o == null ) return new Array();
var a : Array<String> = [];
o.__GetFields(a);
return a;
}

@:analyzer(ignore)
public static function isFunction( f : Dynamic ) : Bool untyped {
return f!=null && f.__GetType() == __global__.vtFunction;
}

@:analyzer(ignore)
public static function compare<T>( a : T, b : T ) : Int {
return ( a == b ) ? 0 : (((a:Dynamic) > (b:Dynamic)) ? 1 : -1);
}

@:analyzer(ignore)
public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool {
if( f1 == f2 )
return true;
Expand All @@ -73,33 +83,38 @@
return untyped __global__.__hxcpp_same_closure(f1,f2);
}

@:analyzer(ignore)
public static function isObject( v : Dynamic ) : Bool untyped {
if (v==null) return false;
var t:Int = v.__GetType();
return t == __global__.vtObject || t==__global__.vtClass || t==__global__.vtString ||
t==__global__.vtArray;
}

@:analyzer(ignore)
public static function isEnumValue( v : Dynamic ) : Bool untyped {
return v!=null && v.__GetType() == __global__.vtEnum;
}

@:analyzer(ignore)
public static function deleteField( o : Dynamic, field : String ) : Bool untyped {
if (o==null) return false;
return untyped __global__.__hxcpp_anon_remove(o,field);
}

@:analyzer(ignore)
public static function copy<T>( o : T ) : T {
if (o==null) return null;
if(untyped o.__GetType()==__global__.vtString ) return o;
if(untyped o.__GetType()==__global__.vtArray )
return untyped o.__Field("copy",true)();
return untyped o.__Field("copy", untyped __cpp__("hx::paccDynamic"))();
var o2 : Dynamic = {};
for( f in Reflect.fields(o) )
Reflect.setField(o2,f,Reflect.field(o,f));
return o2;
}

@:analyzer(ignore)
@:overload(function( f : Array<Dynamic> -> Void ) : Dynamic {})
public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic {
return untyped __global__.__hxcpp_create_var_args(f);
Expand Down

0 comments on commit 6975ff6

Please sign in to comment.