# Look at the autoinit class-annotation
var autoinit = nclassdef.get_single_annotation("autoinit", self)
+ var noautoinit = nclassdef.get_single_annotation("noautoinit", self)
if autoinit != null then
# Just throws the collected initializers
mparameters.clear
initializers.clear
+ if noautoinit != null then
+ error(autoinit, "Error: `autoinit` and `noautoinit` are incompatible.")
+ end
+
+ if autoinit.n_args.is_empty then
+ error(autoinit, "Syntax error: `autoinit` expects method identifiers, use `noautoinit` to clear all autoinits.")
+ end
+
# Get and check each argument
for narg in autoinit.n_args do
var id = narg.as_id
abort
end
end
+ else if noautoinit != null then
+ if initializers.is_empty then
+ warning(noautoinit, "useless-noautoinit", "Warning: the list of autoinit is already empty.")
+ end
+ # Just clear initializers
+ mparameters.clear
+ initializers.clear
else
# Search the longest-one and checks for conflict
var longest = spropdefs.first
# The associated propdef once build by a `ModelBuilder`
var mpropdef: nullable MPROPDEF is writable
- private fun build_property(modelbuilder: ModelBuilder, mclassdef: MClassDef) is abstract
- private fun build_signature(modelbuilder: ModelBuilder) is abstract
- private fun check_signature(modelbuilder: ModelBuilder) is abstract
+ private fun build_property(modelbuilder: ModelBuilder, mclassdef: MClassDef) do end
+ private fun build_signature(modelbuilder: ModelBuilder) do end
+ private fun check_signature(modelbuilder: ModelBuilder) do end
private fun new_property_visibility(modelbuilder: ModelBuilder, mclassdef: MClassDef, nvisibility: nullable AVisibility): MVisibility
do
var mvisibility = public_visibility
self.is_visited = true
return true
end
-
- # Build a visited signature
- fun build_signature(modelbuilder: ModelBuilder): nullable MSignature
- do
- if param_names.length != param_types.length then
- # Some parameters are typed, other parameters are not typed.
- modelbuilder.error(self.n_params[param_types.length], "Error: Untyped parameter `{param_names[param_types.length]}'.")
- return null
- end
-
- var mparameters = new Array[MParameter]
- for i in [0..param_names.length[ do
- var mparameter = new MParameter(param_names[i], param_types[i], i == vararg_rank)
- self.n_params[i].mparameter = mparameter
- mparameters.add(mparameter)
- end
-
- var msignature = new MSignature(mparameters, ret_type)
- return msignature
- end
end
redef class AParam
end
mprop.is_init = is_init
mprop.is_new = n_kwnew != null
+ if mprop.is_new then mclassdef.mclass.has_new_factory = true
if parent isa ATopClassdef then mprop.is_toplevel = true
self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mprop)
else
mpropdef.is_abstract = self.get_single_annotation("abstract", modelbuilder) != null
mpropdef.is_intern = self.get_single_annotation("intern", modelbuilder) != null
mpropdef.is_extern = self.n_extern_code_block != null or self.get_single_annotation("extern", modelbuilder) != null
+
+ # Check annotations
+ var at = self.get_single_annotation("lazy", modelbuilder)
+ if at != null then modelbuilder.error(at, "Syntax error: `lazy` must be used on attributes.")
end
redef fun check_signature(modelbuilder)
redef fun build_property(modelbuilder, mclassdef)
do
var mclass = mclassdef.mclass
+ var nid2 = n_id2
+ var name = nid2.text
+
+ var atabstract = self.get_single_annotation("abstract", modelbuilder)
+ if atabstract == null then
+ if mclass.kind == interface_kind then
+ modelbuilder.error(self, "Error: Attempt to define attribute {name} in the interface {mclass}.")
+ else if mclass.kind == enum_kind then
+ modelbuilder.error(self, "Error: Attempt to define attribute {name} in the enum class {mclass}.")
+ else if mclass.kind == extern_kind then
+ modelbuilder.error(self, "Error: Attempt to define attribute {name} in the extern class {mclass}.")
+ end
- var name: String
- name = self.n_id2.text
-
- if mclass.kind == interface_kind or mclassdef.mclass.kind == enum_kind then
- modelbuilder.error(self, "Error: Attempt to define attribute {name} in the interface {mclass}.")
- else if mclass.kind == enum_kind then
- modelbuilder.error(self, "Error: Attempt to define attribute {name} in the enum class {mclass}.")
- else if mclass.kind == extern_kind then
- modelbuilder.error(self, "Error: Attempt to define attribute {name} in the extern class {mclass}.")
+ var mprop = new MAttribute(mclassdef, "_" + name, private_visibility)
+ var mpropdef = new MAttributeDef(mclassdef, mprop, self.location)
+ self.mpropdef = mpropdef
+ modelbuilder.mpropdef2npropdef[mpropdef] = self
end
- # New attribute style
- var nid2 = self.n_id2
- var mprop = new MAttribute(mclassdef, "_" + name, private_visibility)
- var mpropdef = new MAttributeDef(mclassdef, mprop, self.location)
- self.mpropdef = mpropdef
- modelbuilder.mpropdef2npropdef[mpropdef] = self
-
var readname = name
var mreadprop = modelbuilder.try_get_mproperty_by_name(nid2, mclassdef, readname).as(nullable MMethod)
if mreadprop == null then
var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
mreadprop = new MMethod(mclassdef, readname, mvisibility)
if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then return
- mreadprop.deprecation = mprop.deprecation
else
if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, true, mreadprop) then return
check_redef_property_visibility(modelbuilder, self.n_visibility, mreadprop)
self.mreadpropdef = mreadpropdef
modelbuilder.mpropdef2npropdef[mreadpropdef] = self
set_doc(mreadpropdef, modelbuilder)
- mpropdef.mdoc = mreadpropdef.mdoc
+ if mpropdef != null then mpropdef.mdoc = mreadpropdef.mdoc
+ if atabstract != null then mreadpropdef.is_abstract = true
has_value = n_expr != null or n_block != null
+ if atabstract != null and has_value then
+ modelbuilder.error(atabstract, "Error: `abstract` attributes cannot have an initial value")
+ return
+ end
+
var atnoinit = self.get_single_annotation("noinit", modelbuilder)
+ if atnoinit == null then atnoinit = self.get_single_annotation("noautoinit", modelbuilder)
if atnoinit != null then
noinit = true
if has_value then
- modelbuilder.error(atnoinit, "Error: `noinit` attributes cannot have an initial value")
+ modelbuilder.error(atnoinit, "Error: `noautoinit` attributes cannot have an initial value")
+ return
+ end
+ if atabstract != null then
+ modelbuilder.error(atnoinit, "Error: `noautoinit` attributes cannot be abstract")
return
end
end
end
mwriteprop = new MMethod(mclassdef, writename, mvisibility)
if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef, false, mwriteprop) then return
- mwriteprop.deprecation = mprop.deprecation
+ mwriteprop.deprecation = mreadprop.deprecation
else
if not self.check_redef_keyword(modelbuilder, mclassdef, nwkwredef or else n_kwredef, true, mwriteprop) then return
if atwritable != null then
var mwritepropdef = new MMethodDef(mclassdef, mwriteprop, self.location)
self.mwritepropdef = mwritepropdef
modelbuilder.mpropdef2npropdef[mwritepropdef] = self
- mwritepropdef.mdoc = mpropdef.mdoc
+ mwritepropdef.mdoc = mreadpropdef.mdoc
+ if atabstract != null then mwritepropdef.is_abstract = true
end
redef fun build_signature(modelbuilder)
do
+ var mreadpropdef = self.mreadpropdef
var mpropdef = self.mpropdef
- if mpropdef == null then return # Error thus skipped
- var mclassdef = mpropdef.mclassdef
+ if mreadpropdef == null then return # Error thus skipped
+ var mclassdef = mreadpropdef.mclassdef
var mmodule = mclassdef.mmodule
var mtype: nullable MType = null
- var mreadpropdef = self.mreadpropdef
var ntype = self.n_type
if ntype != null then
var inherited_type: nullable MType = null
# Inherit the type from the getter (usually an abstract getter)
- if mreadpropdef != null and not mreadpropdef.is_intro then
+ if not mreadpropdef.is_intro then
var msignature = mreadpropdef.mproperty.intro.msignature
if msignature == null then return # Error, thus skipped
inherited_type = msignature.return_mtype
var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "String")
if cla != null then mtype = cla.mclass_type
else
- modelbuilder.error(self, "Error: Untyped attribute {mpropdef}. Implicit typing allowed only for literals and new.")
+ modelbuilder.error(self, "Error: Untyped attribute {mreadpropdef}. Implicit typing allowed only for literals and new.")
end
if mtype == null then return
end
if mtype == null then
- modelbuilder.error(self, "Error: Untyped attribute {mpropdef}")
+ modelbuilder.error(self, "Error: Untyped attribute {mreadpropdef}")
return
end
- mpropdef.static_mtype = mtype
+ if mpropdef != null then
+ mpropdef.static_mtype = mtype
+ end
- if mreadpropdef != null then
+ do
var msignature = new MSignature(new Array[MParameter], mtype)
mreadpropdef.msignature = msignature
end