Introduced classes

class CallContext

nitc :: CallContext

Describes the context of the code to be generated by build_ccall and build_csignature
class SignatureLength

nitc :: SignatureLength

Length of the signature of a C function (long version hase the module name as prefix)

Redefined classes

redef class MMethod

nitc :: nitni_utilities $ MMethod

A global method
redef class Sys

nitc :: nitni_utilities $ Sys

The main class of the program.

All class definitions

class CallContext

nitc $ CallContext

Describes the context of the code to be generated by build_ccall and build_csignature
redef class MMethod

nitc :: nitni_utilities $ MMethod

A global method
class SignatureLength

nitc $ SignatureLength

Length of the signature of a C function (long version hase the module name as prefix)
redef class Sys

nitc :: nitni_utilities $ Sys

The main class of the program.
package_diagram nitc::nitni_utilities nitni_utilities nitc::nitni_base nitni_base nitc::nitni_utilities->nitc::nitni_base nitc::modelbuilder modelbuilder nitc::nitni_base->nitc::modelbuilder ...nitc::modelbuilder ... ...nitc::modelbuilder->nitc::modelbuilder nitc::nitni nitni nitc::nitni->nitc::nitni_utilities nitc::light_ffi_base light_ffi_base nitc::light_ffi_base->nitc::nitni_utilities nitc::ffi_base ffi_base nitc::ffi_base->nitc::nitni nitc::ffi_base->nitc::light_ffi_base nitc::ffi_base... ... nitc::ffi_base...->nitc::ffi_base nitc::extern_classes extern_classes nitc::extern_classes->nitc::light_ffi_base nitc::light_c light_c nitc::light_c->nitc::light_ffi_base nitc::extern_classes... ... nitc::extern_classes...->nitc::extern_classes nitc::light_c... ... nitc::light_c...->nitc::light_c

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module loader

nitc :: loader

Loading of Nit source files
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module nitni_base

nitc :: nitni_base

Native interface related services (used underneath the FFI)

Children

module light_ffi_base

nitc :: light_ffi_base

Tools and utilities for implement FFI with different languages
module nitni

nitc :: nitni

Native interface related services (used underneath the FFI)

Descendants

module a_star-m

a_star-m

module abstract_compiler

nitc :: abstract_compiler

Abstract compiler
module android

nitc :: android

Compile program for the Android platform
module c

nitc :: c

Support for nesting C code within a Nit program using its FFI
module c_compiler_options

nitc :: c_compiler_options

Offers the annotations cflags and ldflags to specify
module compiler

nitc :: compiler

Compilation to C
module compiler_ffi

nitc :: compiler_ffi

Full FFI support for the compiler
module compiler_serialization

nitc :: compiler_serialization

Serialization support for the compiler
module cpp

nitc :: cpp

Supports the use of the C++ language through the FFI
module dynamic_loading_ffi

nitc :: dynamic_loading_ffi

Execute FFI code by creating and loading shared libraries
module emscripten

nitc :: emscripten

Compile to JavaScript using the Emscripten SDK
module extern_classes

nitc :: extern_classes

Manages all extern classes and their associated foreign type.
module extra_java_files

nitc :: extra_java_files

Intro the annotation extra_java_files to compile extra java files
module ffi

nitc :: ffi

Full FFI support, independent of the compiler
module ffi_base

nitc :: ffi_base

Tools and utilities for implement FFI with different languages
module global_compiler

nitc :: global_compiler

Global compilation of a Nit program
module header_dependency

nitc :: header_dependency

Tracks which modules has public header code that must be imported
module interpreter

nitc :: interpreter

Interpretation of Nit programs
module ios

nitc :: ios

Compile programs for the iOS platform
module java

nitc :: java

FFI support for the Java language
module light

nitc :: light

Light FFI support for the compiler
module light_c

nitc :: light_c

Support for nesting C code within a Nit program using its FFI
module light_ffi

nitc :: light_ffi

Light FFI support, independent of the compiler
module light_only

nitc :: light_only

Compiler support for the light FFI only, detects unsupported usage of callbacks
module memory_logger

nitc :: memory_logger

Extension to inject memory-tracing instrumentation in code generated by nitc.
module nit

nitc :: nit

A naive Nit interpreter
module nitc

nitc :: nitc

A Nit compiler
module nith

nitc :: nith

A ligHt Nit compiler
module objc

nitc :: objc

FFI support for Objective-C
module on_demand_compiler

nitc :: on_demand_compiler

Compiles extern code within a module to a static library, as needed
module pkgconfig

nitc :: pkgconfig

Offers the PkgconfigPhase to use the external program "pkg-config" in order
module separate_compiler

nitc :: separate_compiler

Separate compilation of a Nit program
module separate_erasure_compiler

nitc :: separate_erasure_compiler

Separate compilation of a Nit program with generic type erasure
module test_astbuilder

nitc :: test_astbuilder

