annotate dmd/InExp.d @ 67:f708f0452e81

some of the backend/codegen stuff implemented
author korDen
date Mon, 23 Aug 2010 21:21:05 +0400
parents 6557375aff35
children 2e2a5c3f943a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.InExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.BinExp;
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
9 import dmd.TOK;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
10 import dmd.Type;
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 8
diff changeset
11 import dmd.Id;
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
12 import dmd.TY;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
13 import dmd.TypeAArray;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
14
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
15 import dmd.expression.util.arrayTypeCompatible;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.elem;
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
18 import dmd.backend.TYM;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
19 import dmd.backend.mTY;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
20 import dmd.backend.OPER;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
21 import dmd.backend.Symbol;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
22 import dmd.backend.Util;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 class InExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this(Loc loc, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
28 super(loc, TOKin, InExp.sizeof, e1, e2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 Expression semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
33 if (type)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
34 return this;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
35
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
36 super.semanticp(sc);
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 Expression e = op_overload(sc);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
39 if (e)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
40 return e;
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 //type = Type.tboolean;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
43 Type t2b = e2.type.toBasetype();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
44 if (t2b.ty != TY.Taarray)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
45 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
46 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
47 type = Type.terror;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
48 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
49 else
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 TypeAArray ta = cast(TypeAArray)t2b;
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 // Special handling for array keys
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
54 if (!arrayTypeCompatible(e1.loc, e1.type, ta.index))
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
55 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
56 // Convert key to type of key
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
57 e1 = e1.implicitCastTo(sc, ta.index);
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
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
60 // Return type is pointer to value
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
61 type = ta.nextOf().pointerTo();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
62 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
63 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 int isBit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 0
diff changeset
68 return 0;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 Identifier opId()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
61
4ae0d790a452 OnScopeStatement.syntaxCopy
korDen
parents: 8
diff changeset
73 return Id.opIn;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 Identifier opId_r()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
62
6557375aff35 InExp.opId_r
korDen
parents: 61
diff changeset
78 return Id.opIn_r;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
83 elem* e;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
84 elem* key = e1.toElem(irs);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
85 elem* aa = e2.toElem(irs);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
86 elem* ep;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
87 elem* keyti;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
88 TypeAArray taa = cast(TypeAArray)e2.type.toBasetype();
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
89
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
90
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
91 // set to:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
92 // aaIn(aa, keyti, key);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
93
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
94 if (tybasic(key.Ety) == TYstruct)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
95 {
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
96 key = el_una(OPstrpar, TYstruct, key);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
97 key.Enumbytes = key.E1.Enumbytes;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
98 assert(key.Enumbytes);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
99 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
100
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
101 Symbol* s = taa.aaGetSymbol("In", 0);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
102 keyti = taa.index.getInternalTypeInfo(null).toElem(irs);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
103 ep = el_params(key, keyti, aa, null);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
104 e = el_bin(OPcall, type.totym(), el_var(s), ep);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
105
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
106 el_setLoc(e,loc);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 62
diff changeset
107 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110