A global static type

MType are global to the model; it means that a MType is not bound to a specific MModule. This characteristic helps the reasoning about static types in a program since a single MType object always denote the same type.

However, because a MType is global, it does not really have properties nor have subtypes to a hierarchy since the property and the class hierarchy depends of a module. Moreover, virtual types an formal generic parameter types also depends on a receiver to have sense.

Therefore, most method of the types require a module and an anchor. The module is used to know what are the classes and the specialization links. The anchor is used to know what is the bound of the virtual types and formal generic parameter types.

MType are not directly usable to get properties. See the anchor_to method and the MClassType class.

FIXME: the order of the parameters is not the best. We mus pick on from:

  • foo(mmodule, anchor, othertype)
  • foo(othertype, anchor, mmodule)
  • foo(anchor, mmodule, othertype)
  • foo(othertype, mmodule, anchor)

Introduced properties

private var _as_nullable_cache: nullable MType

nitc :: MType :: _as_nullable_cache

private var _is_java_primitive: Bool

nitc :: MType :: _is_java_primitive

Is the associated Java type a primitive one?
private var _is_tagged: Bool

nitc :: MType :: _is_tagged

Are values of self tagged?
private var _tag_value: Int

nitc :: MType :: _tag_value

The tag value of the type
fun anchor_to(mmodule: MModule, anchor: nullable MClassType): MType

nitc :: MType :: anchor_to

The base class type on which self is based
fun as_notnull: MType

nitc :: MType :: as_notnull

Returns the not null version of the type.
fun as_nullable: MType

nitc :: MType :: as_nullable

Return the nullable version of the type
private fun as_nullable_cache: nullable MType

nitc :: MType :: as_nullable_cache

private fun as_nullable_cache=(as_nullable_cache: nullable MType)

nitc :: MType :: as_nullable_cache=

private fun call_arg_field: String

nitc :: MType :: call_arg_field

Field to store this type in the C structure nit_call_arg
abstract fun can_resolve_for(mtype: MType, anchor: nullable MClassType, mmodule: MModule): Bool

nitc :: MType :: can_resolve_for

Can the type be resolved?
fun cname: String

nitc :: MType :: cname

Representation of this type in pure C on the FFI extern side
fun cname_blind: String

nitc :: MType :: cname_blind

Representation of this type in C for the internal of the system
protected fun cname_normal_class: String

nitc :: MType :: cname_normal_class

Name of this type in C for normal classes (not extern and not primitive)
abstract fun collect_mclassdefs(mmodule: MModule): Set[MClassDef]

nitc :: MType :: collect_mclassdefs

Compute all the classdefs inherited/imported.
abstract fun collect_mclasses(mmodule: MModule): Set[MClass]

nitc :: MType :: collect_mclasses

Compute all the super-classes.
abstract fun collect_mtypes(mmodule: MModule): Set[MClassType]

nitc :: MType :: collect_mtypes

Compute all the declared super-types.
fun ctype: String

nitc :: MType :: ctype

Return the C type associated to a given Nit static type
fun ctype_extern: String

nitc :: MType :: ctype_extern

C type outside of the compiler code and in boxes
fun ctypename: String

nitc :: MType :: ctypename

Short name of the ctype to use in unions
fun depth: Int

nitc :: MType :: depth

The depth of the type seen as a tree.
private fun gen_arg_convert(template: Template, arg_name: String)

nitc :: MType :: gen_arg_convert

Write code in template to parse the argument arg_name to this parameter type
fun has_mproperty(mmodule: MModule, mproperty: MProperty): Bool

nitc :: MType :: has_mproperty

Is the property in self for a given module
fun is_c_primitive: Bool

nitc :: MType :: is_c_primitive

Is the associated C type a primitive one?
fun is_cprimitive: Bool

nitc :: MType :: is_cprimitive

Does this type have a primitive representation?
fun is_java_primitive: Bool

nitc :: MType :: is_java_primitive

Is the associated Java type a primitive one?
protected fun is_java_primitive=(is_java_primitive: Bool)

nitc :: MType :: is_java_primitive=

Is the associated Java type a primitive one?
fun is_ok: Bool

nitc :: MType :: is_ok

Is the type a MErrorType or contains an MErrorType?
fun is_subtype(mmodule: MModule, anchor: nullable MClassType, sup: MType): Bool

nitc :: MType :: is_subtype

Return true if self is an subtype of sup.
fun is_subtype_invar(mmodule: MModule, anchor: nullable MClassType, sup: MType): Bool

nitc :: MType :: is_subtype_invar

Return true if self is a invariant subtype of sup.
fun is_tagged: Bool

nitc :: MType :: is_tagged

Are values of self tagged?
protected fun is_tagged=(is_tagged: Bool)

nitc :: MType :: is_tagged=

Are values of self tagged?
private fun java_is_nit_object: Bool

nitc :: MType :: java_is_nit_object

Is this type opaque in Java? As so it is represented by nit.app.NitObject.
fun java_type: String

nitc :: MType :: java_type

Return the Java type associated to a given Nit static type
private fun java_type: String

nitc :: MType :: java_type

Type name in Java
private fun jni_format: String

nitc :: MType :: jni_format

JNI short type name (for signatures)
private fun jni_signature_alt: String

nitc :: MType :: jni_signature_alt

Type name appearing within JNI function names.
private fun jni_type: String

nitc :: MType :: jni_type

JNI type name (in C)
fun length: Int

nitc :: MType :: length

The length of the type seen as a tree.
fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType

nitc :: MType :: lookup_bound

Resolve formal type to its verbatim bound.
fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType

nitc :: MType :: lookup_fixed

Resolve the formal type to its simplest equivalent form.
abstract fun mangled_cname: String

nitc :: MType :: mangled_cname

Representation of this type in mangled C
fun need_anchor: Bool

nitc :: MType :: need_anchor

Does self contain a virtual type or a formal generic parameter type?
private fun needs_type_check: Bool

nitc :: MType :: needs_type_check

Does this parameter type needs to be checked before calling the method?
private abstract fun related_mclasses(mmodule: MModule): Array[MClass]

nitc :: MType :: related_mclasses

List classes composing this type
abstract fun resolve_for(mtype: MType, anchor: nullable MClassType, mmodule: MModule, cleanup_virtual: Bool): MType

nitc :: MType :: resolve_for

Replace formals generic types in self with resolved values in mtype
fun supertype_to(mmodule: MModule, anchor: nullable MClassType, super_mclass: MClass): MClassType

nitc :: MType :: supertype_to

Return the supertype when adapted to a class.
fun tag_value: Int

nitc :: MType :: tag_value

The tag value of the type
protected fun tag_value=(tag_value: Int)

nitc :: MType :: tag_value=

The tag value of the type
fun undecorate: MType

nitc :: MType :: undecorate

Remove the base type of a decorated (proxy) type.

Redefined properties

redef type SELF: MType

nitc $ MType :: SELF

Type of this instance, automatically specialized in every class
redef fun cname_blind: String

nitc :: on_demand_compiler $ MType :: cname_blind

The interpreter FFI use void* to represent intern data types
redef fun compile_callback_to_java(mmodule: MModule, mainmodule: MModule, ccu: CCompilationUnit)

nitc :: java $ MType :: compile_callback_to_java

