Mercurial > projects > ddmd
comparison dmd/PowAssignExp.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | |
children | 14feb7ae01a6 |
comparison
equal
deleted
inserted
replaced
134:4251f96733f4 | 135:af1bebfd96a4 |
---|---|
1 module dmd.PowAssignExp; | |
2 | |
3 import dmd.BinExp; | |
4 import dmd.Scope; | |
5 import dmd.Loc; | |
6 import dmd.Identifier; | |
7 import dmd.Expression; | |
8 import dmd.TOK; | |
9 import dmd.STC; | |
10 import dmd.PowExp; | |
11 import dmd.AssignExp; | |
12 import dmd.Lexer; | |
13 import dmd.VarDeclaration; | |
14 import dmd.ExpInitializer; | |
15 import dmd.DeclarationExp; | |
16 import dmd.VarExp; | |
17 import dmd.CommaExp; | |
18 import dmd.ErrorExp; | |
19 import dmd.Id; | |
20 | |
21 // Only a reduced subset of operations for now. | |
22 class PowAssignExp : BinExp | |
23 { | |
24 this(Loc loc, Expression e1, Expression e2) | |
25 { | |
26 super(loc, TOK.TOKpowass, PowAssignExp.sizeof, e1, e2); | |
27 } | |
28 | |
29 override Expression semantic(Scope sc) | |
30 { | |
31 Expression e; | |
32 | |
33 if (type) | |
34 return this; | |
35 | |
36 BinExp.semantic(sc); | |
37 e2 = resolveProperties(sc, e2); | |
38 | |
39 e = op_overload(sc); | |
40 if (e) | |
41 return e; | |
42 | |
43 e1 = e1.modifiableLvalue(sc, e1); | |
44 assert(e1.type && e2.type); | |
45 | |
46 if ( (e1.type.isintegral() || e1.type.isfloating()) && | |
47 (e2.type.isintegral() || e2.type.isfloating())) | |
48 { | |
49 if (e1.op == TOKvar) | |
50 { // Rewrite: e1 = e1 ^^ e2 | |
51 e = new PowExp(loc, e1.syntaxCopy(), e2); | |
52 e = new AssignExp(loc, e1, e); | |
53 } | |
54 else | |
55 { // Rewrite: ref tmp = e1; tmp = tmp ^^ e2 | |
56 Identifier id = Lexer.uniqueId("__powtmp"); | |
57 auto v = new VarDeclaration(e1.loc, e1.type, id, new ExpInitializer(loc, e1)); | |
58 v.storage_class |= STC.STCref | STC.STCforeach; | |
59 Expression de = new DeclarationExp(e1.loc, v); | |
60 VarExp ve = new VarExp(e1.loc, v); | |
61 e = new PowExp(loc, ve, e2); | |
62 e = new AssignExp(loc, new VarExp(e1.loc, v), e); | |
63 e = new CommaExp(loc, de, e); | |
64 } | |
65 e = e.semantic(sc); | |
66 return e; | |
67 } | |
68 error("%s ^^= %s is not supported", e1.type.toChars(), e2.type.toChars() ); | |
69 return new ErrorExp(); | |
70 } | |
71 | |
72 // For operator overloading | |
73 Identifier opId() | |
74 { | |
75 return Id.powass; | |
76 } | |
77 }; |