redef class MModule
private var cpp_file: nullable CPPCompilationUnit = null
- var cpp_compiler_options = "" is writable
+ # Custom options for the C++ compiler (CPPFLAGS)
+ var cppflags = new MultiHashMap[String, String]
end
class CPPLanguage
# Will convert C arguments to C++ and call the C++ implementation function.
fc = new CFunction(indirection_sig)
if not mproperty.is_init then
- var param_name = "recv"
+ var param_name = "self"
var type_name = to_cpp_call_context.name_mtype(mclass_type)
if mclass_type.mclass.ftype isa ForeignCppType then
fc.exprs.add("{type_name} {param_name}_for_cpp = static_cast<{type_name}>({param_name});\n")
end
fc.exprs.add(mproperty.build_ccall(mclass_type, mmodule, "___cpp_impl", long_signature, cpp_call_context, "_for_cpp"))
fc.exprs.add("\n")
- mmodule.cpp_file.add_local_function(fc)
+ mmodule.cpp_file.add_exported_function(fc)
# Custom C++, the body of the Nit C++ method is copied to its own C++ function
var cpp_signature = mproperty.build_csignature(mclass_type, mmodule, "___cpp_impl", long_signature, cpp_call_context)
# write .cpp and .hpp file
cpp_file.header_custom.add("extern \"C\" \{\n")
- cpp_file.header_custom.add("#include \"{mmodule.name}._ffi.h\"\n")
+ cpp_file.header_custom.add("#include \"{mmodule.c_name}._ffi.h\"\n")
cpp_file.header_custom.add("\}\n")
var file = cpp_file.write_to_files(mmodule, compdir)
mmodule.ffi_files.add(file)
# add linked option to support C++
- mmodule.c_linker_options = "{mmodule.c_linker_options} -lstdc++"
+ mmodule.ldflags.add_one("", "-lstdc++")
end
redef fun compile_callback(callback, mmodule, mainmodule, ecc)
fun write_to_files(mmodule: MModule, compdir: String): ExternCppFile
do
- var base_name = "{mmodule.name}._ffi"
+ var base_name = "{mmodule.c_name}._ffi"
var h_file = "{base_name}.hpp"
- var guard = "{mmodule.cname.to_s.to_upper}_NIT_HPP"
+ var guard = "{mmodule.c_name.to_s.to_upper}_NIT_HPP"
write_header_to_file(mmodule, "{compdir}/{h_file}", new Array[String], guard)
super ExternFile
var mmodule: MModule
- init(path: String, mmodule: MModule)
- do
- super
- self.mmodule = mmodule
- end
- redef fun makefile_rule_name do return "{filename.basename("")}.o"
- redef fun makefile_rule_content do return "$(CXX) $(CFLAGS) {mmodule.cpp_compiler_options} -c {filename.basename("")} -o {filename.basename("")}.o"
+ redef fun makefile_rule_name do return "{filename.basename}.o"
+ redef fun makefile_rule_content do return "$(CXX) $(CFLAGS) {mmodule.cppflags[""].join(" ")} -c {filename.basename} -o {filename.basename}.o"
redef fun compiles_to_o_file do return true
end
super ForeignType
var cpp_type: String
-
- init (cpp_type: String)
- do
- self.cpp_type = cpp_type
- end
end
redef class NitniCallback
fun compile_callback_to_cpp(mmodule: MModule, mainmodule: MModule) do end
end
-redef class Object
- private fun cpp_call_context: CppCallContext do return once new CppCallContext
- private fun to_cpp_call_context: ToCppCallContext do return once new ToCppCallContext
- private fun from_cpp_call_context: FromCppCallContext do return once new FromCppCallContext
-end
+fun cpp_call_context: CppCallContext do return once new CppCallContext
+fun to_cpp_call_context: ToCppCallContext do return once new ToCppCallContext
+fun from_cpp_call_context: FromCppCallContext do return once new FromCppCallContext
redef class MExplicitCall
redef fun compile_callback_to_cpp(mmodule, mainmodule)