Build a C function signature for the FFI implementation (uses friendly naming).

  • On a specific static receiver type recv_mtype
  • In referene to the module from_module (used for type resolving and as a possible prefix)
  • Has a possible suffix to the method name (may be "super", "impl", null, etc.)
  • With a specified length indicating whether it uses the sort name or the long name with the module name as prefix
  • The call_context identifying which types and casts to use (see CallContext and its instances)

Property definitions

nitc :: nitni_utilities $ MMethod :: build_csignature
	# Build a C function signature for the FFI implementation (uses friendly naming).
	# * On a specific static receiver type `recv_mtype`
	# * In referene to the module `from_module` (used for type resolving and as a possible prefix)
	# * Has a possible `suffix` to the method name (may be "__super", "__impl", null, etc.)
	# * With a specified length indicating whether it uses the sort name or the long name with
	#   the module name as prefix
	# * The `call_context` identifying which types and casts to use (see `CallContext` and its instances)
	fun build_csignature(recv_mtype: MClassType, from_mmodule: MModule, suffix: nullable String, length: SignatureLength, call_context: CallContext): String
	do
		var mmethoddef = lookup_first_definition(from_mmodule, recv_mtype)
		var signature = mmethoddef.msignature
		assert signature != null

		var creturn_type
		if self.is_init then
			creturn_type = call_context.name_mtype(recv_mtype)
		else if signature.return_mtype != null then
			var ret_mtype = signature.return_mtype
			ret_mtype = ret_mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
			creturn_type = call_context.name_mtype(ret_mtype)
		else
			creturn_type = "void"
		end

		var cname = build_cname(recv_mtype, from_mmodule, suffix, length)

		var cparams = new List[String]
		if not self.is_init then
			cparams.add( "{call_context.name_mtype(recv_mtype)} self" )
		end
		for p in signature.mparameters do
			var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
			cparams.add( "{call_context.name_mtype(param_mtype)} {p.name}" )
		end

		return "{creturn_type} {cname}( {cparams.join(", ")} )"
	end
src/nitni/nitni_utilities.nit:47,2--83,4