Mercurial > projects > ddmd
annotate dmd/InExp.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 |
rev | line source |
---|---|
72 | 1 module dmd.InExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.Identifier; | |
6 import dmd.Loc; | |
7 import dmd.Scope; | |
8 import dmd.IRState; | |
9 import dmd.BinExp; | |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
10 import dmd.TOK; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
11 import dmd.Type; |
72 | 12 import dmd.Id; |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
13 import dmd.TY; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
14 import dmd.TypeAArray; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
15 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
16 import dmd.expression.util.arrayTypeCompatible; |
72 | 17 |
18 import dmd.backend.elem; | |
19 import dmd.backend.TYM; | |
20 import dmd.backend.mTY; | |
21 import dmd.backend.OPER; | |
22 import dmd.backend.Symbol; | |
23 import dmd.backend.Util; | |
24 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 |
0 | 27 class InExp : BinExp |
28 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
29 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 |
0 | 31 this(Loc loc, Expression e1, Expression e2) |
32 { | |
178 | 33 register(); |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
34 super(loc, TOKin, InExp.sizeof, e1, e2); |
0 | 35 } |
36 | |
72 | 37 override Expression semantic(Scope sc) |
0 | 38 { |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
39 if (type) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
40 return this; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
41 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
42 super.semanticp(sc); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
43 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
44 Expression e = op_overload(sc); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
45 if (e) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
46 return e; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
47 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
48 //type = Type.tboolean; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
49 Type t2b = e2.type.toBasetype(); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
50 if (t2b.ty != TY.Taarray) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
51 { |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
52 error("rvalue of in expression must be an associative array, not %s", e2.type.toChars()); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
53 type = Type.terror; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
54 } |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
55 else |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
56 { |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
57 TypeAArray ta = cast(TypeAArray)t2b; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
58 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
59 // Special handling for array keys |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
60 if (!arrayTypeCompatible(e1.loc, e1.type, ta.index)) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
61 { |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
62 // Convert key to type of key |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
63 e1 = e1.implicitCastTo(sc, ta.index); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
64 } |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
65 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
66 // Return type is pointer to value |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
67 type = ta.nextOf().pointerTo(); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
68 } |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
69 return this; |
0 | 70 } |
71 | |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
72 override bool isBit() |
0 | 73 { |
191
52188e7e3fb5
Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents:
187
diff
changeset
|
74 return false; |
0 | 75 } |
76 | |
72 | 77 override Identifier opId() |
0 | 78 { |
61 | 79 return Id.opIn; |
0 | 80 } |
81 | |
72 | 82 override Identifier opId_r() |
0 | 83 { |
62 | 84 return Id.opIn_r; |
0 | 85 } |
86 | |
72 | 87 override elem* toElem(IRState* irs) |
0 | 88 { |
72 | 89 elem* e; |
90 elem* key = e1.toElem(irs); | |
91 elem* aa = e2.toElem(irs); | |
92 elem* ep; | |
93 elem* keyti; | |
94 TypeAArray taa = cast(TypeAArray)e2.type.toBasetype(); | |
95 | |
96 | |
97 // set to: | |
98 // aaIn(aa, keyti, key); | |
99 | |
100 if (tybasic(key.Ety) == TYstruct) | |
101 { | |
102 key = el_una(OPstrpar, TYstruct, key); | |
103 key.Enumbytes = key.E1.Enumbytes; | |
104 assert(key.Enumbytes); | |
105 } | |
79 | 106 else if (tybasic(key.Ety) == TYarray && taa.index.ty == Tsarray) |
107 { | |
108 // e2.elem() turns string literals into a TYarray, so the | |
109 // length is lost. Restore it. | |
110 key = el_una(OPstrpar, TYstruct, key); | |
111 assert(e1.type.size() == taa.index.size()); | |
112 key.Enumbytes = cast(size_t) taa.index.size(); | |
113 } | |
72 | 114 |
115 Symbol* s = taa.aaGetSymbol("In", 0); | |
116 keyti = taa.index.getInternalTypeInfo(null).toElem(irs); | |
117 ep = el_params(key, keyti, aa, null); | |
118 e = el_bin(OPcall, type.totym(), el_var(s), ep); | |
119 | |
120 el_setLoc(e,loc); | |
67 | 121 return e; |
0 | 122 } |
123 } | |
124 |