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
24 private import nit_version
26 abstract 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
82 mod
.dump_module_info
(log_directory
)
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
("{log_directory}/{name}.full_class_hierarchy.new.dot")
89 f
.write
(class_hierarchy
.to_dot
)
92 f
= new OFStream.open
("{log_directory}/{name}.module_hierarchy.new.dot")
93 f
.write
(module_hierarchy
.to_dot
)
99 fun dump_module_info
(directory
: String)
101 var fname
= "{directory}/{name}"
102 var f
= new OFStream.open
("{fname}.class_hierarchy.new.dot")
103 f
.write
(class_specialization_hierarchy
.to_dot
)
106 f
= new OFStream.open
("{fname}.properties.log")
107 for cla
in local_classes
do
108 cla
.dump_properties
(f
)
115 redef class MMLocalClass
116 fun dump_properties
(file
: OStream)
118 file
.write
("class {self}\n")
119 if global
.visibility_level
== 3 and not self == global
.intro
then
120 file
.write
("\tclass not visible in this module\n")
121 else if mmmodule
.visibility_for
(global
.mmmodule
) == 0 then
122 file
.write
("\tclass is defined later in the hierarchy\n")
124 for p
in global_properties
do
126 file
.write
("\t{lp}{lp.signature_for(get_type)}\n")
129 file
.write
("end # {self}\n")