annotate dmd/TypeFunction.d @ 96:acd69f84627e

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