Forráskód Böngészése

[cpp] Add some stdio externs to cpp

Hugh 9 éve
szülő
commit
87ea06c98b
5 módosított fájl, 166 hozzáadás és 2 törlés
  1. 15 2
      src/generators/gencpp.ml
  2. 28 0
      std/cpp/FILE.hx
  3. 73 0
      std/cpp/Stdio.hx
  4. 22 0
      std/cpp/Stdlib.hx
  5. 28 0
      std/cpp/VarArg.hx

+ 15 - 2
src/generators/gencpp.ml

@@ -1352,6 +1352,7 @@ type tcpp =
    | TCppReference of tcpp
    | TCppStar of tcpp
    | TCppVoidStar
+   | TCppVarArg
    | TCppDynamicArray
    | TCppObjectArray of tcpp
    | TCppWrapped of tcpp
@@ -1581,6 +1582,7 @@ and tcpp_to_string_suffix suffix tcpp = match tcpp with
    | TCppStar t -> (tcpp_to_string t) ^" *"
    | TCppVoid -> "void"
    | TCppVoidStar -> "void *"
+   | TCppVarArg -> "vararg"
    | TCppVariant -> "::cpp::Variant"
    | TCppEnum(enum) -> " ::" ^ (join_class_path_remap enum.e_path "::") ^ suffix
    | TCppScalar(scalar) -> scalar
@@ -1774,6 +1776,7 @@ let rec cpp_type_of ctx haxe_type =
       | (["cpp"], "UInt16"),_ -> TCppScalar("unsigned short")
       | (["cpp"], "UInt32"),_ -> TCppScalar("unsigned int")
       | (["cpp"], "UInt64"),_ -> TCppScalar("::cpp::UInt64")
+      | (["cpp"], "VarArg"),_ -> TCppVarArg
 
       | ([],"String"), [] ->
          TCppString
@@ -1994,6 +1997,7 @@ let cpp_variant_type_of t = match t with
    | TCppNativePointer _
    | TCppPointer _
    | TCppRawPointer _
+   | TCppVarArg _
    | TCppVoidStar -> TCppVoidStar
    | TCppScalar "Int"
    | TCppScalar "Bool"
@@ -2867,16 +2871,25 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
       in
       let cppExpr = mk_cppexpr retypedExpr retypedType in
 
-      (* Auto cast rules... *)
+      (* Autocast rules... *)
       if return_type=TCppVoid then
          mk_cppexpr retypedExpr TCppVoid
-      else if (cppExpr.cpptype=TCppVariant || cppExpr.cpptype=TCppDynamic) then begin
+      else if return_type=TCppVarArg then begin
+         match cpp_variant_type_of cppExpr.cpptype with
+         | TCppVoidStar
+         | TCppScalar _ -> cppExpr
+         | TCppString ->  mk_cppexpr (CppVar(VarInternal(cppExpr,".","__s"))) (TCppPointer("ConstPointer", TCppScalar("char")))
+         | TCppDynamic ->  mk_cppexpr (CppCastNative(cppExpr)) TCppVoidStar
+         | _ -> let toDynamic = mk_cppexpr (CppCast(cppExpr, TCppDynamic)) TCppDynamic in
+                mk_cppexpr (CppCastNative(toDynamic)) TCppVoidStar
+      end else if (cppExpr.cpptype=TCppVariant || cppExpr.cpptype=TCppDynamic) then begin
          match return_type with
          | TCppObjectArray _
          | TCppScalarArray _
          | TCppNativePointer _
          | TCppDynamicArray
          | TCppObjectPtr
+         | TCppVarArg
          | TCppInst _
              -> mk_cppexpr (CppCast(cppExpr,return_type)) return_type
 

+ 28 - 0
std/cpp/FILE.hx

@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+@:include("stdio.h")
+@:native(" ::cpp::Pointer<FILE>")
+extern class FILE { }
+

+ 73 - 0
std/cpp/Stdio.hx

@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+@:include("stdio.h")
+extern class Stdio
+{
+   @:native("printf")
+   @:overload(function(format:ConstCharStar,a0:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a8:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a9:VarArg,a10:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a9:VarArg,a10:VarArg,a11:VarArg):Void { })
+   @:overload(function(format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a9:VarArg,a10:VarArg,a11:VarArg,a12:VarArg):Void { })
+   public static function printf(format:ConstCharStar):Void;
+
+   @:native("fopen")
+   public static function fopen(filename:ConstCharStar, mode:ConstCharStar) : FILE;
+
+   @:native("fwrite")
+   public static function fwrite<T>(data:RawPointer<T>, elemSize:SizeT, elemCount:SizeT, file:FILE ) : SizeT;
+
+   @:native("fclose")
+   public static function fclose(file:FILE) : Int;
+
+
+   @:native("fprintf")
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a8:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a9:VarArg,a10:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a9:VarArg,a10:VarArg,a11:VarArg):Void { })
+   @:overload(function(file:FILE,format:ConstCharStar,a0:VarArg,a1:VarArg,a2:VarArg,a3:VarArg,a4:VarArg,a5:VarArg,a6:VarArg,a7:VarArg,a8:VarArg,a9:VarArg,a10:VarArg,a11:VarArg,a12:VarArg):Void { })
+   public static function fprintf(file:FILE,format:ConstCharStar):Void;
+
+
+
+
+}
+

+ 22 - 0
std/cpp/Stdlib.hx

@@ -1,3 +1,25 @@
+/*
+ * 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;
 
 @:include("stdlib.h")

+ 28 - 0
std/cpp/VarArg.hx

@@ -0,0 +1,28 @@
+/*
+ * 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 params correctly, and hxcpp can recognise this use the correct type
+typedef VarArg = Dynamic;
+
+
+