nitsaf: introduce `nitsaf` binary
authorAlexandre Terrasa <alexandre@moz-code.org>
Fri, 16 Oct 2015 23:10:27 +0000 (19:10 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 19 Dec 2015 08:40:58 +0000 (03:40 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/nitsaf.nit [new file with mode: 0644]

diff --git a/src/nitsaf.nit b/src/nitsaf.nit
new file mode 100644 (file)
index 0000000..8ba4239
--- /dev/null
@@ -0,0 +1,50 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Nit Static Analysis Framework client example.
+module nitsaf
+
+import saf
+import test_phase
+import frontend
+
+redef class ToolContext
+
+       # Analysis to apply
+       var opt_analysis = new OptionEnum(["reaching-defs"], "Analysis to apply", 0, "--analysis")
+
+       redef init do
+               super
+               option_context.add_option(opt_analysis)
+       end
+end
+
+redef fun do_work(mainmodule, given_mmodules, modelbuilder) do
+       var toolcontext = modelbuilder.toolcontext
+
+       var analysis: StaticAnalysis
+       var analysis_name = toolcontext.opt_analysis.value_name
+       if analysis_name == "reaching-defs" then
+               analysis = new ReachingDefsAnalysis(modelbuilder)
+       else
+               print "Error: unkown analysis {analysis_name}"
+               sys.exit 1
+               return
+       end
+
+       var mainnode = modelbuilder.mmodule2node(mainmodule)
+       if mainnode == null then return
+       analysis.start_analysis(mainnode)
+       analysis.pretty_print
+end