1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013-2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # FFI support for the Java language
19 # TODO support callbacks to super and casts
24 import c_compiler_options
26 redef class FFILanguageAssignationPhase
27 var java_language
: FFILanguage = new JavaLanguage(self)
33 redef fun identify_language
(n
) do return n
.is_java
35 redef fun compile_module_block
(block
, ccu
, mmodule
)
37 mmodule
.ensure_java_files
38 var java_file
= mmodule
.java_file
39 assert java_file
!= null
41 if block
.is_inner_java
then
42 java_file
.class_content
.add
(block
.code
)
43 else java_file
.header
.add
(block
.code
)
46 redef fun compile_extern_method
(block
, m
, ccu
, mmodule
)
49 mmodule
.ensure_java_files
50 var java_file
= mmodule
.java_file
51 assert java_file
!= null
53 var mclass_type
= m
.parent
.as(AClassdef).mclass
.mclass_type
54 var mmethodef
= m
.mpropdef
55 var mproperty
= m
.mpropdef
.mproperty
57 # C function calling the Java method through JNI
58 var fc
= new ExternCFunction(m
, mmodule
)
62 jmethodID java_meth_id;
64 // retrieve the current JVM
65 Sys sys = Pointer_sys(NULL);
66 JNIEnv *nit_ffi_jni_env = Sys_jni_env(sys);
68 // retrieve the implementation Java class
69 java_class = Sys_load_jclass(sys, "{{{mmodule.impl_java_class_name}}}");
70 if (java_class == NULL) {
71 PRINT_ERROR("Nit FFI with Java error: failed to load class.\\n");
72 (*nit_ffi_jni_env)->ExceptionDescribe(nit_ffi_jni_env);
76 // register callbacks (only once per Nit module)
77 if (!nit_ffi_with_java_registered_natives) nit_ffi_with_java_register_natives(nit_ffi_jni_env, java_class);
80 # Retrieve the Java implementation function id
81 var java_fun_name
= mproperty
.build_cname
(mclass_type
, mmodule
, "___java_impl", long_signature
)
82 var jni_format
= mproperty
.build_jni_format
(mclass_type
, mmodule
)
84 // retreive the implementation static function
85 java_meth_id = (*nit_ffi_jni_env)->GetStaticMethodID(nit_ffi_jni_env, java_class, "{{{java_fun_name}}}", "{{{jni_format}}}");
86 if (java_meth_id == NULL) {
87 PRINT_ERROR("Nit FFI with Java error: Java implementation not found.\\n");
88 (*nit_ffi_jni_env)->ExceptionDescribe(nit_ffi_jni_env);
93 # Call the C Java implementation method from C
94 var signature
= mmethodef
.msignature
95 assert signature
!= null
99 var params
= new Array[String]
100 params
.add
"nit_ffi_jni_env"
101 params
.add
"java_class"
102 params
.add
"java_meth_id"
104 if mproperty
.is_init
then
105 jni_signature_alt
= mclass_type
.jni_signature_alt
106 return_type
= mclass_type
109 if signature
.return_mtype
!= null then
110 var ret_mtype
= signature
.return_mtype
111 ret_mtype
= ret_mtype
.resolve_for
(mclass_type
, mclass_type
, mmodule
, true)
112 return_type
= signature
.return_mtype
113 jni_signature_alt
= return_type
.jni_signature_alt
115 jni_signature_alt
= "Void"
120 for p
in signature
.mparameters
do
121 var param_mtype
= p
.mtype
122 param_mtype
= param_mtype
.resolve_for
(mclass_type
, mclass_type
, mmodule
, true)
123 params
.add
(to_java_call_context
.cast_to
(param_mtype
, p
.name
))
126 var cname
= "(*nit_ffi_jni_env)->CallStatic{jni_signature_alt}Method"
128 if return_type
!= null then
129 ccall
= "{return_type.jni_type} jni_res = {cname}({params.join(", ")});"
130 else ccall
= "{cname}({params.join(", ")});"
133 // execute implementation code
135 if ((*nit_ffi_jni_env)->ExceptionCheck(nit_ffi_jni_env)) {
136 PRINT_ERROR("Nit FFI with Java error: Exception after call.\\n");
137 (*nit_ffi_jni_env)->ExceptionDescribe(nit_ffi_jni_env);
141 (*nit_ffi_jni_env)->DeleteLocalRef(nit_ffi_jni_env, java_class);
144 if return_type
!= null then
145 fc
.exprs
.add
"\treturn {to_java_call_context.cast_from(return_type, "jni_res")};"
148 ccu
.add_exported_function
( fc
)
150 # Java implementation function in Java
151 var java_csig
= mproperty
.build_csignature
(mclass_type
, mmodule
, "___java_impl", long_signature
, java_call_context
)
152 mmodule
.java_file
.class_content
.add
"""
153 public static {{{java_csig}}} {
154 // from Nit FII at: {{{block.location}}}
159 mmodule
.callbacks_used_from_java
.join m
.foreign_callbacks
162 redef fun compile_extern_class
(block
, m
, ccu
, mmodule
) do end
164 redef fun get_ftype
(block
, m
) do return new ForeignJavaType(block
.code
)
166 redef fun compile_to_files
(mmodule
, compdir
)
168 # Make sure we have a .java file
169 mmodule
.ensure_java_files
171 # Needed compiler and linker options
172 mmodule
.insert_compiler_options
174 # Enable linking C callbacks to java native methods
175 mmodule
.ensure_linking_callback_methods
(ffi_ccu
.as(not null))
177 # Java implementation code
178 var java_file
= mmodule
.java_file
179 assert java_file
!= null
180 var extern_java_file
= java_file
.write_to_files
(compdir
)
181 mmodule
.ffi_files
.add
(extern_java_file
)
184 var ffi_ccu
: nullable CCompilationUnit = null # HACK
186 redef fun compile_callback
(callback
, mmodule
, mainmodule
, ccu
)
189 callback
.compile_callback_to_java
(mmodule
, mainmodule
, ccu
)
194 private var callbacks_used_from_java
= new ForeignCallbackSet
196 # Java source file extracted from user FFI code with generated structure
197 var java_file
: nullable JavaClassTemplate = null
199 # Set up the templates of the Java implementation class
200 private fun ensure_java_files
202 if java_file
!= null then return
204 # Java implementation code
205 java_file
= new JavaClassTemplate(impl_java_class_name
)
208 # Compile C code to call JNI and link C callbacks implementations to Java extern methods
209 private fun ensure_linking_callback_methods
(ccu
: CCompilationUnit)
211 var callbacks
= callbacks_used_from_java
.callbacks
212 if callbacks
.is_empty
then
213 ccu
.body_decl
.add
"static int nit_ffi_with_java_registered_natives = 1;\n"
217 ccu
.body_decl
.add
"static int nit_ffi_with_java_registered_natives = 0;\n"
219 var jni_methods
= new Array[String]
220 for cb
in callbacks
do
221 jni_methods
.add_all
(cb
.jni_methods_declaration
(self))
223 for cb
in callbacks_used_from_java
.types
do
224 jni_methods
.add_all
(cb
.jni_methods_declaration
(self))
227 var cf
= new CFunction("void nit_ffi_with_java_register_natives(JNIEnv* env, jclass jclazz)")
229 nit_ffi_with_java_registered_natives = 1;
231 jint n_methods = {{{jni_methods.length}}};
232 JNINativeMethod methods[] = {
233 {{{jni_methods.join(",\n\t\t")}}}
235 jint res = (*env)->RegisterNatives(env, jclazz, methods, n_methods);
237 PRINT_ERROR("RegisterNatives failed\\n");
238 (*env)->ExceptionDescribe(env);
242 ccu
.add_local_function cf
245 # Tell the C compiler where to find jni.h and how to link with libjvm
246 private fun insert_compiler_options
248 cflags
.add_one
("", "-I $(JAVA_HOME)/include/ -I $(JAVA_HOME)/include/linux/")
251 # Name of the generated Java class where to store all implementation methods of this module
252 # as well as generated callbacks.
253 private fun impl_java_class_name
: String do return "Nit_{name}"
256 redef class AMethPropdef
257 redef fun verify_nitni_callbacks
(toolcontext
)
261 var block
= n_extern_code_block
262 if block
!= null and block
.is_java
then
263 insert_artificial_callbacks
(toolcontext
)
267 # Insert additional explicit calls to get the current `JNIEnv`
269 # This forces declaration of callbacks to Nit. The callbacks will be available in Java
270 # but will be used mainly by the FFI itself.
272 # The developer can also customize the JNIEnv used by the FFI by redefining `Sys::jni_env`.
273 private fun insert_artificial_callbacks
(toolcontext
: ToolContext)
275 var fcc
= foreign_callbacks
277 var modelbuilder
= toolcontext
.modelbuilder
278 var mmodule
= mpropdef
.mclassdef
.mmodule
280 # We use callbacks from the C FFI since they will be called from generated C
281 var c_language_visitor
= toolcontext
.ffi_language_assignation_phase
.as(FFILanguageAssignationPhase).c_language
282 if not mmodule
.ffi_callbacks
.keys
.has
(c_language_visitor
) then
283 mmodule
.ffi_callbacks
[c_language_visitor
] = new HashSet[NitniCallback]
287 var pointer_class
= modelbuilder
.try_get_mclass_by_name
(self, mmodule
, "Pointer")
288 assert pointer_class
!= null
289 var pointer_sys_meth
= modelbuilder
.try_get_mproperty_by_name2
(self, mmodule
, pointer_class
.mclass_type
, "sys")
290 assert pointer_sys_meth
!= null and pointer_sys_meth
isa MMethod
292 var explicit_call
= new MExplicitCall(pointer_class
.mclass_type
, pointer_sys_meth
, mmodule
)
293 fcc
.callbacks
.add
(explicit_call
)
294 mmodule
.ffi_callbacks
[c_language_visitor
].add
(explicit_call
)
297 var sys_class
= modelbuilder
.try_get_mclass_by_name
(self, mmodule
, "Sys")
298 assert sys_class
!= null
299 var sys_jni_env_meth
= modelbuilder
.try_get_mproperty_by_name2
(self, mmodule
, sys_class
.mclass_type
, "jni_env")
300 if sys_jni_env_meth
== null or not sys_jni_env_meth
isa MMethod then
301 toolcontext
.error
(self.location
, "Java FFI Error: you must import the `java` module when using the FFI with Java")
305 explicit_call
= new MExplicitCall(sys_class
.mclass_type
, sys_jni_env_meth
, mmodule
)
306 fcc
.callbacks
.add
(explicit_call
)
307 mmodule
.ffi_callbacks
[c_language_visitor
].add
(explicit_call
)
310 var sys_jni_load_jclass_meth
= modelbuilder
.try_get_mproperty_by_name2
(self, mmodule
, sys_class
.mclass_type
, "load_jclass")
311 assert sys_jni_load_jclass_meth
!= null
312 assert sys_jni_load_jclass_meth
isa MMethod
314 explicit_call
= new MExplicitCall(sys_class
.mclass_type
, sys_jni_load_jclass_meth
, mmodule
)
315 fcc
.callbacks
.add
(explicit_call
)
316 mmodule
.ffi_callbacks
[c_language_visitor
].add
(explicit_call
)
317 explicit_call
.fill_type_for
(fcc
, mmodule
)
321 redef class AExternCodeBlock
322 # Is this code block in Java?
323 fun is_java
: Bool do return is_default_java
or (parent
isa AModule and is_inner_java
)
325 # Is this code block in Java, with the default mode? (On module blocks it targets the file header)
326 private fun is_default_java
: Bool do return language_name
!= null and
327 language_name_lowered
== "java"
329 # Is this code block in Java, and for a module block to generate in the class?
330 private fun is_inner_java
: Bool do return language_name
!= null and
331 language_name_lowered
== "java inner"
334 # Java class source template
335 class JavaClassTemplate
338 var java_class_name
: String
340 var header
= new Template
341 var class_content
= new Template
343 fun write_to_files
(compdir
: String): ExternFile
345 var filename
= "{java_class_name}.java"
346 var filepath
= "{compdir}/{filename}"
348 write_to_file filepath
350 return new JavaFile(filename
)
357 add
"public class {java_class_name} \{\n"
363 # A generated Java source file, represent the corresponding Makefile rules
367 redef fun makefile_rule_name
do return "{filename.basename(".java")}.class"
368 redef fun makefile_rule_content
do return "javac {filename.basename} -d ."
369 redef fun add_to_jar
do return true
372 # Context in pure Java code
373 private class JavaCallContext
376 redef fun name_mtype
(mtype
) do return mtype
.java_type
379 # Context in C, when call are from normal C to JNI
380 private class ToJavaCallContext
383 redef fun cast_to
(mtype
, name
) do return "({mtype.jni_type})({name})"
384 redef fun cast_from
(mtype
, name
) do return "({mtype.cname})({name})"
385 redef fun name_mtype
(mtype
) do return mtype
.jni_type
388 # Context in C, when call are from JNI to normal C
389 private class FromJavaCallContext
392 redef fun cast_to
(mtype
, name
) do return "({mtype.cname})({name})"
393 redef fun cast_from
(mtype
, name
) do return "({mtype.jni_type})({name})"
394 redef fun name_mtype
(mtype
) do return mtype
.jni_type
397 # Foreign type attach to Nit extern Java classes
398 class ForeignJavaType
401 var java_type
: String
404 redef class NitniCallback
405 # Compile C and Java code to implement this callback
406 fun compile_callback_to_java
(mmodule
: MModule, mainmodule
: MModule, ccu
: CCompilationUnit) do end
408 # Returns the list of C functions to link with extern Java methods, as required
409 # to enable this callback from Java code.
411 # Return used by `MModule::ensure_linking_callback_methods`
413 # TODO we return an Array to support cast and other features like that
414 fun jni_methods_declaration
(from_module
: MModule): Array[String] do return new Array[String]
417 redef class MExplicitCall
418 redef fun compile_callback_to_java
(mmodule
, mainmodule
, ccu
)
420 if not mmodule
.callbacks_used_from_java
.callbacks
.has
(self) then return
422 var mproperty
= mproperty
423 assert mproperty
isa MMethod
425 # In C, indirection implementing the Java extern methods
426 var csignature
= mproperty
.build_c_implementation_signature
(recv_mtype
, mmodule
, "___indirect", long_signature
, from_java_call_context
)
427 var cf
= new CFunction("JNIEXPORT {csignature}")
428 cf
.exprs
.add
"\t{mproperty.build_ccall(recv_mtype, mainmodule, null, long_signature, from_java_call_context, null)}\n"
429 ccu
.add_non_static_local_function cf
431 # In Java, declare the extern method as a private static local method
432 var java_signature
= mproperty
.build_csignature
(recv_mtype
, mainmodule
, null, short_signature
, java_call_context
)
433 mmodule
.java_file
.class_content
.add
"private native static {java_signature};\n"
436 redef fun jni_methods_declaration
(from_mmodule
)
438 var mproperty
= mproperty
439 assert mproperty
isa MMethod
441 var java_name
= mproperty
.build_cname
(recv_mtype
, from_mmodule
, null, short_signature
)
442 var jni_format
= mproperty
.build_jni_format
(recv_mtype
, from_mmodule
)
443 var c_name
= mproperty
.build_cname
(recv_mtype
, from_mmodule
, "___indirect", long_signature
)
445 return ["""{"{{{java_name}}}", "{{{jni_format}}}", {{{c_name}}}}"""]
453 # * Primitives common to both languages use their Java primitive type
454 # * Nit extern Java classes are represented by their full Java type
455 # * Other Nit objects are represented by `int` in Java. It holds the
456 # pointer to the underlying C structure.
457 # TODO create static Java types to store and hide the pointer
458 private fun java_type
: String do return "int"
460 # JNI type name (in C)
462 # So this is a C type, usually defined in `jni.h`
463 private fun jni_type
: String do return "long"
465 # JNI short type name (for signatures)
467 # Is used by `MMethod::build_jni_format` to pass a Java method signature
468 # to the JNI function `GetStaticMetodId`.
469 private fun jni_format
: String do return "I"
471 # Type name appearing within JNI function names.
473 # Used by `JavaLanguage::compile_extern_method` when calling JNI's `CallStatic*Method`.
474 # This strategy is used by JNI to type the return of callbacks to Java.
475 private fun jni_signature_alt
: String do return "Int"
477 redef fun compile_callback_to_java
(mmodule
, mainmodule
, ccu
)
479 var java_file
= mmodule
.java_file
480 if java_file
== null then return
482 for variation
in ["incr", "decr"] do
483 var friendly_name
= "{mangled_cname}_{variation}_ref"
486 var csignature
= "void {mmodule.impl_java_class_name}_{friendly_name}(JNIEnv *env, jclass clazz, jint object)"
487 var cf
= new CFunction("JNIEXPORT {csignature}")
488 cf
.exprs
.add
"\tnitni_global_ref_{variation}((void*)(long)object);"
489 ccu
.add_non_static_local_function cf
492 java_file
.class_content
.add
"private native static void {friendly_name}(int object);\n"
496 redef fun jni_methods_declaration
(from_mmodule
)
498 var arr
= new Array[String]
499 for variation
in ["incr", "decr"] do
500 var friendly_name
= "{mangled_cname}_{variation}_ref"
501 var jni_format
= "(I)V"
502 var cname
= "{from_mmodule.impl_java_class_name}_{friendly_name}"
503 arr
.add
"""{"{{{friendly_name}}}", "{{{jni_format}}}", {{{cname}}}}"""
510 redef class MClassType
513 var ftype
= mclass
.ftype
514 if ftype
isa ForeignJavaType then return ftype
.java_type
.
515 replace
('/', ".").replace
('$', ".").replace
(' ', "").replace
('\n',"")
516 if mclass
.name
== "Bool" then return "boolean"
517 if mclass
.name
== "Char" then return "int"
518 if mclass
.name
== "Int" then return "long"
519 if mclass
.name
== "Float" then return "double"
520 if mclass
.name
== "Byte" then return "byte"
521 if mclass
.name
== "Int8" then return "byte"
522 if mclass
.name
== "Int16" then return "short"
523 if mclass
.name
== "UInt16" then return "short"
524 if mclass
.name
== "Int32" then return "int"
525 if mclass
.name
== "UInt32" then return "int"
531 var ftype
= mclass
.ftype
532 if ftype
isa ForeignJavaType then return "jobject"
533 if mclass
.name
== "Bool" then return "jboolean"
534 if mclass
.name
== "Char" then return "jint"
535 if mclass
.name
== "Int" then return "jlong"
536 if mclass
.name
== "Float" then return "jdouble"
537 if mclass
.name
== "Byte" then return "jbyte"
538 if mclass
.name
== "Int8" then return "jbyte"
539 if mclass
.name
== "Int16" then return "jshort"
540 if mclass
.name
== "UInt16" then return "jshort"
541 if mclass
.name
== "Int32" then return "jint"
542 if mclass
.name
== "UInt32" then return "jint"
548 var ftype
= mclass
.ftype
549 if ftype
isa ForeignJavaType then
550 var jni_type
= ftype
.java_type
.
551 replace
('.', "/").replace
(' ', "").replace
('\n', "")
553 # Remove parameters of generic types
555 var i
= jni_type
.last_index_of
('<')
557 var j
= jni_type
.index_of_from
('>', i
)
559 print
"Error: missing closing '>' in extern Java type of \"{mclass.name}\
""
562 jni_type
= jni_type
.substring
(0, i
) +
563 jni_type
.substring
(j
+1, jni_type
.length
)
567 # Change `float[]` to `[float`
568 if jni_type
.has
('[') then
569 var depth
= jni_type
.chars
.count
('[')
570 var java_type
= jni_type
.replace
("[]", "")
573 if java_type
== "boolean" then
575 else if java_type
== "byte" then
577 else if java_type
== "char" then
579 else if java_type
== "short" then
581 else if java_type
== "int" then
583 else if java_type
== "long" then
585 else if java_type
== "float" then
587 else if java_type
== "double" then
590 short
= "L{java_type};"
593 return "["*depth
+ short
596 return "L{jni_type};"
598 if mclass
.name
== "Bool" then return "Z"
599 if mclass
.name
== "Char" then return "I"
600 if mclass
.name
== "Int" then return "J"
601 if mclass
.name
== "Float" then return "D"
602 if mclass
.name
== "Byte" then return "B"
603 if mclass
.name
== "Int8" then return "B"
604 if mclass
.name
== "Int16" then return "S"
605 if mclass
.name
== "UInt16" then return "S"
606 if mclass
.name
== "Int32" then return "I"
607 if mclass
.name
== "UInt32" then return "I"
611 redef fun jni_signature_alt
613 var ftype
= mclass
.ftype
615 if ftype
isa ForeignJavaType then return "Object"
616 if mclass
.name
== "Bool" then return "Boolean"
617 if mclass
.name
== "Char" then return "Int"
618 if mclass
.name
== "Int" then return "Long"
619 if mclass
.name
== "Float" then return "Double"
620 if mclass
.name
== "Byte" then return "Byte"
621 if mclass
.name
== "Int8" then return "Byte"
622 if mclass
.name
== "Int16" then return "Short"
623 if mclass
.name
== "UInt16" then return "Short"
624 if mclass
.name
== "Int32" then return "Int"
625 if mclass
.name
== "UInt32" then return "Int"
631 # Returns the JNI signature format of this Nit method
633 # Example: a Nity signature `(Bool, Int, Float, JavaString)` is represented by
634 # the JNI format `(ZIDLjava/lang/string;)V"
635 private fun build_jni_format
(recv_mtype
: MClassType, from_mmodule
: MModule): String
637 var mmethoddef
= lookup_first_definition
(from_mmodule
, recv_mtype
)
638 var msignature
= mmethoddef
.msignature
639 var format
= new Array[String]
644 if not self.is_init
then format
.add recv_mtype
.jni_format
647 for p
in msignature
.mparameters
do
648 var param_mtype
= p
.mtype
.resolve_for
(recv_mtype
, recv_mtype
, from_mmodule
, true)
649 format
.add param_mtype
.jni_format
655 format
.add recv_mtype
.jni_format
657 var return_mtype
= msignature
.return_mtype
658 if return_mtype
!= null then
659 return_mtype
= return_mtype
.resolve_for
(recv_mtype
, recv_mtype
, from_mmodule
, true)
660 format
.add return_mtype
.jni_format
667 # Similar to `build_c_signature` but adapted to create the signature expected by JNI for C functions
668 # implementing Java extern methods.
670 # Is used to generate FFI callbacks to Nit at `MExplicitCall::compile_callback_to_java`.
671 private fun build_c_implementation_signature
(recv_mtype
: MClassType, from_mmodule
: MModule,
672 suffix
: nullable String, length
: SignatureLength, call_context
: CallContext): String
674 var mmethoddef
= lookup_first_definition
(from_mmodule
, recv_mtype
)
675 var signature
= mmethoddef
.msignature
676 assert signature
!= null
680 creturn_type
= call_context
.name_mtype
(recv_mtype
)
681 else if signature
.return_mtype
!= null then
682 var ret_mtype
= signature
.return_mtype
683 ret_mtype
= ret_mtype
.resolve_for
(recv_mtype
, recv_mtype
, from_mmodule
, true)
684 creturn_type
= call_context
.name_mtype
(ret_mtype
)
686 creturn_type
= "void"
689 var cname
= build_cname
(recv_mtype
, from_mmodule
, suffix
, length
)
691 var cparams
= new List[String]
694 cparams
.add
"JNIEnv *env"
695 cparams
.add
"jclass clazz"
697 if not self.is_init
then
698 cparams
.add
"{call_context.name_mtype(recv_mtype)} self"
700 for p
in signature
.mparameters
do
701 var param_mtype
= p
.mtype
.resolve_for
(recv_mtype
, recv_mtype
, from_mmodule
, true)
702 cparams
.add
"{call_context.name_mtype(param_mtype)} {p.name}"
705 return "{creturn_type} {cname}( {cparams.join(", ")} )"
709 private fun java_call_context
: JavaCallContext do return new JavaCallContext
710 private fun to_java_call_context
: ToJavaCallContext do return new ToJavaCallContext
711 private fun from_java_call_context
: FromJavaCallContext do return new FromJavaCallContext
713 redef class CCompilationUnit
714 # Similar to `add_local_function` but not `static`
716 # Used when the signature contains a visibility attribute.
717 private fun add_non_static_local_function
(c_function
: CFunction)
719 body_decl
.add c_function
.signature
723 body_impl
.add c_function
.to_writer