Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / test_phase.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Stub for loading a runing phases on a bunch of modules
16 #
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.
19 #
20 # One other way is to redefine `do_work`. See `test_test_phase.nit`.
21 module test_phase
22
23 import modelbuilder
24
25 redef class ToolContext
26 var default_phase = new DefaultPhase(self, null)
27 end
28
29 # Empty phase that delegates `process_mainmodule` to the global `do_work`.
30 class DefaultPhase
31 super Phase
32 redef fun process_mainmodule(mainmodule, given_mmodules) do
33 do_work(mainmodule, given_mmodules, toolcontext.modelbuilder)
34 end
35 end
36
37 # Easy entry point to prototype a specific work or proof-of-concept.
38 #
39 # Complex or mature work should use the full `phase` framework to enable
40 # combination and orcherstration of works.
41 #
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.
45 #
46 # @toimplement
47 fun do_work(mainmodule: MModule, given_mmodules: SequenceRead[MModule], modelbuilder: ModelBuilder) do end
48
49 # Create a tool context to handle options and paths
50 var toolcontext = new ToolContext
51 toolcontext.tooldescription = "Usage: [OPTION]... <file.nit>..."
52
53 # We do not add other options, so process them now!
54 toolcontext.process_options(args)
55
56 # Get arguments
57 var arguments = toolcontext.option_context.rest
58
59 # We need a model to collect stufs
60 var model = new Model
61 # An a model builder to parse files
62 var modelbuilder = new ModelBuilder(model, toolcontext)
63
64 # Here we load an process all modules passed on the command line
65 var mmodules = modelbuilder.parse_full(arguments)
66 modelbuilder.run_phases
67 toolcontext.run_global_phases(mmodules)