1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2006-2008 Floréal Morandat <morandat@lirmm.fr>
4 # Copyright 2008 Jean Privat <jean@pryen.org>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
19 # Base module for nit tools that load, manipulate or transform NIT models
26 class AbstractCompiler
29 init(tool_name
: String)
31 _tool_name
= tool_name
33 register_loader
(new SrcModuleLoader)
36 # The name of the tool
37 # Used in help messages for instance
38 readable var _tool_name
: String
44 if opt_version
.value
then
45 print
"{tool_name} version {nit_version}"
49 if opt_help
.value
then
50 print
"usage: {tool_name} [options] file..."
55 if option_context
.rest
.length
== 0 then
56 print
"usage: {tool_name} [options] file..."
61 var rest
= option_context
.rest
62 var to_do
= new Array[MMModule]
63 info
("Syntax analysis",1)
64 for i
in [0..rest
.length
[ do
65 var mod
= get_module_from_filename
(rest
[i
])
72 if not to_do
.is_empty
and not opt_only_metamodel
.value
and not opt_only_parse
.value
then
77 fun perform_work
(mods
: Array[MMModule]) is abstract
81 for mod
in module_hierarchy
do
84 var tab
= new Array[MMModule]
85 tab
.add_all
(module_hierarchy
)
86 var name
= module_hierarchy
.select_smallests
(tab
).join
("-")
88 var f
= new OFStream.open
("{name}.full_class_hierarchy.new.dot")
89 f
.write
(class_hierarchy
.to_dot
)
92 f
= new OFStream.open
("{name}.module_hierarchy.new.dot")
93 f
.write
(module_hierarchy
.to_dot
)
101 var p
= filename
.file_path
102 var fname
= "{p}/{name}"
103 var f
= new OFStream.open
("{fname}.class_hierarchy.new.dot")
104 f
.write
(class_specialization_hierarchy
.to_dot
)
107 f
= new OFStream.open
("{fname}.properties.log")
108 for cla
in local_classes
do
109 cla
.dump_properties
(f
)
116 redef class MMLocalClass
117 fun dump_properties
(file
: OStream)
119 file
.write
("class {self}\n")
120 for p
in global_properties
do
122 file
.write
("\t{lp}{lp.signature_for(get_type)}\n")
124 file
.write
("end # {self}\n")