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 # Stub for loading a runing phases on a bunch of modules
17 # The point is to refine this module in executable that does things.
18 # One simple way is to use the `-m` option of engines to plug various phases.
20 # One other way is to redefine `do_work`. See `test_test_phase.nit`.
25 redef class ToolContext
26 var default_phase
= new DefaultPhase(self, null)
29 # Empty phase that delegates `process_mainmodule` to the global `do_work`.
32 redef fun process_mainmodule
(mainmodule
, given_mmodules
) do
33 do_work
(mainmodule
, given_mmodules
, toolcontext
.modelbuilder
)
37 # Easy entry point to prototype a specific work or proof-of-concept.
39 # Complex or mature work should use the full `phase` framework to enable
40 # combination and orcherstration of works.
42 # * `mainmodule` is the bottom main module (possibly implicit).
43 # * `given_mmodules` is the exact list of module from the command line.
44 # * `modelbuilder` is the context that contains a lot of things.
47 fun do_work
(mainmodule
: MModule, given_mmodules
: SequenceRead[MModule], modelbuilder
: ModelBuilder) do end
49 # Create a tool context to handle options and paths
50 var toolcontext
= new ToolContext
51 toolcontext
.tooldescription
= "Usage: [OPTION]... <file.nit>..."
53 # We do not add other options, so process them now!
54 toolcontext
.process_options
(args
)
57 var arguments
= toolcontext
.option_context
.rest
59 # We need a model to collect stufs
61 # An a model builder to parse files
62 var modelbuilder
= new ModelBuilder(model
, toolcontext
)
64 # Here we load an process all modules passed on the command line
65 var mmodules
= modelbuilder
.parse
(arguments
)
66 modelbuilder
.run_phases
67 toolcontext
.run_global_phases
(mmodules
)