Compile C and Java code to implement this callback
redef fun core_serialize_to(v: Serializer)

nitc :: api_base $ MType :: core_serialize_to

Actual serialization of self to serializer
redef fun core_serialize_to(v: Serializer)

nitc :: json_model $ MType :: core_serialize_to

Actual serialization of self to serializer
redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AType

nitc :: astbuilder $ MType :: create_ast_representation

Build a ANode from self
redef fun html_signature(short: nullable Bool): Template

nitc :: html_model $ MType :: html_signature

Returns the MEntity signature decorated with HTML
redef fun jni_methods_declaration(from_mmodule: MModule): Array[String]

nitc :: java $ MType :: jni_methods_declaration

Returns the list of C functions to link with extern Java methods, as required
redef fun name: String

nitc $ MType :: name

The short (unqualified) name of this model entity.
redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode

nitc :: neo $ MType :: to_node

Build a NeoNode representing self.

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 MENTITY: SELF

nitc :: MEntity :: MENTITY

FIXME used to bypass RTA limitation on type resolution
type SELF: Object

core :: Object :: SELF

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

nitc :: MType :: _as_nullable_cache

private var _css_classes: Array[String]

nitc :: MEntity :: _css_classes

CSS classes used to decorate self
private var _deprecation: nullable MDeprecationInfo

nitc :: MEntity :: _deprecation

Is the entity deprecated?
private var _examples: Array[MExample]

nitc :: MEntity :: _examples

Examples found for self
private var _html_full_name: String

nitc :: MEntity :: _html_full_name

The MEntity full_name escaped for HTML
private var _html_id: String

nitc :: MEntity :: _html_id

The MEntity unique ID in the HTML output
private var _html_name: String

nitc :: MEntity :: _html_name

The MEntity name escaped for HTML
private var _html_url: String

nitc :: MEntity :: _html_url

The MEntity URL in the HTML output
private var _html_url: String

nitc :: MEntity :: _html_url

private var _is_broken: Bool

nitc :: MEntity :: _is_broken

The indication that the entity did not pass some semantic verifications.
private var _is_fictive: Bool

nitc :: MEntity :: _is_fictive

Is self created for internal purpose?
private var _is_java_primitive: Bool

nitc :: MType :: _is_java_primitive

Is the associated Java type a primitive one?
private var _is_tagged: Bool

nitc :: MType :: _is_tagged

Are values of self tagged?
private var _is_test: Bool

nitc :: MEntity :: _is_test

Is self created for unit testing purpose?
private var _mdoc: nullable MDoc

nitc :: MEntity :: _mdoc

The documentation associated to the entity
private var _mexample: nullable MExample

nitc :: MEntity :: _mexample

Return this entity as a MExample
private var _tag_value: Int

nitc :: MType :: _tag_value

The tag value of the type
protected fun accept_json_serializer(v: JsonSerializer)

serialization :: Serializable :: accept_json_serializer

Refinable service to customize the serialization of this class to JSON
protected fun accept_msgpack_attribute_counter(v: AttributeCounter)

serialization :: Serializable :: accept_msgpack_attribute_counter

Hook to customize the behavior of the AttributeCounter
protected fun accept_msgpack_serializer(v: MsgPackSerializer)

serialization :: Serializable :: accept_msgpack_serializer

Hook to customize the serialization of this class to MessagePack
private fun add_doc_to_infobox(res: HInfoBox)

nitc :: MEntity :: add_doc_to_infobox

Append an entry for the doc in the given infobox
protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)

serialization :: Serializable :: add_to_bundle

Called by []= to dynamically choose the appropriate method according
fun anchor_to(mmodule: MModule, anchor: nullable MClassType): MType

nitc :: MType :: anchor_to

The base class type on which self is based
fun api_url: String

nitc :: MEntity :: api_url

URL to self within the JSON api.
fun as_notnull: MType

nitc :: MType :: as_notnull

Returns the not null version of the type.
fun as_nullable: MType

nitc :: MType :: as_nullable

Return the nullable version of the type
private fun as_nullable_cache: nullable MType

nitc :: MType :: as_nullable_cache

private fun as_nullable_cache=(as_nullable_cache: nullable MType)

nitc :: MType :: as_nullable_cache=

abstract fun c_name: String

nitc :: MEntity :: c_name

A fully-qualified C-like identifier of this model entity.
private fun call_arg_field: String

nitc :: MType :: call_arg_field

Field to store this type in the C structure nit_call_arg
abstract fun can_resolve_for(mtype: MType, anchor: nullable MClassType, mmodule: MModule): Bool

nitc :: MType :: can_resolve_for

Can the type be resolved?
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 cname: String

nitc :: MType :: cname

Representation of this type in pure C on the FFI extern side
fun cname_blind: String

nitc :: MType :: cname_blind

Representation of this type in C for the internal of the system
protected fun cname_normal_class: String

nitc :: MType :: cname_normal_class

Name of this type in C for normal classes (not extern and not primitive)
fun collect_ancestors(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY]

nitc :: MEntity :: collect_ancestors

Collect self ancestors (direct and indirect)
abstract fun collect_children(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY]

nitc :: MEntity :: collect_children

Collect self children (direct descendants)
fun collect_descendants(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY]

nitc :: MEntity :: collect_descendants

Collect self descendants (direct and direct)
fun collect_linearization(mainmodule: MModule): nullable Array[MEntity]

nitc :: MEntity :: collect_linearization

Collect self linearization anchored on mainmodule
abstract fun collect_mclassdefs(mmodule: MModule): Set[MClassDef]

nitc :: MType :: collect_mclassdefs

Compute all the classdefs inherited/imported.
abstract fun collect_mclasses(mmodule: MModule): Set[MClass]

nitc :: MType :: collect_mclasses

Compute all the super-classes.
fun collect_modifiers: Array[String]

nitc :: MEntity :: collect_modifiers

Collect modifier keywords like redef, private etc
abstract fun collect_mtypes(mmodule: MModule): Set[MClassType]

nitc :: MType :: collect_mtypes

Compute all the declared super-types.
abstract fun collect_parents(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY]

nitc :: MEntity :: collect_parents

Collect self parents (direct ancestors)
fun color: String

nitc :: MEntity :: color

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
private fun complete_mdoc: nullable MDoc

nitc :: MEntity :: complete_mdoc

Doc to use in completion
private fun complete_name: String

nitc :: MEntity :: complete_name

Actual name used in completion
protected fun const_color=(const_color: String)

nitc :: MEntity :: const_color=

fun core_serialize_to(serializer: Serializer)

serialization :: Serializable :: core_serialize_to

Actual serialization of self to serializer
abstract fun create_ast_representation(astbuilder: nullable ASTBuilder): ANode

nitc :: MEntity :: create_ast_representation

Build a ANode from self
fun cs_comment(no_color: nullable Bool): nullable String

nitc :: MEntity :: cs_comment

Returns the comment of this MEntity formatted for console.
fun cs_declaration(no_color: nullable Bool): String

nitc :: MEntity :: cs_declaration

Returns the complete MEntity declaration (modifiers + name + signature).
fun cs_full_name(no_color: nullable Bool): String

nitc :: MEntity :: cs_full_name

Returns self.full_name formatted for console
fun cs_icon(no_color: nullable Bool): String

