various phases: more robust for keep-going
[nit.git] / src / frontend / no_warning.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 # Fill toolcontext information about blacklisting of warnings.
16 module no_warning
17
18 import modelbuilder
19 private import literal
20
21 redef class ToolContext
22 # The phase should be executed before any warning on the module is processed.
23 var no_warning_phase: Phase = new NoWarningPhase(self, [literal_phase])
24 end
25
26 private class NoWarningPhase
27 super Phase
28
29 redef fun process_nmodule(nmodule)
30 do
31 # Get the mmodule
32 var mmodule = nmodule.mmodule
33 if mmodule == null then return
34
35 var source = nmodule.location.file
36
37 # If no decl block then quit
38 var nmoduledecl = nmodule.n_moduledecl
39 if nmoduledecl == null then
40 # Disable `missing-doc` if there is no `module` clause
41 # Rationale: the presence of a `module` clause is a good heuristic to
42 # discriminate quick and dirty prototypes from nice and clean modules
43 if source != null then toolcontext.warning_blacklist[source].add("missing-doc")
44 return
45 end
46
47 var modelbuilder = toolcontext.modelbuilder
48
49 # Disable `missing-doc` for `test_suite`
50 if source != null and not nmoduledecl.get_annotations("test_suite").is_empty then
51 toolcontext.warning_blacklist[source].add("missing-doc")
52 end
53
54 # Get all the `no_warning` annotations
55 var name = "no_warning"
56 var annots = nmoduledecl.get_annotations(name)
57
58 if annots.is_empty then return
59
60 if source == null then
61 modelbuilder.warning(annots.first, "file-less-module", "Warning: annotation `{name}` does not currently work on file-less modules.")
62 return
63 end
64
65 for annot in annots do
66 var args = annot.n_args
67 if args.is_empty then
68 modelbuilder.error(annot, "Annotation error: `{name}` needs a list of warnings. Use `\"all\"` to disable all warnings.")
69 continue
70 end
71 for arg in args do
72 var tag = arg.as_string
73 if tag == null then
74 modelbuilder.error(arg, "Annotation error: `{name}` expects String as arguments.")
75 continue
76 end
77
78 toolcontext.warning_blacklist[source].add(tag)
79 end
80 end
81 end
82 end