annotate dmd/Parameter.d @ 191:52188e7e3fb5

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