comparison dmd/ConditionalDeclaration.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 427f8aa74d28 01cadcfa4842
comparison
equal deleted inserted replaced
-1:000000000000 0:10317f0c89a5
1 module dmd.ConditionalDeclaration;
2
3 import dmd.AttribDeclaration;
4 import dmd.Condition;
5 import dmd.Array;
6 import dmd.Dsymbol;
7 import dmd.Scope;
8 import dmd.ScopeDsymbol;
9 import dmd.OutBuffer;
10 import dmd.HdrGenState;
11
12 class ConditionalDeclaration : AttribDeclaration
13 {
14 Condition condition;
15 Array elsedecl; // array of Dsymbol's for else block
16
17 this(Condition condition, Array decl, Array elsedecl)
18 {
19 super(decl);
20 //printf("ConditionalDeclaration::ConditionalDeclaration()\n");
21 this.condition = condition;
22 this.elsedecl = elsedecl;
23 }
24
25 Dsymbol syntaxCopy(Dsymbol s)
26 {
27 assert(false);
28 }
29
30 bool oneMember(Dsymbol* ps)
31 {
32 assert(false);
33 }
34
35 void emitComment(Scope sc)
36 {
37 assert(false);
38 }
39
40 // Decide if 'then' or 'else' code should be included
41
42 Array include(Scope sc, ScopeDsymbol sd)
43 {
44 //printf("ConditionalDeclaration::include()\n");
45 assert(condition);
46 return condition.include(sc, sd) ? decl : elsedecl;
47 }
48
49 void addComment(ubyte* comment)
50 {
51 /* Because addComment is called by the parser, if we called
52 * include() it would define a version before it was used.
53 * But it's no problem to drill down to both decl and elsedecl,
54 * so that's the workaround.
55 */
56
57 if (comment)
58 {
59 Array d = decl;
60
61 for (int j = 0; j < 2; j++)
62 {
63 if (d)
64 {
65 for (uint i = 0; i < d.dim; i++)
66 {
67 Dsymbol s = cast(Dsymbol)d.data[i];
68 //printf("ConditionalDeclaration::addComment %s\n", s->toChars());
69 s.addComment(comment);
70 }
71 }
72 d = elsedecl;
73 }
74 }
75 }
76
77 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
78 {
79 assert(false);
80 }
81 }