nitc :: MEntity :: cs_icon

Text icon to be displayed in front of the entity
fun cs_list_item(no_color: nullable Bool): String

nitc :: MEntity :: cs_list_item

Returns self as a list element that can be displayed in console.
fun cs_location(no_color: nullable Bool): String

nitc :: MEntity :: cs_location

Source code location of this MEntity formatted for console
fun cs_short_comment(no_color: nullable Bool): nullable String

nitc :: MEntity :: cs_short_comment

Returns the comment of this MEntity formatted for console.
fun cs_signature(no_color: nullable Bool): String

nitc :: MEntity :: cs_signature

Returns self signature formatted for console.
fun cs_source_code: String

nitc :: MEntity :: cs_source_code

Source code associated to this MEntity.
fun css_classes: Array[String]

nitc :: MEntity :: css_classes

CSS classes used to decorate self
protected fun css_classes=(css_classes: Array[String])

nitc :: MEntity :: css_classes=

CSS classes used to decorate self
fun ctype: String

nitc :: MType :: ctype

Return the C type associated to a given Nit static type
fun ctype_extern: String

nitc :: MType :: ctype_extern

C type outside of the compiler code and in boxes
fun ctypename: String

nitc :: MType :: ctypename

Short name of the ctype to use in unions
fun deprecation: nullable MDeprecationInfo

nitc :: MEntity :: deprecation

Is the entity deprecated?
fun deprecation=(deprecation: nullable MDeprecationInfo)

nitc :: MEntity :: deprecation=

Is the entity deprecated?
fun depth: Int

nitc :: MType :: depth

The depth of the type seen as a tree.
fun examples: Array[MExample]

nitc :: MEntity :: examples

Examples found for self
protected fun examples=(examples: Array[MExample])

nitc :: MEntity :: examples=

Examples found for self
init from_deserializer(deserializer: Deserializer)

serialization :: Serializable :: from_deserializer

Create an instance of this class from the deserializer
abstract fun full_name: String

nitc :: MEntity :: full_name

A fully-qualified name of this model entity.
private fun gen_arg_convert(template: Template, arg_name: String)

nitc :: MType :: gen_arg_convert

Write code in template to parse the argument arg_name to this parameter type
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has_mproperty(mmodule: MModule, mproperty: MProperty): Bool

nitc :: MType :: has_mproperty

Is the property in self for a given module
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun hierarchy_poset(mainmodule: MModule, filter: nullable ModelFilter): POSet[MENTITY]

nitc :: MEntity :: hierarchy_poset

Build a poset representing self in it's own hierarchy
private fun href(v: NitlightVisitor): nullable String

nitc :: MEntity :: href

fun html_declaration: Template

nitc :: MEntity :: html_declaration

Returns the complete MEntity declaration decorated with HTML
fun html_full_name: String

nitc :: MEntity :: html_full_name

The MEntity full_name escaped for HTML
protected fun html_full_name=(html_full_name: String)

nitc :: MEntity :: html_full_name=

The MEntity full_name escaped for HTML
fun html_icon: BSIcon

nitc :: MEntity :: html_icon

An icon representative of the mentity
fun html_id: String

nitc :: MEntity :: html_id

The MEntity unique ID in the HTML output
protected fun html_id=(html_id: String)

nitc :: MEntity :: html_id=

The MEntity unique ID in the HTML output
fun html_name: String

nitc :: MEntity :: html_name

The MEntity name escaped for HTML
protected fun html_name=(html_name: String)

nitc :: MEntity :: html_name=

The MEntity name escaped for HTML
abstract fun html_namespace: Template

nitc :: MEntity :: html_namespace

Returns full_name decorated with HTML links
fun html_signature(short: nullable Bool): Template

nitc :: MEntity :: html_signature

Returns the MEntity signature decorated with HTML
fun html_url: String

nitc :: MEntity :: html_url

The MEntity URL in the HTML output
protected fun html_url=(html_url: String)

nitc :: MEntity :: html_url=

The MEntity URL in the HTML output
abstract fun infobox(v: HtmlightVisitor): HInfoBox

nitc :: HInfoBoxable :: infobox

An new infobox documenting the entity
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".
fun is_broken: Bool

nitc :: MEntity :: is_broken

The indication that the entity did not pass some semantic verifications.
fun is_broken=(is_broken: Bool)

nitc :: MEntity :: is_broken=

The indication that the entity did not pass some semantic verifications.
fun is_c_primitive: Bool

nitc :: MType :: is_c_primitive

Is the associated C type a primitive one?
fun is_cprimitive: Bool

nitc :: MType :: is_cprimitive

Does this type have a primitive representation?
fun is_example: Bool

nitc :: MEntity :: is_example

Is self existing for an example purpose?
fun is_fictive: Bool

nitc :: MEntity :: is_fictive

Is self created for internal purpose?
fun is_fictive=(is_fictive: Bool)

nitc :: MEntity :: is_fictive=

Is self created for internal purpose?
fun is_java_primitive: Bool

nitc :: MType :: is_java_primitive

Is the associated Java type a primitive one?
protected fun is_java_primitive=(is_java_primitive: Bool)

nitc :: MType :: is_java_primitive=

Is the associated Java type a primitive one?
fun is_ok: Bool

nitc :: MType :: is_ok

Is the type a MErrorType or contains an MErrorType?
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 is_subtype(mmodule: MModule, anchor: nullable MClassType, sup: MType): Bool

nitc :: MType :: is_subtype

Return true if self is an subtype of sup.
fun is_subtype_invar(mmodule: MModule, anchor: nullable MClassType, sup: MType): Bool

nitc :: MType :: is_subtype_invar

Return true if self is a invariant subtype of sup.
fun is_tagged: Bool

nitc :: MType :: is_tagged

Are values of self tagged?
protected fun is_tagged=(is_tagged: Bool)

nitc :: MType :: is_tagged=

Are values of self tagged?
fun is_test: Bool

nitc :: MEntity :: is_test

Is self created for unit testing purpose?
fun is_test=(is_test: Bool)

nitc :: MEntity :: is_test=

Is self created for unit testing purpose?
private fun java_is_nit_object: Bool

nitc :: MType :: java_is_nit_object

Is this type opaque in Java? As so it is represented by nit.app.NitObject.
private fun java_type: String

nitc :: MType :: java_type

Type name in Java
fun java_type: String

nitc :: MType :: java_type

Return the Java type associated to a given Nit static type
private fun jname: String

nitc :: MEntity :: jname

A Java compatible name for self
private fun jni_format: String

nitc :: MType :: jni_format

JNI short type name (for signatures)
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 fun jni_signature_alt: String

nitc :: MType :: jni_signature_alt

Type name appearing within JNI function names.
private fun jni_type: String

nitc :: MType :: jni_type

JNI type name (in C)
abstract fun json_namespace: JsonNamespace

nitc :: MEntity :: json_namespace

Return self.full_name as an object that can be serialized to json.
fun length: Int

nitc :: MType :: length

The length of the type seen as a tree.
fun linkto(v: HtmlightVisitor): HTMLTag

nitc :: MEntity :: linkto

A HTML version of to_s with hyper-links.
fun linkto_text(v: HtmlightVisitor, text: String): HTMLTag

