Property definitions

nitc $ MExplicitCall :: defaultinit
# A prossible call from C, declared explictly after the `import` keyword
class MExplicitCall
	super NitniCallback

	# Previously resolved mtype
	var recv_mtype: MClassType
	var mproperty: MProperty
	var from_mmodule: MModule

	fun fill_type_for( callback_set: ForeignCallbackSet, from: MModule )
	do
		var first = mproperty.lookup_first_definition( from, recv_mtype )
		var mclassdef = first.mclassdef
		var bound_mtype = mclassdef.bound_mtype

		# receiver / constructor return
		recv_mtype = recv_mtype.resolve_for(bound_mtype, bound_mtype, from, true)
		recv_mtype = recv_mtype.anchor_to(from, bound_mtype)
		callback_set.types.add( recv_mtype )

		if first isa MMethodDef then
			var rmt = first.msignature.return_mtype
			if rmt != null then
				rmt = rmt.resolve_for(bound_mtype, bound_mtype, from, true)
				rmt = rmt.anchor_to(from, bound_mtype)
				callback_set.types.add( rmt )
			end

			for p in first.msignature.mparameters do
				var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from, true)
				param_mtype = param_mtype.resolve_for(bound_mtype, bound_mtype, from, true)
				param_mtype = param_mtype.anchor_to(from, bound_mtype)
				callback_set.types.add( param_mtype )
			end
		end
	end

	# Signature of this call in C as seen by user
	fun csignature: String
	do
		var mproperty = self.mproperty
		if mproperty isa MMethod then
			var signature = mproperty.intro.msignature
			assert signature != null

			var creturn_type
			if mproperty.is_init then
				creturn_type = recv_mtype.cname
			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 = ret_mtype.cname
			else
				creturn_type = "void"
			end

			var cname
			if mproperty.is_init then
				if mproperty.name == "init" or mproperty.name == "new" or mproperty.name == "defaultinit" then
					cname = "new_{recv_mtype.mangled_cname}"
				else
					cname = "new_{recv_mtype.mangled_cname}_{mproperty.short_cname}"
				end
			else
				cname = "{recv_mtype.mangled_cname}_{mproperty.short_cname}"
			end

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

			return "{creturn_type} {cname}( {cparams.join(", ")} )"
		else
			print "Type of callback from foreign code not yet supported."
			abort
		end
	end

	redef fun hash do return recv_mtype.hash + 1024 * mproperty.hash
	redef fun ==(o) do return o isa MExplicitCall and recv_mtype == o.recv_mtype and mproperty == o.mproperty
end
src/nitni/nitni_callbacks.nit:164,1--249,3