Skip to content
← Back

src/syntax/process/conditional_compilation.ghul

1
namespace Syntax.Process is
2
use IO.Std;
3
4
use Collections.Iterable;
5
6
use Logging;
7
use Source;
8
use Trees;
9
10
class CONDITIONAL_COMPILATION: Visitor is
11
_flags: Collections.MAP[string,bool];
12
13
is_analysis: bool;
14
15
init() is
16
super.init();
17
18
_flags = Collections.MAP[string,bool]();
19
si
20
21
set_is_enabled(names: Iterable[string]) is
22
for name in names do
23
set_is_enabled(name, true);
24
od
25
26
set_is_enabled("legacy", false);
27
set_is_enabled("dotnet", true);
28
si
29
30
set_is_enabled(name: string, value: bool) is
31
_flags[name] = value;
32
si
33
34
get_is_enabled(name: string mut) -> bool is
35
let not_result mut = false;
36
let result mut = false;
37
38
if name.starts_with("not.") then
39
name = name.substring(4);
40
41
not_result = true;
42
fi
43
44
if _flags.contains_key(name) then
45
result = _flags[name];
46
fi
47
48
if not_result then
49
return !result;
50
fi
51
52
return result;
53
si
54
55
get_is_enabled(pragma: Pragmas.PRAGMA) -> bool is
56
let name = pragma.name.to_string();
57
58
if !name.starts_with("IF.") then
59
return true;
60
fi
61
62
return get_is_enabled(name.substring(3));
63
si
64
65
apply(
66
node: Node
67
) is
68
node.walk(self);
69
si
70
71
// FIXME: pragma handling code is duplicated across multiple visitors
72
visit(pragma: Definitions.PRAGMA) is
73
if !get_is_enabled(pragma.pragma) then
74
pragma.definition =
75
Definitions.LIST(
76
pragma.definition.location,
77
Collections.LIST[Definitions.Definition](0)
78
);
79
fi
80
si
81
82
visit(pragma: Statements.PRAGMA) is
83
if !get_is_enabled(pragma.pragma) then
84
pragma.statement = null;
85
fi
86
si
87
si
88
si