nitc :: MEntity :: linkto_text

Link to the self with a specific text.
fun location: Location

nitc :: MEntity :: location

The origin of the definition.
fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType

nitc :: MType :: lookup_bound

Resolve formal type to its verbatim bound.
fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType

nitc :: MType :: lookup_fixed

Resolve the formal type to its simplest equivalent form.
private fun make_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode

nitc :: MEntity :: make_node

Make a new NeoNode based on mentity.
abstract fun mangled_cname: String

nitc :: MType :: mangled_cname

Representation of this type in mangled C
fun mdoc: nullable MDoc

nitc :: MEntity :: mdoc

The documentation associated to the entity
fun mdoc=(mdoc: nullable MDoc)

nitc :: MEntity :: mdoc=

The documentation associated to the entity
fun mdoc_or_fallback: nullable MDoc

nitc :: MEntity :: mdoc_or_fallback

The documentation associated to the entity or their main nested entity.
private fun mentity_kind_rank: Int

nitc :: MEntity :: mentity_kind_rank

Compare MEntity class kind
fun mexample: nullable MExample

nitc :: MEntity :: mexample

Return this entity as a MExample
protected fun mexample=(mexample: nullable MExample)

nitc :: MEntity :: mexample=

Return this entity as a MExample
abstract fun model: Model

nitc :: MEntity :: model

A Model Entity has a direct link to its model
protected fun msgpack_extra_array_items: Int

serialization :: Serializable :: msgpack_extra_array_items

Hook to request a larger than usual metadata array
abstract fun name: String

nitc :: MEntity :: name

The short (unqualified) name of this model entity.
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
fun need_anchor: Bool

nitc :: MType :: need_anchor

Does self contain a virtual type or a formal generic parameter type?
private fun needs_type_check: Bool

nitc :: MType :: needs_type_check

Does this parameter type needs to be checked before calling the method?
abstract fun nitdoc_breadcrumbs: Array[MEntity]

nitc :: MEntity :: nitdoc_breadcrumbs

MEntities composing the breadcrumbs of a nitdoc page
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 ratings(config: NitwebConfig, user: nullable String): JsonObject

nitc :: MEntity :: ratings

Get the ratings of a mentity
fun ratings_by_dimension(config: NitwebConfig, dimension: String, user: nullable String): JsonObject

nitc :: MEntity :: ratings_by_dimension

Get the ratings of a dimension
private abstract fun related_mclasses(mmodule: MModule): Array[MClass]

nitc :: MType :: related_mclasses

List classes composing this type
abstract fun resolve_for(mtype: MType, anchor: nullable MClassType, mmodule: MModule, cleanup_virtual: Bool): MType

nitc :: MType :: resolve_for

Replace formals generic types in self with resolved values in mtype
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun serialize_msgpack(plain: nullable Bool): Bytes

serialization :: Serializable :: serialize_msgpack

Serialize self to MessagePack bytes
fun serialize_to(serializer: Serializer)

serialization :: Serializable :: serialize_to

Serialize self to serializer
fun serialize_to_json(plain: nullable Bool, pretty: nullable Bool): String

serialization :: Serializable :: serialize_to_json

Serialize self to JSON
private fun serialize_to_or_delay(v: Serializer)

serialization :: Serializable :: serialize_to_or_delay

Accept references or force direct serialization (using serialize_to)
private fun source_url(url_pattern: nullable String): String

nitc :: MEntity :: source_url

Render a HTML link for the MEntity location
fun supertype_to(mmodule: MModule, anchor: nullable MClassType, super_mclass: MClass): MClassType

nitc :: MType :: supertype_to

Return the supertype when adapted to a class.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun tag_value: Int

nitc :: MType :: tag_value

The tag value of the type
protected fun tag_value=(tag_value: Int)

nitc :: MType :: tag_value=

The tag value of the type
fun to_dot_node: DotNode

nitc :: MEntity :: to_dot_node

Return self as a DotNode
fun to_json: String

serialization :: Serializable :: to_json

Serialize self to plain JSON
fun to_json_ref: MEntityRef

nitc :: MEntity :: to_json_ref

Return a new MEntityRef to self.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

private fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode

nitc :: MEntity :: to_node

Build a NeoNode representing self.
fun to_pretty_json: String

serialization :: Serializable :: to_pretty_json

Serialize self to plain pretty JSON
fun to_s: String

core :: Object :: to_s

User readable representation of self.
abstract fun tpl_class(model: UMLModel): Writable

nitc :: MEntity :: tpl_class

Generates a dot-compatible Writable UML Class diagram from self
abstract fun tpl_module(model: UMLModel): Writable

nitc :: MEntity :: tpl_module

Builds a dot UML package diagram entity from self
fun undecorate: MType

nitc :: MType :: undecorate

Remove the base type of a decorated (proxy) type.
fun visibility: MVisibility

nitc :: MEntity :: visibility

The visibility of the MEntity.
fun visit_all(v: ModelVisitor)

nitc :: MEntity :: visit_all

Call v.enter_visit on all nested entities.
fun web_url: String

nitc :: MEntity :: web_url

URL to self within the web interface.
private fun write_doc(model: Model, mainmodule: MModule, stream: Writer)

nitc :: MEntity :: write_doc

private fun write_extra_doc(model: Model, mainmodule: MModule, stream: Writer)

nitc :: MEntity :: write_extra_doc

Extra auto documentation to append to the stream
private fun write_location(mainmodule: MModule, stream: Writer)

nitc :: MEntity :: write_location

Location (file and line when available) of related declarations
package_diagram nitc::MType MType nitc::MEntity MEntity nitc::MType->nitc::MEntity nitc::NitniCallback NitniCallback nitc::MType->nitc::NitniCallback nitc::HInfoBoxable HInfoBoxable nitc::MEntity->nitc::HInfoBoxable serialization::Serializable Serializable nitc::MEntity->serialization::Serializable core::Object Object nitc::NitniCallback->core::Object ...nitc::HInfoBoxable ... ...nitc::HInfoBoxable->nitc::HInfoBoxable ...serialization::Serializable ... ...serialization::Serializable->serialization::Serializable ...core::Object ... ...core::Object->core::Object nitc::MClassType MClassType nitc::MClassType->nitc::MType nitc::MFormalType MFormalType nitc::MFormalType->nitc::MType nitc::MProxyType MProxyType nitc::MProxyType->nitc::MType nitc::MNullType MNullType nitc::MNullType->nitc::MType nitc::MBottomType MBottomType nitc::MBottomType->nitc::MType nitc::MErrorType MErrorType nitc::MErrorType->nitc::MType nitc::MSignature MSignature nitc::MSignature->nitc::MType nitc::MInitType MInitType nitc::MInitType->nitc::MType nitc::MRawType MRawType nitc::MRawType->nitc::MType nitc::MGenericType MGenericType nitc::MGenericType->nitc::MClassType nitc::MGenericType... ... nitc::MGenericType...->nitc::MGenericType nitc::MVirtualType MVirtualType nitc::MVirtualType->nitc::MFormalType nitc::MParameterType MParameterType nitc::MParameterType->nitc::MFormalType nitc::MVirtualType... ... nitc::MVirtualType...->nitc::MVirtualType nitc::MParameterType... ... nitc::MParameterType...->nitc::MParameterType nitc::MNullableType MNullableType nitc::MNullableType->nitc::MProxyType nitc::MNotNullType MNotNullType nitc::MNotNullType->nitc::MProxyType nitc::MNullableType... ... nitc::MNullableType...->nitc::MNullableType nitc::MNotNullType... ... nitc::MNotNullType...->nitc::MNotNullType

