Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / nitsaf.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 # Nit Static Analysis Framework client example.
16 module nitsaf
17
18 import saf
19 import test_phase
20 import frontend
21
22 redef class ToolContext
23
24 # Analysis to apply
25 var opt_analysis = new OptionEnum(["reaching-defs"], "Analysis to apply", 0, "--analysis")
26
27 redef init do
28 super
29 option_context.add_option(opt_analysis)
30 end
31 end
32
33 redef fun do_work(mainmodule, given_mmodules, modelbuilder) do
34 var toolcontext = modelbuilder.toolcontext
35
36 var analysis: StaticAnalysis
37 var analysis_name = toolcontext.opt_analysis.value_name
38 if analysis_name == "reaching-defs" then
39 analysis = new ReachingDefsAnalysis(modelbuilder)
40 else
41 print "Error: unkown analysis {analysis_name}"
42 sys.exit 1
43 return
44 end
45
46 var mainnode = modelbuilder.mmodule2node(mainmodule)
47 if mainnode == null then return
48 analysis.start_analysis(mainnode)
49 analysis.pretty_print
50 end