0
|
1 module dmd.StaticIfDeclaration;
|
|
2
|
|
3 import dmd.ConditionalDeclaration;
|
|
4 import dmd.ScopeDsymbol;
|
|
5 import dmd.AttribDeclaration;
|
|
6 import dmd.Scope;
|
|
7 import dmd.Condition;
|
|
8 import dmd.Array;
|
|
9 import dmd.Dsymbol;
|
|
10
|
|
11 class StaticIfDeclaration : ConditionalDeclaration
|
|
12 {
|
|
13 ScopeDsymbol sd;
|
|
14 int addisdone;
|
|
15
|
|
16 this(Condition condition, Array decl, Array elsedecl)
|
|
17 {
|
|
18 super(condition, decl, elsedecl);
|
|
19 //printf("StaticIfDeclaration::StaticIfDeclaration()\n");
|
|
20 }
|
|
21
|
|
22 Dsymbol syntaxCopy(Dsymbol s)
|
|
23 {
|
|
24 assert(false);
|
|
25 }
|
|
26
|
|
27 bool addMember(Scope sc, ScopeDsymbol sd, int memnum)
|
|
28 {
|
|
29 //printf("StaticIfDeclaration.addMember() '%s'\n",toChars());
|
|
30 /* This is deferred until semantic(), so that
|
|
31 * expressions in the condition can refer to declarations
|
|
32 * in the same scope, such as:
|
|
33 *
|
|
34 * template Foo(int i)
|
|
35 * {
|
|
36 * const int j = i + 1;
|
|
37 * static if (j == 3)
|
|
38 * const int k;
|
|
39 * }
|
|
40 */
|
|
41 this.sd = sd;
|
|
42 bool m = false;
|
|
43
|
|
44 if (memnum == 0)
|
|
45 {
|
|
46 m = AttribDeclaration.addMember(sc, sd, memnum);
|
|
47 addisdone = 1;
|
|
48 }
|
|
49 return m;
|
|
50 }
|
|
51
|
|
52 void semantic(Scope sc)
|
|
53 {
|
|
54 Array d = include(sc, sd);
|
|
55
|
|
56 //printf("\tStaticIfDeclaration.semantic '%s', d = %p\n",toChars(), d);
|
|
57 if (d)
|
|
58 {
|
|
59 if (!addisdone)
|
|
60 {
|
|
61 AttribDeclaration.addMember(sc, sd, 1);
|
|
62 addisdone = 1;
|
|
63 }
|
|
64
|
|
65 for (uint i = 0; i < d.dim; i++)
|
|
66 {
|
|
67 Dsymbol s = cast(Dsymbol)d.data[i];
|
|
68
|
|
69 s.semantic(sc);
|
|
70 }
|
|
71 }
|
|
72 }
|
|
73
|
|
74 string kind()
|
|
75 {
|
|
76 assert(false);
|
|
77 }
|
|
78 } |