end
end
- generate_serialization_method(nclassdef)
# Check for useless double declarations
if serialize and up_serialize then
toolcontext.warning(node.location, "useless-serialize",
end
end
- generate_deserialization_init(nclassdef)
redef fun process_nclassdef(nclassdef)
do
if not nclassdef isa AStdClassdef then return
var sc = toolcontext.parse_superclass("Serializable")
sc.location = nclassdef.location
nclassdef.n_propdefs.add sc
+
+ # Add services
+ generate_serialization_method(nclassdef, per_attribute)
+ generate_deserialization_init(nclassdef, per_attribute)
end
end
end
end
- fun generate_serialization_method(nclassdef: AClassdef)
+ fun generate_serialization_method(nclassdef: AClassdef, per_attribute: Bool)
do
var npropdefs = nclassdef.n_propdefs
code.add " super"
for attribute in npropdefs do if attribute isa AAttrPropdef then
+
+ # Is `attribute` to be skipped?
+ if (per_attribute and not attribute.is_serialize) or
+ attribute.is_noserialize then continue
+
var name = attribute.name
code.add " v.serialize_attribute(\"{name}\", {name})"
end
end
# Add a constructor to the automated nclassdef
- fun generate_deserialization_init(nclassdef: AStdClassdef)
+ fun generate_deserialization_init(nclassdef: AClassdef, per_attribute: Bool)
do
var npropdefs = nclassdef.n_propdefs
code.add " v.notify_of_creation self"
for attribute in npropdefs do if attribute isa AAttrPropdef then
+
+ # Is `attribute` to be skipped?
+ if (per_attribute and not attribute.is_serialize) or
+ attribute.is_noserialize then continue
+
var n_type = attribute.n_type
var type_name
if n_type == null then
end
private var inits_to_retype = new Array[AMethPropdef]
+
+ redef fun is_serialize do return n_moduledecl != null and n_moduledecl.is_serialize
end
redef class AStdClassdef