Prechádzať zdrojové kódy

[cpp] ConstPointer.raw now casts-away const, and added constRaw to get the actual const pointer. Restore logic for non-dynamic access to unknown array fields

Hugh 9 rokov pred
rodič
commit
b65f0f236f
4 zmenil súbory, kde vykonal 43 pridanie a 29 odobranie
  1. 8 3
      src/generators/gencpp.ml
  2. 24 15
      std/cpp/ConstPointer.hx
  3. 1 1
      std/cpp/NativeArray.hx
  4. 10 10
      std/cpp/Pointer.hx

+ 8 - 3
src/generators/gencpp.ml

@@ -1989,6 +1989,13 @@ let only_stack_access ctx haxe_type =
    | _ -> false;
    | _ -> false;
 ;;
 ;;
 
 
+let cpp_is_real_array obj =
+   match obj.cpptype with
+   | TCppScalarArray _
+   | TCppObjectArray _ -> true
+   | _ -> false
+;;
+
 
 
 let is_array_splice_call obj member =
 let is_array_splice_call obj member =
    match obj.cpptype, member.cf_name with
    match obj.cpptype, member.cf_name with
@@ -2230,9 +2237,7 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
                   CppVar( VarInternal(obj,".","__s")), TCppPointer("ConstPointer", TCppScalar("char"))
                   CppVar( VarInternal(obj,".","__s")), TCppPointer("ConstPointer", TCppScalar("char"))
                else if fieldName="__Index" then
                else if fieldName="__Index" then
                   CppEnumIndex(obj), TCppScalar("Int")
                   CppEnumIndex(obj), TCppScalar("Int")
-               (*else if fieldName="__Tag" then
-                  CppFunction( FuncInternal(obj,"_hx_getTag","->"), TCppString), TCppString*)
-               else if is_internal_member fieldName then begin
+               else if is_internal_member fieldName || cpp_is_real_array obj then begin
                   let cppType = cpp_return_type ctx expr.etype in
                   let cppType = cpp_return_type ctx expr.etype in
                   if obj.cpptype=TCppString then
                   if obj.cpptype=TCppString then
                      CppFunction( FuncInternal(obj,fieldName,"."), cppType), cppType
                      CppFunction( FuncInternal(obj,fieldName,"."), cppType), cppType

+ 24 - 15
std/cpp/ConstPointer.hx

@@ -26,19 +26,28 @@ extern class ConstPointer<T>
 {
 {
    // ptr actually returns the pointer - not strictly a 'T' - for pointers to smart pointers
    // ptr actually returns the pointer - not strictly a 'T' - for pointers to smart pointers
    // Use value or ref to get dereferenced value
    // Use value or ref to get dereferenced value
-	public var ptr:T;
+   public var ptr:T;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
-	public var value(get,never):T;
-	public var raw(get,never):RawConstPointer<T>;
+   public var value(get,never):T;
+
+   // Typecast to non-const
+   public var raw(get,never):RawPointer<T>;
+
+   // const version
+   public var constRaw(get,never):RawConstPointer<T>;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
    public function get_value() : T;
    public function get_value() : T;
 
 
-	public function lt(inOther:ConstPointer<T>):Bool;
-	public function leq(inOther:ConstPointer<T>):Bool;
-	public function gt(inOther:ConstPointer<T>):Bool;
-	public function geq(inOther:ConstPointer<T>):Bool;
+   public function get_constRaw() : RawConstPointer<T>;
+   public function get_raw() : RawPointer<T>;
+
+
+   public function lt(inOther:ConstPointer<T>):Bool;
+   public function leq(inOther:ConstPointer<T>):Bool;
+   public function gt(inOther:ConstPointer<T>):Bool;
+   public function geq(inOther:ConstPointer<T>):Bool;
 
 
    public function setRaw<O>(ptr:RawPointer<O>) : Void;
    public function setRaw<O>(ptr:RawPointer<O>) : Void;
 
 
@@ -47,18 +56,18 @@ extern class ConstPointer<T>
 
 
    public static function fromPointer<T>(inNativePointer:Dynamic) : ConstPointer<T>;
    public static function fromPointer<T>(inNativePointer:Dynamic) : ConstPointer<T>;
 
 
-	public function reinterpret<Other>():Pointer<Other>;
-	public function rawCast<Other>():RawPointer<Other>;
+   public function reinterpret<Other>():Pointer<Other>;
+   public function rawCast<Other>():RawPointer<Other>;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
-	public function at(inIndex:Int):T;
+   public function at(inIndex:Int):T;
 
 
-	public function inc():ConstPointer<T>;
-	public function dec():ConstPointer<T>;
+   public function inc():ConstPointer<T>;
+   public function dec():ConstPointer<T>;
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
-	public function postIncVal():T;
-	public function incBy(inT:Int):ConstPointer<T>;
-	public function add(inT:Int):ConstPointer<T>;
+   public function postIncVal():T;
+   public function incBy(inT:Int):ConstPointer<T>;
+   public function add(inT:Int):ConstPointer<T>;
 
 
 }
 }
 
 

+ 1 - 1
std/cpp/NativeArray.hx

@@ -40,7 +40,7 @@ extern class NativeArray {
 	public static inline function setData<T>( inArray:Array<T>,inData:Pointer<T>,inElementCount:Int ) : Void {
 	public static inline function setData<T>( inArray:Array<T>,inData:Pointer<T>,inElementCount:Int ) : Void {
       untyped inArray.setData(inData.raw,inElementCount);
       untyped inArray.setData(inData.raw,inElementCount);
    }
    }
-	public static inline function setUnmanagedData<T>( inArray:Array<T>,inData:Pointer<T>,inElementCount:Int ) : Void {
+	public static inline function setUnmanagedData<T>( inArray:Array<T>,inData:ConstPointer<T>,inElementCount:Int ) : Void {
       untyped inArray.setUnmanagedData(inData.raw,inElementCount);
       untyped inArray.setUnmanagedData(inData.raw,inElementCount);
    }
    }
 
 

+ 10 - 10
std/cpp/Pointer.hx

@@ -27,7 +27,7 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
    public var elementSize(default,never):Int;
    public var elementSize(default,never):Int;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
-	public var ref(get,set):T;
+   public var ref(get,set):T;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
    public function get_ref() : T;
    public function get_ref() : T;
@@ -43,19 +43,19 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
 
 
    public static function addressOf<T>(inVariable:T) : Pointer<T>;
    public static function addressOf<T>(inVariable:T) : Pointer<T>;
 
 
-	public static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;
+   public static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;
 
 
-   public function get_raw() : RawPointer<T>;
+ 
 
 
-	override public function inc():Pointer<T>;
-	override public function dec():Pointer<T>;
-	override public function incBy(inT:Int):Pointer<T>;
-	override public function add(inT:Int):Pointer<T>;
+   override public function inc():Pointer<T>;
+   override public function dec():Pointer<T>;
+   override public function incBy(inT:Int):Pointer<T>;
+   override public function add(inT:Int):Pointer<T>;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
-	public function postIncRef():T;
+   public function postIncRef():T;
 
 
-	public function destroy():Void;
-	public function destroyArray():Void;
+   public function destroy():Void;
+   public function destroyArray():Void;
 }
 }