Ancestors

interface HInfoBoxable

nitc :: HInfoBoxable

Model entity or whatever that can produce an infobox
interface Object

core :: Object

The root of the class hierarchy.
interface Serializable

serialization :: Serializable

Instances of this class can be passed to Serializer::serialize

Parents

abstract class MEntity

nitc :: MEntity

A named and possibly documented entity in the model.
interface NitniCallback

nitc :: NitniCallback

Classification for all nitni callbacks

Children

class MBottomType

nitc :: MBottomType

The special universal most specific type.
class MClassType

nitc :: MClassType

A type based on a class.
class MErrorType

nitc :: MErrorType

A special type used as a silent error marker when building types.
abstract class MFormalType

nitc :: MFormalType

A formal type (either virtual of parametric).
class MInitType

nitc :: MInitType

Is the type of the initial value inside attributes
class MNullType

nitc :: MNullType

The type of the only value null
abstract class MProxyType

nitc :: MProxyType

A type that decorates another type.
class MRawType

nitc :: MRawType

A type described by a text annoted with links.
class MSignature

nitc :: MSignature

A signature of a method

Descendants

class MGenericType

nitc :: MGenericType

A type based on a generic class.
class MNotNullType

nitc :: MNotNullType

A non-null version of a formal type.
class MNullableType

nitc :: MNullableType

A type prefixed with "nullable"
class MParameterType

nitc :: MParameterType

The type associated to a formal parameter generic type of a class
class MVirtualType

nitc :: MVirtualType

A virtual formal type.

Class definitions

