nitc :: CCompilationUnit :: _body_custom
custom code and generated for ffinitc :: CCompilationUnit :: _body_impl
implementation body of extern methodsnitc :: CCompilationUnit :: _header_c_types
types of extern classes and friendly typesnitc :: CCompilationUnit :: _header_custom
custom C header code or generated for other languagesnitc :: CCompilationUnit :: _header_decl
implementation declaration for extern methodsnitc :: CCompilationUnit :: add_exported_function
Add a publicc_function
accessible from outside this compilation unit
nitc :: CCompilationUnit :: add_local_function
Add astatic
c_function
to be strictly local to this unit
nitc :: CCompilationUnit :: add_non_static_local_function
Similar toadd_local_function
but not static
nitc :: CCompilationUnit :: body_custom=
custom code and generated for ffinitc :: CCompilationUnit :: body_impl=
implementation body of extern methodsnitc :: CCompilationUnit :: compile_body_core
Write the core of the body tostream
nitc :: CCompilationUnit :: compile_header_core
Write the core of the header tostream
nitc :: CCompilationUnit :: defaultinit
nitc :: CCompilationUnit :: header_c_base=
headernitc :: CCompilationUnit :: header_c_types
types of extern classes and friendly typesnitc :: CCompilationUnit :: header_c_types=
types of extern classes and friendly typesnitc :: CCompilationUnit :: header_custom
custom C header code or generated for other languagesnitc :: CCompilationUnit :: header_custom=
custom C header code or generated for other languagesnitc :: CCompilationUnit :: header_decl
implementation declaration for extern methodsnitc :: CCompilationUnit :: header_decl=
implementation declaration for extern methodsnitc :: CCompilationUnit :: write_as_foreign_lib_api
Write this compilation unit as the API of a foreign code librarynitc :: CCompilationUnit :: write_as_impl
Compile as_ffi
files which contains the implementation of extern methods
nitc :: CCompilationUnit :: write_as_nitni
Compile a_nitni
files, used to implement nitni features for the compiler
nitc :: CCompilationUnit :: write_body_to_file
Write the body part tofile
including all includes
nitc :: CCompilationUnit :: write_header_to_file
Write the header part tofile
including all includes
using the guard
nitc $ CCompilationUnit :: SELF
Type of this instance, automatically specialized in every classnitc :: CCompilationUnit :: _body_custom
custom code and generated for ffinitc :: CCompilationUnit :: _body_impl
implementation body of extern methodsnitc :: CCompilationUnit :: _header_c_types
types of extern classes and friendly typesnitc :: CCompilationUnit :: _header_custom
custom C header code or generated for other languagesnitc :: CCompilationUnit :: _header_decl
implementation declaration for extern methodsnitc :: CCompilationUnit :: add_exported_function
Add a publicc_function
accessible from outside this compilation unit
nitc :: CCompilationUnit :: add_local_function
Add astatic
c_function
to be strictly local to this unit
nitc :: CCompilationUnit :: add_non_static_local_function
Similar toadd_local_function
but not static
nitc :: CCompilationUnit :: body_custom=
custom code and generated for ffinitc :: CCompilationUnit :: body_impl=
implementation body of extern methodscore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: CCompilationUnit :: compile_body_core
Write the core of the body tostream
nitc :: CCompilationUnit :: compile_header_core
Write the core of the header tostream
core :: Object :: defaultinit
nitc :: CCompilationUnit :: defaultinit
nitc :: CCompilationUnit :: header_c_base=
headernitc :: CCompilationUnit :: header_c_types
types of extern classes and friendly typesnitc :: CCompilationUnit :: header_c_types=
types of extern classes and friendly typesnitc :: CCompilationUnit :: header_custom
custom C header code or generated for other languagesnitc :: CCompilationUnit :: header_custom=
custom C header code or generated for other languagesnitc :: CCompilationUnit :: header_decl
implementation declaration for extern methodsnitc :: CCompilationUnit :: header_decl=
implementation declaration for extern methodscore :: 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.
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 :: CCompilationUnit :: write_as_foreign_lib_api
Write this compilation unit as the API of a foreign code librarynitc :: CCompilationUnit :: write_as_impl
Compile as_ffi
files which contains the implementation of extern methods
nitc :: CCompilationUnit :: write_as_nitni
Compile a_nitni
files, used to implement nitni features for the compiler
nitc :: CCompilationUnit :: write_body_to_file
Write the body part tofile
including all includes
nitc :: CCompilationUnit :: write_header_to_file
Write the header part tofile
including all includes
using the guard
# Accumulates all C code for a compilation unit
class CCompilationUnit
## header
# comments and native interface imports
var header_c_base = new Template
# custom C header code or generated for other languages
var header_custom = new Template
# types of extern classes and friendly types
var header_c_types = new Template
# implementation declaration for extern methods
var header_decl = new Template
## body
# comments, imports, etc
var body_decl = new Template
# custom code and generated for ffi
var body_custom = new Template
# implementation body of extern methods
var body_impl = new Template
# files to compile TODO check is appropriate
var files = new Array[String]
# Add a `static` `c_function` to be strictly local to this unit
fun add_local_function(c_function: CFunction)
do
body_decl.add "static {c_function.signature};\n"
body_impl.add "\n"
body_impl.add c_function.to_writer
end
# Add a public `c_function` accessible from outside this compilation unit
fun add_exported_function(c_function: CFunction)
do
body_decl.add "{c_function.signature};\n"
body_impl.add "\n"
body_impl.add c_function.to_writer
end
# Write the core of the header to `stream`
fun compile_header_core(stream: Writer)
do
header_c_base.write_to stream
header_custom.write_to stream
header_c_types.write_to stream
header_decl.write_to stream
end
# Write the core of the body to `stream`
fun compile_body_core(stream: Writer)
do
body_decl.write_to stream
body_custom.write_to stream
body_impl.write_to stream
end
end
src/c_tools.nit:22,1--82,3
redef class CCompilationUnit
# Compile as `_ffi` files which contains the implementation of extern methods
fun write_as_impl(mmodule: MModule, compdir: String)
do
var base_name = "{mmodule.c_name}._ffi"
var h_file = "{base_name}.h"
var guard = "{mmodule.c_name.to_upper}_NIT_H"
write_header_to_file(mmodule, "{compdir}/{h_file}", ["<stdint.h>"], guard)
var c_file = "{base_name}.c"
write_body_to_file(mmodule, "{compdir}/{c_file}", ["<stdlib.h>", "<stdio.h>", "<stdint.h>", "\"{h_file}\""])
files.add( "{compdir}/{c_file}" )
end
# Write the header part to `file` including all `includes` using the `guard`
fun write_header_to_file(mmodule: MModule, file: String, includes: Array[String], guard: String)
do
var stream = new FileWriter.open( file )
# header comments
var module_info = "/*\n\tExtern implementation of Nit module {mmodule.name}\n*/\n"
stream.write( module_info )
stream.write( "#ifndef {guard}\n" )
stream.write( "#define {guard}\n\n" )
for incl in includes do stream.write( "#include {incl}\n" )
compile_header_core( stream )
# header file guard close
stream.write( "#endif\n" )
stream.close
end
# Write the body part to `file` including all `includes`
fun write_body_to_file(mmodule: MModule, file: String, includes: Array[String])
do
var stream = new FileWriter.open(file)
var module_info = "/*\n\tExtern implementation of Nit module {mmodule.name}\n*/\n"
stream.write( module_info )
for incl in includes do stream.write( "#include {incl}\n" )
compile_body_core( stream )
stream.close
end
end
src/ffi/light_ffi_base.nit:156,1--208,3
redef class CCompilationUnit
# Similar to `add_local_function` but not `static`
#
# Used when the signature contains a visibility attribute.
private fun add_non_static_local_function(c_function: CFunction)
do
body_decl.add c_function.signature
body_decl.add ";\n"
body_impl.add "\n"
body_impl.add c_function.to_writer
end
end
src/ffi/java.nit:838,1--850,3
redef class CCompilationUnit
# Compile a `_nitni` files, used to implement nitni features for the compiler
fun write_as_nitni(mmodule: MModule, compdir: String)
do
var base_name = "{mmodule.c_name}._nitni"
var h_file = "{base_name}.h"
write_header_to_file( mmodule, "{compdir}/{h_file}", new Array[String],
"{mmodule.c_name.to_s.to_upper}_NITG_NITNI_H")
var c_file = "{base_name}.c"
write_body_to_file( mmodule, "{compdir}/{c_file}", ["\"{h_file}\""] )
files.add( "{compdir}/{c_file}" )
end
end
src/compiler/compiler_ffi/light.nit:223,1--238,3
redef class CCompilationUnit
# Write this compilation unit as the API of a foreign code library
private fun write_as_foreign_lib_api(mmodule: MModule, compdir: String)
do
# The FFI expects the support header to end with `._nitni.h`
var base_name = mmodule.c_name + "._nitni"
var guard = mmodule.c_name.to_s.to_upper + "_API_H"
var header_comment = """
/*
Public API to foreign code of the Nit module {{{mmodule.name}}}
*/
"""
# Header file
var h_file = base_name+".h"
var stream = new FileWriter.open(compdir/h_file)
stream.write header_comment
stream.write """
#ifndef {{{guard}}}
#define {{{guard}}}
"""
compile_header_core stream
stream.write """
#endif
"""
stream.close
# Body file
var c_file = base_name+".c"
stream = new FileWriter.open(compdir/c_file)
stream.write header_comment
stream.write """
#include "{{{h_file}}}"
"""
compile_body_core stream
stream.close
# Only the C files needs compiling
files.add compdir / c_file
end
end
src/interpreter/dynamic_loading_ffi/on_demand_compiler.nit:240,1--281,3