Introduced properties

private var _from: MType

nitc :: MExplicitCast :: _from

private var _to: MType

nitc :: MExplicitCast :: _to

protected fun from=(from: MType)

nitc :: MExplicitCast :: from=

fun to: MType

nitc :: MExplicitCast :: to

protected fun to=(to: MType)

nitc :: MExplicitCast :: to=

Redefined properties

redef fun ==(o: nullable Object): Bool

nitc $ MExplicitCast :: ==

Have self and other the same value?
redef type SELF: MExplicitCast

nitc $ MExplicitCast :: SELF

Type of this instance, automatically specialized in every class
redef fun hash: Int

nitc $ MExplicitCast :: hash

The hash code of the object.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _from: MType

nitc :: MExplicitCast :: _from

private var _to: MType

nitc :: MExplicitCast :: _to

protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun compile_callback_to_java(mmodule: MModule, mainmodule: MModule, ccu: CCompilationUnit)

nitc :: NitniCallback :: compile_callback_to_java

Compile C and Java code to implement this callback
fun compile_callback_to_objc(mmodule: MModule, mainmodule: MModule)

nitc :: NitniCallback :: compile_callback_to_objc

Compile this callback to be callable from Objective-C
protected fun from=(from: MType)

nitc :: MExplicitCast :: from=

fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun jni_methods_declaration(from_module: MModule): Array[String]

nitc :: NitniCallback :: jni_methods_declaration

Returns the list of C functions to link with extern Java methods, as required
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to: MType

nitc :: MExplicitCast :: to

protected fun to=(to: MType)

nitc :: MExplicitCast :: to=

abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitc::MExplicitCast MExplicitCast nitc::NitniCallback NitniCallback nitc::MExplicitCast->nitc::NitniCallback core::Object Object nitc::NitniCallback->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface NitniCallback

nitc :: NitniCallback

Classification for all nitni callbacks

Class definitions

nitc $ MExplicitCast
class MExplicitCast
	super NitniCallback

	var from: MType
	var to: MType

	fun check_cname: String do return "{from.mangled_cname}_is_a_{to.mangled_cname}"

	fun cast_cname: String do return "{from.mangled_cname}_as_{to.mangled_cname}"

	redef fun hash do return from.hash + 1024 * to.hash
	redef fun ==(o) do return o isa MExplicitCast and from == o.from and to == o.to
end
src/nitni/nitni_callbacks.nit:260,1--272,3

nitc :: compiler_ffi $ MExplicitCast
redef class MExplicitCast
	private fun compile_extern_callbacks(v: AbstractCompilerVisitor, ccu: CCompilationUnit, compile_implementation_too: Bool)
	do
		var from = from
		var to = to

		#
		## check type
		#

		# In nitni files, declare internal function as extern
		var full_friendly_csignature = "int {v.compiler.mainmodule.c_name }___{from.mangled_cname}_is_a_{to.mangled_cname}({from.cname_blind})"
		ccu.header_decl.add("extern {full_friendly_csignature};\n")

		# In nitni files, #define friendly as extern
		ccu.header_decl.add "#ifndef {check_cname}\n"
		ccu.header_decl.add "#define {check_cname} {v.compiler.mainmodule.c_name}___{check_cname}\n"
		ccu.header_decl.add "#endif\n"

		if compile_implementation_too then
			# Internally, implement internal function
			var nitni_visitor = v.compiler.new_visitor
			nitni_visitor.frame = v.frame

			var full_internal_csignature = "int {v.compiler.mainmodule.c_name }___{from.mangled_cname}_is_a_{to.mangled_cname}({internal_call_context.name_mtype(from)} from)"

			nitni_visitor.add_decl("/* nitni check for {from} to {to} */")
			nitni_visitor.add_decl("{full_internal_csignature} \{")

			var from_var = nitni_visitor.var_from_c("from", from)
			from_var = nitni_visitor.box_extern(from_var, from)
			var recv_var = nitni_visitor.type_test(from_var, to, "isa")
			nitni_visitor.add("return {recv_var};")

			nitni_visitor.add("\}")
		end

		# special checks
		if from == to.as_nullable then
			# format A_is_null
			ccu.header_decl.add "#ifndef {from.mangled_cname}_is_null\n"
			ccu.header_decl.add "#define {from.mangled_cname}_is_null !{from.mangled_cname}_is_a_{to.mangled_cname}\n"
			ccu.header_decl.add "#endif\n"
		end

		#
		## cast
		#

		# In nitni files, declare internal function as extern
		full_friendly_csignature = "{to.cname_blind} {v.compiler.mainmodule.c_name }___{from.mangled_cname}_as_{to.mangled_cname}({from.cname_blind})"
		ccu.header_decl.add("extern {full_friendly_csignature};\n")

		# In nitni files, #define friendly as extern
		ccu.header_decl.add "#ifndef {cast_cname}\n"
		ccu.header_decl.add "#define {cast_cname} {v.compiler.mainmodule.c_name}___{cast_cname}\n"
		ccu.header_decl.add "#endif\n"

		if compile_implementation_too then
			# Internally, implement internal function
			var nitni_visitor = v.compiler.new_visitor
			nitni_visitor.frame = v.frame

			var full_internal_csignature = "{to.cname_blind} {v.compiler.mainmodule.c_name }___{from.mangled_cname}_as_{to.mangled_cname}({internal_call_context.name_mtype(from)} from)"
			nitni_visitor.add_decl("/* nitni cast for {from} to {to} */")
			nitni_visitor.add_decl("{full_internal_csignature} \{")

			var from_var = nitni_visitor.var_from_c("from", from)
			from_var = nitni_visitor.box_extern(from_var, from)

			## test type
			var check = nitni_visitor.type_test(from_var, to, "as")
			nitni_visitor.add("if (!{check}) \{")
			nitni_visitor.add_abort("FFI cast failed")
			nitni_visitor.add("\}")

			## internal cast
			var recv_var = nitni_visitor.autobox(from_var, to)
			recv_var = nitni_visitor.unbox_extern(recv_var, to)

			nitni_visitor.ret_to_c(recv_var, to)

			nitni_visitor.add("\}")
		end

		# special casts
		if from.as_nullable == to then
			# format A_as_nullable
			ccu.header_decl.add "#ifndef {from.mangled_cname}_as_nullable\n"
			ccu.header_decl.add "#define {from.mangled_cname}_as_nullable {from.mangled_cname}_as_{to.mangled_cname}\n"
			ccu.header_decl.add "#endif\n"
		end

		if from == to.as_nullable then
			# format A_as_nullable
			ccu.header_decl.add "#ifndef {to.mangled_cname}_as_not_nullable\n"
			ccu.header_decl.add "#define {to.mangled_cname}_as_not_nullable {from.mangled_cname}_as_{to.mangled_cname}\n"
			ccu.header_decl.add "#endif\n"
		end
	end
end
src/compiler/compiler_ffi/compiler_ffi.nit:254,1--354,3