Mercurial > projects > ddmd
annotate dmd/Argument.d @ 56:51605de93870
TupleExp.optimize
UnrolledLoopStatement.ctor
UnrolledLoopStatement.semantic
UnrolledLoopStatement.blockExit
OrOrExp.checkSideEffect
FuncExp.syntaxCopy
FuncLiteralDeclaration.syntaxCopy
WhileStatement.hasBreak
StructInitializer.toExpression
StructLiteralExp.ctor
StructLiteralExp.optimize
BinExp.commonSemanticAssign
ModAssignExp.opId
Argument.isLazyArray
CommaExp.implicitConvTo
CommaExp.castTo
TypeClass.isBaseOf
createTypeInfoArray
TypeTuple.getTypeInfoDeclaration
TypeInfoTupleDeclaration.ctor
TypeNext.constConv
XorExp.implicitConvTo
TemplateParameter.isTemplateValueParameter
author | korDen |
---|---|
date | Sat, 21 Aug 2010 14:16:53 +0400 |
parents | 5c9b78899f5d |
children | e28b18c23469 |
rev | line source |
---|---|
0 | 1 module dmd.Argument; |
2 | |
3 import dmd.Type; | |
4 import dmd.Identifier; | |
56 | 5 import dmd.TypeArray; |
6 import dmd.TypeFunction; | |
7 import dmd.TypeDelegate; | |
0 | 8 import dmd.TypeTuple; |
9 import dmd.TY; | |
10 import dmd.Expression; | |
11 import dmd.OutBuffer; | |
12 import dmd.HdrGenState; | |
13 import dmd.ArrayTypes; | |
14 import dmd.StorageClassDeclaration; | |
15 import dmd.Global; | |
16 import dmd.MOD; | |
17 import dmd.CppMangleState; | |
18 import dmd.STC; | |
19 | |
20 class Argument | |
21 { | |
22 //enum InOut inout; | |
23 STC storageClass; | |
24 Type type; | |
25 Identifier ident; | |
26 Expression defaultArg; | |
27 | |
28 this(STC storageClass, Type type, Identifier ident, Expression defaultArg) | |
29 { | |
30 this.type = type; | |
31 this.ident = ident; | |
32 this.storageClass = storageClass; | |
33 this.defaultArg = defaultArg; | |
34 } | |
35 | |
36 Argument clone() | |
37 { | |
38 return new Argument(storageClass, type, ident, defaultArg); | |
39 } | |
40 | |
41 Argument syntaxCopy() | |
42 { | |
43 return new Argument(storageClass, type ? type.syntaxCopy() : null, ident, defaultArg ? defaultArg.syntaxCopy() : null); | |
44 } | |
45 | |
56 | 46 /**************************************************** |
47 * Determine if parameter is a lazy array of delegates. | |
48 * If so, return the return type of those delegates. | |
49 * If not, return null. | |
50 */ | |
0 | 51 Type isLazyArray() |
52 { | |
56 | 53 // if (inout == Lazy) |
54 { | |
55 Type tb = type.toBasetype(); | |
56 if (tb.ty == Tsarray || tb.ty == Tarray) | |
57 { | |
58 Type tel = (cast(TypeArray)tb).next.toBasetype(); | |
59 if (tel.ty == Tdelegate) | |
60 { | |
61 TypeDelegate td = cast(TypeDelegate)tel; | |
62 TypeFunction tf = cast(TypeFunction)td.next; | |
63 | |
64 if (!tf.varargs && Argument.dim(tf.parameters) == 0) | |
65 { | |
66 return tf.next; // return type of delegate | |
67 } | |
68 } | |
69 } | |
70 } | |
71 return null; | |
0 | 72 } |
73 | |
74 void toDecoBuffer(OutBuffer buf) | |
75 { | |
76 if (storageClass & STC.STCscope) | |
77 buf.writeByte('M'); | |
78 switch (storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STClazy)) | |
79 { | |
80 case STC.STCundefined: | |
81 case STC.STCin: | |
82 break; | |
83 case STC.STCout: | |
84 buf.writeByte('J'); | |
85 break; | |
86 case STC.STCref: | |
87 buf.writeByte('K'); | |
88 break; | |
89 case STC.STClazy: | |
90 buf.writeByte('L'); | |
91 break; | |
92 } | |
93 static if (false) { | |
94 int mod = 0x100; | |
95 if (type.toBasetype().ty == TY.Tclass) | |
96 mod = 0; | |
97 type.toDecoBuffer(buf, mod); | |
98 } else { | |
99 //type.toHeadMutable().toDecoBuffer(buf, 0); | |
100 type.toDecoBuffer(buf, 0); | |
101 } | |
102 } | |
103 | |
104 static Arguments arraySyntaxCopy(Arguments args) | |
105 { | |
106 Arguments a = null; | |
107 | |
108 if (args) | |
109 { | |
110 a = new Arguments(); | |
111 a.setDim(args.dim); | |
112 | |
113 for (size_t i = 0; i < a.dim; i++) | |
114 { | |
115 Argument arg = cast(Argument)args.data[i]; | |
116 | |
117 arg = arg.syntaxCopy(); | |
118 a.data[i] = cast(void*)arg; | |
119 } | |
120 } | |
121 | |
122 return a; | |
123 } | |
124 | |
125 static string argsTypesToChars(Arguments args, int varargs) | |
126 { | |
127 scope OutBuffer buf = new OutBuffer(); | |
128 | |
129 static if (true) { | |
130 HdrGenState hgs; | |
131 argsToCBuffer(buf, &hgs, args, varargs); | |
132 } else { | |
133 buf.writeByte('('); | |
134 if (args) | |
135 { | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
136 OutBuffer argbuf = new OutBuffer(); |
0 | 137 HdrGenState hgs; |
138 | |
139 for (int i = 0; i < args.dim; i++) | |
140 { | |
141 if (i) | |
142 buf.writeByte(','); | |
143 Argument arg = cast(Argument)args.data[i]; | |
144 argbuf.reset(); | |
145 arg.type.toCBuffer2(&argbuf, &hgs, 0); | |
146 buf.write(&argbuf); | |
147 } | |
148 if (varargs) | |
149 { | |
150 if (i && varargs == 1) | |
151 buf.writeByte(','); | |
152 buf.writestring("..."); | |
153 } | |
154 } | |
155 buf.writeByte(')'); | |
156 } | |
157 return buf.toChars(); | |
158 } | |
159 | |
160 static void argsCppMangle(OutBuffer buf, CppMangleState* cms, Arguments arguments, int varargs) | |
161 { | |
162 assert(false); | |
163 } | |
164 | |
165 static void argsToCBuffer(OutBuffer buf, HdrGenState* hgs, Arguments arguments, int varargs) | |
166 { | |
167 buf.writeByte('('); | |
168 if (arguments) | |
169 { | |
170 int i; | |
171 scope OutBuffer argbuf = new OutBuffer(); | |
172 | |
173 for (i = 0; i < arguments.dim; i++) | |
174 { | |
175 if (i) | |
176 buf.writestring(", "); | |
177 Argument arg = cast(Argument)arguments.data[i]; | |
178 | |
179 if (arg.storageClass & STCout) | |
180 buf.writestring("out "); | |
181 else if (arg.storageClass & STCref) | |
182 buf.writestring((global.params.Dversion == 1) ? "inout " : "ref "); | |
183 else if (arg.storageClass & STCin) | |
184 buf.writestring("in "); | |
185 else if (arg.storageClass & STClazy) | |
186 buf.writestring("lazy "); | |
187 else if (arg.storageClass & STCalias) | |
188 buf.writestring("alias "); | |
189 else if (arg.storageClass & STCauto) | |
190 buf.writestring("auto "); | |
191 | |
192 uint stc = arg.storageClass; | |
193 if (arg.type && arg.type.mod & MODshared) | |
194 stc &= ~STCshared; | |
195 | |
196 StorageClassDeclaration.stcToCBuffer(buf, stc & (STCconst | STCimmutable | STCshared | STCscope)); | |
197 | |
198 argbuf.reset(); | |
199 if (arg.storageClass & STCalias) | |
200 { | |
201 if (arg.ident) | |
202 argbuf.writestring(arg.ident.toChars()); | |
203 } | |
204 else | |
205 arg.type.toCBuffer(argbuf, arg.ident, hgs); | |
206 if (arg.defaultArg) | |
207 { | |
208 argbuf.writestring(" = "); | |
209 arg.defaultArg.toCBuffer(argbuf, hgs); | |
210 } | |
211 buf.write(argbuf); | |
212 } | |
213 if (varargs) | |
214 { | |
215 if (i && varargs == 1) | |
216 buf.writeByte(','); | |
217 buf.writestring("..."); | |
218 } | |
219 } | |
220 buf.writeByte(')'); | |
221 } | |
222 | |
223 static void argsToDecoBuffer(OutBuffer buf, Arguments arguments) | |
224 { | |
225 //printf("Argument::argsToDecoBuffer()\n"); | |
226 | |
227 // Write argument types | |
228 if (arguments) | |
229 { | |
230 size_t dim = Argument.dim(arguments); | |
231 for (size_t i = 0; i < dim; i++) | |
232 { | |
233 Argument arg = Argument.getNth(arguments, i); | |
234 arg.toDecoBuffer(buf); | |
235 } | |
236 } | |
237 } | |
238 | |
239 static int isTPL(Arguments arguments) | |
240 { | |
241 assert(false); | |
242 } | |
243 | |
244 /*************************************** | |
245 * Determine number of arguments, folding in tuples. | |
246 */ | |
247 static size_t dim(Arguments args) | |
248 { | |
249 size_t n = 0; | |
250 if (args) | |
251 { | |
252 for (size_t i = 0; i < args.dim; i++) | |
253 { | |
254 Argument arg = cast(Argument)args.data[i]; | |
255 Type t = arg.type.toBasetype(); | |
256 | |
257 if (t.ty == TY.Ttuple) | |
258 { | |
259 TypeTuple tu = cast(TypeTuple)t; | |
260 n += dim(tu.arguments); | |
261 } | |
262 else | |
263 n++; | |
264 } | |
265 } | |
266 return n; | |
267 } | |
268 | |
269 /*************************************** | |
270 * Get nth Argument, folding in tuples. | |
271 * Returns: | |
272 * Argument nth Argument | |
273 * null not found, *pn gets incremented by the number | |
274 * of Arguments | |
275 */ | |
276 static Argument getNth(Arguments args, size_t nth, size_t* pn = null) | |
277 { | |
278 if (!args) | |
279 return null; | |
280 | |
281 size_t n = 0; | |
282 for (size_t i = 0; i < args.dim; i++) | |
283 { | |
284 Argument arg = cast(Argument)args.data[i]; | |
285 Type t = arg.type.toBasetype(); | |
286 | |
287 if (t.ty == TY.Ttuple) | |
288 { TypeTuple tu = cast(TypeTuple)t; | |
289 arg = getNth(tu.arguments, nth - n, &n); | |
290 if (arg) | |
291 return arg; | |
292 } | |
293 else if (n == nth) | |
294 return arg; | |
295 else | |
296 n++; | |
297 } | |
298 | |
299 if (pn) | |
300 *pn += n; | |
301 | |
302 return null; | |
303 } | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
304 } |