annotate dmd/InExp.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 43073c7c7769
children e3afd1303184
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
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 class InExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
29 super(loc, TOKin, InExp.sizeof, e1, e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
32 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
34 if (type)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
35 return this;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
36
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
37 super.semanticp(sc);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
38
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
39 Expression e = op_overload(sc);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
40 if (e)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
41 return e;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
42
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
43 //type = Type.tboolean;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
44 Type t2b = e2.type.toBasetype();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
45 if (t2b.ty != TY.Taarray)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
46 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
47 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
48 type = Type.terror;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
49 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
50 else
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 TypeAArray ta = cast(TypeAArray)t2b;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
53
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
54 // Special handling for array keys
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
55 if (!arrayTypeCompatible(e1.loc, e1.type, ta.index))
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 // Convert key to type of key
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
58 e1 = e1.implicitCastTo(sc, ta.index);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
59 }
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 // Return type is pointer to value
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
62 type = ta.nextOf().pointerTo();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
63 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
64 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
67 override int isBit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
69 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
72 override Identifier opId()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 8
diff changeset
74 return Id.opIn;
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_r()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
62
6557375aff35 InExp.opId_r
korDen
parents: 61
diff changeset
79 return Id.opIn_r;
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 elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
84 elem* e;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
85 elem* key = e1.toElem(irs);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
86 elem* aa = e2.toElem(irs);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
87 elem* ep;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
88 elem* keyti;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
89 TypeAArray taa = cast(TypeAArray)e2.type.toBasetype();
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
90
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
91
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
92 // set to:
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
93 // aaIn(aa, keyti, key);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
94
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
95 if (tybasic(key.Ety) == TYstruct)
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 key = el_una(OPstrpar, TYstruct, key);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
98 key.Enumbytes = key.E1.Enumbytes;
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
99 assert(key.Enumbytes);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
100 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
101 else if (tybasic(key.Ety) == TYarray && taa.index.ty == Tsarray)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
102 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
103 // e2.elem() turns string literals into a TYarray, so the
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
104 // length is lost. Restore it.
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
105 key = el_una(OPstrpar, TYstruct, key);
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
106 assert(e1.type.size() == taa.index.size());
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
107 key.Enumbytes = cast(size_t) taa.index.size();
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
108 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
109
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
110 Symbol* s = taa.aaGetSymbol("In", 0);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
111 keyti = taa.index.getInternalTypeInfo(null).toElem(irs);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
112 ep = el_params(key, keyti, aa, null);
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 67
diff changeset
113 e = el_bin(OPcall, type.totym(), el_var(s), ep);
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 el_setLoc(e,loc);
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
116 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119