Mercurial > projects > ddmd
annotate dmd/ConditionalDeclaration.d @ 79:43073c7c7769
updated to 2.035
also implemented a few missing functions
still crashes in Import.importAll though
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 03:57:51 +0200 |
parents | ad4792a1cfd6 |
children | e28b18c23469 |
rev | line source |
---|---|
0 | 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; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
15 Dsymbols elsedecl; // array of Dsymbol's for else block |
0 | 16 |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
17 this(Condition condition, Dsymbols decl, Dsymbols elsedecl) |
0 | 18 { |
19 super(decl); | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
20 //printf("ConditionalDeclaration.ConditionalDeclaration()\n"); |
0 | 21 this.condition = condition; |
22 this.elsedecl = elsedecl; | |
23 } | |
24 | |
72 | 25 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 26 { |
79 | 27 ConditionalDeclaration dd; |
28 | |
29 assert(!s); | |
30 dd = new ConditionalDeclaration(condition.syntaxCopy(), | |
31 Dsymbol.arraySyntaxCopy(decl), | |
32 Dsymbol.arraySyntaxCopy(elsedecl)); | |
33 return dd; | |
0 | 34 } |
35 | |
72 | 36 override bool oneMember(Dsymbol* ps) |
0 | 37 { |
13 | 38 //printf("ConditionalDeclaration.oneMember(), inc = %d\n", condition.inc); |
39 if (condition.inc) | |
40 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
41 auto d = condition.include(null, null) ? decl : elsedecl; |
13 | 42 return Dsymbol.oneMembers(d, ps); |
43 } | |
44 *ps = null; | |
45 return true; | |
0 | 46 } |
47 | |
72 | 48 override void emitComment(Scope sc) |
0 | 49 { |
79 | 50 //printf("ConditionalDeclaration.emitComment(sc = %p)\n", sc); |
51 if (condition.inc) | |
52 { | |
53 AttribDeclaration.emitComment(sc); | |
54 } | |
55 else if (sc.docbuf) | |
56 { | |
57 /* If generating doc comment, be careful because if we're inside | |
58 * a template, then include(NULL, NULL) will fail. | |
59 */ | |
60 auto d = decl ? decl : elsedecl; | |
61 foreach(s; d) | |
62 s.emitComment(sc); | |
63 } | |
0 | 64 } |
65 | |
66 // Decide if 'then' or 'else' code should be included | |
67 | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
68 override Dsymbols include(Scope sc, ScopeDsymbol sd) |
0 | 69 { |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
70 //printf("ConditionalDeclaration.include()\n"); |
0 | 71 assert(condition); |
72 return condition.include(sc, sd) ? decl : elsedecl; | |
73 } | |
74 | |
79 | 75 override void addComment(string comment) |
0 | 76 { |
77 /* Because addComment is called by the parser, if we called | |
78 * include() it would define a version before it was used. | |
79 * But it's no problem to drill down to both decl and elsedecl, | |
80 * so that's the workaround. | |
81 */ | |
82 | |
83 if (comment) | |
84 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
85 auto d = decl; |
0 | 86 |
87 for (int j = 0; j < 2; j++) | |
88 { | |
89 if (d) | |
90 { | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
91 foreach(s; d) |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
92 //printf("ConditionalDeclaration::addComment %s\n", s.toChars()); |
0 | 93 s.addComment(comment); |
94 } | |
95 d = elsedecl; | |
96 } | |
97 } | |
98 } | |
99 | |
72 | 100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 101 { |
79 | 102 condition.toCBuffer(buf, hgs); |
103 if (decl || elsedecl) | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
104 { |
79 | 105 buf.writenl(); |
106 buf.writeByte('{'); | |
107 buf.writenl(); | |
108 if (decl) | |
109 { | |
110 foreach (Dsymbol s; decl) | |
111 { | |
112 buf.writestring(" "); | |
113 s.toCBuffer(buf, hgs); | |
114 } | |
115 } | |
116 buf.writeByte('}'); | |
117 if (elsedecl) | |
118 { | |
119 buf.writenl(); | |
120 buf.writestring("else"); | |
121 buf.writenl(); | |
122 buf.writeByte('{'); | |
123 buf.writenl(); | |
124 foreach (Dsymbol s; elsedecl) | |
125 { | |
126 buf.writestring(" "); | |
127 s.toCBuffer(buf, hgs); | |
128 } | |
129 buf.writeByte('}'); | |
130 } | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
131 } |
79 | 132 else |
133 buf.writeByte(':'); | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
134 buf.writenl(); |
79 | 135 } |
136 | |
137 override void toJsonBuffer(OutBuffer buf) | |
138 { | |
139 // writef("ConditionalDeclaration::toJsonBuffer()\n"); | |
140 if (condition.inc) | |
141 { | |
142 super.toJsonBuffer(buf); | |
143 } | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
144 } |
79 | 145 |
146 override void importAll(Scope sc) | |
147 { | |
148 Dsymbols d = include(sc, null); | |
149 | |
150 //writef("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d); | |
151 if (d) | |
152 { | |
153 foreach (s; d) | |
154 s.importAll(sc); | |
155 } | |
19
01cadcfa4842
Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
156 } |
79 | 157 |
158 override void setScope(Scope sc) | |
159 { | |
160 Dsymbols d = include(sc, null); | |
161 | |
162 //writef("\tConditionalDeclaration::setScope '%s', d = %p\n",toChars(), d); | |
163 if (d) | |
164 { | |
165 foreach (s; d) | |
166 s.setScope(sc); | |
167 } | |
168 | |
169 } | |
170 } |