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