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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
1 module dmd.InExp;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3 import dmd.common;
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
4 import dmd.Expression;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
5 import dmd.Identifier;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
6 import dmd.Loc;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
7 import dmd.Scope;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
8 import dmd.IRState;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
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
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
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
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
17
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
18 import dmd.backend.elem;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
19 import dmd.backend.TYM;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
20 import dmd.backend.mTY;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
21 import dmd.backend.OPER;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
22 import dmd.backend.Symbol;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
23 import dmd.backend.Util;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 class InExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
37 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
72 override bool isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
74 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
77 override Identifier opId()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 8
diff changeset
79 return Id.opIn;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
82 override Identifier opId_r()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
62
6557375aff35 InExp.opId_r
korDen
parents: 61
diff changeset
84 return Id.opIn_r;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
87 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
89 elem* e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
90 elem* key = e1.toElem(irs);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
91 elem* aa = e2.toElem(irs);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
92 elem* ep;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
93 elem* keyti;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
94 TypeAArray taa = cast(TypeAArray)e2.type.toBasetype();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
95
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
96
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
97 // set to:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
98 // aaIn(aa, keyti, key);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
99
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
100 if (tybasic(key.Ety) == TYstruct)
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
101 {
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
102 key = el_una(OPstrpar, TYstruct, key);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
103 key.Enumbytes = key.E1.Enumbytes;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
104 assert(key.Enumbytes);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
105 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
106 else if (tybasic(key.Ety) == TYarray && taa.index.ty == Tsarray)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
107 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
108 // e2.elem() turns string literals into a TYarray, so the
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
109 // length is lost. Restore it.
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
110 key = el_una(OPstrpar, TYstruct, key);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
111 assert(e1.type.size() == taa.index.size());
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
112 key.Enumbytes = cast(size_t) taa.index.size();
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
113 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
114
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
115 Symbol* s = taa.aaGetSymbol("In", 0);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
116 keyti = taa.index.getInternalTypeInfo(null).toElem(irs);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
117 ep = el_params(key, keyti, aa, null);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
118 e = el_bin(OPcall, type.totym(), el_var(s), ep);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
119
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
120 el_setLoc(e,loc);
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
121 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124