Skip to content

[cpp] Generate Typed Functions #11151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module Setup = struct
add_std "php";
"php"
| Cpp ->
Common.define_value com Define.HxcppApiLevel "430";
Common.define_value com Define.HxcppApiLevel "500";
add_std "cpp";
if Common.defined com Define.Cppia then
actx.classes <- (Path.parse_path "cpp.cppia.HostClasses" ) :: actx.classes;
Expand Down
12 changes: 8 additions & 4 deletions src/generators/cpp/cppAst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ type tcpp =
| TCppAutoCast
| TCppDynamicArray
| TCppObjectArray of tcpp
| TCppWrapped of tcpp
| TCppCallable of tcpp list * tcpp
| TCppScalarArray of tcpp
| TCppObjC of tclass
| TCppNativePointer of tclass
| TCppVariant
| TCppVariant of tcpp option
| TCppCode of tcpp
| TCppInst of tclass * tcpp list
| TCppInterface of tclass
Expand Down Expand Up @@ -100,7 +100,10 @@ and tcppvarloc =
| VarStatic of tclass * bool * tclass_field
| VarInternal of tcppexpr * string * string

and tcppinst = InstPtr | InstObjC | InstStruct
and tcppinst =
| InstPtr of tcpp
| InstObjC
| InstStruct

and tcppfuncloc =
| FuncThis of tclass_field * tcpp
Expand Down Expand Up @@ -143,7 +146,7 @@ and tcpp_expr_expr =
| CppThis of tcppthis
| CppSuper of tcppthis
| CppCode of string * tcppexpr list
| CppClosure of tcpp_closure
| CppCallable of tcpp_closure
| CppVar of tcppvarloc
| CppExtern of string * bool
| CppDynamicField of tcppexpr * string
Expand Down Expand Up @@ -211,6 +214,7 @@ and tcpp_class_function = {
tcf_field : tclass_field;
tcf_name : string;
tcf_func : tfunc;
tcf_callable : tcpp;

tcf_is_virtual : bool;
tcf_is_reflective : bool;
Expand Down
23 changes: 14 additions & 9 deletions src/generators/cpp/cppAstTools.ml
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ let rec s_tcpp = function
| CppThis _ -> "CppThis"
| CppSuper _ -> "CppSuper"
| CppCode _ -> "CppCode"
| CppClosure _ -> "CppClosure"
| CppCallable _ -> "CppCallable"
| CppVar (VarLocal _) -> "CppVarLocal"
| CppVar (VarClosure _) -> "CppVarClosure"
| CppVar (VarThis _) -> "CppVarThis"
Expand All @@ -296,7 +296,7 @@ let rec s_tcpp = function
| CppCall (FuncInstance (obj, inst, field), _) ->
(match inst with
| InstObjC -> "CppCallObjCInstance("
| InstPtr -> "CppCallInstance("
| InstPtr _ -> "CppCallInstance("
| _ -> "CppCallStruct(")
^ tcpp_to_string obj.cpptype ^ "," ^ field.cf_name ^ ")"
| CppCall (FuncInterface _, _) -> "CppCallInterface"
Expand Down Expand Up @@ -366,7 +366,13 @@ and tcpp_to_string_suffix suffix tcpp =
| TCppRest _ -> "vaarg_list"
| TCppVarArg -> "vararg"
| TCppAutoCast -> "::cpp::AutoCast"
| TCppVariant -> "::cpp::Variant"
| TCppVariant None -> "::cpp::Variant"
| TCppVariant Some t -> Printf.sprintf "::cpp::Variant( %s )" (tcpp_to_string t)
| TCppCallable (arguments, return) ->
let return_str = tcpp_to_string return in
let arguments_str = arguments |> List.map tcpp_to_string |> String.concat "," in

Printf.sprintf "::hx::Callable< %s ( %s ) >" return_str arguments_str
| TCppEnum enum -> " ::" ^ join_class_path_remap enum.e_path "::" ^ suffix
| TCppScalar scalar -> scalar
| TCppString -> "::String"
Expand All @@ -384,7 +390,6 @@ and tcpp_to_string_suffix suffix tcpp =
tcpp_objc_block_struct argTypes retType ^ "::t"
| TCppDynamicArray -> "::cpp::VirtualArray" ^ suffix
| TCppObjectArray _ -> "::Array" ^ suffix ^ "< ::Dynamic>"
| TCppWrapped _ -> " ::Dynamic"
| TCppScalarArray value ->
"::Array" ^ suffix ^ "< " ^ tcpp_to_string value ^ " >"
| TCppObjC klass ->
Expand Down Expand Up @@ -647,7 +652,7 @@ let rec cpp_is_native_array_access t =
| _ -> false

let cpp_is_dynamic_type = function
| TCppDynamic | TCppObject | TCppVariant | TCppWrapped _ | TCppGlobal | TCppNull
| TCppDynamic | TCppObject | TCppVariant _ | TCppGlobal | TCppNull
| TCppInterface _
-> true
| _ -> false
Expand All @@ -665,10 +670,10 @@ let is_object_element member_type =
| TCppFunction _
| TCppDynamicArray
| TCppObjectArray _
| TCppWrapped _
| TCppScalarArray _
| TCppClass
-> true
| TCppCallable _
-> true
| _ -> false

let cpp_variant_type_of t = match t with
Expand All @@ -684,7 +689,6 @@ let cpp_variant_type_of t = match t with
| TCppDynamicArray
| TCppObjectArray _
| TCppScalarArray _
| TCppWrapped _
| TCppObjC _
| TCppObjCBlock _
| TCppRest _
Expand All @@ -695,6 +699,7 @@ let cpp_variant_type_of t = match t with
| TCppClass
| TCppGlobal
| TCppNull
| TCppCallable _
| TCppEnum _ -> TCppDynamic
| TCppString -> TCppString
| TCppFunction _
Expand All @@ -711,7 +716,7 @@ let cpp_variant_type_of t = match t with
| TCppScalar "double"
| TCppScalar "float" -> TCppScalar("Float")
| TCppScalar _ -> TCppScalar("int")
| TCppVariant -> TCppVariant
| TCppVariant v -> TCppVariant v

let cpp_cast_variant_type_of t = match t with
| TCppObjectArray _
Expand Down
Loading
Loading