# Skip if we are not interested
if nat.n_atid.n_id.text != "auto_serializable" then return
if not nclassdef isa AStdClassdef then
- toolcontext.error(nclassdef.location, "Syntax error: only a concrete class can be automatically serialized.")
+ toolcontext.error(nclassdef.location, "Syntax Error: only a concrete class can be automatically serialized.")
return
end
# Add a constructor to the automated nclassdef
fun generate_deserialization_init(nclassdef: AStdClassdef)
do
- # Do not generate constructors for abstract classes
- if nclassdef.n_classkind isa AAbstractClasskind then return
-
var npropdefs = nclassdef.n_propdefs
var code = new Array[String]
- code.add "init from_deserializer(v: Deserializer)"
+ code.add "redef init from_deserializer(v: Deserializer)"
code.add "do"
+ code.add " super"
code.add " v.notify_of_creation self"
for attribute in npropdefs do if attribute isa AAttrPropdef then
code.add ""
code.add "\tvar {name} = v.deserialize_attribute(\"{name}\")"
- code.add "\tassert {name} isa {type_name} else print \"Unsupported type for attribute '{name}', got '\{{name}.class_name\}' (ex {type_name})\""
+ code.add "\tassert {name} isa {type_name} else print \"Unsupported type for `\{class_name\}::{name}`, got '\{{name}.class_name\}'; expected {type_name}\""
code.add "\tself.{name} = {name}"
end
code.add " redef fun deserialize_class(name)"
code.add " do"
else
- toolcontext.error(deserializer_npropdef.location, "Annotation error: you cannot define Deserializer::deserialize_class in a module where you use \"auto_serializable\".")
+ toolcontext.error(deserializer_npropdef.location, "Error: you cannot define `Deserializer::deserialize_class` in a module where you use `auto_serializable`.")
return
end
redef fun process_nmodule(nmodule)
do
for npropdef in nmodule.inits_to_retype do
- var v = new PreciseTypeVisitor(npropdef, npropdef.mpropdef.mclassdef, toolcontext)
+ var mpropdef = npropdef.mpropdef
+ if mpropdef == null then continue # skip error
+ var v = new PreciseTypeVisitor(npropdef, mpropdef.mclassdef, toolcontext)
npropdef.accept_precise_type_visitor v
end
end