Program used to test the clone method of the astbuilder tool
module xcode_templates

nitc :: xcode_templates

Templates and other services to create XCode projects
import nitni_base

redef class MMethod
	# Build a C function name for the FFI implementation (uses friendly naming).
	# * On a specific static receiver type `recv_mtype`
	# * In referene to the module `from_module` (used for type resolving and as a possible prefix)
	# * Has a possible `suffix` to the method name (may be "__super", "__impl", null, etc.)
	# * With a specified length indicating whether it uses the sort name or the long name with
	#   the module name as prefix
	fun build_cname(recv_mtype: MClassType, from_mmodule: MModule, suffix: nullable String, length: SignatureLength): String
	do
		var cname
		if self.is_init then
			if self.name == "init" or self.name == "new" or self.name == "defaultinit" then
				cname = "new_{recv_mtype.mangled_cname}"
			else
				cname = "new_{recv_mtype.mangled_cname}_{self.short_cname}"
			end
		else
			cname = "{recv_mtype.mangled_cname}_{self.short_cname}"
		end

		if suffix != null then cname = "{cname}{suffix}"

		if length.long then cname = "{from_mmodule.c_name}___{cname}"

		return cname
	end

	# Build a C function signature for the FFI implementation (uses friendly naming).
	# * On a specific static receiver type `recv_mtype`
	# * In referene to the module `from_module` (used for type resolving and as a possible prefix)
	# * Has a possible `suffix` to the method name (may be "__super", "__impl", null, etc.)
	# * With a specified length indicating whether it uses the sort name or the long name with
	#   the module name as prefix
	# * The `call_context` identifying which types and casts to use (see `CallContext` and its instances)
	fun build_csignature(recv_mtype: MClassType, from_mmodule: MModule, suffix: nullable String, length: SignatureLength, call_context: CallContext): String
	do
		var mmethoddef = lookup_first_definition(from_mmodule, recv_mtype)
		var signature = mmethoddef.msignature
		assert signature != null

		var creturn_type
		if self.is_init then
			creturn_type = call_context.name_mtype(recv_mtype)
		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 = call_context.name_mtype(ret_mtype)
		else
			creturn_type = "void"
		end

		var cname = build_cname(recv_mtype, from_mmodule, suffix, length)

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

		return "{creturn_type} {cname}( {cparams.join(", ")} )"
	end

	# Build a C function call for the FFI implementation (uses friendly naming).
	# * On a specific static receiver type `recv_mtype`
	# * In referene to the module `from_module` (used for type resolving and as a possible prefix)
	# * Has a possible `suffix` to the method name (may be "__super", "__impl", null, etc.)
	# * With a specified length indicating whether it uses the sort name or the long name with
	#   the module name as prefix
	# * The `call_context` identifying which types and casts to use (see `CallContext` and its instances)
	# * Possible suffix to the parameters `param_suffix`
	fun build_ccall(recv_mtype: MClassType, from_mmodule: MModule, suffix: nullable String, length: SignatureLength, call_context: CallContext, param_suffix: nullable String): String
	do
		if param_suffix == null then param_suffix = ""

		var mmethoddef = lookup_first_definition(from_mmodule, recv_mtype)
		var signature = mmethoddef.msignature
		assert signature != null

		var return_mtype = null
		if self.is_init then
			return_mtype = recv_mtype
		else if signature.return_mtype != null then
			return_mtype = signature.return_mtype
			return_mtype = return_mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
		end

		var cname = build_cname(recv_mtype, from_mmodule, suffix, length)

		var cparams = new List[String]
		if not self.is_init then
			cparams.add(call_context.cast_to(recv_mtype, "self{param_suffix}"))
		end

		for p in signature.mparameters do
			var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
			cparams.add(call_context.cast_to(param_mtype, "{p.name}{param_suffix}"))
		end

		var joined_cparams = cparams.join(", ")
		var ccall = "{cname}({joined_cparams})"
		if return_mtype != null then
			return "return {call_context.cast_from(return_mtype, ccall)};"
		else
			return "{ccall};"
		end
	end
end

# Describes the context of the code to be generated by `build_ccall` and `build_csignature`
class CallContext
	# Which C name to use for type `mtype`
	fun name_mtype(mtype: MType): String do return mtype.cname_blind

	# How to cast a returned C variable named `name` of type `mtype`
	fun cast_from(mtype: MType, name: String): String do return name

	# How to cast a C argument named `name` of type `mtype`
	fun cast_to(mtype: MType, name: String): String do return name
end

# Call context to use
fun internal_call_context: CallContext do return new CallContext
fun long_signature: SignatureLength do return once new SignatureLength(true)
fun short_signature: SignatureLength do return once new SignatureLength(false)

# Length of the signature of a C function (long version hase the module name as prefix)
class SignatureLength
	private var long: Bool

	# TODO: private init because singleton class.
end
src/nitni/nitni_utilities.nit:18,1--153,3