Mercurial > projects > ddmd
comparison 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 |
comparison
equal
deleted
inserted
replaced
78:b98fa8a4bf04 | 79:43073c7c7769 |
---|---|
22 this.elsedecl = elsedecl; | 22 this.elsedecl = elsedecl; |
23 } | 23 } |
24 | 24 |
25 override Dsymbol syntaxCopy(Dsymbol s) | 25 override Dsymbol syntaxCopy(Dsymbol s) |
26 { | 26 { |
27 ConditionalDeclaration dd; | 27 ConditionalDeclaration dd; |
28 | 28 |
29 assert(!s); | 29 assert(!s); |
30 dd = new ConditionalDeclaration(condition.syntaxCopy(), | 30 dd = new ConditionalDeclaration(condition.syntaxCopy(), |
31 Dsymbol.arraySyntaxCopy(decl), | 31 Dsymbol.arraySyntaxCopy(decl), |
32 Dsymbol.arraySyntaxCopy(elsedecl)); | 32 Dsymbol.arraySyntaxCopy(elsedecl)); |
33 return dd; | 33 return dd; |
34 } | 34 } |
35 | 35 |
36 override bool oneMember(Dsymbol* ps) | 36 override bool oneMember(Dsymbol* ps) |
37 { | 37 { |
38 //printf("ConditionalDeclaration.oneMember(), inc = %d\n", condition.inc); | 38 //printf("ConditionalDeclaration.oneMember(), inc = %d\n", condition.inc); |
45 return true; | 45 return true; |
46 } | 46 } |
47 | 47 |
48 override void emitComment(Scope sc) | 48 override void emitComment(Scope sc) |
49 { | 49 { |
50 //printf("ConditionalDeclaration.emitComment(sc = %p)\n", sc); | 50 //printf("ConditionalDeclaration.emitComment(sc = %p)\n", sc); |
51 if (condition.inc) | 51 if (condition.inc) |
52 { | 52 { |
53 AttribDeclaration.emitComment(sc); | 53 AttribDeclaration.emitComment(sc); |
54 } | 54 } |
55 else if (sc.docbuf) | 55 else if (sc.docbuf) |
56 { | 56 { |
57 /* If generating doc comment, be careful because if we're inside | 57 /* If generating doc comment, be careful because if we're inside |
58 * a template, then include(NULL, NULL) will fail. | 58 * a template, then include(NULL, NULL) will fail. |
59 */ | 59 */ |
60 auto d = decl ? decl : elsedecl; | 60 auto d = decl ? decl : elsedecl; |
61 foreach(s; d) | 61 foreach(s; d) |
62 s.emitComment(sc); | 62 s.emitComment(sc); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 // Decide if 'then' or 'else' code should be included | 66 // Decide if 'then' or 'else' code should be included |
67 | 67 |
68 override Dsymbols include(Scope sc, ScopeDsymbol sd) | 68 override Dsymbols include(Scope sc, ScopeDsymbol sd) |
70 //printf("ConditionalDeclaration.include()\n"); | 70 //printf("ConditionalDeclaration.include()\n"); |
71 assert(condition); | 71 assert(condition); |
72 return condition.include(sc, sd) ? decl : elsedecl; | 72 return condition.include(sc, sd) ? decl : elsedecl; |
73 } | 73 } |
74 | 74 |
75 override void addComment(ubyte* comment) | 75 override void addComment(string comment) |
76 { | 76 { |
77 /* Because addComment is called by the parser, if we called | 77 /* Because addComment is called by the parser, if we called |
78 * include() it would define a version before it was used. | 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, | 79 * But it's no problem to drill down to both decl and elsedecl, |
80 * so that's the workaround. | 80 * so that's the workaround. |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) | 100 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
101 { | 101 { |
102 condition.toCBuffer(buf, hgs); | 102 condition.toCBuffer(buf, hgs); |
103 if (decl || elsedecl) | 103 if (decl || elsedecl) |
104 { | |
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 } | |
131 } | |
132 else | |
133 buf.writeByte(':'); | |
134 buf.writenl(); | |
135 } | |
136 | |
137 override void toJsonBuffer(OutBuffer buf) | |
138 { | |
139 // writef("ConditionalDeclaration::toJsonBuffer()\n"); | |
140 if (condition.inc) | |
141 { | |
142 super.toJsonBuffer(buf); | |
143 } | |
144 } | |
145 | |
146 override void importAll(Scope sc) | |
104 { | 147 { |
105 buf.writenl(); | 148 Dsymbols d = include(sc, null); |
106 buf.writeByte('{'); | 149 |
107 buf.writenl(); | 150 //writef("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d); |
108 if (decl) | 151 if (d) |
109 { | 152 { |
110 foreach (Dsymbol s; decl) | 153 foreach (s; d) |
111 { | 154 s.importAll(sc); |
112 buf.writestring(" "); | 155 } |
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 } | |
131 } | 156 } |
132 else | 157 |
133 buf.writeByte(':'); | 158 override void setScope(Scope sc) |
134 buf.writenl(); | 159 { |
135 } | 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 } | |
136 } | 170 } |