nitc $ MType
# A global static type
#
# MType are global to the model; it means that a `MType` is not bound to a
# specific `MModule`.
# This characteristic helps the reasoning about static types in a program
# since a single `MType` object always denote the same type.
#
# However, because a `MType` is global, it does not really have properties
# nor have subtypes to a hierarchy since the property and the class hierarchy
# depends of a module.
# Moreover, virtual types an formal generic parameter types also depends on
# a receiver to have sense.
#
# Therefore, most method of the types require a module and an anchor.
# The module is used to know what are the classes and the specialization
# links.
# The anchor is used to know what is the bound of the virtual types and formal
# generic parameter types.
#
# MType are not directly usable to get properties. See the `anchor_to` method
# and the `MClassType` class.
#
# FIXME: the order of the parameters is not the best. We mus pick on from:
#  * foo(mmodule, anchor, othertype)
#  * foo(othertype, anchor, mmodule)
#  * foo(anchor, mmodule, othertype)
#  * foo(othertype, mmodule, anchor)
abstract class MType
	super MEntity

	redef fun name do return to_s

	# Return true if `self` is an subtype of `sup`.
	# The typing is done using the standard typing policy of Nit.
	#
	# REQUIRE: `anchor == null implies not self.need_anchor and not sup.need_anchor`
	# REQUIRE: `anchor != null implies self.can_resolve_for(anchor, null, mmodule) and sup.can_resolve_for(anchor, null, mmodule)`
	fun is_subtype(mmodule: MModule, anchor: nullable MClassType, sup: MType): Bool
	do
		var sub = self
		if sub == sup then return true

		#print "1.is {sub} a {sup}? ===="

		if anchor == null then
			assert not sub.need_anchor
			assert not sup.need_anchor
		else
			# First, resolve the formal types to the simplest equivalent forms in the receiver
			assert sub.can_resolve_for(anchor, null, mmodule)
			sub = sub.lookup_fixed(mmodule, anchor)
			assert sup.can_resolve_for(anchor, null, mmodule)
			sup = sup.lookup_fixed(mmodule, anchor)
		end

		# Does `sup` accept null or not?
		# Discard the nullable marker if it exists
		var sup_accept_null = false
		if sup isa MNullableType then
			sup_accept_null = true
			sup = sup.mtype
		else if sup isa MNotNullType then
			sup = sup.mtype
		else if sup isa MNullType then
			sup_accept_null = true
		end

		# Can `sub` provide null or not?
		# Thus we can match with `sup_accept_null`
		# Also discard the nullable marker if it exists
		var sub_reject_null = false
		if sub isa MNullableType then
			if not sup_accept_null then return false
			sub = sub.mtype
		else if sub isa MNotNullType then
			sub_reject_null = true
			sub = sub.mtype
		else if sub isa MNullType then
			return sup_accept_null
		end
		# Now the case of direct null and nullable is over.

		# If `sub` is a formal type, then it is accepted if its bound is accepted
		while sub isa MFormalType do
			#print "3.is {sub} a {sup}?"

			# A unfixed formal type can only accept itself
			if sub == sup then return true

			assert anchor != null
			sub = sub.lookup_bound(mmodule, anchor)
			if sub_reject_null then sub = sub.as_notnull

			#print "3.is {sub} a {sup}?"

			# Manage the second layer of null/nullable
			if sub isa MNullableType then
				if not sup_accept_null and not sub_reject_null then return false
				sub = sub.mtype
			else if sub isa MNotNullType then
				sub_reject_null = true
				sub = sub.mtype
			else if sub isa MNullType then
				return sup_accept_null
			end
		end
		#print "4.is {sub} a {sup}? <- no more resolution"

		if sub isa MBottomType or sub isa MErrorType then
			return true
		end

		assert sub isa MClassType else print_error "{sub} <? {sup}" # It is the only remaining type

		# Handle sup-type when the sub-type is class-based (other cases must have be identified before).
		if sup isa MFormalType or sup isa MNullType or sup isa MBottomType or sup isa MErrorType then
			# These types are not super-types of Class-based types.
			return false
		end

		assert sup isa MClassType else print_error "got {sup} {sub.inspect}" # It is the only remaining type

		# Now both are MClassType, we need to dig

		if sub == sup then return true

		if anchor == null then anchor = sub # UGLY: any anchor will work
		var resolved_sub = sub.anchor_to(mmodule, anchor)
		var res = resolved_sub.collect_mclasses(mmodule).has(sup.mclass)
		if not res then return false
		if not sup isa MGenericType then return true
		var sub2 = sub.supertype_to(mmodule, anchor, sup.mclass)
		assert sub2.mclass == sup.mclass
		for i in [0..sup.mclass.arity[ do
			var sub_arg = sub2.arguments[i]
			var sup_arg = sup.arguments[i]
			res = sub_arg.is_subtype(mmodule, anchor, sup_arg)
			if not res then return false
		end
		return true
	end

	# The base class type on which self is based
	#
	# This base type is used to get property (an internally to perform
	# unsafe type comparison).
	#
	# Beware: some types (like null) are not based on a class thus this
	# method will crash
	#
	# Basically, this function transform the virtual types and parameter
	# types to their bounds.
	#
	# Example
	#
	#     class A end
	#     class B super A end
	#     class X end
	#     class Y super X end
	#     class G[T: A]
	#       type U: X
	#     end
	#     class H
	#       super G[B]
	#       redef type U: Y
	#     end
	#
	# Map[T,U]  anchor_to  H  #->  Map[B,Y]
	#
	# Explanation of the example:
	# In H, T is set to B, because "H super G[B]", and U is bound to Y,
	# because "redef type U: Y". Therefore, Map[T, U] is bound to
	# Map[B, Y]
	#
	# REQUIRE: `self.need_anchor implies anchor != null`
	# ENSURE: `not self.need_anchor implies result == self`
	# ENSURE: `not result.need_anchor`
	fun anchor_to(mmodule: MModule, anchor: nullable MClassType): MType
	do
		if not need_anchor then return self
		assert anchor != null and not anchor.need_anchor
		# Just resolve to the anchor and clear all the virtual types
		var res = self.resolve_for(anchor, null, mmodule, true)
		assert not res.need_anchor
		return res
	end

	# Does `self` contain a virtual type or a formal generic parameter type?
	# In order to remove those types, you usually want to use `anchor_to`.
	fun need_anchor: Bool do return true

	# Return the supertype when adapted to a class.
	#
	# In Nit, for each super-class of a type, there is a equivalent super-type.
	#
	# Example:
	#
	# ~~~nitish
	#     class G[T, U] end
	#     class H[V] super G[V, Bool] end
	#
	# H[Int]  supertype_to  G  #->  G[Int, Bool]
	# ~~~
	#
	# REQUIRE: `super_mclass` is a super-class of `self`
	# REQUIRE: `self.need_anchor implies anchor != null and self.can_resolve_for(anchor, null, mmodule)`
	# ENSURE: `result.mclass = super_mclass`
	fun supertype_to(mmodule: MModule, anchor: nullable MClassType, super_mclass: MClass): MClassType
	do
		if super_mclass.arity == 0 then return super_mclass.mclass_type
		if self isa MClassType and self.mclass == super_mclass then return self
		var resolved_self
		if self.need_anchor then
			assert anchor != null
			resolved_self = self.anchor_to(mmodule, anchor)
		else
			resolved_self = self
		end
		var supertypes = resolved_self.collect_mtypes(mmodule)
		for supertype in supertypes do
			if supertype.mclass == super_mclass then
				# FIXME: Here, we stop on the first goal. Should we check others and detect inconsistencies?
				return supertype.resolve_for(self, anchor, mmodule, false)
			end
		end
		abort
	end

	# Replace formals generic types in self with resolved values in `mtype`
	# If `cleanup_virtual` is true, then virtual types are also replaced
	# with their bounds.
	#
	# This function returns self if `need_anchor` is false.
	#
	# ## Example 1
	#
	# ~~~
	# class G[E] end
	# class H[F] super G[F] end
	# class X[Z] end
	# ~~~
	#
	#  * Array[E].resolve_for(H[Int])  #->  Array[Int]
	#  * Array[E].resolve_for(G[Z], X[Int]) #->  Array[Z]
	#
	# Explanation of the example:
	#  * Array[E].need_anchor is true because there is a formal generic parameter type E
	#  * E makes sense for H[Int] because E is a formal parameter of G and H specialize G
	#  * Since "H[F] super G[F]", E is in fact F for H
	#  * More specifically, in H[Int], E is Int
	#  * So, in H[Int], Array[E] is Array[Int]
	#
	# This function is mainly used to inherit a signature.
	# Because, unlike `anchor_to`, we do not want a full resolution of
	# a type but only an adapted version of it.
	#
	# ## Example 2
	#
	# ~~~
	# class A[E]
	#     fun foo(e:E):E is abstract
	# end
	# class B super A[Int] end
	# ~~~
	#
	# The signature on foo is (e: E): E
	# If we resolve the signature for B, we get (e:Int):Int
	#
	# ## Example 3
	#
	# ~~~nitish
	# class A[E]
	#     fun foo(e:E):E is abstract
	# end
	# class C[F]
	#     var a: A[Array[F]]
	#     fun bar do a.foo(x) # <- x is here
	# end
	# ~~~
	#
	# The first question is: is foo available on `a`?
	#
	# The static type of a is `A[Array[F]]`, that is an open type.
	# in order to find a method `foo`, whe must look at a resolved type.
	#
	#   A[Array[F]].anchor_to(C[nullable Object])  #->  A[Array[nullable Object]]
	#
	# the method `foo` exists in `A[Array[nullable Object]]`, therefore `foo` exists for `a`.
	#
	# The next question is: what is the accepted types for `x`?
	#
	# the signature of `foo` is `foo(e:E)`, thus we must resolve the type E
	#
	#   E.resolve_for(A[Array[F]],C[nullable Object])  #->  Array[F]
	#
	# The resolution can be done because `E` make sense for the class A (see `can_resolve_for`)
	#
	# FIXME: the parameter `cleanup_virtual` is just a bad idea, but having
	# two function instead of one seems also to be a bad idea.
	#
	# REQUIRE: `can_resolve_for(mtype, anchor, mmodule)`
	# ENSURE: `not self.need_anchor implies result == self`
	fun resolve_for(mtype: MType, anchor: nullable MClassType, mmodule: MModule, cleanup_virtual: Bool): MType is abstract

	# Resolve formal type to its verbatim bound.
	# If the type is not formal, just return self
	#
	# The result is returned exactly as declared in the "type" property (verbatim).
	# So it could be another formal type.
	#
	# In case of conflicts or inconsistencies in the model, the method returns a `MErrorType`.
	fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType do return self

	# Resolve the formal type to its simplest equivalent form.
	#
	# Formal types are either free or fixed.
	# When it is fixed, it means that it is equivalent with a simpler type.
	# When a formal type is free, it means that it is only equivalent with itself.
	# This method return the most simple equivalent type of `self`.
	#
	# This method is mainly used for subtype test in order to sanely compare fixed.
	#
	# By default, return self.
	# See the redefinitions for specific behavior in each kind of type.
	#
	# In case of conflicts or inconsistencies in the model, the method returns a `MErrorType`.
	fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType do return self

	# Is the type a `MErrorType` or contains an `MErrorType`?
	#
	# `MErrorType` are used in result with conflict or inconsistencies.
	#
	# See `is_legal_in` to check conformity with generic bounds.
	fun is_ok: Bool do return true

	# Is the type legal in a given `mmodule` (with an optional `anchor`)?
	#
	# A type is valid if:
	#
	# * it does not contain a `MErrorType` (see `is_ok`).
	# * its generic formal arguments are within their bounds.
	fun is_legal_in(mmodule: MModule, anchor: nullable MClassType): Bool do return is_ok

	# Can the type be resolved?
	#
	# In order to resolve open types, the formal types must make sence.
	#
	# ## Example
	#
	#     class A[E]
	#     end
	#     class B[F]
	#     end
	#
	# ~~~nitish
	# E.can_resolve_for(A[Int])  #->  true, E make sense in A
	#
	# E.can_resolve_for(B[Int])  #->  false, E does not make sense in B
	#
	# B[E].can_resolve_for(A[F], B[Object])  #->  true,
	# # B[E] is a red hearing only the E is important,
	# # E make sense in A
	# ~~~
	#
	# REQUIRE: `anchor != null implies not anchor.need_anchor`
	# REQUIRE: `mtype.need_anchor implies anchor != null and mtype.can_resolve_for(anchor, null, mmodule)`
	# ENSURE: `not self.need_anchor implies result == true`
	fun can_resolve_for(mtype: MType, anchor: nullable MClassType, mmodule: MModule): Bool is abstract

	# Return the nullable version of the type
	# If the type is already nullable then self is returned
	fun as_nullable: MType
	do
		var res = self.as_nullable_cache
		if res != null then return res
		res = new MNullableType(self)
		self.as_nullable_cache = res
		return res
	end

	# Remove the base type of a decorated (proxy) type.
	# Is the type is not decorated, then self is returned.
	#
	# Most of the time it is used to return the not nullable version of a nullable type.
	# In this case, this just remove the `nullable` notation, but the result can still contains null.
	# For instance if `self isa MNullType` or self is a formal type bounded by a nullable type.
	# If you really want to exclude the `null` value, then use `as_notnull`
	fun undecorate: MType
	do
		return self
	end

	# Returns the not null version of the type.
	# That is `self` minus the `null` value.
	#
	# For most types, this return `self`.
	# For formal types, this returns a special `MNotNullType`
	fun as_notnull: MType do return self

	private var as_nullable_cache: nullable MType = null


	# The depth of the type seen as a tree.
	#
	# * A -> 1
	# * G[A] -> 2
	# * H[A, B] -> 2
	# * H[G[A], B] -> 3
	#
	# Formal types have a depth of 1.
	# Only `MClassType` and `MFormalType` nodes are counted.
	fun depth: Int
	do
		return 1
	end

	# The length of the type seen as a tree.
	#
	# * A -> 1
	# * G[A] -> 2
	# * H[A, B] -> 3
	# * H[G[A], B] -> 4
	#
	# Formal types have a length of 1.
	# Only `MClassType` and `MFormalType` nodes are counted.
	fun length: Int
	do
		return 1
	end

	# Compute all the classdefs inherited/imported.
	# The returned set contains:
	#  * the class definitions from `mmodule` and its imported modules
	#  * the class definitions of this type and its super-types
	#
	# This function is used mainly internally.
	#
	# REQUIRE: `not self.need_anchor`
	fun collect_mclassdefs(mmodule: MModule): Set[MClassDef] is abstract

	# Compute all the super-classes.
	# This function is used mainly internally.
	#
	# REQUIRE: `not self.need_anchor`
	fun collect_mclasses(mmodule: MModule): Set[MClass] is abstract

	# Compute all the declared super-types.
	# Super-types are returned as declared in the classdefs (verbatim).
	# This function is used mainly internally.
	#
	# REQUIRE: `not self.need_anchor`
	fun collect_mtypes(mmodule: MModule): Set[MClassType] is abstract

	# Is the property in self for a given module
	# This method does not filter visibility or whatever
	#
	# REQUIRE: `not self.need_anchor`
	fun has_mproperty(mmodule: MModule, mproperty: MProperty): Bool
	do
		assert not self.need_anchor
		return self.collect_mclassdefs(mmodule).has(mproperty.intro_mclassdef)
	end
end
src/model/model.nit:822,1--1284,3

nitc :: nitni_base $ MType
redef class MType
	# Representation of this type in pure C on the FFI extern side
	#   Object -> Object
	#   Pointer -> void*
	fun cname: String do return cname_normal_class

	# Representation of this type in C for the internal of the system
	# Hides extern types.
	fun cname_blind: String do return "struct nitni_instance *"

	# Representation of this type in mangled C
	#   Object -> Object
	#   Pointer -> Pointer
	fun mangled_cname: String is abstract

	# Does this type have a primitive representation?
	#
	#   type Object is_primitive? false
	#   type Pointer is_primitive? true
	fun is_cprimitive: Bool do return false

	# Name of this type in C for normal classes (not extern and not primitive)
	protected fun cname_normal_class: String do return mangled_cname
end
src/nitni/nitni_base.nit:66,1--89,3

nitc :: detect_covariance $ MType
redef class MType
	# Return true if `self` is a invariant subtype of `sup`.
	# This is just a copy of the original `is_subtype` method with only two new lines
	fun is_subtype_invar(mmodule: MModule, anchor: nullable MClassType, sup: MType): Bool
	do
		var sub = self
		if sub == sup then return true

		#print "1.is {sub} a {sup}? ===="

		if anchor == null then
			assert not sub.need_anchor
			assert not sup.need_anchor
		else
			# First, resolve the formal types to the simplest equivalent forms in the receiver
			assert sub.can_resolve_for(anchor, null, mmodule)
			sub = sub.lookup_fixed(mmodule, anchor)
			assert sup.can_resolve_for(anchor, null, mmodule)
			sup = sup.lookup_fixed(mmodule, anchor)
		end

		# Does `sup` accept null or not?
		# Discard the nullable marker if it exists
		var sup_accept_null = false
		if sup isa MNullableType then
			sup_accept_null = true
			sup = sup.mtype
		else if sup isa MNullType then
			sup_accept_null = true
		end

		# Can `sub` provide null or not?
		# Thus we can match with `sup_accept_null`
		# Also discard the nullable marker if it exists
		if sub isa MNullableType then
			if not sup_accept_null then return false
			sub = sub.mtype
		else if sub isa MNullType then
			return sup_accept_null
		end
		# Now the case of direct null and nullable is over.

		# If `sub` is a formal type, then it is accepted if its bound is accepted
		while sub isa MFormalType do
			#print "3.is {sub} a {sup}?"

			# A unfixed formal type can only accept itself
			if sub == sup then return true

			assert anchor != null
			sub = sub.lookup_bound(mmodule, anchor)

			#print "3.is {sub} a {sup}?"

			# Manage the second layer of null/nullable
			if sub isa MNullableType then
				if not sup_accept_null then return false
				sub = sub.mtype
			else if sub isa MNullType then
				return sup_accept_null
			end
		end
		#print "4.is {sub} a {sup}? <- no more resolution"

		if sub isa MBottomType or sub isa MErrorType then
			return true
		end

		assert sub isa MClassType else print_error "{sub} <? {sup}" # It is the only remaining type

		# Handle sup-type when the sub-type is class-based (other cases must have be identified before).
		if sup isa MFormalType or sup isa MNullType or sup isa MBottomType or sup isa MErrorType then
			# These types are not super-types of Class-based types.
			return false
		end

		assert sup isa MClassType else print_error "got {sup} {sub.inspect}" # It is the only remaining type

		# Now both are MClassType, we need to dig

		if sub == sup then return true

		if anchor == null then anchor = sub # UGLY: any anchor will work
		var resolved_sub = sub.anchor_to(mmodule, anchor)
		var res = resolved_sub.collect_mclasses(mmodule).has(sup.mclass)
		if not res then return false
		if not sup isa MGenericType then return true
		var sub2 = sub.supertype_to(mmodule, anchor, sup.mclass)
		assert sub2.mclass == sup.mclass
		for i in [0..sup.mclass.arity[ do
			var sub_arg = sub2.arguments[i]
			var sup_arg = sup.arguments[i]
			res = sub_arg.is_subtype(mmodule, anchor, sup_arg)
			if not res then return false
			# The two new lines
			res = sup_arg.is_subtype(mmodule, anchor, sub_arg)
			if not res then return false
			# End of the two new lines
		end
		return true
	end
end
src/metrics/detect_covariance.nit:412,1--513,3

nitc :: neo $ MType
redef class MType
	redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do
		if nodes.has_key(self) then return nodes[self]
		var node = make_node(nodes, model_name)
		node.labels.add "MType"
		return node
	end
end
src/neo.nit:978,1--985,3

nitc :: astbuilder $ MType
redef class MType
	redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AType do
		return new AType.make(self)
	end
end
src/astbuilder.nit:1043,1--1047,3

nitc :: nitni_callbacks $ MType
redef class MType
	super NitniCallback
end
src/nitni/nitni_callbacks.nit:160,1--162,3

nitc :: rta_metrics $ MType
redef class MType
	private fun signature_depth: Int do
		var mtype = self.undecorate
		if not mtype isa MGenericType then return 0

		var depth = 0
		for ft in mtype.arguments do
			var ftd = ft.signature_depth
			if ftd > depth then depth = ftd
		end
		return depth + 1
	end
end
src/metrics/rta_metrics.nit:389,1--401,3

nitc :: nitrestful $ MType
redef class MType
	# Write code in `template` to parse the argument `arg_name` to this parameter type
	private fun gen_arg_convert(template: Template, arg_name: String)
	do
		if self.name == "String" or self.name == "nullable String" then
			# String are used as is
			template.add """
			var out_{{{arg_name}}} = in_{{{arg_name}}}
"""
		else
			# Deserialize everything else
			template.add """
			var out_{{{arg_name}}} = deserialize_arg(in_{{{arg_name}}}, "{{{self.name}}}")
"""
		end
	end

	# Does this parameter type needs to be checked before calling the method?
	#
	# Some nullable types do not need to be check as `null` values are acceptable.
	private fun needs_type_check: Bool do return true
end
src/nitrestful.nit:122,1--143,3

nitc :: nitserial $ MType
redef class MType
	# List classes composing this type
	private fun related_mclasses(mmodule: MModule): Array[MClass] is abstract
end
src/nitserial.nit:59,1--62,3

nitc :: java_compiler $ MType
redef class MType
	# Return the Java type associated to a given Nit static type
	fun java_type: String do return "RTVal"

	# Is the associated Java type a primitive one?
	#
	# ENSURE `result == (java_type != "RTVal")`
	var is_java_primitive: Bool is lazy do return java_type != "RTVal"
end
src/compiler/java_compiler.nit:1298,1--1306,3

nitc :: java $ MType
redef class MType

	# Type name in Java
	#
	# * Primitives common to both languages use their Java primitive type
	# * Nit extern Java classes are represented by their full Java type
	# * Other Nit objects are represented by `NitObject` in Java, a class
	#   encapsulating the pointer to the underlying C structure.
	private fun java_type: String do return "nit.app.NitObject"

	# Is this type opaque in Java? As so it is represented by `nit.app.NitObject`.
	private fun java_is_nit_object: Bool do return true

	# JNI type name (in C)
	#
	# So this is a C type, usually defined in `jni.h`
	private fun jni_type: String do return "jobject"

	# JNI short type name (for signatures)
	#
	# Is used by `MMethod::build_jni_format` to pass a Java method signature
	# to the JNI function `GetStaticMetodId`.
	private fun jni_format: String do return "Lnit/app/NitObject;"

	# Type name appearing within JNI function names.
	#
	# Used by `JavaLanguage::compile_extern_method` when calling JNI's `CallStatic*Method`.
	# This strategy is used by JNI to type the return of callbacks to Java.
	private fun jni_signature_alt: String do return "Int"

	redef fun compile_callback_to_java(mmodule, mainmodule, ccu)
	do
		if self isa MClassType and mclass.ftype isa ForeignJavaType then return

		var java_file = mmodule.java_file
		if java_file == null or mmodule.callbacks_used_from_java.callbacks.is_empty then return

		for variation in ["incr", "decr"] do
			var friendly_name = "{mangled_cname}_{variation}_ref"

			# C
			var csignature = "void {mmodule.impl_java_class_name}_{friendly_name}(JNIEnv *nit_ffi_jni_env, jclass clazz, jobject object)"
			var cf = new CFunction("JNIEXPORT {csignature}")
			cf.exprs.add "\tnitni_global_ref_{variation}(nit_ffi_with_java_nit_object_data(nit_ffi_jni_env, object));"
			ccu.add_non_static_local_function cf

			# Java
			java_file.class_content.add "private native static void {friendly_name}(nit.app.NitObject object);\n"
		end
	end

	redef fun jni_methods_declaration(from_mmodule)
	do
		var arr = new Array[String]
		for variation in ["incr", "decr"] do
			var friendly_name = "{mangled_cname}_{variation}_ref"
			var jni_format = "(Lnit/app/NitObject;)V"
			var cname = "{from_mmodule.impl_java_class_name}_{friendly_name}"
			arr.add """{"{{{friendly_name}}}", "{{{jni_format}}}", {{{cname}}}}"""
		end

		return arr
	end
end
src/ffi/java.nit:545,1--608,3

nitc :: abstract_compiler $ MType
redef class MType
	# Return the C type associated to a given Nit static type
	fun ctype: String do return "val*"

	# C type outside of the compiler code and in boxes
	fun ctype_extern: String do return "val*"

	# Short name of the `ctype` to use in unions
	fun ctypename: String do return "val"

	# Is the associated C type a primitive one?
	#
	# ENSURE `result == (ctype != "val*")`
	fun is_c_primitive: Bool do return false
end
src/compiler/abstract_compiler.nit:2433,1--2447,3

nitc :: html_model $ MType
redef class MType
	redef fun html_signature(short) do return html_link
end
src/doc/templates/html_model.nit:275,1--277,3

nitc :: separate_compiler $ MType
redef class MType
	# Are values of `self` tagged?
	# If false, it means that the type is not primitive, or is boxed.
	var is_tagged = false

	# The tag value of the type
	#
	# ENSURE `is_tagged == (tag_value > 0)`
	# ENSURE `not is_tagged == (tag_value == 0)`
	var tag_value = 0
end
src/compiler/separate_compiler.nit:2630,1--2640,3

nitc :: on_demand_compiler $ MType
redef class MType
	# The interpreter FFI use `void*` to represent intern data types
	redef fun cname_blind do return "void*"

	# Field to store this type in the C structure `nit_call_arg`
	private fun call_arg_field: String do return "value_Pointer"
end
src/interpreter/dynamic_loading_ffi/on_demand_compiler.nit:377,1--383,3

nitc :: json_model $ MType
redef class MType
	redef fun core_serialize_to(v) do
		v.serialize_attribute("name", name)

		var mdoc = mdoc_or_fallback
		if mdoc != null then
			v.serialize_attribute("synopsis", mdoc.synopsis)
			v.serialize_attribute("html_synopsis", mdoc.html_synopsis.write_to_string)
		end
	end
end
src/doc/templates/json_model.nit:304,1--314,3

nitc :: api_base $ MType
redef class MType
	redef fun core_serialize_to(v) do
		super
		v.serialize_attribute("web_url", web_url)
		v.serialize_attribute("api_url", api_url)
	end
end
src/doc/api/api_base.nit:201,1--207,3