import
keywordnitc :: MExplicitCall :: _from_mmodule
nitc :: MExplicitCall :: _mproperty
nitc :: MExplicitCall :: csignature
Signature of this call in C as seen by usernitc :: MExplicitCall :: defaultinit
nitc :: MExplicitCall :: fill_type_for
nitc :: MExplicitCall :: from_mmodule
nitc :: MExplicitCall :: from_mmodule=
nitc :: MExplicitCall :: mproperty
nitc :: MExplicitCall :: mproperty=
nitc :: MExplicitCall :: recv_mtype=
Previously resolved mtypenitc $ MExplicitCall :: SELF
Type of this instance, automatically specialized in every classnitc :: c $ MExplicitCall :: compile_callback_to_c
nitc :: cpp $ MExplicitCall :: compile_callback_to_cpp
nitc :: java $ MExplicitCall :: compile_callback_to_java
Compile C and Java code to implement this callbacknitc :: objc $ MExplicitCall :: compile_callback_to_objc
Compile this callback to be callable from Objective-Cnitc :: java $ MExplicitCall :: jni_methods_declaration
Returns the list of C functions to link with extern Java methods, as requirednitc :: MExplicitCall :: _from_mmodule
nitc :: MExplicitCall :: _mproperty
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: NitniCallback :: compile_callback_to_java
Compile C and Java code to implement this callbacknitc :: NitniCallback :: compile_callback_to_objc
Compile this callback to be callable from Objective-Cnitc :: MExplicitCall :: csignature
Signature of this call in C as seen by usernitc :: NitniCallback :: defaultinit
core :: Object :: defaultinit
nitc :: MExplicitCall :: defaultinit
nitc :: MExplicitCall :: fill_type_for
nitc :: MExplicitCall :: from_mmodule
nitc :: MExplicitCall :: from_mmodule=
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: NitniCallback :: jni_methods_declaration
Returns the list of C functions to link with extern Java methods, as requirednitc :: MExplicitCall :: mproperty
nitc :: MExplicitCall :: mproperty=
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: MExplicitCall :: recv_mtype=
Previously resolved mtype
# 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
redef class MExplicitCall
redef fun compile_callback_to_c(mmodule, ffi_ccu)
do
var mproperty = mproperty.as(MMethod)
var full_cname = mproperty.build_cname(recv_mtype, mmodule, null, long_signature)
var friendly_cname = mproperty.build_cname(recv_mtype, mmodule, null, short_signature)
ffi_ccu.body_decl.add("#define {friendly_cname} {full_cname}\n")
end
end
src/ffi/c.nit:34,1--43,3
redef class MExplicitCall
private fun compile_extern_callback(v: AbstractCompilerVisitor, ccu: CCompilationUnit, compile_implementation_too: Bool)
do
var mproperty = mproperty
assert mproperty isa MMethod
# In nitni files, declare internal function as extern
var full_friendly_csignature = mproperty.build_csignature(recv_mtype, v.compiler.mainmodule, null, long_signature, internal_call_context)
ccu.header_decl.add("extern {full_friendly_csignature};\n")
if not compile_implementation_too then return
# Internally, implement internal function
var nitni_visitor = v.compiler.new_visitor
nitni_visitor.frame = v.frame
var msignature = mproperty.lookup_first_definition(v.compiler.mainmodule, recv_mtype).msignature
var csignature_blind = mproperty.build_csignature(recv_mtype, v.compiler.mainmodule, null, long_signature, internal_call_context)
nitni_visitor.add_decl("/* nitni callback for {mproperty.full_name} */")
nitni_visitor.add_decl("{csignature_blind} \{")
var vars = new Array[RuntimeVariable]
var mtype: MType = recv_mtype
var recv_var = null
if mproperty.is_init then
var recv_mtype = recv_mtype
recv_var = nitni_visitor.init_instance_or_extern(recv_mtype)
nitni_visitor.add("{mtype.ctype} self /* var self: {mtype} */;")
nitni_visitor.add("self = {recv_var};")
else
mtype = mtype.anchor_to(v.compiler.mainmodule, recv_mtype)
recv_var = nitni_visitor.var_from_c("self", mtype)
recv_var = nitni_visitor.box_extern(recv_var, mtype)
end
vars.add(recv_var)
for p in msignature.mparameters do
var arg_mtype = p.mtype.anchor_to(v.compiler.mainmodule, recv_mtype)
var arg = nitni_visitor.var_from_c(p.name, arg_mtype)
arg = nitni_visitor.box_extern(arg, arg_mtype)
vars.add(arg)
end
var ret_var = nitni_visitor.send(mproperty, vars)
var return_mtype = msignature.return_mtype
if mproperty.is_init then
if recv_mtype.mclass.kind != extern_kind then ret_var = recv_var
return_mtype = recv_mtype
end
if return_mtype != null then
assert ret_var != null
return_mtype = return_mtype.anchor_to(v.compiler.mainmodule, recv_mtype)
ret_var = nitni_visitor.autobox(ret_var, return_mtype)
ret_var = nitni_visitor.unbox_extern(ret_var, return_mtype)
nitni_visitor.ret_to_c(ret_var, return_mtype)
end
nitni_visitor.add("\}")
end
end
src/compiler/compiler_ffi/compiler_ffi.nit:83,1--143,3
redef class MExplicitCall
redef fun compile_callback_to_cpp(mmodule, mainmodule)
do
var mproperty = mproperty
assert mproperty isa MMethod
var cpp_signature = mproperty.build_csignature(recv_mtype, mainmodule, null, short_signature, from_cpp_call_context)
var ccall = mproperty.build_ccall(recv_mtype, mainmodule, null, long_signature, from_cpp_call_context, null)
var fc = new CFunction(cpp_signature)
fc.exprs.add(ccall)
mmodule.cpp_file.add_local_function( fc )
end
end
src/ffi/cpp.nit:202,1--214,3
redef class MExplicitCall
redef fun compile_callback_to_objc(mmodule, mainmodule)
do
var mproperty = mproperty
assert mproperty isa MMethod
var objc_signature = mproperty.build_csignature(recv_mtype, mainmodule, null, short_signature, from_objc_call_context)
var ccall = mproperty.build_ccall(recv_mtype, mainmodule, null, long_signature, from_objc_call_context, null)
var fc = new CFunction(objc_signature)
fc.exprs.add ccall
mmodule.objc_file.add_local_function fc
end
end
src/ffi/objc.nit:190,1--202,3
redef class MExplicitCall
redef fun compile_callback_to_java(mmodule, mainmodule, ccu)
do
if not mmodule.callbacks_used_from_java.callbacks.has(self) then return
var mproperty = mproperty
assert mproperty isa MMethod
# In C, indirection implementing the Java extern methods
var csignature = mproperty.build_c_implementation_signature(recv_mtype, mmodule, "___indirect", long_signature, from_java_call_context)
var cf = new CFunction("JNIEXPORT {csignature}")
cf.exprs.add "\t{mproperty.build_ccall(recv_mtype, mainmodule, null, long_signature, from_java_call_context, null)}\n"
ccu.add_non_static_local_function cf
# In Java, declare the extern method as a private static local method
var java_signature = mproperty.build_csignature(recv_mtype, mainmodule, null, short_signature, java_call_context)
mmodule.java_file.class_content.add "private native static {java_signature};\n"
end
redef fun jni_methods_declaration(from_mmodule)
do
var mproperty = mproperty
assert mproperty isa MMethod
var java_name = mproperty.build_cname(recv_mtype, from_mmodule, null, short_signature)
var jni_format = mproperty.build_jni_format(recv_mtype, from_mmodule)
var c_name = mproperty.build_cname(recv_mtype, from_mmodule, "___indirect", long_signature)
return ["""{"{{{java_name}}}", "{{{jni_format}}}", {{{c_name}}}}"""]
end
end
src/ffi/java.nit:513,1--543,3