Each parameter type is associated to a specific class. It means that all refinements of a same class "share" the parameter type, but that a generic subclass has its own parameter types.
However, in the sense of the meta-model, a parameter type of a class is a valid type in a subclass. The "in the sense of the meta-model" is important because, in the Nit language, the programmer cannot refers directly to the parameter types of the super-classes.
Example:
class A[E]
fun e: E is abstract
end
class B[F]
super A[Array[F]]
end
In the class definition B[F], F
is a valid type but E
is not.
However, self.e
is a valid method call, and the signature of e
is
declared e: E
.
Note that parameter types are shared among class refinements.
Therefore parameter only have an internal name (see to_s
for details).
nitc :: MParameterType :: _api_url
nitc :: MParameterType :: _c_name
nitc :: MParameterType :: _full_name
nitc :: MParameterType :: _mclass
The generic class where the parameter belongnitc :: MParameterType :: _name
nitc :: MParameterType :: _rank
The position of the parameter (0 for the first parameter)nitc :: MParameterType :: _web_url
nitc :: MParameterType :: api_url=
nitc :: MParameterType :: c_name=
nitc :: MParameterType :: defaultinit
nitc :: MParameterType :: full_name=
nitc :: MParameterType :: mclass=
The generic class where the parameter belongnitc :: MParameterType :: name=
nitc :: MParameterType :: rank
The position of the parameter (0 for the first parameter)nitc :: MParameterType :: rank=
The position of the parameter (0 for the first parameter)nitc :: MParameterType :: web_url=
nitc $ MParameterType :: SELF
Type of this instance, automatically specialized in every classnitc $ MParameterType :: c_name
A fully-qualified C-like identifier of this model entity.nitc $ MParameterType :: can_resolve_for
Can the type be resolved?nitc :: json_model $ MParameterType :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: astbuilder $ MParameterType :: create_ast_representation
Build a ANode fromself
nitc :: term_model $ MParameterType :: cs_signature
Returnsself
signature formatted for console.
nitc $ MParameterType :: full_name
A fully-qualified name of this model entity.nitc :: html_model $ MParameterType :: html_link
Link to the MEntity in the HTML outputnitc :: htmlight $ MParameterType :: infobox
An new infobox documenting the entitynitc $ MParameterType :: lookup_bound
Resolve formal type to its verbatim bound.nitc $ MParameterType :: lookup_fixed
A PT is fixed when:nitc $ MParameterType :: name
The short (unqualified) name of this model entity.nitc $ MParameterType :: resolve_for
Replace formals generic types in self with resolved values inmtype
nitc :: MParameterType :: _api_url
nitc :: MFormalType :: _as_notnull
nitc :: MType :: _as_nullable_cache
nitc :: MParameterType :: _c_name
nitc :: MEntity :: _const_color
nitc :: MEntity :: _css_classes
CSS classes used to decorateself
nitc :: MEntity :: _deprecation
Is the entity deprecated?nitc :: MParameterType :: _full_name
nitc :: MEntity :: _html_full_name
The MEntityfull_name
escaped for HTML
nitc :: MEntity :: _is_broken
The indication that the entity did not pass some semantic verifications.nitc :: MType :: _is_java_primitive
Is the associated Java type a primitive one?nitc :: MParameterType :: _mclass
The generic class where the parameter belongnitc :: MParameterType :: _name
nitc :: MParameterType :: _rank
The position of the parameter (0 for the first parameter)nitc :: MParameterType :: _web_url
serialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePacknitc :: MEntity :: add_doc_to_infobox
Append an entry for the doc in the given infoboxserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
nitc :: MParameterType :: api_url=
nitc :: MFormalType :: as_notnull=
nitc :: MType :: as_nullable_cache
nitc :: MType :: as_nullable_cache=
nitc :: MParameterType :: c_name=
nitc :: MType :: call_arg_field
Field to store this type in the C structurenit_call_arg
nitc :: MType :: can_resolve_for
Can the type be resolved?core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: MType :: cname_blind
Representation of this type in C for the internal of the systemnitc :: MType :: cname_normal_class
Name of this type in C for normal classes (not extern and not primitive)nitc :: MEntity :: collect_ancestors
Collectself
ancestors (direct and indirect)
nitc :: MEntity :: collect_children
Collectself
children (direct descendants)
nitc :: MEntity :: collect_descendants
Collectself
descendants (direct and direct)
nitc :: MEntity :: collect_linearization
Collectself
linearization anchored on mainmodule
nitc :: MType :: collect_mclassdefs
Compute all the classdefs inherited/imported.nitc :: MType :: collect_mclasses
Compute all the super-classes.nitc :: MEntity :: collect_metrics
nitc :: MEntity :: collect_modifiers
Collect modifier keywords likeredef
, private
etc
nitc :: MType :: collect_mtypes
Compute all the declared super-types.nitc :: MEntity :: collect_parents
Collectself
parents (direct ancestors)
nitc :: NitniCallback :: compile_callback_to_java
Compile C and Java code to implement this callbacknitc :: NitniCallback :: compile_callback_to_objc
Compile this callback to be callable from Objective-Cnitc :: MType :: compile_extern_type
nitc :: MEntity :: const_color
nitc :: MEntity :: const_color=
nitc :: MEntity :: core_serialize_base
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: MEntity :: create_ast_representation
Build a ANode fromself
nitc :: MEntity :: cs_comment
Returns the comment of this MEntity formatted for console.nitc :: MEntity :: cs_declaration
Returns the complete MEntity declaration (modifiers + name + signature).nitc :: MEntity :: cs_full_name
Returnsself.full_name
formatted for console
nitc :: MEntity :: cs_list_item
Returnsself
as a list element that can be displayed in console.
nitc :: MEntity :: cs_location
Source code location of this MEntity formatted for consolenitc :: MEntity :: cs_short_comment
Returns the comment of this MEntity formatted for console.nitc :: MEntity :: cs_signature
Returnsself
signature formatted for console.
nitc :: MEntity :: cs_source_code
Source code associated to this MEntity.nitc :: MEntity :: css_classes=
CSS classes used to decorateself
nitc :: MType :: ctype_extern
C type outside of the compiler code and in boxesnitc :: HInfoBoxable :: defaultinit
nitc :: MFormalType :: defaultinit
nitc :: NitniCallback :: defaultinit
nitc :: MParameterType :: defaultinit
nitc :: MType :: defaultinit
core :: Object :: defaultinit
nitc :: MEntity :: defaultinit
nitc :: MEntity :: deprecation=
Is the entity deprecated?nitc :: MEntity :: field_separator
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
nitc :: MParameterType :: full_name=
nitc :: MType :: gen_arg_convert
Write code intemplate
to parse the argument arg_name
to this parameter type
nitc :: MType :: has_mproperty
Is the property in self for a given modulenitc :: MEntity :: hierarchy_poset
Build a poset representingself
in it's own hierarchy
nitc :: MEntity :: html_declaration
Returns the complete MEntity declaration decorated with HTMLnitc :: MEntity :: html_full_name=
The MEntityfull_name
escaped for HTML
nitc :: MEntity :: html_name=
The MEntity name escaped for HTMLnitc :: MEntity :: html_namespace
Returnsfull_name
decorated with HTML links
nitc :: MEntity :: html_signature
Returns the MEntity signature decorated with HTMLnitc :: HInfoBoxable :: infobox
An new infobox documenting the entitynitc :: MEntity :: is_broken=
The indication that the entity did not pass some semantic verifications.nitc :: MType :: is_cprimitive
Does this type have a primitive representation?nitc :: MEntity :: is_fictive=
Isself
created for internal purpose?
nitc :: MType :: is_java_primitive
Is the associated Java type a primitive one?nitc :: MType :: is_java_primitive=
Is the associated Java type a primitive one?nitc :: MType :: is_legal_in
Is the type legal in a givenmmodule
(with an optional anchor
)?
core :: 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.
nitc :: MType :: is_subtype
Return true ifself
is an subtype of sup
.
nitc :: MType :: is_subtype_invar
Return true ifself
is a invariant subtype of sup
.
nitc :: MType :: java_is_nit_object
Is this type opaque in Java? As so it is represented bynit.app.NitObject
.
nitc :: NitniCallback :: jni_methods_declaration
Returns the list of C functions to link with extern Java methods, as requirednitc :: MType :: jni_signature_alt
Type name appearing within JNI function names.nitc :: MEntity :: json_namespace
Returnself.full_name
as an object that can be serialized to json.
nitc :: MEntity :: line_separator
nitc :: MEntity :: linkto_text
Link to theself
with a specific text.
nitc :: MType :: lookup_bound
Resolve formal type to its verbatim bound.nitc :: MType :: lookup_fixed
Resolve the formal type to its simplest equivalent form.nitc :: MType :: mangled_cname
Representation of this type in mangled Cnitc :: MParameterType :: mclass=
The generic class where the parameter belongnitc :: MEntity :: mdoc_or_fallback
The documentation associated to the entity or their main nested entity.serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraynitc :: MParameterType :: name=
core :: Object :: native_class_name
The class name of the object in CString format.nitc :: MType :: need_anchor
Doesself
contain a virtual type or a formal generic parameter type?
nitc :: MType :: needs_type_check
Does this parameter type needs to be checked before calling the method?core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: MParameterType :: rank
The position of the parameter (0 for the first parameter)nitc :: MParameterType :: rank=
The position of the parameter (0 for the first parameter)mentity
nitc :: MEntity :: ratings_by_dimension
Get the ratings of adimension
nitc :: MType :: resolve_for
Replace formals generic types in self with resolved values inmtype
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
nitc :: MType :: signature_depth
nitc :: MEntity :: source_url
Render a HTML link for the MEntity locationnitc :: MType :: supertype_to
Return the supertype when adapted to a class.serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
nitc :: MEntity :: tpl_module
Builds a dot UML package diagram entity fromself
v.enter_visit
on all nested entities.
nitc :: MParameterType :: web_url=
nitc :: MEntity :: write_extra_doc
Extra auto documentation to append to thestream
nitc :: MEntity :: write_location
Location (file and line when available) of related declarations
# The type associated to a formal parameter generic type of a class
#
# Each parameter type is associated to a specific class.
# It means that all refinements of a same class "share" the parameter type,
# but that a generic subclass has its own parameter types.
#
# However, in the sense of the meta-model, a parameter type of a class is
# a valid type in a subclass. The "in the sense of the meta-model" is
# important because, in the Nit language, the programmer cannot refers
# directly to the parameter types of the super-classes.
#
# Example:
#
# class A[E]
# fun e: E is abstract
# end
# class B[F]
# super A[Array[F]]
# end
#
# In the class definition B[F], `F` is a valid type but `E` is not.
# However, `self.e` is a valid method call, and the signature of `e` is
# declared `e: E`.
#
# Note that parameter types are shared among class refinements.
# Therefore parameter only have an internal name (see `to_s` for details).
class MParameterType
super MFormalType
# The generic class where the parameter belong
var mclass: MClass
redef fun model do return self.mclass.intro_mmodule.model
redef fun location do return mclass.location
# The position of the parameter (0 for the first parameter)
# FIXME: is `position` a better name?
var rank: Int
redef var name
redef fun to_s do return name
redef var full_name is lazy do return "{mclass.full_name}::{name}"
redef var c_name is lazy do return mclass.c_name + "__" + "#{name}".to_cmangle
redef fun lookup_bound(mmodule: MModule, resolved_receiver: MType): MType
do
assert not resolved_receiver.need_anchor
resolved_receiver = resolved_receiver.undecorate
assert resolved_receiver isa MClassType # It is the only remaining type
var goalclass = self.mclass
if resolved_receiver.mclass == goalclass then
return resolved_receiver.arguments[self.rank]
end
var supertypes = resolved_receiver.collect_mtypes(mmodule)
for t in supertypes do
if t.mclass == goalclass then
# Yeah! c specialize goalclass with a "super `t'". So the question is what is the argument of f
# FIXME: Here, we stop on the first goal. Should we check others and detect inconsistencies?
var res = t.arguments[self.rank]
return res
end
end
# Cannot found `self` in `resolved_receiver`
return new MErrorType(model)
end
# A PT is fixed when:
# * The `resolved_receiver` is a subclass of `self.mclass`,
# so it is necessarily fixed in a `super` clause, either with a normal type
# or with another PT.
# See `resolve_for` for examples about related issues.
redef fun lookup_fixed(mmodule: MModule, resolved_receiver: MType): MType
do
assert not resolved_receiver.need_anchor
resolved_receiver = resolved_receiver.undecorate
assert resolved_receiver isa MClassType # It is the only remaining type
var res = self.resolve_for(resolved_receiver.mclass.mclass_type, resolved_receiver, mmodule, false)
return res
end
redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual)
do
assert can_resolve_for(mtype, anchor, mmodule)
#print "{class_name}: {self}/{mtype}/{anchor}?"
if mtype isa MGenericType and mtype.mclass == self.mclass then
return mtype.arguments[self.rank]
end
# self is a parameter type of mtype (or of a super-class of mtype)
# The point of the function it to get the bound of the virtual type that make sense for mtype
# But because mtype is maybe a virtual/formal type, we need to get a real receiver first
# FIXME: What happens here is far from clear. Thus this part must be validated and clarified
var resolved_receiver
if mtype.need_anchor then
assert anchor != null
resolved_receiver = mtype.resolve_for(anchor.mclass.mclass_type, anchor, mmodule, true)
else
resolved_receiver = mtype
end
if resolved_receiver isa MNullableType then resolved_receiver = resolved_receiver.mtype
if resolved_receiver isa MParameterType then
assert anchor != null
assert resolved_receiver.mclass == anchor.mclass
resolved_receiver = anchor.arguments[resolved_receiver.rank]
if resolved_receiver isa MNullableType then resolved_receiver = resolved_receiver.mtype
end
assert resolved_receiver isa MClassType # It is the only remaining type
# Eh! The parameter is in the current class.
# So we return the corresponding argument, no mater what!
if resolved_receiver.mclass == self.mclass then
var res = resolved_receiver.arguments[self.rank]
#print "{class_name}: {self}/{mtype}/{anchor} -> direct {res}"
return res
end
if resolved_receiver.need_anchor then
assert anchor != null
resolved_receiver = resolved_receiver.resolve_for(anchor, null, mmodule, false)
end
# Now, we can get the bound
var verbatim_bound = lookup_bound(mmodule, resolved_receiver)
# The bound is exactly as declared in the "type" property, so we must resolve it again
var res = verbatim_bound.resolve_for(mtype, anchor, mmodule, cleanup_virtual)
#print "{class_name}: {self}/{mtype}/{anchor} -> indirect {res}"
return res
end
redef fun can_resolve_for(mtype, anchor, mmodule)
do
if mtype.need_anchor then
assert anchor != null
mtype = mtype.anchor_to(mmodule, anchor)
end
return mtype.collect_mclassdefs(mmodule).has(mclass.intro)
end
end
src/model/model.nit:1625,1--1768,3
redef class MParameterType
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 = super
node.labels.add "MParameterType"
node["rank"] = rank
node.out_edges.add(new NeoEdge(node, "CLASS", mclass.to_node(nodes, model_name)))
return node
end
end
src/neo.nit:913,1--922,3
redef class MParameterType
redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AFormaldef do
var n_type = super
return new AFormaldef.make(self, n_type)
end
end
src/astbuilder.nit:1025,1--1030,3
redef class MParameterType
redef fun cs_signature(no_color) do return name
end
src/doc/templates/term_model.nit:244,1--246,3
redef class MParameterType
redef fun tpl_class(model) do
return name
end
end
src/uml/uml_class.nit:195,1--199,3
redef class MParameterType
redef fun core_serialize_to(v) do
v.serialize_attribute("name", name)
v.serialize_attribute("mtype", mclass.intro.bound_mtype.arguments[rank])
end
end
src/doc/templates/json_model.nit:325,1--330,3