nitc :: MMethod :: _getter_for
The attribute this getter is fornitc :: MMethod :: _is_root_init
The constructor is a (the) root init with empty signature but a set of initializersnitc :: MMethod :: _is_toplevel
Is the property defined at the top_level of the module?nitc :: MMethod :: _mcontract_facet
The contract facet of the methodnitc :: MMethod :: _restful_async
Is this arestful
method to be executed asynchronously
nitc :: MMethod :: _restful_resources
Associated resources within an action, e.g.foo
in http://localhost/foo?arg=bar
nitc :: MMethod :: _restful_verbs
HTTP access methods, e.g.GET
nitc :: MMethod :: _setter_for
The attribute this setter is fornitc :: MMethod :: build_c_implementation_signature
Similar tobuild_c_signature
but adapted to create the signature expected by JNI for C functions
nitc :: MMethod :: build_ccall
Build a C function call for the FFI implementation (uses friendly naming).nitc :: MMethod :: build_cname
Build a C function name for the FFI implementation (uses friendly naming).nitc :: MMethod :: build_contract_facet
Buildmcontract_facet
if is not exist and return it
nitc :: MMethod :: build_csignature
Build a C function signature for the FFI implementation (uses friendly naming).nitc :: MMethod :: build_ensure
Buildmensure
if is not exist and return it
nitc :: MMethod :: build_expect
Buildmexpect
if is not exist and return it
nitc :: MMethod :: build_jni_format
Returns the JNI signature format of this Nit methodnitc :: MMethod :: create_facet
Method to create a facet of the method.nitc :: MMethod :: defaultinit
nitc :: MMethod :: define_contract_facet
Define contract facet for MMethod in the given mclassdef. The facet represents the entry point with contracts (expect, ensure) of the method.nitc :: MMethod :: getter_for=
The attribute this getter is fornitc :: MMethod :: is_init_for
Is the property a legal constructor for a given class?nitc :: MMethod :: is_null_safe
A specific method that is safe to call on null.nitc :: MMethod :: is_root_init
The constructor is a (the) root init with empty signature but a set of initializersnitc :: MMethod :: is_root_init=
The constructor is a (the) root init with empty signature but a set of initializersnitc :: MMethod :: is_toplevel
Is the property defined at the top_level of the module?nitc :: MMethod :: is_toplevel=
Is the property defined at the top_level of the module?nitc :: MMethod :: mcontract_facet
The contract facet of the methodnitc :: MMethod :: mcontract_facet=
The contract facet of the methodnitc :: MMethod :: restful_async
Is this arestful
method to be executed asynchronously
nitc :: MMethod :: restful_async=
Is this arestful
method to be executed asynchronously
nitc :: MMethod :: restful_resources
Associated resources within an action, e.g.foo
in http://localhost/foo?arg=bar
nitc :: MMethod :: restful_resources=
Associated resources within an action, e.g.foo
in http://localhost/foo?arg=bar
nitc :: MMethod :: restful_verbs
HTTP access methods, e.g.GET
nitc :: MMethod :: restful_verbs=
HTTP access methods, e.g.GET
nitc :: MMethod :: setter_for=
The attribute this setter is fornitc :: MMethod :: short_cname
Short name of this method in C (without the class name)nitc :: json_model $ MMethod :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: MEntity :: _const_color
nitc :: MEntity :: _css_classes
CSS classes used to decorateself
nitc :: MEntity :: _deprecation
Is the entity deprecated?nitc :: MMethod :: _getter_for
The attribute this getter is fornitc :: MEntity :: _html_full_name
The MEntityfull_name
escaped for HTML
nitc :: MProperty :: _intro_mclassdef
The classdef that introduce the propertynitc :: MProperty :: _is_after_all
Does self have theafter_all
annotation?
nitc :: MProperty :: _is_autoinit
Is the property usable as an initializer?nitc :: MProperty :: _is_before_all
Does self have thebefore_all
annotation?
nitc :: MEntity :: _is_broken
The indication that the entity did not pass some semantic verifications.nitc :: MProperty :: _is_example
nitc :: MMethod :: _is_root_init
The constructor is a (the) root init with empty signature but a set of initializersnitc :: MMethod :: _is_toplevel
Is the property defined at the top_level of the module?nitc :: MMethod :: _mcontract_facet
The contract facet of the methodnitc :: MProperty :: _mpropdefs
All definitions of the property.nitc :: MMethod :: _restful_async
Is this arestful
method to be executed asynchronously
nitc :: MMethod :: _restful_resources
Associated resources within an action, e.g.foo
in http://localhost/foo?arg=bar
nitc :: MMethod :: _restful_verbs
HTTP access methods, e.g.GET
nitc :: MMethod :: _setter_for
The attribute this setter is fornitc :: MProperty :: _visibility
The visibility of the propertyserialization :: 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 :: MMethod :: build_c_implementation_signature
Similar tobuild_c_signature
but adapted to create the signature expected by JNI for C functions
nitc :: MMethod :: build_ccall
Build a C function call for the FFI implementation (uses friendly naming).nitc :: MMethod :: build_cname
Build a C function name for the FFI implementation (uses friendly naming).nitc :: MMethod :: build_contract_facet
Buildmcontract_facet
if is not exist and return it
nitc :: MMethod :: build_csignature
Build a C function signature for the FFI implementation (uses friendly naming).nitc :: MMethod :: build_ensure
Buildmensure
if is not exist and return it
nitc :: MMethod :: build_expect
Buildmexpect
if is not exist and return it
nitc :: MMethod :: build_jni_format
Returns the JNI signature format of this Nit methodcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
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 :: MEntity :: collect_metrics
nitc :: MEntity :: collect_modifiers
Collect modifier keywords likeredef
, private
etc
nitc :: MProperty :: collect_mpropdefs
Collect all property definitions ofself
nitc :: MEntity :: collect_parents
Collectself
parents (direct ancestors)
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 :: MMethod :: create_facet
Method to create a facet of the method.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
core :: Object :: defaultinit
nitc :: HInfoBoxable :: defaultinit
nitc :: MProperty :: defaultinit
nitc :: TableCallable :: defaultinit
nitc :: MMethod :: defaultinit
nitc :: MEntity :: defaultinit
nitc :: MMethod :: define_contract_facet
Define contract facet for MMethod in the given mclassdef. The facet represents the entry point with contracts (expect, ensure) of the method.nitc :: MEntity :: deprecation=
Is the entity deprecated?nitc :: MEntity :: field_separator
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
nitc :: MProperty :: full_name=
The canonical name of the property.nitc :: MMethod :: getter_for=
The attribute this getter is fornitc :: 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 :: MProperty :: intro_mclassdef
The classdef that introduce the propertynitc :: MProperty :: intro_mclassdef=
The classdef that introduce the propertynitc :: MProperty :: is_after_all=
Does self have theafter_all
annotation?
nitc :: MProperty :: is_autoinit=
Is the property usable as an initializer?nitc :: MProperty :: is_before=
Does self have thebefore
annotation?
nitc :: MProperty :: is_before_all
Does self have thebefore_all
annotation?
nitc :: MProperty :: is_before_all=
Does self have thebefore_all
annotation?
nitc :: MEntity :: is_broken=
The indication that the entity did not pass some semantic verifications.nitc :: MProperty :: is_example=
nitc :: MEntity :: is_fictive=
Isself
created for internal purpose?
nitc :: MMethod :: is_init_for
Is the property a legal constructor for a given class?nitc :: MMethod :: is_null_safe
A specific method that is safe to call on null.nitc :: MMethod :: is_root_init
The constructor is a (the) root init with empty signature but a set of initializersnitc :: MMethod :: is_root_init=
The constructor is a (the) root init with empty signature but a set of initializerscore :: 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 :: MMethod :: is_toplevel
Is the property defined at the top_level of the module?nitc :: MMethod :: is_toplevel=
Is the property defined at the top_level of the module?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 :: MProperty :: lookup_all_definitions
Return all definitions in a linearization ordernitc :: MProperty :: lookup_definitions
Return the most specific property definitions defined or inherited by a type.nitc :: MProperty :: lookup_first_definition
Return the most specific definition in the linearization ofmtype
.
nitc :: MProperty :: lookup_super_definitions
Return the most specific property definitions inherited by a type.nitc :: MMethod :: mcontract_facet
The contract facet of the methodnitc :: MMethod :: mcontract_facet=
The contract facet of the methodnitc :: MEntity :: mdoc_or_fallback
The documentation associated to the entity or their main nested entity.nitc :: MProperty :: mpropdefs=
All definitions of the property.serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).mentity
nitc :: MEntity :: ratings_by_dimension
Get the ratings of adimension
nitc :: MMethod :: restful_async
Is this arestful
method to be executed asynchronously
nitc :: MMethod :: restful_async=
Is this arestful
method to be executed asynchronously
nitc :: MMethod :: restful_resources
Associated resources within an action, e.g.foo
in http://localhost/foo?arg=bar
nitc :: MMethod :: restful_resources=
Associated resources within an action, e.g.foo
in http://localhost/foo?arg=bar
nitc :: MMethod :: restful_verbs
HTTP access methods, e.g.GET
nitc :: MMethod :: restful_verbs=
HTTP access methods, e.g.GET
nitc :: MProperty :: select_most_specific
Return an array containing olny the most specific property definitionsserialization :: 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 :: MMethod :: setter_for=
The attribute this setter is fornitc :: MMethod :: short_cname
Short name of this method in C (without the class name)nitc :: MEntity :: source_url
Render a HTML link for the MEntity locationserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
nitc :: MEntity :: tpl_module
Builds a dot UML package diagram entity fromself
nitc :: MProperty :: visibility=
The visibility of the propertyv.enter_visit
on all nested entities.
nitc :: MEntity :: write_extra_doc
Extra auto documentation to append to thestream
nitc :: MEntity :: write_location
Location (file and line when available) of related declarationsnitc :: MProperty :: write_synopsis
Serializer::serialize
table_send
invariant
and ensure
).
# A global method
class MMethod
super MProperty
redef type MPROPDEF: MMethodDef
# Is the property defined at the top_level of the module?
# Currently such a property are stored in `Object`
var is_toplevel: Bool = false is writable
# Is the property a constructor?
# Warning, this property can be inherited by subclasses with or without being a constructor
# therefore, you should use `is_init_for` the verify if the property is a legal constructor for a given class
var is_init: Bool = false is writable
# The constructor is a (the) root init with empty signature but a set of initializers
var is_root_init: Bool = false is writable
# Is the property a 'new' constructor?
var is_new: Bool = false is writable
# Is the property a legal constructor for a given class?
# As usual, visibility is not considered.
# FIXME not implemented
fun is_init_for(mclass: MClass): Bool
do
return self.is_init
end
# A specific method that is safe to call on null.
# Currently, only `==`, `!=` and `is_same_instance` are safe
fun is_null_safe: Bool do return name == "==" or name == "!=" or name == "is_same_instance"
# Is this method a getter (auto or not)?
#
# See `getter_for`.
fun is_getter: Bool do return getter_for != null
# The attribute this getter is for
#
# Return `null` is this method is not a getter.
var getter_for: nullable MAttribute = null is writable
# Is this method a setter (auto or not)?
#
# See `setter_for`.
fun is_setter: Bool do return setter_for != null
# The attribute this setter is for
#
# Return `null` is this method is not a setter.
var setter_for: nullable MAttribute = null is writable
# Is this method a getter or a setter?
fun is_accessor: Bool do return is_getter or is_setter
end
src/model/model.nit:2411,1--2466,3
redef class MMethod
# Short name of this method in C (without the class name)
fun short_cname: String do
var nit_name = name
if nit_name == "+" then return "_plus"
if nit_name == "-" then return "_minus"
if nit_name == "unary -" then return "_unary_minus"
if nit_name == "unary +" then return "_unary_plus"
if nit_name == "unary ~" then return "_unary_tilde"
if nit_name == "*" then return "_star"
if nit_name == "/" then return "_slash"
if nit_name == "%" then return "_percent"
if nit_name == "[]" then return "_index"
if nit_name == "[]=" then return "_index_assign"
if nit_name == "==" then return "_equal"
if nit_name == "<" then return "_less"
if nit_name == ">" then return "_greater"
if nit_name == "<=" then return "_less_or_equal"
if nit_name == ">=" then return "_greater_or_equal"
if nit_name == "!=" then return "_not_equal"
if nit_name == "<<" then return "_left"
if nit_name == ">>" then return "_right"
if nit_name == "<=>" then return "_starship"
if nit_name == "|" then return "_pipe"
if nit_name == "^" then return "_caret"
if nit_name == "&" then return "_amp"
if nit_name == "~" then return "_tilde"
if nit_name.chars.last == '=' then return "{nit_name.substring(0, nit_name.length-1)}__assign"
return nit_name
end
end
src/nitni/nitni_base.nit:26,1--58,3
redef class MMethod
# The contract facet of the method
# is representing the method with a contract
# This method calls contracts (expect, ensure) and the method
var mcontract_facet: nullable MFacet = null
# The `MExpect` contract if any
var mexpect: nullable MExpect = null
# The `MEnsure` contract if any
var mensure: nullable MEnsure = null
# Build `mensure` if is not exist and return it
private fun build_ensure: MEnsure
do
var m_mensure = self.mensure
# build a new `MEnsure` contract
if m_mensure == null then m_mensure = new MEnsure(intro_mclassdef, "_ensure_{name}", intro_mclassdef.location, public_visibility)
self.mensure = m_mensure
return m_mensure
end
# Is there an ensure contract?
fun has_ensure: Bool
do
return self.mensure != null
end
# Build `mexpect` if is not exist and return it
private fun build_expect: MExpect
do
var m_mexpect = self.mexpect
# build a new `MExpect` contract
if m_mexpect == null then m_mexpect = new MExpect(intro_mclassdef, "_expect_{name}", intro_mclassdef.location, public_visibility)
self.mexpect = m_mexpect
return m_mexpect
end
# Is there an expect contract?
fun has_expect: Bool
do
return self.mexpect != null
end
# Build `mcontract_facet` if is not exist and return it
private fun build_contract_facet: MFacet
do
var m_mcontract_facet = self.mcontract_facet
# build a new `MFacet` contract
if m_mcontract_facet == null then m_mcontract_facet = new MFacet(intro_mclassdef, "_contract_{name}", intro_mclassdef.location, public_visibility)
self.mcontract_facet = m_mcontract_facet
return m_mcontract_facet
end
# Is there an contract facet?
fun has_contract_facet: Bool
do
return self.mcontract_facet != null
end
end
src/model/model_contract.nit:60,1--120,3
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
src/nitni/nitni_utilities.nit:20,1--129,3
redef class MMethod
# HTTP access methods, e.g. `GET, POST, PUT or DELETE`
private var restful_verbs = new Array[String] is lazy
# Associated resources within an action, e.g. `foo` in `http://localhost/foo?arg=bar`
private var restful_resources: Array[String] = [name] is lazy
# Is this a `restful` method to be executed asynchronously
private var restful_async = false
end
src/nitrestful.nit:94,1--103,3
redef class MMethod
# Define contract facet for MMethod in the given mclassdef. The facet represents the entry point with contracts (expect, ensure) of the method.
# If a contract is given adapt the contract facet.
#
# `classdef`: Indicates the class where we want to introduce our facet
# `exist_contract`: Indicates if it is necessary to define a new facet for the contract. If `exist_contract_facet and exist_contract` it's not necessary to add a facet.
#
# Exemple:
# ~~~nitish
# from:
# classe A
# i :Int
# fun add_one is ensure(old(i) + 1 == i)
# end
# to:
# classe A
# fun add_one is ensure(old(i) + 1 == i)
#
# # The contract facet
# fun contract_add_one do
# add_one
# ensure_add_one(old_add_one)
# end
# end
# ~~
private fun define_contract_facet(v: ContractsVisitor, classdef: MClassDef, mcontract: nullable MContract)
do
var exist_contract_facet = has_contract_facet
var contract_facet = build_contract_facet
# Do nothing the contract and the contract facet already exist
if mcontract != null and mcontract.is_already_applied(contract_facet) then return
var n_contract_facet: AMethPropdef
if not exist_contract_facet then
# If has no contract facet in intro just create it
if classdef != intro_mclassdef then
var n_intro_face = create_facet(v, intro_mclassdef, contract_facet, self)
n_intro_face.location = self.intro.location
n_intro_face.do_all(v.toolcontext)
end
n_contract_facet = create_facet(v, classdef, contract_facet, self)
else
# Check if the contract facet already exist in this context (in this classdef)
if classdef.mpropdefs_by_property.has_key(contract_facet) then
# get the definition
n_contract_facet = v.toolcontext.modelbuilder.mpropdef2node(classdef.mpropdefs_by_property[contract_facet]).as(AMethPropdef)
else
# create a new contract facet definition
n_contract_facet = create_facet(v, classdef, contract_facet, self)
var block = v.ast_builder.make_block
# super call to the contract facet
var args = n_contract_facet.n_signature.make_parameter_read(v.ast_builder)
var n_super_call = v.ast_builder.make_super_call(args)
# verification for add a return or not
if self.intro.msignature.return_mtype != null then
block.add(v.ast_builder.make_return(n_super_call))
else
block.add(n_super_call)
end
n_contract_facet.n_block = block
end
end
if mcontract != null then mcontract.adapt_method_to_contract(v, contract_facet, n_contract_facet)
n_contract_facet.location = v.current_location
n_contract_facet.do_all(v.toolcontext)
end
# Method to create a facet of the method.
# See `define_contract_facet` for more information about two types of facets.
#
# `called` : is the property to call in this facet.
private fun create_facet(v: ContractsVisitor, classdef: MClassDef, facet: MFacet, called: MMethod): AMethPropdef
is
expect( called.is_same_instance(self) or called.is_same_instance(self.mcontract_facet) )
do
# Defines the contract facet is an init or not
# it is necessary to use the contracts with in a constructor
facet.is_init = is_init
var n_contractdef = v.toolcontext.modelbuilder.create_method_from_property(facet, classdef, false, self.intro.msignature)
# FIXME set the location because the callsite creation need the node location
n_contractdef.location = v.current_location
n_contractdef.validate
var block = v.ast_builder.make_block
# Arguments to call the `called` property
var args: Array[AExpr]
args = n_contractdef.n_signature.make_parameter_read(v.ast_builder)
var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_contractdef, called, true)
var n_call = v.ast_builder.make_call(new ASelfExpr, callsite, args)
if self.intro.msignature.return_mtype == null then
block.add(n_call)
else
block.add(v.ast_builder.make_return(n_call))
end
n_contractdef.n_block = block
n_contractdef.do_all(v.toolcontext)
return n_contractdef
end
end
src/contracts.nit:553,1--657,3
redef class MMethod
# Returns the JNI signature format of this Nit method
#
# Example: a Nity signature `(Bool, Int, Float, JavaString)` is represented by
# the JNI format `(ZIDLjava/lang/string;)V"
private fun build_jni_format(recv_mtype: MClassType, from_mmodule: MModule): String
do
var mmethoddef = lookup_first_definition(from_mmodule, recv_mtype)
var msignature = mmethoddef.msignature
var format = new Array[String]
format.add "("
# receiver
if not self.is_init then format.add recv_mtype.jni_format
# parameters
for p in msignature.mparameters do
var param_mtype = p.mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
format.add param_mtype.jni_format
end
format.add ")"
# return
if self.is_init then
format.add recv_mtype.jni_format
else
var return_mtype = msignature.return_mtype
if return_mtype != null then
return_mtype = return_mtype.resolve_for(recv_mtype, recv_mtype, from_mmodule, true)
format.add return_mtype.jni_format
else format.add "V"
end
return format.join
end
# Similar to `build_c_signature` but adapted to create the signature expected by JNI for C functions
# implementing Java extern methods.
#
# Is used to generate FFI callbacks to Nit at `MExplicitCall::compile_callback_to_java`.
private fun build_c_implementation_signature(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]
cparams.add "JNIEnv *nit_ffi_jni_env"
cparams.add "jclass clazz"
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
end
src/ffi/java.nit:756,1--832,3
redef class MMethod
super TableCallable
end
src/compiler/java_compiler.nit:1395,1--1397,3
redef class MMethod
redef fun core_serialize_to(v) do
super
if is_init then
v.serialize_attribute("is_init", true)
end
v.serialize_attribute("msignature", intro.msignature)
end
end
src/doc/templates/json_model.nit:223,1--231,3