frontend: new phase and annotation `no_warning` to disable warning per module
authorJean Privat <jean@pryen.org>
Thu, 18 Dec 2014 20:12:13 +0000 (15:12 -0500)
committerJean Privat <jean@pryen.org>
Fri, 19 Dec 2014 01:23:59 +0000 (20:23 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/frontend/check_annotation.nit
src/frontend/frontend.nit
src/frontend/no_warning.nit [new file with mode: 0644]

index 7cd186e..2e45627 100644 (file)
@@ -88,6 +88,7 @@ old_style_init
 abstract
 intern
 extern
+no_warning
 
 pkgconfig
 c_compiler_option
index 53c1a77..713c6fa 100644 (file)
@@ -15,6 +15,7 @@
 # Collect and orchestration of main frontend phases
 module frontend
 
+import no_warning
 import simple_misc_analysis
 import literal
 import modelize
diff --git a/src/frontend/no_warning.nit b/src/frontend/no_warning.nit
new file mode 100644 (file)
index 0000000..c862075
--- /dev/null
@@ -0,0 +1,70 @@
+# 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.
+
+# Fill toolcontext information about blacklisting of warnings.
+module no_warning
+
+import modelbuilder
+private import literal
+
+redef class ToolContext
+       # The phase should be executed before any warning on the module is processed.
+       var no_warning_phase: Phase = new NoWarningPhase(self, [literal_phase])
+end
+
+private class NoWarningPhase
+       super Phase
+
+       redef fun process_nmodule(nmodule)
+       do
+               # Get the mmodule
+               var mmodule = nmodule.mmodule
+               assert mmodule != null
+
+               # If no decl block then quit
+               var nmoduledecl = nmodule.n_moduledecl
+               if nmoduledecl == null then return
+
+               var modelbuilder = toolcontext.modelbuilder
+
+               # Get all the new annotations
+               var name = "no_warning"
+               var annots = nmoduledecl.get_annotations(name)
+
+               if annots.is_empty then return
+
+               var source = nmodule.location.file
+               if source == null then
+                       modelbuilder.warning(annots.first, "file-less-module", "Warning: annotation `{name}` does not currently work on file-less modules.")
+                       return
+               end
+
+               for annot in annots do
+                       var args = annot.n_args
+                       if args.is_empty then
+                               modelbuilder.error(annot, "Annotation error: `{name}` needs a list of warnings. Use `\"all\"` to disable all warnings.")
+                               continue
+                       end
+                       for arg in args do
+                               var tag = arg.as_string
+                               if tag == null then
+                                       modelbuilder.error(arg, "Annotation error: `{name}` expects String as arguments.")
+                                       continue
+                               end
+
+                               toolcontext.warning_blacklist[source].add(tag)
+                       end
+               end
+       end
+end