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
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 class ConditionalDeclaration : AttribDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 this.condition = condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 this.elsedecl = elsedecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
25 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
27 ConditionalDeclaration dd;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
28
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
29 assert(!s);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
30 dd = new ConditionalDeclaration(condition.syntaxCopy(),
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
31 Dsymbol.arraySyntaxCopy(decl),
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
32 Dsymbol.arraySyntaxCopy(elsedecl));
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
33 return dd;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
36 override bool oneMember(Dsymbol* ps)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
13
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
38 //printf("ConditionalDeclaration.oneMember(), inc = %d\n", condition.inc);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
39 if (condition.inc)
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
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
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
42 return Dsymbol.oneMembers(d, ps);
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
43 }
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
44 *ps = null;
427f8aa74d28 On the road to make Phobos compilable
korDen
parents: 0
diff changeset
45 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
48 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
50 //printf("ConditionalDeclaration.emitComment(sc = %p)\n", sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
51 if (condition.inc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
52 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
53 AttribDeclaration.emitComment(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
54 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
55 else if (sc.docbuf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
56 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
57 /* If generating doc comment, be careful because if we're inside
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
58 * a template, then include(NULL, NULL) will fail.
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
59 */
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
60 auto d = decl ? decl : elsedecl;
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
61 foreach(s; d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
62 s.emitComment(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
63 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 // Decide if 'then' or 'else' code should be included
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 assert(condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 return condition.include(sc, sd) ? decl : elsedecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
75 override void addComment(string comment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 /* Because addComment is called by the parser, if we called
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 * include() it would define a version before it was used.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 * But it's no problem to drill down to both decl and elsedecl,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 * so that's the workaround.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 if (comment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 for (int j = 0; j < 2; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (d)
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 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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 s.addComment(comment);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 d = elsedecl;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 23
diff changeset
100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
102 condition.toCBuffer(buf, hgs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
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
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
105 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
106 buf.writeByte('{');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
107 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
108 if (decl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
109 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
110 foreach (Dsymbol s; decl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
111 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
112 buf.writestring(" ");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
113 s.toCBuffer(buf, hgs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
114 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
115 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
116 buf.writeByte('}');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
117 if (elsedecl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
118 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
119 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
120 buf.writestring("else");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
121 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
122 buf.writeByte('{');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
123 buf.writenl();
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
124 foreach (Dsymbol s; elsedecl)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
125 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
126 buf.writestring(" ");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
127 s.toCBuffer(buf, hgs);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
128 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
129 buf.writeByte('}');
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
130 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
131 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
132 else
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
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
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
135 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
136
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
137 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
138 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
139 // writef("ConditionalDeclaration::toJsonBuffer()\n");
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
140 if (condition.inc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
141 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
142 super.toJsonBuffer(buf);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
143 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
144 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
145
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
146 override void importAll(Scope sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
147 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
148 Dsymbols d = include(sc, null);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
149
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
150 //writef("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
151 if (d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
152 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
153 foreach (s; d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
154 s.importAll(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
155 }
19
01cadcfa4842 Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
156 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
157
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
158 override void setScope(Scope sc)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
159 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
160 Dsymbols d = include(sc, null);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
161
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
162 //writef("\tConditionalDeclaration::setScope '%s', d = %p\n",toChars(), d);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
163 if (d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
164 {
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
165 foreach (s; d)
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
166 s.setScope(sc);
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
167 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
168
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
169 }
43073c7c7769 updated to 2.035
Trass3r
parents: 77
diff changeset
170 }