summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/glcpp/tests/142-defined-within-macro.c
blob: b60c04232a6e21859b9acb8c28f3ec93d4f3d7f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* Macro using defined with a hard-coded identifier (no parentheses) */
#define is_foo_defined defined /*...*/ foo
#undef foo
#if is_foo_defined
failure
#else
success
#endif
#define foo
#if is_foo_defined
success
#else
failure
#endif

/* Macro using defined with a hard-coded identifier within parentheses */
#define is_foo_defined_parens defined /*...*/ ( /*...*/ foo /*...*/ ) //
#define foo
#if is_foo_defined_parens
success
#else
failure
#endif
#undef foo
#if is_foo_defined_parens
failure
#else
success
#endif

/* Macro using defined with an argument identifier (no parentheses) */
#define is_defined(arg) defined /*...*/ arg
#define foo bar
#undef bar
#if is_defined(foo)
failure
#else
success
#endif
#define bar bar
#if is_defined(foo)
success
#else
failure
#endif

/* Macro using defined with an argument identifier within parentheses */
#define is_defined_parens(arg) defined /*...*/ ( /*...*/ arg /*...*/ ) //
#define foo bar
#define bar bar
#if is_defined_parens(foo)
success
#else
failure
#endif
#undef bar
#if is_defined_parens(foo)
failure
#else
success
#endif

/* Multiple levels of macro resulting in defined */
#define X defined A && Y
#define Y defined B && Z
#define Z defined C
#define A
#define B
#define C
#if X
success
#else
failure
#endif
#undef A
#if X
failure
#else
success
#endif
#define A
#undef B
#if X
failure
#else
success
#endif
#define B
#undef C
#if X
failure
#else
success
#endif