src/compiler: Added fixint variants to compiler
[nit.git] / src / ffi / java.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2013-2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 # FFI support for the Java language
18 #
19 # TODO support callbacks to super and casts
20 module java
21
22 import extern_classes
23 import c
24 import c_compiler_options
25
26 redef class FFILanguageAssignationPhase
27 var java_language: FFILanguage = new JavaLanguage(self)
28 end
29
30 class JavaLanguage
31 super FFILanguage
32
33 redef fun identify_language(n) do return n.is_java
34
35 redef fun compile_module_block(block, ccu, mmodule)
36 do
37 mmodule.ensure_java_files
38 var java_file = mmodule.java_file
39 assert java_file != null
40
41 if block.is_inner_java then
42 java_file.class_content.add(block.code)
43 else java_file.header.add(block.code)
44 end
45
46 redef fun compile_extern_method(block, m, ccu, mmodule)
47 do
48 ffi_ccu = ccu
49 mmodule.ensure_java_files
50 var java_file = mmodule.java_file
51 assert java_file != null
52
53 var mclass_type = m.parent.as(AClassdef).mclass.mclass_type
54 var mmethodef = m.mpropdef
55 var mproperty = m.mpropdef.mproperty
56
57 # C function calling the Java method through JNI
58 var fc = new ExternCFunction(m, mmodule)
59
60 fc.exprs.add """
61 jclass java_class;
62 jmethodID java_meth_id;
63
64 // retrieve the current JVM
65 Sys sys = Pointer_sys(NULL);
66 JNIEnv *nit_ffi_jni_env = Sys_jni_env(sys);
67
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);
73 exit(1);
74 }
75
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);
78 """
79
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)
83 fc.exprs.add """
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);
89 exit(1);
90 }
91 """
92
93 # Call the C Java implementation method from C
94 var signature = mmethodef.msignature
95 assert signature != null
96
97 var jni_signature_alt
98 var return_type
99 var params = new Array[String]
100 params.add "nit_ffi_jni_env"
101 params.add "java_class"
102 params.add "java_meth_id"
103
104 if mproperty.is_init then
105 jni_signature_alt = mclass_type.jni_signature_alt
106 return_type = mclass_type
107 else
108 params.add "self"
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
114 else
115 jni_signature_alt = "Void"
116 return_type = null
117 end
118 end
119
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))
124 end
125
126 var cname = "(*nit_ffi_jni_env)->CallStatic{jni_signature_alt}Method"
127 var ccall
128 if return_type != null then
129 ccall = "{return_type.jni_type} jni_res = {cname}({params.join(", ")});"
130 else ccall = "{cname}({params.join(", ")});"
131
132 fc.exprs.add """
133 // execute implementation code
134 {{{ccall}}}
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);
138 exit(1);
139 }
140
141 (*nit_ffi_jni_env)->DeleteLocalRef(nit_ffi_jni_env, java_class);
142 """
143
144 if return_type != null then
145 fc.exprs.add "\treturn {to_java_call_context.cast_from(return_type, "jni_res")};"
146 end
147
148 ccu.add_exported_function( fc )
149
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}}}
155 {{{block.code}}}
156 }
157 """
158
159 mmodule.callbacks_used_from_java.join m.foreign_callbacks
160 end
161
162 redef fun compile_extern_class(block, m, ccu, mmodule) do end
163
164 redef fun get_ftype(block, m) do return new ForeignJavaType(block.code)
165
166 redef fun compile_to_files(mmodule, compdir)
167 do
168 # Make sure we have a .java file
169 mmodule.ensure_java_files
170
171 # Needed compiler and linker options
172 mmodule.insert_compiler_options
173
174 # Enable linking C callbacks to java native methods
175 mmodule.ensure_linking_callback_methods(ffi_ccu.as(not null))
176
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)
182 end
183
184 var ffi_ccu: nullable CCompilationUnit = null # HACK
185
186 redef fun compile_callback(callback, mmodule, mainmodule, ccu)
187 do
188 ffi_ccu = ccu
189 callback.compile_callback_to_java(mmodule, mainmodule, ccu)
190 end
191 end
192
193 redef class MModule
194 private var callbacks_used_from_java = new ForeignCallbackSet
195
196 # Pure java class source file
197 private var java_file: nullable JavaClassTemplate = null
198
199 # Set up the templates of the Java implementation class
200 private fun ensure_java_files
201 do
202 if java_file != null then return
203
204 # Java implementation code
205 java_file = new JavaClassTemplate(impl_java_class_name)
206 end
207
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)
210 do
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"
214 return
215 end
216
217 ccu.body_decl.add "static int nit_ffi_with_java_registered_natives = 0;\n"
218
219 var jni_methods = new Array[String]
220 for cb in callbacks do
221 jni_methods.add_all(cb.jni_methods_declaration(self))
222 end
223
224 var cf = new CFunction("void nit_ffi_with_java_register_natives(JNIEnv* env, jclass jclazz)")
225 cf.exprs.add """
226 nit_ffi_with_java_registered_natives = 1;
227
228 jint n_methods = {{{jni_methods.length}}};
229 JNINativeMethod methods[] = {
230 {{{jni_methods.join(",\n\t\t")}}}
231 };
232 jint res = (*env)->RegisterNatives(env, jclazz, methods, n_methods);
233 if (res != JNI_OK) {
234 PRINT_ERROR("RegisterNatives failed\\n");
235 (*env)->ExceptionDescribe(env);
236 exit(1);
237 }
238 """
239 ccu.add_local_function cf
240 end
241
242 # Tell the C compiler where to find jni.h and how to link with libjvm
243 private fun insert_compiler_options
244 do
245 cflags.add_one("", "-I $(JAVA_HOME)/include/ -I $(JAVA_HOME)/include/linux/")
246 end
247
248 # Name of the generated Java class where to store all implementation methods of this module
249 # as well as generated callbacks.
250 private fun impl_java_class_name: String do return "Nit_{name}"
251 end
252
253 redef class AMethPropdef
254 redef fun verify_nitni_callbacks(toolcontext)
255 do
256 super
257
258 var block = n_extern_code_block
259 if block != null and block.is_java then
260 insert_artificial_callbacks(toolcontext)
261 end
262 end
263
264 # Insert additional explicit calls to get the current `JNIEnv`
265 #
266 # This forces declaration of callbacks to Nit. The callbacks will be available in Java
267 # but will be used mainly by the FFI itself.
268 #
269 # The developer can also customize the JNIEnv used by the FFI by redefining `Sys::jni_env`.
270 private fun insert_artificial_callbacks(toolcontext: ToolContext)
271 do
272 var fcc = foreign_callbacks
273
274 var modelbuilder = toolcontext.modelbuilder
275 var mmodule = mpropdef.mclassdef.mmodule
276
277 # We use callbacks from the C FFI since they will be called from generated C
278 var c_language_visitor = toolcontext.ffi_language_assignation_phase.as(FFILanguageAssignationPhase).c_language
279 if not mmodule.ffi_callbacks.keys.has(c_language_visitor) then
280 mmodule.ffi_callbacks[c_language_visitor] = new HashSet[NitniCallback]
281 end
282
283 # Pointer::sys
284 var pointer_class = modelbuilder.try_get_mclass_by_name(self, mmodule, "Pointer")
285 assert pointer_class != null
286 var pointer_sys_meth = modelbuilder.try_get_mproperty_by_name2(self, mmodule, pointer_class.mclass_type, "sys")
287 assert pointer_sys_meth != null and pointer_sys_meth isa MMethod
288
289 var explicit_call = new MExplicitCall(pointer_class.mclass_type, pointer_sys_meth, mmodule)
290 fcc.callbacks.add(explicit_call)
291 mmodule.ffi_callbacks[c_language_visitor].add(explicit_call)
292
293 # Sys::jni_env
294 var sys_class = modelbuilder.try_get_mclass_by_name(self, mmodule, "Sys")
295 assert sys_class != null
296 var sys_jni_env_meth = modelbuilder.try_get_mproperty_by_name2(self, mmodule, sys_class.mclass_type, "jni_env")
297 if sys_jni_env_meth == null or not sys_jni_env_meth isa MMethod then
298 toolcontext.error(self.location, "Java FFI Error: you must import the `java` module when using the FFI with Java")
299 return
300 end
301
302 explicit_call = new MExplicitCall(sys_class.mclass_type, sys_jni_env_meth, mmodule)
303 fcc.callbacks.add(explicit_call)
304 mmodule.ffi_callbacks[c_language_visitor].add(explicit_call)
305
306 # Sys::load_jclass
307 var sys_jni_load_jclass_meth = modelbuilder.try_get_mproperty_by_name2(self, mmodule, sys_class.mclass_type, "load_jclass")
308 assert sys_jni_load_jclass_meth != null
309 assert sys_jni_load_jclass_meth isa MMethod
310
311 explicit_call = new MExplicitCall(sys_class.mclass_type, sys_jni_load_jclass_meth, mmodule)
312 fcc.callbacks.add(explicit_call)
313 mmodule.ffi_callbacks[c_language_visitor].add(explicit_call)
314 explicit_call.fill_type_for(fcc, mmodule)
315 end
316 end
317
318 redef class AExternCodeBlock
319 # Is this code block in Java?
320 fun is_java: Bool do return is_default_java or (parent isa AModule and is_inner_java)
321
322 # Is this code block in Java, with the default mode? (On module blocks it targets the file header)
323 private fun is_default_java: Bool do return language_name != null and
324 language_name_lowered == "java"
325
326 # Is this code block in Java, and for a module block to generate in the class?
327 private fun is_inner_java: Bool do return language_name != null and
328 language_name_lowered == "java inner"
329 end
330
331 # Java class source template
332 class JavaClassTemplate
333 super Template
334
335 var java_class_name: String
336
337 var header = new Template
338 var class_content = new Template
339
340 fun write_to_files(compdir: String): ExternFile
341 do
342 var filename = "{java_class_name}.java"
343 var filepath = "{compdir}/{filename}"
344
345 write_to_file filepath
346
347 return new JavaFile(filename)
348 end
349
350 redef fun rendering
351 do
352 add header
353 add "\n"
354 add "public class {java_class_name} \{\n"
355 add class_content
356 add "\}"
357 end
358 end
359
360 # A generated Java source file, represent the corresponding Makefile rules
361 class JavaFile
362 super ExternFile
363
364 redef fun makefile_rule_name do return "{filename.basename(".java")}.class"
365 redef fun makefile_rule_content do return "javac {filename.basename} -d ."
366 redef fun add_to_jar do return true
367 end
368
369 # Context in pure Java code
370 private class JavaCallContext
371 super CallContext
372
373 redef fun name_mtype(mtype) do return mtype.java_type
374 end
375
376 # Context in C, when call are from normal C to JNI
377 private class ToJavaCallContext
378 super CallContext
379
380 redef fun cast_to(mtype, name) do return "({mtype.jni_type})({name})"
381 redef fun cast_from(mtype, name) do return "({mtype.cname})({name})"
382 redef fun name_mtype(mtype) do return mtype.jni_type
383 end
384
385 # Context in C, when call are from JNI to normal C
386 private class FromJavaCallContext
387 super CallContext
388
389 redef fun cast_to(mtype, name) do return "({mtype.cname})({name})"
390 redef fun cast_from(mtype, name) do return "({mtype.jni_type})({name})"
391 redef fun name_mtype(mtype) do return mtype.jni_type
392 end
393
394 # Foreign type attach to Nit extern Java classes
395 class ForeignJavaType
396 super ForeignType
397
398 var java_type: String
399 end
400
401 redef class NitniCallback
402 # Compile C and Java code to implement this callback
403 fun compile_callback_to_java(mmodule: MModule, mainmodule: MModule, ccu: CCompilationUnit) do end
404
405 # Returns the list of C functions to link with extern Java methods, as required
406 # to enable this callback from Java code.
407 #
408 # Return used by `MModule::ensure_linking_callback_methods`
409 #
410 # TODO we return an Array to support cast and other features like that
411 fun jni_methods_declaration(from_module: MModule): Array[String] do return new Array[String]
412 end
413
414 redef class MExplicitCall
415 redef fun compile_callback_to_java(mmodule, mainmodule, ccu)
416 do
417 if not mmodule.callbacks_used_from_java.callbacks.has(self) then return
418
419 var mproperty = mproperty
420 assert mproperty isa MMethod
421
422 # In C, indirection implementing the Java extern methods
423 var csignature = mproperty.build_c_implementation_signature(recv_mtype, mmodule, "___indirect", long_signature, from_java_call_context)
424 var cf = new CFunction("JNIEXPORT {csignature}")
425 cf.exprs.add "\t{mproperty.build_ccall(recv_mtype, mainmodule, null, long_signature, from_java_call_context, null)}\n"
426 ccu.add_non_static_local_function cf
427
428 # In Java, declare the extern method as a private static local method
429 var java_signature = mproperty.build_csignature(recv_mtype, mainmodule, null, short_signature, java_call_context)
430 mmodule.java_file.class_content.add "private native static {java_signature};\n"
431 end
432
433 redef fun jni_methods_declaration(from_mmodule)
434 do
435 var mproperty = mproperty
436 assert mproperty isa MMethod
437
438 var java_name = mproperty.build_cname(recv_mtype, from_mmodule, null, short_signature)
439 var jni_format = mproperty.build_jni_format(recv_mtype, from_mmodule)
440 var c_name = mproperty.build_cname(recv_mtype, from_mmodule, "___indirect", long_signature)
441
442 return ["""{"{{{java_name}}}", "{{{jni_format}}}", {{{c_name}}}}"""]
443 end
444 end
445
446 redef class MType
447
448 # Type name in Java
449 #
450 # * Primitives common to both languages use their Java primitive type
451 # * Nit extern Java classes are represented by their full Java type
452 # * Other Nit objects are represented by `int` in Java. It holds the
453 # pointer to the underlying C structure.
454 # TODO create static Java types to store and hide the pointer
455 private fun java_type: String do return "int"
456
457 # JNI type name (in C)
458 #
459 # So this is a C type, usually defined in `jni.h`
460 private fun jni_type: String do return "long"
461
462 # JNI short type name (for signatures)
463 #
464 # Is used by `MMethod::build_jni_format` to pass a Java method signature
465 # to the JNI function `GetStaticMetodId`.
466 private fun jni_format: String do return "I"
467
468 # Type name appearing within JNI function names.
469 #
470 # Used by `JavaLanguage::compile_extern_method` when calling JNI's `CallStatic*Method`.
471 # This strategy is used by JNI to type the return of callbacks to Java.
472 private fun jni_signature_alt: String do return "Int"
473 end
474
475 redef class MClassType
476 redef fun java_type
477 do
478 var ftype = mclass.ftype
479 if ftype isa ForeignJavaType then return ftype.java_type.
480 replace('/', ".").replace('$', ".").replace(' ', "").replace('\n',"")
481 if mclass.name == "Bool" then return "boolean"
482 if mclass.name == "Char" then return "int"
483 if mclass.name == "Int" then return "long"
484 if mclass.name == "Float" then return "double"
485 if mclass.name == "Byte" then return "byte"
486 if mclass.name == "Int8" then return "byte"
487 if mclass.name == "Int16" then return "short"
488 if mclass.name == "UInt16" then return "short"
489 if mclass.name == "Int32" then return "int"
490 if mclass.name == "UInt32" then return "int"
491 return super
492 end
493
494 redef fun jni_type
495 do
496 var ftype = mclass.ftype
497 if ftype isa ForeignJavaType then return "jobject"
498 if mclass.name == "Bool" then return "jboolean"
499 if mclass.name == "Char" then return "jint"
500 if mclass.name == "Int" then return "jlong"
501 if mclass.name == "Float" then return "jdouble"
502 if mclass.name == "Byte" then return "jbyte"
503 if mclass.name == "Int8" then return "jbyte"
504 if mclass.name == "Int16" then return "jshort"
505 if mclass.name == "UInt16" then return "jshort"
506 if mclass.name == "Int32" then return "jint"
507 if mclass.name == "UInt32" then return "jint"
508 return super
509 end
510
511 redef fun jni_format
512 do
513 var ftype = mclass.ftype
514 if ftype isa ForeignJavaType then
515 var jni_type = ftype.java_type.
516 replace('.', "/").replace(' ', "").replace('\n', "")
517
518 # Remove parameters of generic types
519 loop
520 var i = jni_type.last_index_of('<')
521 if i >= 0 then
522 var j = jni_type.index_of_from('>', i)
523 if j == -1 then
524 print "Error: missing closing '>' in extern Java type of \"{mclass.name}\""
525 exit 1
526 end
527 jni_type = jni_type.substring(0, i) +
528 jni_type.substring(j+1, jni_type.length)
529 else break
530 end
531
532 # Change `float[]` to `[float`
533 if jni_type.has('[') then
534 var depth = jni_type.chars.count('[')
535 var java_type = jni_type.replace("[]", "")
536 var short
537
538 if java_type == "boolean" then
539 short = "Z"
540 else if java_type == "byte" then
541 short = "B"
542 else if java_type == "char" then
543 short = "C"
544 else if java_type == "short" then
545 short = "S"
546 else if java_type == "int" then
547 short = "I"
548 else if java_type == "long" then
549 short = "J"
550 else if java_type == "float" then
551 short = "F"
552 else if java_type == "double" then
553 short = "D"
554 else
555 short = "L{java_type};"
556 end
557
558 return "["*depth + short
559 end
560
561 return "L{jni_type};"
562 end
563 if mclass.name == "Bool" then return "Z"
564 if mclass.name == "Char" then return "I"
565 if mclass.name == "Int" then return "J"
566 if mclass.name == "Float" then return "D"
567 if mclass.name == "Byte" then return "B"
568 if mclass.name == "Int8" then return "B"
569 if mclass.name == "Int16" then return "S"
570 if mclass.name == "UInt16" then return "S"
571 if mclass.name == "Int32" then return "I"
572 if mclass.name == "UInt32" then return "I"
573 return super
574 end
575
576 redef fun jni_signature_alt
577 do
578 var ftype = mclass.ftype
579
580 if ftype isa ForeignJavaType then return "Object"
581 if mclass.name == "Bool" then return "Boolean"
582 if mclass.name == "Char" then return "Int"
583 if mclass.name == "Int" then return "Long"
584 if mclass.name == "Float" then return "Double"
585 if mclass.name == "Byte" then return "Byte"
586 if mclass.name == "Int8" then return "Byte"
587 if mclass.name == "Int16" then return "Short"
588 if mclass.name == "UInt16" then return "Short"
589 if mclass.name == "Int32" then return "Int"
590 if mclass.name == "UInt32" then return "Int"
591 return super
592 end
593 end
594
595 redef class MMethod
596 # Returns the JNI signature format of this Nit method
597 #
598 # Example: a Nity signature `(Bool, Int, Float, JavaString)` is represented by
599 # the JNI format `(ZIDLjava/lang/string;)V"
600 private fun build_jni_format(recv_mtype: MClassType, from_mmodule: MModule): String
601 do
602 var mmethoddef = lookup_first_definition(from_mmodule, recv_mtype)
603 var msignature = mmethoddef.msignature
604 var format = new Array[String]
605
606 format.add "("
607
608 # receiver
609 if not self.is_init then format.add recv_mtype.jni_format
610
611 # parameters
612 for p in msignature.mparameters do
613 var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
614 format.add param_mtype.jni_format
615 end
616 format.add ")"
617
618 # return
619 if self.is_init then
620 format.add recv_mtype.jni_format
621 else
622 var return_mtype = msignature.return_mtype
623 if return_mtype != null then
624 return_mtype = return_mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
625 format.add return_mtype.jni_format
626 else format.add "V"
627 end
628
629 return format.join
630 end
631
632 # Similar to `build_c_signature` but adapted to create the signature expected by JNI for C functions
633 # implementing Java extern methods.
634 #
635 # Is used to generate FFI callbacks to Nit at `MExplicitCall::compile_callback_to_java`.
636 private fun build_c_implementation_signature(recv_mtype: MClassType, from_mmodule: MModule,
637 suffix: nullable String, length: SignatureLength, call_context: CallContext): String
638 do
639 var mmethoddef = lookup_first_definition(from_mmodule, recv_mtype)
640 var signature = mmethoddef.msignature
641 assert signature != null
642
643 var creturn_type
644 if self.is_init then
645 creturn_type = call_context.name_mtype(recv_mtype)
646 else if signature.return_mtype != null then
647 var ret_mtype = signature.return_mtype
648 ret_mtype = ret_mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
649 creturn_type = call_context.name_mtype(ret_mtype)
650 else
651 creturn_type = "void"
652 end
653
654 var cname = build_cname(recv_mtype, from_mmodule, suffix, length)
655
656 var cparams = new List[String]
657
658 # This is different
659 cparams.add "JNIEnv *env"
660 cparams.add "jclass clazz"
661
662 if not self.is_init then
663 cparams.add "{call_context.name_mtype(recv_mtype)} self"
664 end
665 for p in signature.mparameters do
666 var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
667 cparams.add "{call_context.name_mtype(param_mtype)} {p.name}"
668 end
669
670 return "{creturn_type} {cname}( {cparams.join(", ")} )"
671 end
672 end
673
674 private fun java_call_context: JavaCallContext do return new JavaCallContext
675 private fun to_java_call_context: ToJavaCallContext do return new ToJavaCallContext
676 private fun from_java_call_context: FromJavaCallContext do return new FromJavaCallContext
677
678 redef class CCompilationUnit
679 # Similar to `add_local_function` but not `static`
680 #
681 # Used when the signature contains a visibility attribute.
682 private fun add_non_static_local_function(c_function: CFunction)
683 do
684 body_decl.add c_function.signature
685 body_decl.add ";\n"
686
687 body_impl.add "\n"
688 body_impl.add c_function.to_writer
689 end
690 end