Skip to content

Commit 8164bef

Browse files
committed
move interface static implementations out of the header
1 parent ef6fe96 commit 8164bef

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

src/generators/cpp/gen/cppGenClassHeader.ml

+6-7
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,18 @@ let gen_class_header ctx tcpp_class h_file scriptable parents =
8787
else h_file#add_include klass.cl_path
8888
| _ -> ());
8989

90-
(* And any interfaces ... *)
90+
(* And any native interfaces ... *)
9191
List.iter
92-
(fun imp ->
93-
let interface = fst imp in
92+
(fun interface ->
9493
let include_files =
95-
get_all_meta_string_path interface.cl_meta Meta.Include
94+
get_all_meta_string_path interface.if_class.cl_meta Meta.Include
9695
in
9796
if List.length include_files > 0 then
9897
List.iter
9998
(fun inc -> h_file#add_include (path_of_string inc))
10099
include_files
101-
else h_file#add_include interface.cl_path)
102-
(real_interfaces tcpp_class.tcl_class.cl_implements);
100+
else h_file#add_include interface.if_class.cl_path)
101+
tcpp_class.tcl_native_interfaces;
103102

104103
(* Only need to forward-declare classes that are mentioned in the header file
105104
(ie, not the implementation) *)
@@ -325,7 +324,7 @@ let generate_managed_header base_ctx tcpp_class =
325324
let alreadyGlued = Hashtbl.create 0 in
326325
List.iter
327326
(fun src ->
328-
let rec check_interface (interface:tcpp_interface) =
327+
let rec check_interface interface =
329328
let check_field func =
330329
let cast = cpp_tfun_signature false func.iff_args func.iff_return in
331330
let class_implementation = find_class_implementation func tcpp_class

src/generators/cpp/gen/cppGenInterfaceHeader.ml

+1-12
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,10 @@ let gen_function ctx interface func =
3232
let output = ctx.ctx_output in
3333
let argList = print_tfun_arg_list true func.iff_args in
3434
let returnType = type_to_string func.iff_return in
35-
let returnStr = if returnType = "void" then "" else "return " in
3635
let commaArgList = if argList = "" then argList else "," ^ argList in
37-
let cast = Printf.sprintf "::hx::interface_cast< ::%s_obj *>" (join_class_path_remap interface.if_class.cl_path "::") in
3836

3937
Printf.sprintf "\t\t%s (::hx::Object :: *_hx_%s)(%s);\n" returnType func.iff_name argList |> output;
40-
Printf.sprintf "\t\tstatic inline %s %s( ::Dynamic _hx_%s ){\n" returnType func.iff_name commaArgList |> output;
41-
output "\t\t\t#ifdef HXCPP_CHECK_POINTER\n";
42-
output "\t\t\tif (::hx::IsNull(_hx_)) ::hx::NullReference(\"Object\", false);\n";
43-
output "\t\t\t#ifdef HXCPP_GC_CHECK_POINTER\n";
44-
output "\t\t\t\tGCCheckPointer(_hx_.mPtr);\n";
45-
output "\t\t\t#endif\n";
46-
output "\t\t\t#endif\n";
47-
Printf.sprintf
48-
"\t\t\t%s( _hx_.mPtr->*( %s(_hx_.mPtr->_hx_getInterface(%s)))->_hx_%s )(%s);\n\t\t}\n"
49-
returnStr cast interface.if_hash func.iff_name (print_arg_names func.iff_args) |> output
38+
Printf.sprintf "\t\tstatic %s %s( ::Dynamic _hx_%s );\n" returnType func.iff_name commaArgList |> output
5039

5140
let gen_includes h_file interface_def =
5241
let add_class_includes cls =

src/generators/cpp/gen/cppGenInterfaceImplementation.ml

+23
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,29 @@ let generate_managed_interface base_ctx tcpp_interface =
104104
begin_namespace output_cpp class_path;
105105
output_cpp "\n";
106106

107+
let gen_function func =
108+
let argList = print_tfun_arg_list true func.iff_args in
109+
let returnType = type_to_string func.iff_return in
110+
let returnStr = if returnType = "void" then "" else "return " in
111+
let commaArgList = if argList = "" then argList else "," ^ argList in
112+
let cast = Printf.sprintf "::hx::interface_cast< %s *>" tcpp_interface.if_name in
113+
114+
Printf.sprintf "%s %s::%s( ::Dynamic _hx_%s ) {\n" returnType tcpp_interface.if_name func.iff_name commaArgList |> output_cpp;
115+
output_cpp "#ifdef HXCPP_CHECK_POINTER\n";
116+
output_cpp "\tif (::hx::IsNull(_hx_)) ::hx::NullReference(\"Object\", false);\n";
117+
output_cpp "#ifdef HXCPP_GC_CHECK_POINTER\n";
118+
output_cpp "\tGCCheckPointer(_hx_.mPtr);\n";
119+
output_cpp "#endif\n";
120+
output_cpp "#endif\n";
121+
Printf.sprintf
122+
"\t%s( _hx_.mPtr->*( %s(_hx_.mPtr->_hx_getInterface(%s)))->_hx_%s )(%s);\n}\n"
123+
returnStr cast tcpp_interface.if_hash func.iff_name (print_arg_names func.iff_args) |> output_cpp
124+
in
125+
126+
all_interface_functions tcpp_interface |> List.iter gen_function;
127+
128+
output_cpp "\n";
129+
107130
output_cpp (get_class_code tcpp_interface.if_class Meta.CppNamespaceCode);
108131

109132
output_cpp "\n";

0 commit comments

Comments
 (0)