annotate dmd/TypeFunction.d @ 131:206db751bd4c

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