Complete compilation of generated code

Property definitions

nitc $ FFILanguage :: compile_to_files
	# Complete compilation of generated code
	fun compile_to_files(mmodule: MModule, directory: String) do end
src/ffi/light_ffi_base.nit:134,2--135,65

nitc $ CPPLanguage :: compile_to_files
	redef fun compile_to_files(mmodule, compdir)
	do
		var cpp_file = mmodule.cpp_file
		assert cpp_file != null

		# write .cpp and .hpp file
		cpp_file.header_custom.add("extern \"C\" \{\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)

		# add complation to makefile
		mmodule.ffi_files.add(file)

		# add linked option to support C++
		mmodule.ldflags.add_one("", "-lstdc++")
	end
src/ffi/cpp.nit:121,2--138,4

nitc $ JavaLanguage :: compile_to_files
	redef fun compile_to_files(mmodule, compdir)
	do
		var ffi_ccu = ffi_ccu
		assert ffi_ccu != null

		# Make sure we have a .java file
		mmodule.ensure_java_files

		# Needed compiler and linker options
		mmodule.insert_compiler_options

		# Enable linking C callbacks to java native methods
		mmodule.ensure_linking_callback_methods(ffi_ccu)

		# Function to build instances to the Java class NitObject
		var callbacks = mmodule.callbacks_used_from_java.callbacks
		if callbacks.not_empty then
			var cf = new CFunction("jobject nit_ffi_with_java_new_nit_object(JNIEnv *env, void *data)")
			cf.exprs.add """
	// retrieve the current JVM
	Sys sys = Pointer_sys(NULL);

	jclass java_class = Sys_load_jclass(sys, "nit/app/NitObject");
	if (java_class == NULL) {
		PRINT_ERROR("Nit FFI with Java error: failed to load class NitObject.\\n");
		(*env)->ExceptionDescribe(env);
		exit(1);
	}

	jmethodID java_init = (*env)->GetMethodID(env, java_class, "<init>", "(J)V");
	if (java_init == NULL) {
		PRINT_ERROR("Nit FFI with Java error: NitObject constructor not found.\\n");
		(*env)->ExceptionDescribe(env);
		exit(1);
	}

	jobject nit_object = (*env)->NewObject(env, java_class, java_init, (jlong)data);
	if (nit_object == NULL) {
		PRINT_ERROR("Nit FFI with Java error: NitObject construction failed.\\n");
		(*env)->ExceptionDescribe(env);
		exit(1);
	}

	return nit_object;
	"""
			ffi_ccu.add_local_function cf

			# Function to extract the pointer held by instances of the Java class NitObject
			cf = new CFunction("void *nit_ffi_with_java_nit_object_data(JNIEnv *env, jobject nit_object)")
			cf.exprs.add """
	Sys sys = Pointer_sys(NULL);
	jclass java_class = Sys_load_jclass(sys, "nit/app/NitObject");
	if (java_class == NULL) {
		PRINT_ERROR("Nit FFI with Java error: failed to load class NitObject.\\n");
		(*env)->ExceptionDescribe(env);
		exit(1);
	}

	jfieldID java_field = (*env)->GetFieldID(env, java_class, "pointer", "J");
	if (java_field == NULL) {
		PRINT_ERROR("Nit FFI with Java error: NitObject field not found.\\n");
		(*env)->ExceptionDescribe(env);
		exit(1);
	}

	jlong data = (*env)->GetLongField(env, nit_object, java_field);

	return (void*)data;
	"""
			ffi_ccu.add_local_function cf
		end

		# Java implementation code
		var java_file = mmodule.java_file
		assert java_file != null
		var extern_java_file = java_file.write_to_files(compdir)
		mmodule.ffi_files.add(extern_java_file)
	end
src/ffi/java.nit:166,2--243,4

nitc :: extra_java_files $ JavaLanguage :: compile_to_files
	redef fun compile_to_files(mmodule, compdir)
	do
		super

		# Also copy over the extra Java files
		var extra_java_files = mmodule.extra_java_files
		if extra_java_files != null then for file in extra_java_files do

			var dir = compdir / file.filename.dirname
			dir.mkdir

			file.src_path.file_copy_to(compdir/file.filename)
		end
	end
src/ffi/extra_java_files.nit:94,2--107,4

nitc $ ObjCLanguage :: compile_to_files
	redef fun compile_to_files(mmodule, compdir)
	do
		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"
"""

		var file = objc_file.write_to_files(mmodule, compdir)

		# add compilation to makefile
		mmodule.ffi_files.add file
	end
src/ffi/objc.nit:98,2--118,4