annotate dmd/TypeFunction.d @ 130:60bb0fe4563e

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