nitc :: compiler_serialization $ AMethPropdef
A definition of all kind of method (including constructors)nitc :: compiler_serialization $ ModelBuilder
A model builder knows how to load nit source files and build the associated modelnitc :: compiler_serialization $ AMethPropdef
A definition of all kind of method (including constructors)nitc :: compiler_serialization $ ModelBuilder
A model builder knows how to load nit source files and build the associated modelSerializable::inspect
to show more useful information
nitc :: modelbuilder
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsserialize_to_json
and JsonSerializer
nitc :: toolcontext
Common command-line tool infrastructure than handle options and error messagescore :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Serialization support for the compiler
module compiler_serialization
import model::serialize_model
import abstract_compiler
redef class ModelBuilder
redef fun write_and_make(compiler)
do
var uses_json_serialization_read = false
for mod in compiler.mainmodule.in_importation.greaters do
var concern = mod.parent_concern
if mod.name == "serialization_read" and concern != null and concern.name == "json" then
uses_json_serialization_read = true
break
end
end
if uses_json_serialization_read then
write_poset_to_file(compiler, "nit_class_inheritance_metamodel", compiler.mainmodule.flatten_mclass_hierarchy)
end
super
end
# Write `poset` to a C file
private fun write_poset_to_file(compiler: AbstractCompiler, name: String, poset: POSet[Object])
do
var json = poset.to_thin_json
var code = new CodeFile(name)
compiler.files.add code
var writer = new CodeWriter(code)
writer.add """
char *{{{name}}} = "{{{json.escape_to_c}}}";
"""
end
end
redef class AMethPropdef
redef fun compile_intern_to_c(v, mpropdef, arguments)
do
var pname = mpropdef.mproperty.name
var ret = mpropdef.msignature.as(not null).return_mtype
if pname == "class_inheritance_metamodel_json" then
v.add("extern char* nit_class_inheritance_metamodel;")
v.ret(v.new_expr("nit_class_inheritance_metamodel", ret.as(not null)))
return true
end
return super
end
end
src/compiler/compiler_serialization.nit:15,1--68,3