Mercurial > projects > ddmd
annotate dmd/UnaExp.d @ 154:14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
and enabled warnings
+ reduced warnings by adding appriopriate overrides
+ IfStatement.interpret()
+ ScopeStatement.interpret()
+ TypeSArray.constConv()
+ TypedefDeclaration.syntaxCopy()
* fixed a bug in StringExp
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 15:32:31 +0200 |
parents | 60bb0fe4563e |
children | e3afd1303184 |
rev | line source |
---|---|
72 | 1 module dmd.UnaExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
5 import dmd.InterState; | |
6 import dmd.TY; | |
7 import dmd.TypeClass; | |
8 import dmd.TypeStruct; | |
9 import dmd.Dsymbol; | |
10 import dmd.AggregateDeclaration; | |
11 import dmd.Type; | |
12 import dmd.OutBuffer; | |
13 import dmd.Loc; | |
14 import dmd.TOK; | |
15 import dmd.Scope; | |
16 import dmd.InlineCostState; | |
17 import dmd.InlineDoState; | |
18 import dmd.HdrGenState; | |
19 import dmd.InlineScanState; | |
20 import dmd.DotIdExp; | |
21 import dmd.ArrayExp; | |
22 import dmd.CallExp; | |
23 import dmd.PREC; | |
24 import dmd.Token; | |
25 import dmd.expression.Util; | |
26 | |
0 | 27 class UnaExp : Expression |
28 { | |
29 Expression e1; | |
30 | |
31 this(Loc loc, TOK op, int size, Expression e1) | |
32 { | |
72 | 33 super(loc, op, size); |
0 | 34 this.e1 = e1; |
35 } | |
36 | |
72 | 37 override Expression syntaxCopy() |
0 | 38 { |
72 | 39 UnaExp e = cast(UnaExp)copy(); |
40 e.type = null; | |
41 e.e1 = e.e1.syntaxCopy(); | |
42 | |
0 | 43 return e; |
44 } | |
45 | |
72 | 46 override Expression semantic(Scope sc) |
0 | 47 { |
72 | 48 version (LOGSEMANTIC) { |
49 writef("UnaExp.semantic('%s')\n", toChars()); | |
50 } | |
51 e1 = e1.semantic(sc); | |
52 // if (!e1.type) | |
53 // error("%s has no value", e1.toChars()); | |
0 | 54 return this; |
55 } | |
56 | |
72 | 57 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 58 { |
72 | 59 buf.writestring(Token.toChars(op)); |
0 | 60 expToCBuffer(buf, hgs, e1, precedence[op]); |
61 } | |
62 | |
72 | 63 override Expression optimize(int result) |
0 | 64 { |
72 | 65 e1 = e1.optimize(result); |
0 | 66 return this; |
67 } | |
68 | |
72 | 69 override void dump(int indent) |
0 | 70 { |
71 assert(false); | |
72 } | |
73 | |
72 | 74 override void scanForNestedRef(Scope sc) |
0 | 75 { |
64 | 76 e1.scanForNestedRef(sc); |
0 | 77 } |
78 | |
63 | 79 Expression interpretCommon(InterState istate, Expression *(*fp)(Type* a0, Expression* a1)) |
0 | 80 { |
81 assert(false); | |
82 } | |
83 | |
72 | 84 override bool canThrow() |
0 | 85 { |
86 return e1.canThrow(); | |
87 } | |
88 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
130
diff
changeset
|
89 override Expression resolveLoc(Loc loc, Scope sc) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
90 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
91 e1 = e1.resolveLoc(loc, sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
92 return this; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
93 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
94 |
72 | 95 override int inlineCost(InlineCostState* ics) |
0 | 96 { |
97 return 1 + e1.inlineCost(ics); | |
98 } | |
99 | |
72 | 100 override Expression doInline(InlineDoState ids) |
0 | 101 { |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
102 auto ue = cast(UnaExp)copy(); |
72 | 103 |
104 ue.e1 = e1.doInline(ids); | |
0 | 105 return ue; |
106 } | |
107 | |
72 | 108 override Expression inlineScan(InlineScanState* iss) |
0 | 109 { |
72 | 110 e1 = e1.inlineScan(iss); |
0 | 111 return this; |
72 | 112 } |
113 | |
114 /************************************ | |
115 * Operator overload. | |
116 * Check for operator overload, if so, replace | |
117 * with function call. | |
118 * Return null if not an operator overload. | |
0 | 119 */ |
120 Expression op_overload(Scope sc) | |
121 { | |
72 | 122 //printf("UnaExp.op_overload() (%s)\n", toChars()); |
123 AggregateDeclaration ad; | |
124 Dsymbol fd; | |
125 Type t1 = e1.type.toBasetype(); | |
126 | |
127 if (t1.ty == TY.Tclass) | |
128 { | |
129 ad = (cast(TypeClass)t1).sym; | |
130 goto L1; | |
131 } | |
132 else if (t1.ty == TY.Tstruct) | |
133 { | |
134 ad = (cast(TypeStruct)t1).sym; | |
135 | |
136 L1: | |
137 fd = search_function(ad, opId()); | |
138 if (fd) | |
139 { | |
140 if (op == TOK.TOKarray) | |
141 { | |
142 /* Rewrite op e1[arguments] as: | |
143 * e1.fd(arguments) | |
144 */ | |
145 Expression e = new DotIdExp(loc, e1, fd.ident); | |
146 ArrayExp ae = cast(ArrayExp)this; | |
147 e = new CallExp(loc, e, ae.arguments); | |
148 e = e.semantic(sc); | |
149 return e; | |
150 } | |
151 else | |
152 { | |
153 // Rewrite +e1 as e1.add() | |
154 return build_overload(loc, sc, e1, null, fd.ident); | |
155 } | |
156 } | |
157 | |
158 version (DMDV2) { | |
159 // Didn't find it. Forward to aliasthis | |
160 if (ad.aliasthis) | |
161 { | |
162 /* Rewrite op(e1) as: | |
163 * op(e1.aliasthis) | |
164 */ | |
165 Expression e1 = new DotIdExp(loc, this.e1, ad.aliasthis.ident); | |
166 Expression e = copy(); | |
167 (cast(UnaExp)e).e1 = e1; | |
168 e = e.semantic(sc); | |
169 return e; | |
170 } | |
171 } | |
172 } | |
0 | 173 return null; |
174 } | |
175 } | |
176 |