Browse Source

[cpp] Correctly name the types involved with converting pointers

hughsando 8 years ago
parent
commit
9e1b37fe9e
4 changed files with 41 additions and 17 deletions
  1. 6 1
      src/generators/gencpp.ml
  2. 24 0
      std/cpp/AutoCast.hx
  3. 5 7
      std/cpp/Function.hx
  4. 6 9
      std/cpp/Pointer.hx

+ 6 - 1
src/generators/gencpp.ml

@@ -1366,6 +1366,7 @@ type tcpp =
    | TCppStar of tcpp
    | TCppVoidStar
    | TCppVarArg
+   | TCppAutoCast
    | TCppDynamicArray
    | TCppObjectArray of tcpp
    | TCppWrapped of tcpp
@@ -1598,6 +1599,7 @@ and tcpp_to_string_suffix suffix tcpp = match tcpp with
    | TCppVoidStar -> "void *"
    | TCppRest _ -> "vaarg_list"
    | TCppVarArg -> "vararg"
+   | TCppAutoCast -> "::cpp::AutoCast"
    | TCppVariant -> "::cpp::Variant"
    | TCppEnum(enum) -> " ::" ^ (join_class_path_remap enum.e_path "::") ^ suffix
    | TCppScalar(scalar) -> scalar
@@ -1792,6 +1794,7 @@ let rec cpp_type_of ctx haxe_type =
       | (["cpp"], "UInt32"),_ -> TCppScalar("unsigned int")
       | (["cpp"], "UInt64"),_ -> TCppScalar("::cpp::UInt64")
       | (["cpp"], "VarArg"),_ -> TCppVarArg
+      | (["cpp"], "AutoCast"),_ -> TCppAutoCast
 
       | ([],"String"), [] ->
          TCppString
@@ -2015,6 +2018,7 @@ let cpp_variant_type_of t = match t with
    | TCppNativePointer _
    | TCppPointer _
    | TCppRawPointer _
+   | TCppAutoCast
    | TCppVarArg
    | TCppVoidStar -> TCppVoidStar
    | TCppScalar "Int"
@@ -2944,9 +2948,10 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
          | _ -> cppExpr
       end else match cppExpr.cpptype, return_type with
          | _, TCppUnchanged -> cppExpr
+         | TCppAutoCast, _
          | TCppObjC(_), TCppDynamic
          | TCppObjCBlock(_), TCppDynamic
-              -> mk_cppexpr (CppCast(cppExpr,TCppDynamic)) return_type
+              -> mk_cppexpr (CppCast(cppExpr,return_type)) return_type
          | TCppReference(TCppDynamic), TCppReference(_) -> cppExpr
          | TCppReference(TCppDynamic),  t ->
              mk_cppexpr retypedExpr (TCppReference(t))

+ 24 - 0
std/cpp/AutoCast.hx

@@ -0,0 +1,24 @@
+/*
+ * Copyright (C)2005-2016 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cpp;
+
+extern class AutoCast { }

+ 5 - 7
std/cpp/Function.hx

@@ -30,19 +30,17 @@ extern class Function<T,ABI:cpp.abi.Abi>
 	public var call(default,null):T;
 
    @:native("::cpp::Function_obj::getProcAddress")
-   static function nativeGetProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : Function<T,ABI>;
-   public static function getProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : Function<T,ABI>
+   static function nativeGetProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : AutoCast;
+   inline public static function getProcAddress<T,ABI:cpp.abi.Abi>(inModule:String, inFunction:String) : Function<T,ABI>
    {
-      var autoCast = nativeGetProcAddress(inModule, inFunction);
-      return autoCast;
+      return cast nativeGetProcAddress(inModule, inFunction);
    }
 
    @:native("::cpp::Function_obj::fromStaticFunction")
-   static function nativeFromStaticFunction<T>(inStaticFunction:T) : Callable<T>;
+   static function nativeFromStaticFunction<T>(inStaticFunction:T) : AutoCast;
    inline public static function fromStaticFunction<T>(inStaticFunction:T) : Callable<T>
    {
-      var autoCast = nativeFromStaticFunction(inStaticFunction);
-      return autoCast;
+      return cast nativeFromStaticFunction(inStaticFunction);
    }
 
 	public function lt(inOther:Function<T,ABI>):Bool;

+ 6 - 9
std/cpp/Pointer.hx

@@ -34,11 +34,10 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
    public static function fromRaw<T>(ptr:RawPointer<T>) : Pointer<T>;
 
    @:native("::cpp::Pointer_obj::fromHandle")
-   static function nativeFromHandle<T>(inHandle:Dynamic,?inKind:String):Pointer<T>;
+   static function nativeFromHandle<T>(inHandle:Dynamic,?inKind:String):AutoCast;
    inline public static function fromHandle<T>(inHandle:Dynamic,?inKind:String) : Pointer<T>
    {
-     var autoCast = nativeFromHandle(inHandle,inKind);
-     return autoCast;
+     return cast nativeFromHandle(inHandle,inKind);
    }
 
    public static function fromPointer<T>(inNativePointer:Dynamic) : Pointer<T>;
@@ -48,19 +47,17 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
    public static function endOf<T:{}>(inVariable:T) : Pointer<cpp.Void>;
 
    @:native("::cpp::Pointer_obj::arrayElem")
-   static function nativeArrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;
+   static function nativeArrayElem<T>(array:Array<T>, inElem:Int):AutoCast;
    inline static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>
    {
-      var autoCast = nativeArrayElem(array,inElem);
-      return autoCast;
+      return cast nativeArrayElem(array,inElem);
    }
 
    @:native("::cpp::Pointer_obj::ofArray")
-   static function nativeOfArray<T>(array:Array<T>):Pointer<T>;
+   static function nativeOfArray<T>(array:Array<T>):AutoCast;
    inline public static function ofArray<T>(array:Array<T>):Pointer<T>
    {
-     var autoCast = nativeOfArray(array);
-     return autoCast;
+     return cast nativeOfArray(array);
    }
 
    inline public function toUnmanagedArray(elementCount:Int) : Array<T>