In order to have a more POLA `to_s` on collections, it is required that a new method with the old behavior is provided for clients that need it (especially the interpreter that use it for superstrings).
the compiler use `native_to_s` for superstrings but `c_src/nitg` still use `to_s` on array, so a regeneration of the bootstrap is required before changing the behavior of `to_s` on collections.
Pull-Request: #1385
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Blondin Massé <alexandre.blondin.masse@gmail.com>
Reviewed-by: Romain Chanoir <chanoir.romain@courrier.uqam.ca>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
# Print `objects` on the standard output (`stdout`).
fun printn(objects: Object...)
do
- sys.stdout.write(objects.to_s)
+ sys.stdout.write(objects.plain_to_s)
end
# Print an `object` on the standard output (`stdout`) and add a newline.
# Concatenate elements.
redef fun to_s
do
+ return plain_to_s
+ end
+
+ # Concatenate element without separators
+ fun plain_to_s: String
+ do
var s = new FlatBuffer
for e in self do if e != null then s.append(e.to_s)
return s.to_s
redef class Array[E]
# Fast implementation
- redef fun to_s
+ redef fun plain_to_s
do
var l = length
if l == 0 then return ""
array.add(i)
end
var i = v.array_instance(array, v.mainmodule.object_type)
- var res = v.send(v.force_get_primitive_method("to_s", i.mtype), [i])
+ var res = v.send(v.force_get_primitive_method("plain_to_s", i.mtype), [i])
assert res != null
return res
end
redef fun accept_rapid_type_visitor(v)
do
var mmodule = v.analysis.mainmodule
- var object_type = mmodule.object_type
+ var object_type = mmodule.string_type
var arraytype = mmodule.array_type(object_type)
v.add_type(arraytype)
var nattype = mmodule.native_array_type(object_type)
redef fun deserialize_class(name)
do
# Module: test_serialization
- if name == "Array[Object]" then return new Array[Object].from_deserializer(self)
+ if name == "Array[String]" then return new Array[String].from_deserializer(self)
if name == "Array[nullable Object]" then return new Array[nullable Object].from_deserializer(self)
if name == "Array[Serializable]" then return new Array[Serializable].from_deserializer(self)
- if name == "Array[String]" then return new Array[String].from_deserializer(self)
+ if name == "Array[Object]" then return new Array[Object].from_deserializer(self)
return super
end
end