1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Serialization support for the compiler
16 module compiler_serialization
18 import model
::serialize_model
19 import abstract_compiler
21 redef class ModelBuilder
22 redef fun write_and_make
(compiler
)
24 var uses_json_serialization_read
= false
25 for mod
in compiler
.mainmodule
.in_importation
.greaters
do
26 var concern
= mod
.parent_concern
27 if mod
.name
== "serialization_read" and concern
!= null and concern
.name
== "json" then
28 uses_json_serialization_read
= true
33 if uses_json_serialization_read
then
34 write_poset_to_file
(compiler
, "nit_class_inheritance_metamodel", compiler
.mainmodule
.flatten_mclass_hierarchy
)
40 # Write `poset` to a C file
41 private fun write_poset_to_file
(compiler
: AbstractCompiler, name
: String, poset
: POSet[Object])
43 var json
= poset
.to_thin_json
45 var code
= new CodeFile(name
)
46 compiler
.files
.add code
48 var writer
= new CodeWriter(code
)
50 char *{{{name}}} = "{{{json.escape_to_c}}}";
55 redef class AMethPropdef
56 redef fun compile_intern_to_c
(v
, mpropdef
, arguments
)
58 var pname
= mpropdef
.mproperty
.name
59 var ret
= mpropdef
.msignature
.as(not null).return_mtype
60 if pname
== "class_inheritance_metamodel_json" then
61 v
.add
("extern char* nit_class_inheritance_metamodel;")
62 v
.ret
(v
.new_expr
("nit_class_inheritance_metamodel", ret
.as(not null)))