Skip to content
← Back

src/syntax/process/collect_suppress_pragmas.ghul

1
namespace Syntax.Process is
2
use Source;
3
use Trees;
4
5
use Logging.Logger;
6
7
// Walks the AST, finds every `@suppress("slug", ...)` pragma, and
8
// registers a suppression region on the logger for each slug
9
// covering the wrapped definition or statement. Runs once per
10
// source file in a build, re-runs per file on each analyse-mode
11
// edit (the entry clears the file's regions before re-collecting).
12
//
13
// The regions are consulted by `DIAGNOSTICS_STORE.is_suppressed`
14
// at warn / info / hint emission time, so every IDed diagnostic
15
// benefits without per-pass push / pop wiring.
16
class COLLECT_SUPPRESS_PRAGMAS: Visitor is
17
_logger: Logger;
18
19
init(logger: Logger) is
20
super.init();
21
22
_logger = logger;
23
si
24
25
apply(source_file: Compiler.SOURCE_FILE) is
26
_logger.clear_suppression_regions(source_file.file_name);
27
28
source_file.definition.walk(self);
29
si
30
31
visit(pragma: Definitions.PRAGMA) is
32
_register(pragma.pragma, pragma.location);
33
si
34
35
visit(pragma: Statements.PRAGMA) is
36
_register(pragma.pragma, pragma.location);
37
si
38
39
_register(pragma: Pragmas.PRAGMA, region: LOCATION) is
40
if !pragma.is_name_equal_to("suppress") then
41
return;
42
fi
43
44
for i in 0..pragma.arguments.expressions.count do
45
let slug = pragma.try_get_string_literal_at(i);
46
47
if slug? /\ slug.length > 0 then
48
_logger.register_suppression_region(region, slug);
49
fi
50
od
51
si
52
si
53
si