annotate dmd/OrOrExp.d @ 56:51605de93870

TupleExp.optimize UnrolledLoopStatement.ctor UnrolledLoopStatement.semantic UnrolledLoopStatement.blockExit OrOrExp.checkSideEffect FuncExp.syntaxCopy FuncLiteralDeclaration.syntaxCopy WhileStatement.hasBreak StructInitializer.toExpression StructLiteralExp.ctor StructLiteralExp.optimize BinExp.commonSemanticAssign ModAssignExp.opId Argument.isLazyArray CommaExp.implicitConvTo CommaExp.castTo TypeClass.isBaseOf createTypeInfoArray TypeTuple.getTypeInfoDeclaration TypeInfoTupleDeclaration.ctor TypeNext.constConv XorExp.implicitConvTo TemplateParameter.isTemplateValueParameter
author korDen
date Sat, 21 Aug 2010 14:16:53 +0400
parents 10317f0c89a5
children cab4c37afb89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.OrOrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.CommaExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.BoolExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.expression.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 class OrOrExp : 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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc, TOK.TOKoror, OrOrExp.sizeof, e1, e2);
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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 uint cs1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 // same as for AndAnd
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 e1 = e1.checkToPointer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 e1 = e1.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 cs1 = sc.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 if (sc.flags & SCOPE.SCOPEstaticif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 /* If in static if, don't evaluate e2 if we don't have to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 e1 = e1.optimize(WANTflags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 if (e1.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 return new IntegerExp(loc, 1, Type.tboolean);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 sc.mergeCallSuper(loc, cs1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 e2 = e2.checkToPointer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 type = Type.tboolean;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 if (e2.type.ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 if (e2.op == TOKtype || e2.op == TOKimport)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 error("%s is not an expression", e2.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 Expression checkToBoolean()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 e2 = e2.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 int isBit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 Expression optimize(int result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 e1 = e1.optimize(WANTflags | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 if (e1.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 // Replace with (e1, 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 e = new CommaExp(loc, e1, new IntegerExp(loc, 1, type));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 e.type = type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 e = e.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 e2 = e2.optimize(WANTflags | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (result && e2.type.toBasetype().ty == Tvoid && !global.errors)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 error("void has no value");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (e1.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (e2.isConst())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 int n1 = e1.isBool(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 int n2 = e2.isBool(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e = new IntegerExp(loc, n1 || n2, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 else if (e1.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 e = new BoolExp(loc, e2, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 Expression interpret(InterState* istate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 bool checkSideEffect(int flag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
56
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
118 if (flag == 2)
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
119 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
120 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
121 }
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
122 else
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
123 {
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
124 e1.checkSideEffect(1);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
125 return e2.checkSideEffect(flag);
51605de93870 TupleExp.optimize
korDen
parents: 0
diff changeset
126 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 elem* toElem(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 elem* e = toElemBin(irs,OPoror);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 if (global.params.cov && e2.loc.linnum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 e.E2() = el_combine(incUsageElem(irs, e2.loc), e.E2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }