comparison dmd/OrExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children a8b50ff7f201
comparison
equal deleted inserted replaced
-1:000000000000 0:10317f0c89a5
1 module dmd.OrExp;
2
3 import dmd.Expression;
4 import dmd.Identifier;
5 import dmd.InterState;
6 import dmd.MATCH;
7 import dmd.Type;
8 import dmd.OutBuffer;
9 import dmd.Loc;
10 import dmd.Scope;
11 import dmd.IntRange;
12 import dmd.IRState;
13 import dmd.ArrayTypes;
14 import dmd.BinExp;
15 import dmd.TOK;
16 import dmd.TY;
17 import dmd.Id;
18
19 import dmd.backend.elem;
20 import dmd.backend.OPER;
21
22 import dmd.expression.Or;
23
24 class OrExp : BinExp
25 {
26 this(Loc loc, Expression e1, Expression e2)
27 {
28 super(loc, TOK.TOKor, OrExp.sizeof, e1, e2);
29 }
30
31 Expression semantic(Scope sc)
32 {
33 Expression e;
34
35 if (!type)
36 {
37 BinExp.semanticp(sc);
38 e = op_overload(sc);
39
40 if (e)
41 return e;
42
43 if (e1.type.toBasetype().ty == TY.Tbool && e2.type.toBasetype().ty == TY.Tbool)
44 {
45 type = e1.type;
46 e = this;
47 }
48 else
49 {
50 typeCombine(sc);
51 if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
52 {
53 e1.checkIntegral();
54 e2.checkIntegral();
55 }
56 }
57 }
58
59 return this;
60 }
61
62 Expression optimize(int result)
63 {
64 Expression e;
65
66 e1 = e1.optimize(result);
67 e2 = e2.optimize(result);
68
69 if (e1.isConst() == 1 && e2.isConst() == 1)
70 e = Or(type, e1, e2);
71 else
72 e = this;
73
74 return e;
75 }
76
77 Expression interpret(InterState* istate)
78 {
79 assert(false);
80 }
81
82 void buildArrayIdent(OutBuffer buf, Expressions arguments)
83 {
84 assert(false);
85 }
86
87 Expression buildArrayLoop(Arguments fparams)
88 {
89 assert(false);
90 }
91
92 MATCH implicitConvTo(Type t)
93 {
94 MATCH result = Expression.implicitConvTo(t);
95
96 if (result == MATCH.MATCHnomatch)
97 {
98 MATCH m1 = e1.implicitConvTo(t);
99 MATCH m2 = e2.implicitConvTo(t);
100
101 // Pick the worst match
102 result = (m1 < m2) ? m1 : m2;
103 }
104
105 return result;
106 }
107
108 IntRange getIntRange()
109 {
110 assert(false);
111 }
112
113 bool isCommutative()
114 {
115 return true;
116 }
117
118 Identifier opId()
119 {
120 return Id.ior;
121 }
122
123 Identifier opId_r()
124 {
125 return Id.ior_r;
126 }
127
128 elem* toElem(IRState* irs)
129 {
130 return toElemBin(irs, OPER.OPor);
131 }
132 }
133