annotate dmd/TypeFunction.d @ 123:9e39c7de8438

Make dmd test suite compile
author korDen
date Fri, 03 Sep 2010 20:46:58 +0400
parents e28b18c23469
children 1765f3ef917d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 113
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TypeArray;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
7 import dmd.TemplateTupleParameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.MOD;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
15 import dmd.PROT;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
16 import dmd.TypeIdentifier;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
17 import dmd.TemplateParameter;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
18 import dmd.Tuple;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.CppMangleState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TypeInfoDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Argument;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.RET;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Util;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
33 import dmd.TemplateInstance : isTuple;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.backend.PARAM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.TF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 class TypeFunction : TypeNext
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 // .next is the return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Arguments parameters; // function parameters
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 int varargs; // 1: T t, ...) style for variable number of arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 // 2: T t ...) style for variable number of arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 bool isnothrow; // true: nothrow
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 bool ispure; // true: pure
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 bool isproperty; // can be called without parentheses
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 bool isref; // true: returns a reference
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 LINK linkage; // calling convention
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 int inuse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 this(Arguments parameters, Type treturn, int varargs, LINK linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 super(TY.Tfunction, treturn);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 //if (!treturn) *(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 // assert(treturn);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 assert(0 <= varargs && varargs <= 2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 this.parameters = parameters;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 this.varargs = varargs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 this.linkage = linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
72 override Type syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 Type treturn = next ? next.syntaxCopy() : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 Arguments params = Argument.arraySyntaxCopy(parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 TypeFunction t = new TypeFunction(params, treturn, varargs, linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 t.mod = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 t.isnothrow = isnothrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 t.ispure = ispure;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 t.isproperty = isproperty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 t.isref = isref;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 version (DumbClone) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 final TypeFunction cloneTo(TypeFunction t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 super.cloneTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 // these 3 should be set by ctor
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 assert(t.parameters is null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 assert(t.varargs == varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 assert(t.linkage == linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 t.isnothrow = isnothrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 t.ispure = ispure;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 t.isproperty = isproperty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 t.isref = isref;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 t.inuse = inuse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (parameters)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 t.parameters = parameters.copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 for (size_t i = 0; i < parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Argument arg = cast(Argument)parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Argument cpy = arg.clone();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 t.parameters.data[i] = cast(void*)cpy;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 TypeFunction clone()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 assert(this.classinfo == TypeFunction.classinfo);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return cloneTo(new TypeFunction(null, next, varargs, linkage));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
123 override Type semantic(Loc loc, Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if (deco) // if semantic() already run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 //printf("already done\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 //printf("TypeFunction.semantic() this = %p\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 //printf("TypeFunction.semantic() %s, sc.stc = %x\n", toChars(), sc.stc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 /* Copy in order to not mess up original.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 * This can produce redundant copies if inferring return type,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 * as semantic() will get called again on this.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 TypeFunction tf = cast(TypeFunction)clone();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 if (sc.stc & STC.STCpure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 tf.ispure = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (sc.stc & STC.STCnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 tf.isnothrow = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 if (sc.stc & STC.STCref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 tf.isref = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 tf.linkage = sc.linkage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 if (tf.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 tf.next = tf.next.semantic(loc,sc);
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
151 version(SARRAYVALUE) {} else
acd69f84627e further work
Trass3r
parents: 95
diff changeset
152 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 if (tf.next.toBasetype().ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 { error(loc, "functions cannot return static array %s", tf.next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 tf.next = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
157 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 if (tf.next.toBasetype().ty == TY.Tfunction)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 { error(loc, "functions cannot return a function");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 tf.next = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 if (tf.next.toBasetype().ty == TY.Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 { error(loc, "functions cannot return a tuple");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 tf.next = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 error(loc, "functions cannot return scope %s", tf.next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (tf.parameters)
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
171 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
172 /* Create a scope for evaluating the default arguments for the parameters
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
173 */
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
174 Scope argsc = sc.push();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
175 argsc.stc = STCundefined; // don't inherit storage class
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
176 argsc.protection = PROT.PROTpublic;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
177
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
178 size_t dim = Argument.dim(tf.parameters);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 for (size_t i = 0; i < dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 { Argument arg = Argument.getNth(tf.parameters, i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 tf.inuse++;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
184 arg.type = arg.type.semantic(loc, argsc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (tf.inuse == 1) tf.inuse--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 arg.type = arg.type.addStorageClass(arg.storageClass);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (arg.storageClass & (STC.STCauto | STC.STCalias | STC.STCstatic))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 if (!arg.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 Type t = arg.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
199 //if (t.ty == TY.Tsarray)
acd69f84627e further work
Trass3r
parents: 95
diff changeset
200 //error(loc, "cannot have out or ref parameter of type %s", t.toChars());
acd69f84627e further work
Trass3r
parents: 95
diff changeset
201 if (arg.storageClass & STC.STCout && arg.type.mod & (STCconst | STCimmutable))
acd69f84627e further work
Trass3r
parents: 95
diff changeset
202 error(loc, "cannot have const or immutabl out parameter of type %s", t.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (!(arg.storageClass & STC.STClazy) && t.ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 error(loc, "cannot have parameter of type %s", arg.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 if (arg.defaultArg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
209 arg.defaultArg = arg.defaultArg.semantic(argsc);
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
210 arg.defaultArg = resolveProperties(argsc, arg.defaultArg);
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
211 arg.defaultArg = arg.defaultArg.implicitCastTo(argsc, arg.type);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 /* If arg turns out to be a tuple, the number of parameters may
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 * change.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 if (t.ty == TY.Ttuple)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 { dim = Argument.dim(tf.parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 i--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
222 argsc.pop();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 if (tf.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 tf.deco = tf.merge().deco;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 if (tf.inuse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 { error(loc, "recursive type");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 tf.inuse = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 return terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 if (tf.varargs == 1 && tf.linkage != LINK.LINKd && Argument.dim(tf.parameters) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 error(loc, "variadic functions with non-D linkage must have at least one parameter");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 /* Don't return merge(), because arg identifiers and default args
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 * can be different
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 * even though the types match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 return tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
243 override void toDecoBuffer(OutBuffer buf, int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 ubyte mc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 //printf("TypeFunction.toDecoBuffer() this = %p %s\n", this, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 //static int nest; if (++nest == 50) *(char*)0=0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 if (inuse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 inuse = 2; // flag error to caller
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 inuse++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (mod & MOD.MODshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 buf.writeByte('O');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 if (mod & MOD.MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 buf.writeByte('x');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 else if (mod & MOD.MODinvariant)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 buf.writeByte('y');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 switch (linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 case LINK.LINKd: mc = 'F'; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 case LINK.LINKc: mc = 'U'; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 case LINK.LINKwindows: mc = 'W'; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 case LINK.LINKpascal: mc = 'V'; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 case LINK.LINKcpp: mc = 'R'; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 buf.writeByte(mc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 if (ispure || isnothrow || isproperty || isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 buf.writestring("Na");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (isnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 buf.writestring("Nb");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if (isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 buf.writestring("Nc");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 if (isproperty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 buf.writestring("Nd");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 // Write argument types
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 Argument.argsToDecoBuffer(buf, parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 //if (buf.data[buf.offset - 1] == '@') halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 buf.writeByte('Z' - varargs); // mark end of arg list
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
287 assert(next);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 next.toDecoBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 inuse--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
292 override void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 //printf("TypeFunction.toCBuffer() this = %p\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 string p = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 if (inuse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 inuse = 2; // flag error to caller
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 inuse++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 /* Use 'storage class' style for attributes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 if (mod & MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 buf.writestring("const ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 if (mod & MODinvariant)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 buf.writestring("immutable ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 if (mod & MODshared)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 buf.writestring("shared ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 if (ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 buf.writestring("pure ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 if (isnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 buf.writestring("nothrow ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (isproperty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 buf.writestring("@property ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 if (isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 buf.writestring("ref ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (next && (!ident || ident.toHChars2() == ident.toChars()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 next.toCBuffer2(buf, hgs, MODundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 if (hgs.ddoc != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 switch (linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 case LINKd: p = null; break;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
329 case LINKc: p = " C"; break;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
330 case LINKwindows: p = " Windows"; break;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
331 case LINKpascal: p = " Pascal"; break;
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 72
diff changeset
332 case LINKcpp: p = " C++"; break;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 if (!hgs.hdrgen && p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 buf.writestring(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 if (ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 buf.writeByte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 buf.writestring(ident.toHChars2());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 Argument.argsToCBuffer(buf, hgs, parameters, varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 inuse--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
349 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 //printf("TypeFunction::toCBuffer2() this = %p, ref = %d\n", this, isref);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 string p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 if (inuse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 inuse = 2; // flag error to caller
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 inuse++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 if (next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 next.toCBuffer2(buf, hgs, MODundefined);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 if (hgs.ddoc != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 switch (linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 case LINKd: p = null; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 case LINKc: p = "C "; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 case LINKwindows: p = "Windows "; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 case LINKpascal: p = "Pascal "; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 case LINKcpp: p = "C++ "; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 default: assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 if (!hgs.hdrgen && p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 buf.writestring(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 buf.writestring(" function");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 Argument.argsToCBuffer(buf, hgs, parameters, varargs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 /* Use postfix style for attributes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 if (mod != this.mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 modToBuffer(buf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 if (ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 buf.writestring(" pure");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 if (isnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 buf.writestring(" nothrow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 if (isproperty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 buf.writestring(" @property");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 if (isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 buf.writestring(" ref");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 inuse--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
401 override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
403 //printf("TypeFunction.deduceType()\n");
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
404 //printf("\tthis = %d, ", ty); print();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
405 //printf("\ttparam = %d, ", tparam.ty); tparam.print();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
406
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
407 // Extra check that function characteristics must match
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
408 if (tparam && tparam.ty == Tfunction)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
409 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
410 TypeFunction tp = cast(TypeFunction)tparam;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
411 if (varargs != tp.varargs ||
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
412 linkage != tp.linkage)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
413 return MATCHnomatch;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
414
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
415 size_t nfargs = Argument.dim(this.parameters);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
416 size_t nfparams = Argument.dim(tp.parameters);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
417
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
418 /* See if tuple match
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
419 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
420 if (nfparams > 0 && nfargs >= nfparams - 1)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
421 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
422 /* See if 'A' of the template parameter matches 'A'
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
423 * of the type of the last function parameter.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
424 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
425 Argument fparam = Argument.getNth(tp.parameters, nfparams - 1);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
426 assert(fparam);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
427 assert(fparam.type);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
428 if (fparam.type.ty != Tident)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
429 goto L1;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
430 TypeIdentifier tid = cast(TypeIdentifier)fparam.type;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
431 if (tid.idents.dim)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
432 goto L1;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
433
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
434 /* Look through parameters to find tuple matching tid.ident
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
435 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
436 size_t tupi = 0;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
437 for (; 1; tupi++)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
438 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
439 if (tupi == parameters.dim)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
440 goto L1;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
441 TemplateParameter t = parameters[tupi];
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
442 TemplateTupleParameter tup = t.isTemplateTupleParameter();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
443 if (tup && tup.ident.equals(tid.ident))
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
444 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
445 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
446
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
447 /* The types of the function arguments [nfparams - 1 .. nfargs]
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
448 * now form the tuple argument.
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
449 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
450 int tuple_dim = nfargs - (nfparams - 1);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
451
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
452 /* See if existing tuple, and whether it matches or not
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
453 */
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
454 Object o = dedtypes[tupi];
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
455 if (o)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
456 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
457 // Existing deduced argument must be a tuple, and must match
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
458 Tuple t = isTuple(o);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
459 if (!t || t.objects.dim != tuple_dim)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
460 return MATCHnomatch;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
461 for (size_t i = 0; i < tuple_dim; i++)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
462 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
463 Argument arg = Argument.getNth(this.parameters, nfparams - 1 + i);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
464 if (!arg.type.equals(t.objects[i]))
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
465 return MATCHnomatch;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
466 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
467 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
468 else
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
469 { // Create new tuple
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
470 Tuple t = new Tuple();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
471 t.objects.setDim(tuple_dim);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
472 for (size_t i = 0; i < tuple_dim; i++)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
473 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
474 Argument arg = Argument.getNth(this.parameters, nfparams - 1 + i);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
475 t.objects[i] = arg.type;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
476 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
477 dedtypes[tupi] = t;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
478 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
479 nfparams--; // don't consider the last parameter for type deduction
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
480 goto L2;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
481 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
482
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
483 L1:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
484 if (nfargs != nfparams)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
485 return MATCHnomatch;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
486 L2:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
487 for (size_t i = 0; i < nfparams; i++)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
488 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
489 Argument a = Argument.getNth(this.parameters, i);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
490 Argument ap = Argument.getNth(tp.parameters, i);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
491 if (a.storageClass != ap.storageClass ||
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
492 !a.type.deduceType(sc, ap.type, parameters, dedtypes))
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
493 return MATCHnomatch;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
494 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
495 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
496 return Type.deduceType(sc, tparam, parameters, dedtypes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
499 override TypeInfoDeclaration getTypeInfoDeclaration()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
504 override Type reliesOnTident()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 if (parameters)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 for (size_t i = 0; i < parameters.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 Argument arg = cast(Argument)parameters.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 Type t = arg.type.reliesOnTident();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 if (t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 return next.reliesOnTident();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 version (CPP_MANGLE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 void toCppMangle(OutBuffer buf, CppMangleState* cms)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 /***************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 * Examine function signature for parameter p and see if
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 * p can 'escape' the scope of the function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 bool parameterEscapes(Argument p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 /* Scope parameters do not escape.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 * Allow 'lazy' to imply 'scope' -
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 * lazy parameters can be passed along
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 * as lazy parameters to the next function, but that isn't
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 * escaping.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 if (p.storageClass & (STC.STCscope | STC.STClazy))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 if (ispure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 { /* With pure functions, we need only be concerned if p escapes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 * via any return statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 Type tret = nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 if (!isref && !tret.hasPointers())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 { /* The result has no references, so p could not be escaping
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 * that way.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 /* Assume it escapes in the absence of better information.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 * 'args' are being matched to function 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 * Determine match level.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 * MATCHxxxx
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 MATCH callMatch(Expression ethis, Expressions args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 //printf("TypeFunction.callMatch() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 MATCH match = MATCH.MATCHexact; // assume exact match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 if (ethis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 Type t = ethis.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 if (t.toBasetype().ty == TY.Tpointer)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 t = t.toBasetype().nextOf(); // change struct* to struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 if (t.mod != mod)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 if (mod == MOD.MODconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 match = MATCH.MATCHconst;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 return MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 size_t nparams = Argument.dim(parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 size_t nargs = args ? args.dim : 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 if (nparams == nargs) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 } else if (nargs > nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 if (varargs == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 goto Nomatch; // too many args; no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 match = MATCH.MATCHconvert; // match ... with a "conversion" match level
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 for (size_t u = 0; u < nparams; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 MATCH m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 Expression arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 // BUG: what about out and ref?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 Argument p = Argument.getNth(parameters, u);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 assert(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 if (u >= nargs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 if (p.defaultArg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 if (varargs == 2 && u + 1 == nparams)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 goto Nomatch; // not enough arguments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 96
diff changeset
614 arg = cast(Expression)args[u];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 assert(arg);
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
616 // writef("arg: %s, type: %s\n", arg.toChars(), arg.type.toChars());
acd69f84627e further work
Trass3r
parents: 95
diff changeset
617
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 // Non-lvalues do not match ref or out parameters
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
620 if (p.storageClass & (STC.STCref | STC.STCout))
acd69f84627e further work
Trass3r
parents: 95
diff changeset
621 {
acd69f84627e further work
Trass3r
parents: 95
diff changeset
622 if (!arg.isLvalue())
acd69f84627e further work
Trass3r
parents: 95
diff changeset
623 goto Nomatch;
acd69f84627e further work
Trass3r
parents: 95
diff changeset
624 }
acd69f84627e further work
Trass3r
parents: 95
diff changeset
625
acd69f84627e further work
Trass3r
parents: 95
diff changeset
626 if (p.storageClass & STCref)
acd69f84627e further work
Trass3r
parents: 95
diff changeset
627 {
acd69f84627e further work
Trass3r
parents: 95
diff changeset
628 /* Don't allow static arrays to be passed to mutable refereces
acd69f84627e further work
Trass3r
parents: 95
diff changeset
629 * to static arrays if the argument cannot be modified.
acd69f84627e further work
Trass3r
parents: 95
diff changeset
630 */
acd69f84627e further work
Trass3r
parents: 95
diff changeset
631 Type targb = arg.type.toBasetype();
acd69f84627e further work
Trass3r
parents: 95
diff changeset
632 Type tparb = p.type.toBasetype();
acd69f84627e further work
Trass3r
parents: 95
diff changeset
633 //writef("%s\n", targb.toChars());
acd69f84627e further work
Trass3r
parents: 95
diff changeset
634 //writef("%s\n", tparb.toChars());
acd69f84627e further work
Trass3r
parents: 95
diff changeset
635 if (targb.nextOf() && tparb.ty == Tsarray &&
acd69f84627e further work
Trass3r
parents: 95
diff changeset
636 targb.nextOf().mod != tparb.nextOf().mod &&
acd69f84627e further work
Trass3r
parents: 95
diff changeset
637 !tparb.nextOf().isConst())
acd69f84627e further work
Trass3r
parents: 95
diff changeset
638 goto Nomatch;
acd69f84627e further work
Trass3r
parents: 95
diff changeset
639 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 m = MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 m = arg.implicitConvTo(p.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 //printf("\tm = %d\n", m);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 if (m == MATCH.MATCHnomatch) // if no match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 if (varargs == 2 && u + 1 == nparams) // if last varargs param
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 Type tb = p.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 TypeSArray tsa;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 long sz;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 switch (tb.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 case TY.Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 tsa = cast(TypeSArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 sz = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 if (sz != nargs - u)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 goto Nomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 TypeArray ta = cast(TypeArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 for (; u < nargs; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 96
diff changeset
667 arg = cast(Expression)args[u];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 assert(arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 /* If lazy array of delegates,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 * convert arg(s) to delegate(s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 Type tret = p.isLazyArray();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 if (tret)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 if (ta.next.equals(arg.type))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 m = MATCH.MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 m = arg.implicitConvTo(tret);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 if (m == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 if (tret.toBasetype().ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 m = MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 m = arg.implicitConvTo(ta.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 m = arg.implicitConvTo(ta.next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 if (m == MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 goto Nomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 if (m < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 match = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 case TY.Tclass:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 // Should see if there's a constructor match?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 // Or just leave it ambiguous?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 goto Nomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 goto Nomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 if (m < match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 match = m; // pick worst match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 Ldone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 //printf("match = %d\n", match);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 return match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 Nomatch:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 //printf("no match\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 return MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
730 override type* toCtype()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 if (ctype) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 return ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 if (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 param_t* paramtypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 tym_t tyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 type* tp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 paramtypes = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 size_t nparams = Argument.dim(parameters);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 for (size_t i = 0; i < nparams; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 Argument arg = Argument.getNth(parameters, i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 tp = arg.type.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 if (arg.storageClass & (STC.STCout | STC.STCref))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 // C doesn't have reference types, so it's really a pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 // to the parameter type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 tp = type_allocn(TYM.TYref, tp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 param_append_type(&paramtypes,tp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 tyf = totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 t = type_alloc(tyf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 t.Tflags |= TF.TFprototype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 if (varargs != 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 t.Tflags |= TF.TFfixed;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 t.Tnext = next.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 t.Tnext.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 t.Tparamtypes = paramtypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 ctype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 /***************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 * Determine return style of function - whether in registers or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 * through a hidden pointer to the caller's stack.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 */
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
775 RET retStyle()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 //printf("TypeFunction.retStyle() %s\n", toChars());
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
778 version (DMDV2)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
779 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 if (isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 return RET.RETregs; // returns a pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 Type tn = next.toBasetype();
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
785 Type tns = tn;
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
786 ulong sz = tn.size();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
788 version(SARRAYVALUE)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
789 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
790 if (tn.ty == Tsarray)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
791 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
792 do
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
793 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
794 tns = tns.nextOf().toBasetype();
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
795 } while (tns.ty == Tsarray);
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
796 if (tns.ty != Tstruct)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
797 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
798 if (global.params.isLinux && linkage != LINKd)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
799 {}
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
800 else
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
801 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
802 switch (sz)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
803 { case 1:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
804 case 2:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
805 case 4:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
806 case 8:
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
807 return RET.RETregs; // return small structs in regs
acd69f84627e further work
Trass3r
parents: 95
diff changeset
808 // (not 3 byte structs!)
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
809 default:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
810 break;
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
811 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
812 }
96
acd69f84627e further work
Trass3r
parents: 95
diff changeset
813 return RET.RETstack;
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
814 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
815 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
816 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
817 if (tns.ty == TY.Tstruct)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 StructDeclaration sd = (cast(TypeStruct)tn).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 if (global.params.isLinux && linkage != LINK.LINKd) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 }
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
823 ///version (DMDV2) { // TODO:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
824 else if (sd.dtor || sd.cpctor)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
825 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 {
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 79
diff changeset
830 switch (sz)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 case 4:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 case 8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 return RET.RETregs; // return small structs in regs
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 // (not 3 byte structs!)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 return RET.RETstack;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 else if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 linkage == LINK.LINKc &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 tn.iscomplex())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 if (tn.ty == TY.Tcomplex32)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 return RET.RETregs; // in EDX:EAX, not ST1:ST0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 return RET.RETstack;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 return RET.RETregs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 22
diff changeset
857 override TYM totym()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 TYM tyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 //printf("TypeFunction.totym(), linkage = %d\n", linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 switch (linkage)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 case LINK.LINKwindows:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnsfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 case LINK.LINKpascal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYnpfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 case LINK.LINKc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 tyf = TYM.TYnfunc;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
874 version (POSIX) {///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 if (retStyle() == RET.RETstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 tyf = TYM.TYhfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 case LINK.LINKd:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 tyf = (varargs == 1) ? TYM.TYnfunc : TYM.TYjfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 case LINK.LINKcpp:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 tyf = TYM.TYnfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 writef("linkage = %d\n", linkage);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 if (isnothrow)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 tyf |= mTY.mTYnothrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 return tyf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 }
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
898 }