2
0
Эх сурвалжийг харах

[cpp] Add special type, cpp.Star, to name internal type

hughsando 9 жил өмнө
parent
commit
eef5be8926

+ 14 - 14
src/generators/gencpp.ml

@@ -1314,6 +1314,7 @@ type tcpp =
    | TCppRawPointer of string * tcpp
    | TCppRawPointer of string * tcpp
    | TCppFunction of tcpp list * tcpp * string
    | TCppFunction of tcpp list * tcpp * string
    | TCppReference of tcpp
    | TCppReference of tcpp
+   | TCppStar of tcpp
    | TCppVoidStar
    | TCppVoidStar
    | TCppDynamicArray
    | TCppDynamicArray
    | TCppObjectArray of tcpp
    | TCppObjectArray of tcpp
@@ -1538,6 +1539,7 @@ and tcpp_to_string_suffix suffix tcpp = match tcpp with
    | TCppDynamic -> " ::Dynamic"
    | TCppDynamic -> " ::Dynamic"
    | TCppObject -> " ::Dynamic"
    | TCppObject -> " ::Dynamic"
    | TCppReference t -> (tcpp_to_string t) ^" &"
    | TCppReference t -> (tcpp_to_string t) ^" &"
+   | TCppStar t -> (tcpp_to_string t) ^" *"
    | TCppVoid -> "void"
    | TCppVoid -> "void"
    | TCppVoidStar -> "void *"
    | TCppVoidStar -> "void *"
    | TCppVariant -> "::cpp::Variant"
    | TCppVariant -> "::cpp::Variant"
@@ -1638,19 +1640,10 @@ let rec const_string_of expr =
 ;;
 ;;
 
 
 
 
-let rec cpp_is_struct_access obj =
-   match obj.cpptype with
+let rec cpp_is_struct_access t =
+   match t with
    | TCppInst (class_def) -> (has_meta_key class_def.cl_meta Meta.StructAccess)
    | TCppInst (class_def) -> (has_meta_key class_def.cl_meta Meta.StructAccess)
-   | TCppReference (r) ->
-       (match obj.cppexpr with
-       (* Magic cpp.Pointer.ptr is actually a pointer, not a reference (when it is not stored in a temp) *)
-       | CppVar(VarInstance(_,{ cf_name="ptr"} , class_name, _) ) when
-          (String.length class_name > 15) && String.sub class_name 0 15 = "::cpp::Pointer<" -> false
-       | _ -> (match r with
-              | TCppInst (class_def) -> (has_meta_key class_def.cl_meta Meta.StructAccess)
-              | _ -> false
-              )
-       )
+   | TCppReference (r) -> cpp_is_struct_access r
    | _ -> false
    | _ -> false
 ;;
 ;;
 
 
@@ -1740,6 +1733,8 @@ let rec cpp_type_of ctx haxe_type =
             cpp_function_type_of_string ctx function_type "";
             cpp_function_type_of_string ctx function_type "";
       | (["cpp"],"Reference"), [param] ->
       | (["cpp"],"Reference"), [param] ->
             TCppReference(cpp_type_of ctx param)
             TCppReference(cpp_type_of ctx param)
+      | (["cpp"],"Star"), [param] ->
+            TCppStar(cpp_type_of ctx param)
 
 
       | ([],"Array"), [p] ->
       | ([],"Array"), [p] ->
          let arrayOf = cpp_type_of ctx p in
          let arrayOf = cpp_type_of ctx p in
@@ -1750,6 +1745,7 @@ let rec cpp_type_of ctx haxe_type =
 
 
             | TCppObject
             | TCppObject
             | TCppReference _
             | TCppReference _
+            | TCppStar _
             | TCppEnum _
             | TCppEnum _
             | TCppInst _
             | TCppInst _
             | TCppInterface _
             | TCppInterface _
@@ -1892,6 +1888,7 @@ let cpp_variant_type_of t = match t with
    | TCppDynamic
    | TCppDynamic
    | TCppObject
    | TCppObject
    | TCppReference _
    | TCppReference _
+   | TCppStar _
    | TCppVoid
    | TCppVoid
    | TCppFastIterator _
    | TCppFastIterator _
    | TCppDynamicArray
    | TCppDynamicArray
@@ -2247,7 +2244,7 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
                     CppFunction( FuncInstance(retypedObj,false,member), funcReturn ), exprType
                     CppFunction( FuncInstance(retypedObj,false,member), funcReturn ), exprType
                   else
                   else
                      CppDynamicField(retypedObj, member.cf_name), TCppVariant
                      CppDynamicField(retypedObj, member.cf_name), TCppVariant
-               end else if cpp_is_struct_access retypedObj then begin
+               end else if cpp_is_struct_access retypedObj.cpptype then begin
                   match retypedObj.cppexpr with
                   match retypedObj.cppexpr with
                   | CppThis ThisReal ->
                   | CppThis ThisReal ->
                       CppVar(VarThis(member)), exprType
                       CppVar(VarThis(member)), exprType
@@ -2276,7 +2273,7 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
                         CppDynamicField(retypedObj, member.cf_name), TCppVariant
                         CppDynamicField(retypedObj, member.cf_name), TCppVariant
 
 
                      | _ ->
                      | _ ->
-                        let operator = if cpp_is_struct_access retypedObj || retypedObj.cpptype=TCppString then "." else "->" in
+                        let operator = if cpp_is_struct_access retypedObj.cpptype || retypedObj.cpptype=TCppString then "." else "->" in
                         CppVar(VarInstance(retypedObj,member,tcpp_to_string clazzType, operator) ), exprType
                         CppVar(VarInstance(retypedObj,member,tcpp_to_string clazzType, operator) ), exprType
                      )
                      )
                end else if (clazz.cl_interface && not is_objc (* Use instance call for objc interfaces *)) then
                end else if (clazz.cl_interface && not is_objc (* Use instance call for objc interfaces *)) then
@@ -2755,6 +2752,9 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
          | TCppReference(TCppDynamic), TCppReference(_) -> cppExpr
          | TCppReference(TCppDynamic), TCppReference(_) -> cppExpr
          | TCppReference(TCppDynamic),  t ->
          | TCppReference(TCppDynamic),  t ->
              mk_cppexpr retypedExpr (TCppReference(t))
              mk_cppexpr retypedExpr (TCppReference(t))
+         | TCppStar(TCppDynamic), TCppStar(_) -> cppExpr
+         | TCppStar(TCppDynamic),  t ->
+             mk_cppexpr retypedExpr (TCppStar(t))
          | _ -> cppExpr
          | _ -> cppExpr
    in
    in
    retype request_type expression_tree
    retype request_type expression_tree

+ 1 - 1
std/cpp/ConstPointer.hx

@@ -26,7 +26,7 @@ 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:Reference<T>;
+   public var ptr:Star<T>;
 
 
    @:analyzer(no_simplification)
    @:analyzer(no_simplification)
    public var value(get,never):T;
    public var value(get,never):T;

+ 27 - 0
std/cpp/Star.hx

@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+// Allows haxe to type result correctly, and hxcpp can recognise this use the correct type
+typedef Star<T> = T;
+
+