Bladeren bron

[cpp] Add RawPointer.addressOf

hughsando 9 jaren geleden
bovenliggende
commit
141829b64c
3 gewijzigde bestanden met toevoegingen van 14 en 1 verwijderingen
  1. 10 1
      src/generators/gencpp.ml
  2. 2 0
      std/cpp/RawConstPointer.hx
  3. 2 0
      std/cpp/RawPointer.hx

+ 10 - 1
src/generators/gencpp.ml

@@ -1463,6 +1463,7 @@ and tcpp_expr_expr =
    | CppEnumField of tenum * tenum_field
    | CppCall of tcppfuncloc * tcppexpr list
    | CppFunctionAddress of tclass * tclass_field
+   | CppAddressOf of tcppexpr
    | CppArray of tcpparrayloc
    | CppCrement of  tcppcrementop * Ast.unop_flag * tcpplvalue
    | CppSet of tcpplvalue * tcppexpr
@@ -1540,6 +1541,7 @@ let rec s_tcpp = function
    | CppCall (FuncGlobal _,_) -> "CppCallGlobal"
    | CppCall (FuncFromStaticFunction,_) -> "CppCallFromStaticFunction"
 
+   | CppAddressOf _  -> "CppAddressOf"
    | CppFunctionAddress  _ -> "CppFunctionAddress"
    | CppArray  _ -> "CppArray"
    | CppCrement  _ -> "CppCrement"
@@ -2549,6 +2551,10 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
                |  CppFunction( FuncInstance(obj, false, member), args ) when return_type=TCppVoid && is_array_splice_call obj member ->
                      CppCall( FuncInstance(obj, false, {member with cf_name="removeRange"}), retypedArgs), TCppVoid
 
+               |  CppFunction( FuncStatic(obj, false, member), _ ) when member.cf_name = "hx::AddressOf" ->
+                    let arg = retype TCppUnchanged (List.hd args) in
+                    CppAddressOf(arg), TCppRawPointer("", arg.cpptype)
+
                |  CppFunction( FuncStatic(obj, false, member), returnType ) when cpp_is_templated_call ctx member ->
                      (match retypedArgs with
                      | {cppexpr = CppClassOf(path,native) }::rest ->
@@ -3268,6 +3274,9 @@ let gen_cpp_ast_expression_tree ctx class_name func_name function_args injection
             ) !argsRef;
          out (")" ^ !closeCall);
 
+      | CppAddressOf(e) ->
+         out ("&("); gen e; out ")";
+
       | CppFunctionAddress(klass, member) ->
          let signature = ctx_function_signature ctx false member.cf_type "" in
          let name = cpp_member_name_of member in
@@ -5017,7 +5026,7 @@ let generate_protocol_delegate ctx class_def output =
          let nativeName = get_meta_string field.cf_meta Meta.ObjcProtocol in
          let fieldName,argNames = if nativeName<>"" then begin
             let parts = ExtString.String.nsplit nativeName ":" in
-            List.hd parts, List.tl parts
+            List.hd parts, parts
          end else
             field.cf_name, List.map (fun (n,_,_) -> n ) args
          in

+ 2 - 0
std/cpp/RawConstPointer.hx

@@ -24,4 +24,6 @@
 @:unreflective
 extern class RawConstPointer<T> implements ArrayAccess<T>
 {
+   @:native("hx::AddressOf")
+   public static function addressOf<T>(t:T) : RawConstPointer<T>;
 }

+ 2 - 0
std/cpp/RawPointer.hx

@@ -24,4 +24,6 @@
 @:unreflective
 extern class RawPointer<T> extends RawConstPointer<T>
 {
+   @:native("hx::AddressOf")
+   public static function addressOf<T>(t:T) : RawPointer<T>;
 }