Mercurial > projects > ddmd
comparison dmd/TypeFunction.d @ 129:010eb8f0e18d
further work on dmd test suite
author | korDen |
---|---|
date | Sun, 05 Sep 2010 15:32:22 +0400 |
parents | 1765f3ef917d |
children | 60bb0fe4563e |
comparison
equal
deleted
inserted
replaced
128:e6e542f37b94 | 129:010eb8f0e18d |
---|---|
13 import dmd.STC; | 13 import dmd.STC; |
14 import dmd.MOD; | 14 import dmd.MOD; |
15 import dmd.PROT; | 15 import dmd.PROT; |
16 import dmd.TypeIdentifier; | 16 import dmd.TypeIdentifier; |
17 import dmd.TemplateParameter; | 17 import dmd.TemplateParameter; |
18 import dmd.TypeInfoFunctionDeclaration; | |
18 import dmd.Tuple; | 19 import dmd.Tuple; |
19 import dmd.Type; | 20 import dmd.Type; |
20 import dmd.Loc; | 21 import dmd.Loc; |
21 import dmd.Scope; | 22 import dmd.Scope; |
22 import dmd.Identifier; | 23 import dmd.Identifier; |
40 import dmd.backend.mTY; | 41 import dmd.backend.mTY; |
41 | 42 |
42 import core.stdc.stdlib; | 43 import core.stdc.stdlib; |
43 import core.stdc.string; | 44 import core.stdc.string; |
44 | 45 |
46 import std.stdio; | |
47 | |
45 class TypeFunction : TypeNext | 48 class TypeFunction : TypeNext |
46 { | 49 { |
47 // .next is the return type | 50 // .next is the return type |
48 | 51 |
49 Arguments parameters; // function parameters | 52 Arguments parameters; // function parameters |
101 t.inuse = inuse; | 104 t.inuse = inuse; |
102 | 105 |
103 if (parameters) | 106 if (parameters) |
104 { | 107 { |
105 t.parameters = parameters.copy(); | 108 t.parameters = parameters.copy(); |
106 for (size_t i = 0; i < parameters.dim; i++) | 109 foreach (arg; parameters) |
107 { | 110 { |
108 Argument arg = cast(Argument)parameters.data[i]; | |
109 Argument cpy = arg.clone(); | 111 Argument cpy = arg.clone(); |
110 t.parameters.data[i] = cast(void*)cpy; | 112 t.parameters[i] = cpy; |
111 } | 113 } |
112 } | 114 } |
113 | 115 |
114 return t; | 116 return t; |
115 } | 117 } |
116 | 118 |
117 TypeFunction clone() | 119 TypeFunction clone() |
118 { | 120 { |
119 assert(this.classinfo == TypeFunction.classinfo); | 121 assert(this.classinfo is TypeFunction.classinfo); |
120 return cloneTo(new TypeFunction(null, next, varargs, linkage)); | 122 return cloneTo(new TypeFunction(null, next, varargs, linkage)); |
121 } | 123 } |
122 } | 124 } |
123 override Type semantic(Loc loc, Scope sc) | 125 override Type semantic(Loc loc, Scope sc) |
124 { | 126 { |
133 /* Copy in order to not mess up original. | 135 /* Copy in order to not mess up original. |
134 * This can produce redundant copies if inferring return type, | 136 * This can produce redundant copies if inferring return type, |
135 * as semantic() will get called again on this. | 137 * as semantic() will get called again on this. |
136 */ | 138 */ |
137 | 139 |
138 TypeFunction tf = cast(TypeFunction)clone(); | 140 TypeFunction tf = cloneThis(this); |
139 | 141 |
140 if (sc.stc & STC.STCpure) | 142 if (sc.stc & STC.STCpure) |
141 tf.ispure = true; | 143 tf.ispure = true; |
142 if (sc.stc & STC.STCnothrow) | 144 if (sc.stc & STC.STCnothrow) |
143 tf.isnothrow = true; | 145 tf.isnothrow = true; |
149 { | 151 { |
150 tf.next = tf.next.semantic(loc,sc); | 152 tf.next = tf.next.semantic(loc,sc); |
151 version(SARRAYVALUE) {} else | 153 version(SARRAYVALUE) {} else |
152 { | 154 { |
153 if (tf.next.toBasetype().ty == TY.Tsarray) | 155 if (tf.next.toBasetype().ty == TY.Tsarray) |
154 { error(loc, "functions cannot return static array %s", tf.next.toChars()); | 156 { |
157 error(loc, "functions cannot return static array %s", tf.next.toChars()); | |
155 tf.next = Type.terror; | 158 tf.next = Type.terror; |
156 } | 159 } |
157 } | 160 } |
158 if (tf.next.toBasetype().ty == TY.Tfunction) | 161 if (tf.next.toBasetype().ty == TY.Tfunction) |
159 { error(loc, "functions cannot return a function"); | 162 { |
163 error(loc, "functions cannot return a function"); | |
160 tf.next = Type.terror; | 164 tf.next = Type.terror; |
161 } | 165 } |
162 if (tf.next.toBasetype().ty == TY.Ttuple) | 166 if (tf.next.toBasetype().ty == TY.Ttuple) |
163 { error(loc, "functions cannot return a tuple"); | 167 { |
168 error(loc, "functions cannot return a tuple"); | |
164 tf.next = Type.terror; | 169 tf.next = Type.terror; |
165 } | 170 } |
166 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) | 171 if (tf.next.isauto() && !(sc.flags & SCOPE.SCOPEctor)) |
167 error(loc, "functions cannot return scope %s", tf.next.toChars()); | 172 error(loc, "functions cannot return scope %s", tf.next.toChars()); |
168 } | 173 } |
169 | 174 |
170 if (tf.parameters) | 175 if (tf.parameters) |
171 { | 176 { |
172 /* Create a scope for evaluating the default arguments for the parameters | 177 /* Create a scope for evaluating the default arguments for the parameters |
496 return Type.deduceType(sc, tparam, parameters, dedtypes); | 501 return Type.deduceType(sc, tparam, parameters, dedtypes); |
497 } | 502 } |
498 | 503 |
499 override TypeInfoDeclaration getTypeInfoDeclaration() | 504 override TypeInfoDeclaration getTypeInfoDeclaration() |
500 { | 505 { |
501 assert(false); | 506 return new TypeInfoFunctionDeclaration(this); |
502 } | 507 } |
503 | 508 |
504 override Type reliesOnTident() | 509 override Type reliesOnTident() |
505 { | 510 { |
506 if (parameters) | 511 if (parameters) |