annotate dmd/ConditionalDeclaration.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.ConditionalDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
13 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
14
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 class ConditionalDeclaration : AttribDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
17 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
18
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 Condition condition;
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
20 Dsymbols elsedecl; // array of Dsymbol's for else block
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
22 this(Condition condition, Dsymbols decl, Dsymbols elsedecl)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
24 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 super(decl);
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
26 //printf("ConditionalDeclaration.ConditionalDeclaration()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 this.condition = condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this.elsedecl = elsedecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
31 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
33 ConditionalDeclaration dd;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
34
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
35 assert(!s);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
36 dd = new ConditionalDeclaration(condition.syntaxCopy(),
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
37 Dsymbol.arraySyntaxCopy(decl),
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
38 Dsymbol.arraySyntaxCopy(elsedecl));
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
39 return dd;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
42 override bool oneMember(Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
44 //printf("ConditionalDeclaration.oneMember(), inc = %d\n", condition.inc);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
45 if (condition.inc)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
46 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
47 auto d = condition.include(null, null) ? decl : elsedecl;
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
48 return Dsymbol.oneMembers(d, ps);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
49 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
50 *ps = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
51 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
54 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
56 //printf("ConditionalDeclaration.emitComment(sc = %p)\n", sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
57 if (condition.inc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
58 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
59 AttribDeclaration.emitComment(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
60 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
61 else if (sc.docbuf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
62 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
63 /* If generating doc comment, be careful because if we're inside
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
64 * a template, then include(NULL, NULL) will fail.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
65 */
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
66 auto d = decl ? decl : elsedecl;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
67 foreach(s; d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
68 s.emitComment(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
69 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 // Decide if 'then' or 'else' code should be included
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
74 override Dsymbols include(Scope sc, ScopeDsymbol sd)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
76 //printf("ConditionalDeclaration.include()\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 assert(condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 return condition.include(sc, sd) ? decl : elsedecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
81 override void addComment(string comment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 /* Because addComment is called by the parser, if we called
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 * include() it would define a version before it was used.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 * But it's no problem to drill down to both decl and elsedecl,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 * so that's the workaround.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (comment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
91 auto d = decl;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 for (int j = 0; j < 2; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (d)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
97 foreach(s; d)
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
98 //printf("ConditionalDeclaration::addComment %s\n", s.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 s.addComment(comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 d = elsedecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
106 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
108 condition.toCBuffer(buf, hgs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
109 if (decl || elsedecl)
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
110 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
111 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
112 buf.writeByte('{');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
113 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
114 if (decl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
115 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
116 foreach (Dsymbol s; decl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
117 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
118 buf.writestring(" ");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
119 s.toCBuffer(buf, hgs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
120 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
121 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
122 buf.writeByte('}');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
123 if (elsedecl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
124 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
125 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
126 buf.writestring("else");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
127 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
128 buf.writeByte('{');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
129 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
130 foreach (Dsymbol s; elsedecl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
131 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
132 buf.writestring(" ");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
133 s.toCBuffer(buf, hgs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
134 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
135 buf.writeByte('}');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
136 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
137 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
138 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
139 buf.writeByte(':');
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
140 buf.writenl();
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
141 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
142
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
143 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
144 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
145 // writef("ConditionalDeclaration::toJsonBuffer()\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
146 if (condition.inc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
147 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
148 super.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
149 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
150 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
151
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
152 override void importAll(Scope sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
153 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
154 Dsymbols d = include(sc, null);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
155
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
156 //writef("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
157 if (d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
158 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
159 foreach (s; d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
160 s.importAll(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
161 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
162 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
163
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
164 override void setScope(Scope sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
165 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
166 Dsymbols d = include(sc, null);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
167
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
168 //writef("\tConditionalDeclaration::setScope '%s', d = %p\n",toChars(), d);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
169 if (d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
170 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
171 foreach (s; d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
172 s.setScope(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
173 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
174
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
175 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
176 }