Explorar el Código

[cpp] Add explicit Native.star for dereferencing pointers.

hughsando hace 6 años
padre
commit
cb082b6b10
Se han modificado 2 ficheros con 13 adiciones y 2 borrados
  1. 4 0
      src/generators/gencpp.ml
  2. 9 2
      std/cpp/Native.hx

+ 4 - 0
src/generators/gencpp.ml

@@ -2671,6 +2671,10 @@ let retype_expression ctx request_type function_args function_type expression_tr
                     let rawType = match arg.cpptype with | TCppReference(x) -> x | x -> x in
                     CppAddressOf(arg), TCppStar(rawType,false)
 
+               | CppFunction( FuncStatic(obj, false, member), _ ) when member.cf_name = "hx::Dereference" ->
+                    let arg = retype TCppUnchanged (List.hd args) in
+                    CppDereference(arg), arg.cpptype
+
                | CppFunction( FuncStatic(obj, false, member), _ ) when member.cf_name = "_hx_create_array_length" ->
                   let retypedArgs = List.map (retype TCppDynamic ) args in
                   (* gc_stack - not needed yet *)

+ 9 - 2
std/cpp/Native.hx

@@ -40,16 +40,19 @@ extern class Native
    public static function sizeof<T>(t:T) : Int;
 
    #if !cppia
+   @:native("hx::Dereference")
+   public static function star<T>(ptr:cpp.Star<T>) : cpp.Reference<T>;
+
    @:generic
    public static inline function set<T>(ptr:cpp.Star<T>,value:T) : Void
    {
-      var ref: cpp.Reference<T> = ptr;
+      var ref: cpp.Reference<T> = star(ptr);
       ref = value;
    }
    @:generic
    public static inline function get<T>(ptr:cpp.Star<T>) : T
    {
-      var ref: cpp.Reference<T> = ptr;
+      var ref: cpp.Reference<T> = star(ptr);
       return ref;
    }
 
@@ -85,6 +88,10 @@ extern class Native
    {
       throw "Native.addressOf not available in cppia";
    }
+   public static inline function star<T>(ptr:cpp.Star<T>) : cpp.Reference<T>
+   {
+      throw "Native.star not available in cppia";
+   }
 
    public static inline function set<T>(ptr:cpp.Star<T>,value:T) : Void
    {