annotate dmd/Expression.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents b0d41ff5e0df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 109
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TOK;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
6 import dmd.Parameter;
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
7 import dmd.IdentifierExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Scope;
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
11 import dmd.Array;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.IntRange;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.TypeExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.DYNCAST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.TemplateInstance;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.NullExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.AddrExp;
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
36 import dmd.LINK;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
37 import dmd.FuncExp;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
38 import dmd.ReturnStatement;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
39 import dmd.Statement;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
40 import dmd.FuncLiteralDeclaration;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
41 import dmd.TypeFunction;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.ErrorExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.Global;
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
46 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.TypeClass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.PtrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.TypeReference;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.Complex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.elem;
141
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
56 import dmd.backend.Util;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
59 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
60
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
61 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
62
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 import std.stdio : writef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 import std.conv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 /* Things like:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 * int.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 * foo.size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 * (foo).size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 * cast(foo).size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 Expression typeDotIdExp(Loc loc, Type type, Identifier ident)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 return new DotIdExp(loc, new TypeExp(loc, type), ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 * Determine if 'this' is available.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 * If it is, return the FuncDeclaration that has it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 FuncDeclaration hasThis(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 FuncDeclaration fdthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 //printf("hasThis()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 fdthis = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 //printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis.toChars() : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 // Go upwards until we find the enclosing member function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 fd = fdthis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (!fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (!fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 Dsymbol parent = fd.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 while (parent)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 TemplateInstance ti = parent.isTemplateInstance();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 if (ti)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 parent = ti.parent;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 fd = fd.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (!fd.isThis())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 //printf("test '%s'\n", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 goto Lno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 assert(fd.vthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 return fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 Lno:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 return null; // don't have 'this' available
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 * Pull out any properties.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 Expression resolveProperties(Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 //printf("resolveProperties(%s)\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 if (e.type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 Type t = e.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 if (t.ty == TY.Tfunction || e.op == TOK.TOKoverloadset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 {
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
142 static if(false)
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
143 {
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
144 if (t.ty == Tfunction && !(cast(TypeFunction)t).isproperty)
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
145 error(e.loc, "not a property %s\n", e.toChars());
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
146 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 e = new CallExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 /* Look for e being a lazy parameter; rewrite as delegate call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 else if (e.op == TOK.TOKvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 { VarExp ve = cast(VarExp)e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (ve.var.storage_class & STC.STClazy)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 e = new CallExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 else if (e.op == TOK.TOKdotexp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 e.error("expression has no value");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 else if (e.op == TOK.TOKdottd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 e = new CallExp(e.loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
177 void indent(int indent)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
178 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
179 foreach (i; 0 .. indent)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
180 writef(" ");
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
181 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
182
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
183 string type_print(Type type)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
184 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
185 return type ? type.toChars() : "null";
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
186 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
187
178
e3afd1303184 Many small bugs fixed
korDen
parents: 141
diff changeset
188 import dmd.TObject;
e3afd1303184 Many small bugs fixed
korDen
parents: 141
diff changeset
189
e3afd1303184 Many small bugs fixed
korDen
parents: 141
diff changeset
190 class Expression : TObject
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
192 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
193
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 Loc loc; // file location
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 TOK op; // handy to minimize use of dynamic_cast
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 Type type; // !=null means that semantic() has been run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 int size; // # of bytes in Expression so we can copy() it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 this(Loc loc, TOK op, int size)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 141
diff changeset
201 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 //writef("Expression.Expression(op = %d %s) this = %p\n", op, to!(string)(op), this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 this.op = op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 this.size = size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 type = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 23
diff changeset
209 bool equals(Object o)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 return this is o;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 /*********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 * Does *not* do a deep copy.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 */
178
e3afd1303184 Many small bugs fixed
korDen
parents: 141
diff changeset
217 Expression copy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 141
diff changeset
219 return cloneThis(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 Expression syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 //printf("Expression::syntaxCopy()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 //dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 return copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 printf("Expression.semantic() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 type = type.semantic(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 Expression trySemantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 uint errors = global.errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 global.gag++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 Expression e = semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 global.gag--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 if (errors != global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 global.errors = errors;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 DYNCAST dyncast() { return DYNCAST.DYNCAST_EXPRESSION; } // kludge for template.isExpression()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 void print()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 string toChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 HdrGenState hgs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 toCBuffer(buf, &hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 return buf.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
271 void dump(int i)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
273 indent(i);
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
274 writef("%p %s type=%s\n", this, Token.toChars(op), type_print(type));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 .error(loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 void warning(T...)(string formar, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 .warning(loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 void rvalue()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 if (type && type.toBasetype().ty == TY.Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 error("expression %s is void and has no value", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 static Expression combine(Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 if (e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 if (e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 e1 = new CommaExp(e1.loc, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 e1.type = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 e1 = e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 return e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 static Expressions arraySyntaxCopy(Expressions exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 Expressions a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 if (exps)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 a = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 a.setDim(exps.dim);
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
326 for (size_t i = 0; i < a.dim; i++)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 {
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
328 auto e = exps[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
330 if (e)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
331 e = e.syntaxCopy();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
332 a[i] = e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 return a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 ulong toInteger()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
340 //printf("Expression %s\n", Token.toChars(op));
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
341 error("Integer constant expression expected instead of %s", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
342 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 ulong toUInteger()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 //printf("Expression %s\n", Token.toChars(op));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 return cast(ulong)toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 real toReal()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
353 error("Floating point constant expression expected instead of %s", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
354 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 real toImaginary()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
359 error("Floating point constant expression expected instead of %s", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
360 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 Complex!(real) toComplex()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
365 error("Floating point constant expression expected instead of %s", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
366 return Complex!real(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 buf.writestring(Token.toChars(op));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 void toMangleBuffer(OutBuffer buf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 {
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
376 error("expression %s is not a valid template value argument", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 assert(false);
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
378 version (DEBUG) {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
379 dump(0);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
380 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382
66
efb1e5bdf63c more implementations
korDen
parents: 55
diff changeset
383 /***************************************
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
384 * Return true if expression is an lvalue.
66
efb1e5bdf63c more implementations
korDen
parents: 55
diff changeset
385 */
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
386 bool isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
388 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 }
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
390
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
391 /*******************************
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
392 * Give error if we're not an lvalue.
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
393 * If we can, convert expression to be an lvalue.
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
394 */
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
395 Expression toLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
397 if (!e)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
398 e = this;
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
399 else if (!loc.filename)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
400 loc = e.loc;
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
401 error("%s is not an lvalue", e.toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
402 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 }
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
404
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 Expression modifiableLvalue(Scope sc, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 //printf("Expression::modifiableLvalue() %s, type = %s\n", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 // See if this expression is a modifiable lvalue (i.e. not const)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 if (type && (!type.isMutable() || !type.isAssignable()))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 error("%s is not mutable", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 return toLvalue(sc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 * Do an implicit cast.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 * Issue error if it can't be done.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 Expression implicitCastTo(Scope sc, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 //printf("Expression.implicitCastTo(%s of type %s) => %s\n", toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 MATCH match = implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 if (match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 TY tyfrom = type.toBasetype().ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 TY tyto = t.toBasetype().ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 if (global.params.warnings &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 Type.impcnvWarn[tyfrom][tyto] &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 op != TOKint64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 Expression e = optimize(WANT.WANTflags | WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 if (e.op == TOK.TOKint64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 return e.implicitCastTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 if (tyfrom == Tint32 && (op == TOKadd || op == TOKmin || op == TOKand || op == TOKor || op == TOKxor))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 /* This is really only a semi-kludge fix,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 * we really should look at the operands of op
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 * and see if they are narrower types.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 * For example, b=b|b and b=b|7 and s=b+b should be allowed,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 * but b=b|i should be an error.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 warning("implicit conversion of expression (%s) of type %s to %s can cause loss of data", toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 if (match == MATCH.MATCHconst && t == type.constOf())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 Expression e = copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 return castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 Expression e = optimize(WANT.WANTflags | WANT.WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 if (e != this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 return e.implicitCastTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 printf("ty = %d\n", type.ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 type.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 printf("to:\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 t.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 printf("%p %p type: %s to: %s\n", type.deco, t.deco, type.deco, t.deco);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 //printf("%p %p %p\n", type.nextOf().arrayOf(), type, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 fflush(stdout);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 if (!t.deco) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 /* Can happen with:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 * enum E { One }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 * class A
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 * { static void fork(EDG dg) { dg(E.One); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 * alias void delegate(E) EDG;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 * }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 * Should eventually make it work.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 error("forward reference to type %s", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 } else if (t.reliesOnTident()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 error("forward reference to type %s", t.reliesOnTident().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 error("cannot implicitly convert expression (%s) of type %s to %s", toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 return castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 * Return !=0 if we can implicitly convert this to type t.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 * Don't do the actual cast.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 MATCH implicitConvTo(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 printf("Expression.implicitConvTo(this=%s, type=%s, t=%s)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 //static int nest; if (++nest == 10) halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 error("%s is not an expression", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 type = Type.terror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 Expression e = optimize(WANT.WANTvalue | WANT.WANTflags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 if (e.type == t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 return MATCH.MATCHexact;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 if (e != this)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 //printf("\toptimized to %s of type %s\n", e.toChars(), e.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 return e.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 MATCH match = type.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 if (match != MATCH.MATCHnomatch)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 return match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 /* See if we can do integral narrowing conversions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 if (type.isintegral() && t.isintegral() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 type.isTypeBasic() && t.isTypeBasic())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 IntRange ir = getIntRange();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 if (ir.imax <= t.sizemask())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 Type tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 if (tb.ty == Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 TypeDelegate td = cast(TypeDelegate)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 TypeFunction tf = cast(TypeFunction)td.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 if (!tf.varargs && !(tf.arguments && tf.arguments.dim))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 match = type.implicitConvTo(tf.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 if (match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 return match;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 if (tf.nextOf().toBasetype().ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 return MATCH.MATCHconvert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 return MATCH.MATCHnomatch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 IntRange getIntRange()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 {
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 45
diff changeset
559 IntRange ir;
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 45
diff changeset
560 ir.imin = 0;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
561 if (type.isintegral())
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
562 ir.imax = type.sizemask();
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
563 else
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
564 ir.imax = 0xFFFFFFFFFFFFFFFFUL; // assume the worst
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
565
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 45
diff changeset
566 return ir;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 * Do an explicit cast.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 Expression castTo(Scope sc, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 //printf("Expression.castTo(this=%s, t=%s)\n", toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 writef("Expression.castTo(this=%s, type=%s, t=%s)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 toChars(), type.toChars(), t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 if (type is t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 Type tb = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 Type typeb = type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 if (tb != typeb)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 // Do (type *) cast of (type [dim])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 if (tb.ty == TY.Tpointer && typeb.ty == TY.Tsarray
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 //printf("Converting [dim] to *\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 if (typeb.size(loc) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 e = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 e = new AddrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 if (tb.ty == Tdelegate && type.ty != Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 TypeDelegate td = cast(TypeDelegate)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 TypeFunction tf = cast(TypeFunction)td.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 return toDelegate(sc, tf.nextOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 if (typeb.ty == TY.Tstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 TypeStruct ts = cast(TypeStruct)typeb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 if (!(tb.ty == TY.Tstruct && ts.sym == (cast(TypeStruct)tb).sym) &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 ts.sym.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 { /* Forward the cast to our alias this member, rewrite to:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 * cast(to)e1.aliasthis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 Expression e1 = new DotIdExp(loc, this, ts.sym.aliasthis.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 Expression e2 = new CastExp(loc, e1, tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 return e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 else if (typeb.ty == TY.Tclass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 TypeClass ts = cast(TypeClass)typeb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 if (tb.ty != TY.Tclass && ts.sym.aliasthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 { /* Forward the cast to our alias this member, rewrite to:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 * cast(to)e1.aliasthis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 Expression e1 = new DotIdExp(loc, this, ts.sym.aliasthis.ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 Expression e2 = new CastExp(loc, e1, tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 return e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 e = new CastExp(loc, e, tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 e = e.copy(); // because of COW for assignment to e.type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 assert(e != this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 //printf("Returning: %s\n", e.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 * Detect cases where pointers to the stack can 'escape' the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 * lifetime of the stack frame.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 void checkEscape()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
655 void checkEscapeRef()
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
656 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
657 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
658
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 void checkScalar()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 if (!type.isscalar())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 error("'%s' is not a scalar, it is a %s", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 void checkNoBool()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 if (type.toBasetype().ty == TY.Tbool)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 error("operation not allowed on bool '%s'", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 Expression checkIntegral()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 if (!type.isintegral())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 error("'%s' is not of integral type, it is a %s", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 Expression checkArithmetic()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 if (!type.isintegral() && !type.isfloating())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 error("'%s' is not of arithmetic type, it is a %s", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 return new ErrorExp();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 rvalue();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 void checkDeprecated(Scope sc, Dsymbol s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 s.checkDeprecated(loc, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 void checkPurity(Scope sc, FuncDeclaration f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 if (sc.func)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
707 /* Given:
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
708 * void f()
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
709 * { pure void g()
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
710 * {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
711 * void h()
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
712 * {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
713 * void i() { }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
714 * }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
715 * }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
716 * }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
717 * g() can call h() but not f()
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
718 * i() can call h() and g() but not f()
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
719 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 FuncDeclaration outerfunc = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 while (outerfunc.toParent2() && outerfunc.toParent2().isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 outerfunc = outerfunc.toParent2().isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
725 if (outerfunc.isPure() && !sc.intypeof && (!f.isNested() && !f.isPure()))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 error("pure function '%s' cannot call impure function '%s'\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 sc.func.toChars(), f.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 if (sc.func && sc.func.isPure() && !sc.intypeof && !f.isPure())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 error("pure function '%s' cannot call impure function '%s'\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 sc.func.toChars(), .toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
735
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
736 void checkSafety(Scope sc, FuncDeclaration f)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
737 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
738 if (sc.func && sc.func.isSafe() && !sc.intypeof &&
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
739 !f.isSafe() && !f.isTrusted())
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
740 error("safe function '%s' cannot call system function '%s'\n",
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
741 sc.func.toChars(), f.toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
742 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 /*****************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 * Check that expression can be tested for true or false.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 Expression checkToBoolean()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 // Default is 'yes' - do nothing
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 if (!type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 dump(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 if (!type.checkBoolean())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 error("expression %s of type %s does not have a boolean value", toChars(), type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 Expression checkToPointer()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 {
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
766 //writef("Expression::checkToPointer()\n");
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
767 Expression e = this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
769 version(SARRAYVALUE) {} else
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
770 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 // If C static array, convert to pointer
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
772 Type tb = type.toBasetype();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 if (tb.ty == Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 TypeSArray ts = cast(TypeSArray)tb;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 if (ts.size(loc) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 e = new NullExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 e = new AddrExp(loc, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 e.type = ts.next.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 }
109
ceda59b4d255 expression.c changes, now only ddoc should be left
Trass3r
parents: 95
diff changeset
782 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 Expression addressOf(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 //printf("Expression::addressOf()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 Expression e = toLvalue(sc, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 e = new AddrExp(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 e.type = type.pointerTo();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 * If this is a reference, dereference it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 Expression deref()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 //printf("Expression::deref()\n");
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
801 // type could be null if forward referencing an 'auto' variable
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
802 if (type && type.ty == Treference)
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
803 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 Expression e = new PtrExp(loc, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 e.type = (cast(TypeReference)type).next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 * Do integral promotions (convertchk).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 * Don't convert <array of> to <pointer to>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 Expression integralPromotions(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 //printf("integralPromotions %s %s\n", e.toChars(), e.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 switch (type.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 case TY.Tvoid:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 error("void has no value");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 case TY.Tint8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 case TY.Tuns8:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 case TY.Tint16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 case TY.Tuns16:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 case TY.Tbit:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 case TY.Tbool:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 case TY.Tchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 case TY.Twchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 e = e.castTo(sc, Type.tint32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 case TY.Tdchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 e = e.castTo(sc, Type.tuns32);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
846 /********************************************
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
847 * Convert from expression to delegate that returns the expression,
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
848 * i.e. convert:
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
849 * expr
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
850 * to:
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
851 * t delegate() { return expr; }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
852 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 Expression toDelegate(Scope sc, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 {
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
855 //printf("Expression.toDelegate(t = %s) %s\n", t.toChars(), toChars());
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
856 TypeFunction tf = new TypeFunction(null, t, 0, LINKd);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
857 FuncLiteralDeclaration fld = new FuncLiteralDeclaration(loc, loc, tf, TOKdelegate, null);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
858 Expression e;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
859 static if (true) {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
860 sc = sc.push();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
861 sc.parent = fld; // set current function to be the delegate
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
862 e = this;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
863 e.scanForNestedRef(sc);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
864 sc = sc.pop();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
865 } else {
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
866 e = this.syntaxCopy();
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
867 }
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
868 Statement s = new ReturnStatement(loc, e);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
869 fld.fbody = s;
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
870 e = new FuncExp(loc, fld);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
871 e = e.semantic(sc);
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
872 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 void scanForNestedRef(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 {
55
8c2c7b7579f8 Expression.toMangleBuffer
korDen
parents: 53
diff changeset
877 //printf("Expression.scanForNestedRef(%s)\n", toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 Expression optimize(int result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 //printf("Expression.optimize(result = x%x) %s\n", result, toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
886 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 {
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
888 version(LOG)
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
889 {
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
890 writef("Expression::interpret() %s\n", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
891 writef("type = %s\n", type.toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
892 dump(0);
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
893 }
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
894 error("Cannot interpret %s at compile time", toChars());
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 84
diff changeset
895 return EXP_CANT_INTERPRET;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 int isConst()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 //printf("Expression::isConst(): %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 * Does this expression statically evaluate to a boolean TRUE or FALSE?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 bool isBool(bool result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911
141
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
912 /********************************
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
913 * Does this expression result in either a 1 or a 0?
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
914 */
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
915 bool isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 {
141
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
917 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 * Check for expressions that have no use.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 * flag 0 not going to use the result, so issue error message if no
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 * side effects
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 * 1 the result of the expression is used, but still check
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 * for useless subexpressions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 * 2 do not issue error messages, just return !=0 if expression
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 * has side effects
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 bool checkSideEffect(int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 if (flag == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 {
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
934 if (op == TOKerror)
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
935 {
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
936 // Error should have already been printed
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
937 }
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 66
diff changeset
938 else if (op == TOKimport)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 error("%s has no effect", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 error("%s has no effect in expression (%s)",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 Token.toChars(op), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 bool canThrow()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
958 /****************************************
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
959 * Resolve __LINE__ and __FILE__ to loc.
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
960 */
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
961 Expression resolveLoc(Loc loc, Scope sc)
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
962 {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
963 return this;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
964 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
965
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 //printf("Expression.doInline(%s): %s\n", Token.toChars(op), toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 return copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 Expression inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 * Determine if operands of binary op can be reversed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 * to fit operator overload.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 // For operator overloading
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 bool isCommutative()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 return false; // default is no reverse
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 * Get Identifier for operator overload.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 Identifier opId()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 * Get Identifier for reverse operator overload,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 * null if not supported for this operator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 Identifier opId_r()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 // For array ops
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1011 /******************************************
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1012 * Construct the identifier for the array operation function,
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1013 * and build the argument list to pass to it.
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1014 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 void buildArrayIdent(OutBuffer buf, Expressions arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1017 buf.writestring("Exp");
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
1018 arguments.shift(this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
1021 Expression buildArrayLoop(Parameters fparams)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 {
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1023 Identifier id = Identifier.generateId("c", fparams.dim);
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 126
diff changeset
1024 auto param = new Parameter(STC.STCundefined, type, id, null);
126
1765f3ef917d ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1025 fparams.shift(param);
12
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1026 Expression e = new IdentifierExp(Loc(0), id);
832f71e6f96c *Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents: 4
diff changeset
1027 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 }
95
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1029
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1030 /***********************************************
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1031 * Test if operand is a valid array op operand.
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1032 */
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1033 int isArrayOperand()
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1034 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1035 //writef("Expression::isArrayOperand() %s\n", toChars());
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1036 if (op == TOKslice)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1037 return 1;
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1038 if (type.toBasetype().ty == TY.Tarray)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1039 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1040 switch (op)
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1041 {
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1042 case TOKadd:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1043 case TOKmin:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1044 case TOKmul:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1045 case TOKdiv:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1046 case TOKmod:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1047 case TOKxor:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1048 case TOKand:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1049 case TOKor:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1050 case TOKneg:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1051 case TOKtilde:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1052 return 1;
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1053
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1054 default:
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1055 break;
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1056 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1057 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1058 return 0;
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1059 }
ae5b11064a9a beginning of 2.036 branch
Trass3r
parents: 93
diff changeset
1060
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 {
141
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1064 print();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 assert(false);
141
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1066 return null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 dt_t** toDt(dt_t** pdt)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 {
141
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1071 debug
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1072 {
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1073 writef("Expression::toDt() %d\n", op);
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1074 dump(0);
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1075 }
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1076 error("non-constant expression %s", toChars());
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1077 pdt = dtnzeros(pdt, 1);
7171e6ea651d + Expression.toElem
Trass3r
parents: 135
diff changeset
1078 return pdt;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 }
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1080 }
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
1081
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
1082 alias Vector!Expression Expressions;