Mercurial > projects > ddmd
annotate dmd/InExp.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | e28b18c23469 |
children | b0d41ff5e0df |
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 | |
0 | 25 class InExp : BinExp |
26 { | |
27 this(Loc loc, Expression e1, Expression e2) | |
28 { | |
178 | 29 register(); |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
30 super(loc, TOKin, InExp.sizeof, e1, e2); |
0 | 31 } |
32 | |
72 | 33 override Expression semantic(Scope sc) |
0 | 34 { |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
35 if (type) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
36 return this; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
37 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
38 super.semanticp(sc); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
39 |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
40 Expression e = op_overload(sc); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
41 if (e) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
42 return e; |
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 //type = Type.tboolean; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
45 Type t2b = e2.type.toBasetype(); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
46 if (t2b.ty != TY.Taarray) |
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 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
|
49 type = Type.terror; |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
50 } |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
51 else |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
52 { |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
53 TypeAArray ta = cast(TypeAArray)t2b; |
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 // Special handling for array keys |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
56 if (!arrayTypeCompatible(e1.loc, e1.type, ta.index)) |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
57 { |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
58 // Convert key to type of key |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
59 e1 = e1.implicitCastTo(sc, ta.index); |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
60 } |
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 // Return type is pointer to value |
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
63 type = ta.nextOf().pointerTo(); |
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 return this; |
0 | 66 } |
67 | |
72 | 68 override int isBit() |
0 | 69 { |
8
d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents:
0
diff
changeset
|
70 return 0; |
0 | 71 } |
72 | |
72 | 73 override Identifier opId() |
0 | 74 { |
61 | 75 return Id.opIn; |
0 | 76 } |
77 | |
72 | 78 override Identifier opId_r() |
0 | 79 { |
62 | 80 return Id.opIn_r; |
0 | 81 } |
82 | |
72 | 83 override elem* toElem(IRState* irs) |
0 | 84 { |
72 | 85 elem* e; |
86 elem* key = e1.toElem(irs); | |
87 elem* aa = e2.toElem(irs); | |
88 elem* ep; | |
89 elem* keyti; | |
90 TypeAArray taa = cast(TypeAArray)e2.type.toBasetype(); | |
91 | |
92 | |
93 // set to: | |
94 // aaIn(aa, keyti, key); | |
95 | |
96 if (tybasic(key.Ety) == TYstruct) | |
97 { | |
98 key = el_una(OPstrpar, TYstruct, key); | |
99 key.Enumbytes = key.E1.Enumbytes; | |
100 assert(key.Enumbytes); | |
101 } | |
79 | 102 else if (tybasic(key.Ety) == TYarray && taa.index.ty == Tsarray) |
103 { | |
104 // e2.elem() turns string literals into a TYarray, so the | |
105 // length is lost. Restore it. | |
106 key = el_una(OPstrpar, TYstruct, key); | |
107 assert(e1.type.size() == taa.index.size()); | |
108 key.Enumbytes = cast(size_t) taa.index.size(); | |
109 } | |
72 | 110 |
111 Symbol* s = taa.aaGetSymbol("In", 0); | |
112 keyti = taa.index.getInternalTypeInfo(null).toElem(irs); | |
113 ep = el_params(key, keyti, aa, null); | |
114 e = el_bin(OPcall, type.totym(), el_var(s), ep); | |
115 | |
116 el_setLoc(e,loc); | |
67 | 117 return e; |
0 | 118 } |
119 } | |
120 |