end
# Build the properties of `nclassdef`.
- # REQUIRE: all superclasses are built.
private fun build_properties(nclassdef: AClassdef)
do
# Force building recursively
# Visit and fill information about a signature
private fun visit_signature(modelbuilder: ModelBuilder, mclassdef: MClassDef): Bool
do
- var mmodule = mclassdef.mmodule
var param_names = self.param_names
var param_types = self.param_types
for np in self.n_params do
param_names.add(np.n_id.text)
var ntype = np.n_type
if ntype != null then
- var mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, ntype, true)
+ var mtype = modelbuilder.resolve_mtype_unchecked(mclassdef, ntype, true)
if mtype == null then return false # Skip error
for i in [0..param_names.length-param_types.length[ do
param_types.add(mtype)
end
var ntype = self.n_type
if ntype != null then
- self.ret_type = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, ntype, true)
+ self.ret_type = modelbuilder.resolve_mtype_unchecked(mclassdef, ntype, true)
if self.ret_type == null then return false # Skip error
end
for np in self.n_params do
var ntype = np.n_type
if ntype != null then
- if modelbuilder.resolve_mtype(mclassdef.mmodule, mclassdef, ntype) == null then
+ if modelbuilder.resolve_mtype(mclassdef, ntype) == null then
res = false
end
end
end
var ntype = self.n_type
if ntype != null then
- if modelbuilder.resolve_mtype(mclassdef.mmodule, mclassdef, ntype) == null then
+ if modelbuilder.resolve_mtype(mclassdef, ntype) == null then
res = false
end
end
do
var n_kwinit = n_kwinit
var n_kwnew = n_kwnew
- var is_init = n_kwinit != null or n_kwnew != null
+ var is_new = n_kwnew != null
+ var is_init = n_kwinit != null or is_new
var name: String
var amethodid = self.n_methid
var name_node: ANode
if amethodid == null then
- if not is_init then
- name = "main"
- name_node = self
- else if n_kwinit != null then
+ if n_kwinit != null then
name = "init"
name_node = n_kwinit
else if n_kwnew != null then
name = "new"
name_node = n_kwnew
else
- abort
+ name = "main"
+ name_node = self
end
else if amethodid isa AIdMethid then
name = amethodid.n_id.text
mprop.is_root_init = true
end
mprop.is_init = is_init
- mprop.is_new = n_kwnew != null
- if mprop.is_new then mclassdef.mclass.has_new_factory = true
+ mprop.is_new = is_new
+ if is_new then mclassdef.mclass.has_new_factory = true
if name == "sys" then mprop.is_toplevel = true # special case for sys allowed in `new` factories
if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mprop) then
mprop.is_broken = true
do
var mpropdef = self.mpropdef
if mpropdef == null then return # Error thus skiped
+ var mproperty = mpropdef.mproperty
var mclassdef = mpropdef.mclassdef
var mmodule = mclassdef.mmodule
var nsig = self.n_signature
- if mpropdef.mproperty.is_root_init and not mclassdef.is_intro then
+ if mproperty.is_root_init and not mclassdef.is_intro then
var root_init = mclassdef.mclass.root_init
if root_init != null then
# Inherit the initializers by refinement
# FIXME: do not inherit from the intro, but from the most specific
var msignature: nullable MSignature = null
if not mpropdef.is_intro then
- msignature = mpropdef.mproperty.intro.msignature
+ msignature = mproperty.intro.msignature
if msignature == null then return # Skip error
# The local signature is adapted to use the local formal types, if any.
if param_names.length != msignature.arity then
var node: ANode
if nsig != null then node = nsig else node = self
- modelbuilder.error(node, "Redef Error: expected {msignature.arity} parameter(s) for `{mpropdef.mproperty.name}{msignature}`; got {param_names.length}. See introduction at `{mpropdef.mproperty.full_name}`.")
+ modelbuilder.error(node, "Redef Error: expected {msignature.arity} parameter(s) for `{mproperty.name}{msignature}`; got {param_names.length}. See introduction at `{mproperty.full_name}`.")
return
end
- else if mpropdef.mproperty.is_init and not mpropdef.mproperty.is_new then
+ else if mproperty.is_init and not mproperty.is_new then
# FIXME UGLY: inherit signature from a super-constructor
for msupertype in mclassdef.supertypes do
msupertype = msupertype.anchor_to(mmodule, mclassdef.bound_mtype)
- var candidate = modelbuilder.try_get_mproperty_by_name2(self, mmodule, msupertype, mpropdef.mproperty.name)
+ var candidate = modelbuilder.try_get_mproperty_by_name2(self, mmodule, msupertype, mproperty.name)
if candidate != null then
if msignature == null then
msignature = candidate.intro.as(MMethodDef).msignature
end
# In `new`-factories, the return type is by default the classtype.
- if ret_type == null and mpropdef.mproperty.is_new then ret_type = mclassdef.mclass.mclass_type
+ if ret_type == null and mproperty.is_new then ret_type = mclassdef.mclass.mclass_type
# Special checks for operator methods
if not accept_special_last_parameter and mparameters.not_empty and mparameters.last.is_vararg then
- modelbuilder.error(self.n_signature.n_params.last, "Error: illegal variadic parameter `{mparameters.last}` for `{mpropdef.mproperty.name}`.")
+ modelbuilder.error(self.n_signature.n_params.last, "Error: illegal variadic parameter `{mparameters.last}` for `{mproperty.name}`.")
end
if ret_type == null and return_is_mandatory then
- modelbuilder.error(self.n_methid, "Error: mandatory return type for `{mpropdef.mproperty.name}`.")
+ modelbuilder.error(self.n_methid, "Error: mandatory return type for `{mproperty.name}`.")
end
msignature = new MSignature(mparameters, ret_type)
# Is the node tagged optional?
var is_optional = false
- # Has the node a default value?
- # Could be through `n_expr` or `n_block`
+ # Does the node have a default value?
+ # Could be through `n_expr`, `n_block` or `is_lazy`
var has_value = false
# The guard associated to a lazy attribute.
var ntype = self.n_type
if ntype != null then
- mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, ntype, true)
+ mtype = modelbuilder.resolve_mtype_unchecked(mclassdef, ntype, true)
if mtype == null then return
end
if mtype == null then
if nexpr != null then
if nexpr isa ANewExpr then
- mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, nexpr.n_type, true)
+ mtype = modelbuilder.resolve_mtype_unchecked(mclassdef, nexpr.n_type, true)
else if nexpr isa AAsCastExpr then
- mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, nexpr.n_type, true)
+ mtype = modelbuilder.resolve_mtype_unchecked(mclassdef, nexpr.n_type, true)
else if nexpr isa AIntegerExpr then
var cla: nullable MClass = null
if nexpr.value isa Int then
end
else if ntype != null and inherited_type == mtype then
if nexpr isa ANewExpr then
- var xmtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, nexpr.n_type, true)
+ var xmtype = modelbuilder.resolve_mtype_unchecked(mclassdef, nexpr.n_type, true)
if xmtype == mtype then
modelbuilder.advice(ntype, "useless-type", "Warning: useless type definition")
end
# Check types
if ntype != null then
- if modelbuilder.resolve_mtype(mmodule, mclassdef, ntype) == null then return
+ if modelbuilder.resolve_mtype(mclassdef, ntype) == null then return
end
var nexpr = n_expr
if nexpr isa ANewExpr then
- if modelbuilder.resolve_mtype(mmodule, mclassdef, nexpr.n_type) == null then return
+ if modelbuilder.resolve_mtype(mclassdef, nexpr.n_type) == null then return
end
# Lookup for signature in the precursor
var mpropdef = self.mpropdef
if mpropdef == null then return # Error thus skipped
var mclassdef = mpropdef.mclassdef
- var mmodule = mclassdef.mmodule
var mtype: nullable MType = null
var ntype = self.n_type
- mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, ntype, true)
+ mtype = modelbuilder.resolve_mtype_unchecked(mclassdef, ntype, true)
if mtype == null then return
mpropdef.bound = mtype
var anchor = mclassdef.bound_mtype
var ntype = self.n_type
- if modelbuilder.resolve_mtype(mmodule, mclassdef, ntype) == null then
+ if modelbuilder.resolve_mtype(mclassdef, ntype) == null then
mpropdef.bound = null
return
end