redef class MModule
private var objc_file: nullable ObjCCompilationUnit = null
+
+ private var has_public_objc_header = false
+
+ # Imported modules with public Objective-C code blocks
+ var objc_imported_headers: HashSet[MModule] is lazy do
+ var dep = new HashSet[MModule]
+
+ # gather from importation
+ for m in in_importation.direct_greaters do
+ # does the super module has inherited dependencies?
+ var import_dep = m.objc_imported_headers
+ if not import_dep.is_empty then
+ dep.add_all import_dep
+ end
+
+ # does the super module itself has a public header?
+ if m.has_public_objc_header then dep.add(m)
+ end
+
+ return dep
+ end
end
# The Objective-C langugage visitor
if block.is_objc_header then
mmodule.objc_file.header_custom.add block.location.as_line_pragma
mmodule.objc_file.header_custom.add block.code
+
+ mmodule.has_public_objc_header = true
else if block.is_objc_body then
mmodule.objc_file.body_custom.add block.location.as_line_pragma
mmodule.objc_file.body_custom.add block.code
var objc_file = mmodule.objc_file
assert objc_file != null
+ # Import public Objective-C header of imported modules
+ var dep = mmodule.objc_imported_headers
+ for mod in dep do
+ objc_file.header_custom.add "#include \"{mod.c_name}._ffi_m.h\"\n"
+ end
+
# write .m and _m.h file
mmodule.objc_file.header_c_types.add """
#include "{{{mmodule.c_name}}}._ffi.h"
files.add compdir/c_file
- mmodule.c_linker_options = "{mmodule.c_linker_options} -lobjc"
+ mmodule.ldflags.add_one("", "-lobjc")
return new ExternObjCFile(compdir/c_file, mmodule)
end
redef fun makefile_rule_name do return "{filename.basename(".m")}_m.o"
redef fun makefile_rule_content do
- return "clang $(CFLAGS) -c {filename.basename("")} -o {makefile_rule_name}"
+ return "clang $(CFLAGS) -c {filename.basename} -o {makefile_rule_name}"
end
redef fun compiles_to_o_file do return true
end
private class FromObjCCallContext
super ObjCCallContext
+ redef fun cast_to(mtype, name)
+ do
+ if mtype isa MClassType and mtype.mclass.ftype isa ForeignObjCType then
+ return "(__bridge void*)({name})"
+ else return name
+ end
+
redef fun cast_from(mtype, name)
do
if mtype isa MClassType and mtype.mclass.ftype isa ForeignObjCType then
- return "({name_mtype(mtype)})({name})"
+ return "(__bridge {name_mtype(mtype)})({name})"
else return name
end
end