1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2012 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 private import more_collections
26 redef class ToolContext
27 # Option --ignore-visibility
28 var opt_ignore_visibility
= new OptionBool("Do not check, and produce errors, on visibility issues", "--ignore-visibility")
33 option_context
.add_option
(opt_ignore_visibility
)
36 # Combine module to make a single one if required.
37 fun make_main_module
(mmodules
: Array[MModule]): MModule
39 assert not mmodules
.is_empty
41 # We need a main module, so we build it by importing all modules
42 mainmodule
= new MModule(modelbuilder
.model
, null, mmodules
.first
.name
+ "-m", new Location(mmodules
.first
.location
.file
, 0, 0, 0, 0))
43 mainmodule
.is_fictive
= true
44 mainmodule
.first_real_mmodule
= mmodules
.first
.first_real_mmodule
45 mainmodule
.set_imported_mmodules
(mmodules
)
46 modelbuilder
.apply_conditional_importations
(mainmodule
)
47 modelbuilder
.run_phases
51 # Run `process_mainmodule` on all phases
52 fun run_global_phases
(mmodules
: Array[MModule])
54 if not mmodules
.is_empty
then
55 var mainmodule
= make_main_module
(mmodules
)
56 for phase
in phases_list
do
57 if phase
.disabled
then continue
58 phase
.process_mainmodule
(mainmodule
, mmodules
)
68 # Specific action to execute on the whole program.
69 # Called by the `ToolContext::run_global_phases`.
71 # `mainmodule` is the main module of the program.
72 # It could be an implicit module (called like the first given_mmodules).
74 # `given_modules` is the list of explicitely requested modules.
75 # from the command-line for instance.
77 # REQUIRE: `not given_modules.is_empty`
78 # REQUIRE: `(given_modules.length == 1) == (mainmodule == given_modules.first)`
81 fun process_mainmodule
(mainmodule
: MModule, given_mmodules
: SequenceRead[MModule]) do end
85 redef class ModelBuilder
86 # Run phases on all loaded modules
89 var mmodules
= parsed_modules
.to_a
90 model
.mmodule_importation_hierarchy
.sort
(mmodules
)
91 var nmodules
= new Array[AModule]
93 if mm
.is_fictive
then continue
94 nmodules
.add
(mmodule2node
(mm
).as(not null))
96 toolcontext
.run_phases
(nmodules
)
98 if toolcontext
.opt_only_metamodel
.value
then
99 self.toolcontext
.info
("*** ONLY METAMODEL", 1)