Mercurial > projects > ddmd
annotate dmd/AssertExp.d @ 72:2e2a5c3f943a
reduced warnings by adding override to the methods
think this also normalizes different line endings used all over the place
author | Trass3r |
---|---|
date | Sat, 28 Aug 2010 16:19:48 +0200 |
parents | cab4c37afb89 |
children | e28b18c23469 |
rev | line source |
---|---|
72 | 1 module dmd.AssertExp; |
2 | |
3 import dmd.Expression; | |
4 import dmd.backend.elem; | |
5 import dmd.UnaExp; | |
6 import dmd.InterState; | |
7 import dmd.OutBuffer; | |
8 import dmd.Loc; | |
9 import dmd.Scope; | |
10 import dmd.InlineCostState; | |
11 import dmd.InlineDoState; | |
12 import dmd.IRState; | |
13 import dmd.HdrGenState; | |
0 | 14 import dmd.InlineScanState; |
15 import dmd.Type; | |
16 import dmd.Global; | |
72 | 17 import dmd.InvariantDeclaration; |
0 | 18 import dmd.TOK; |
19 import dmd.TY; | |
20 import dmd.TypeClass; | |
21 import dmd.Module; | |
22 import dmd.WANT; | |
23 import dmd.FuncDeclaration; | |
24 import dmd.HaltExp; | |
25 import dmd.TypeStruct; | |
26 import dmd.backend.Util; | |
27 import dmd.codegen.Util; | |
28 import dmd.backend.OPER; | |
29 import dmd.backend.TYM; | |
30 import dmd.backend.RTLSYM; | |
31 import dmd.backend.Symbol; | |
32 import dmd.backend.dt_t; | |
33 import dmd.backend.SC; | |
72 | 34 import dmd.backend.FL; |
0 | 35 |
36 import core.stdc.string; | |
37 import std.string : toStringz; | |
38 | |
39 static __gshared Symbol* assertexp_sfilename = null; | |
40 static __gshared string assertexp_name = null; | |
41 static __gshared Module assertexp_mn = null; | |
72 | 42 |
0 | 43 class AssertExp : UnaExp |
44 { | |
45 Expression msg; | |
46 | |
47 this(Loc loc, Expression e, Expression msg = null) | |
48 { | |
49 super(loc, TOK.TOKassert, AssertExp.sizeof, e); | |
50 this.msg = msg; | |
51 } | |
52 | |
72 | 53 override Expression syntaxCopy() |
0 | 54 { |
72 | 55 AssertExp ae = new AssertExp(loc, e1.syntaxCopy(), |
56 msg ? msg.syntaxCopy() : null); | |
53 | 57 return ae; |
0 | 58 } |
59 | |
72 | 60 override Expression semantic(Scope sc) |
0 | 61 { |
62 version (LOGSEMANTIC) { | |
63 printf("AssertExp.semantic('%s')\n", toChars()); | |
64 } | |
65 UnaExp.semantic(sc); | |
66 e1 = resolveProperties(sc, e1); | |
67 // BUG: see if we can do compile time elimination of the Assert | |
68 e1 = e1.optimize(WANTvalue); | |
69 e1 = e1.checkToBoolean(); | |
70 if (msg) | |
71 { | |
72 msg = msg.semantic(sc); | |
73 msg = resolveProperties(sc, msg); | |
74 msg = msg.implicitCastTo(sc, Type.tchar.constOf().arrayOf()); | |
75 msg = msg.optimize(WANTvalue); | |
76 } | |
77 if (e1.isBool(false)) | |
78 { | |
79 FuncDeclaration fd = sc.parent.isFuncDeclaration(); | |
80 fd.hasReturnExp |= 4; | |
81 | |
82 if (!global.params.useAssert) | |
83 { | |
84 Expression e = new HaltExp(loc); | |
85 e = e.semantic(sc); | |
86 return e; | |
87 } | |
88 } | |
89 type = Type.tvoid; | |
90 return this; | |
91 } | |
92 | |
72 | 93 override Expression interpret(InterState istate) |
0 | 94 { |
95 assert(false); | |
96 } | |
97 | |
72 | 98 override bool checkSideEffect(int flag) |
0 | 99 { |
100 return true; | |
101 } | |
102 | |
103 version (DMDV2) { | |
72 | 104 override bool canThrow() |
0 | 105 { |
106 /* assert()s are non-recoverable errors, so functions that | |
107 * use them can be considered "nothrow" | |
108 */ | |
109 return 0; //(global.params.useAssert != 0); | |
110 } | |
111 } | |
72 | 112 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 113 { |
114 assert(false); | |
115 } | |
116 | |
72 | 117 override int inlineCost(InlineCostState* ics) |
0 | 118 { |
119 return 1 + e1.inlineCost(ics) + (msg ? msg.inlineCost(ics) : 0); | |
120 } | |
121 | |
72 | 122 override Expression doInline(InlineDoState ids) |
0 | 123 { |
124 AssertExp ae = cast(AssertExp)copy(); | |
125 | |
126 ae.e1 = e1.doInline(ids); | |
127 if (msg) | |
128 ae.msg = msg.doInline(ids); | |
129 return ae; | |
130 } | |
131 | |
72 | 132 override Expression inlineScan(InlineScanState* iss) |
0 | 133 { |
134 e1 = e1.inlineScan(iss); | |
135 if (msg) | |
136 msg = msg.inlineScan(iss); | |
137 return this; | |
138 } | |
139 | |
140 static private void* castToVoid(int i) | |
141 { | |
142 return cast(void*)i; | |
143 } | |
144 | |
72 | 145 override elem* toElem(IRState* irs) |
0 | 146 { |
147 elem* e; | |
148 elem* ea; | |
149 Type t1 = e1.type.toBasetype(); | |
150 | |
151 //printf("AssertExp.toElem() %s\n", toChars()); | |
152 if (global.params.useAssert) | |
153 { | |
154 e = e1.toElem(irs); | |
155 | |
156 InvariantDeclaration inv = cast(InvariantDeclaration)castToVoid(1); | |
157 | |
158 // If e1 is a class object, call the class invariant on it | |
159 if (global.params.useInvariants && t1.ty == Tclass && | |
160 !(cast(TypeClass)t1).sym.isInterfaceDeclaration()) | |
161 { | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
162 version (POSIX) {///TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 163 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM__DINVARIANT]), e); |
164 } else { | |
165 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM_DINVARIANT]), e); | |
166 } | |
167 } | |
168 // If e1 is a struct object, call the struct invariant on it | |
169 else if (global.params.useInvariants && | |
170 t1.ty == Tpointer && | |
171 t1.nextOf().ty == Tstruct && | |
172 (inv = (cast(TypeStruct)t1.nextOf()).sym.inv) !is null) | |
173 { | |
174 e = callfunc(loc, irs, 1, inv.type.nextOf(), e, e1.type, inv, inv.type, null, null); | |
175 } | |
176 else | |
177 { | |
178 // Construct: (e1 || ModuleAssert(line)) | |
179 Symbol* sassert; | |
180 Module m = irs.blx.module_; | |
181 string mname = m.srcfile.toChars(); | |
182 | |
183 //printf("filename = '%s'\n", loc.filename); | |
184 //printf("module = '%s'\n", m.srcfile.toChars()); | |
185 | |
186 /* If the source file name has changed, probably due | |
187 * to a #line directive. | |
188 */ | |
189 if (loc.filename && (msg || loc.filename != mname)) | |
190 { | |
191 elem* efilename; | |
192 | |
193 /* Cache values. | |
194 */ | |
195 //static Symbol *assertexp_sfilename = null; | |
196 //static char *assertexp_name = null; | |
197 //static Module *assertexp_mn = null; | |
198 | |
199 if (!assertexp_sfilename || loc.filename != assertexp_name || assertexp_mn != m) | |
200 { | |
201 dt_t* dt = null; | |
202 | |
203 string id = loc.filename; | |
204 int len = id.length; | |
205 dtdword(&dt, len); | |
206 dtabytes(&dt,TYnptr, 0, len + 1, toStringz(id)); | |
207 | |
208 assertexp_sfilename = symbol_generate(SCstatic,type_fake(TYdarray)); | |
209 assertexp_sfilename.Sdt = dt; | |
210 assertexp_sfilename.Sfl = FLdata; | |
211 version (ELFOBJ) { | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
212 assertexp_sfilename.Sseg = Segment.CDATA; |
0 | 213 } |
214 version (MACHOBJ) { | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
215 assertexp_sfilename.Sseg = Segment.DATA; |
0 | 216 } |
217 outdata(assertexp_sfilename); | |
218 | |
219 assertexp_mn = m; | |
220 assertexp_name = id; | |
221 } | |
222 | |
223 efilename = el_var(assertexp_sfilename); | |
224 | |
225 if (msg) | |
72 | 226 { |
0 | 227 elem* emsg = msg.toElem(irs); |
228 ea = el_var(rtlsym[RTLSYM_DASSERT_MSG]); | |
229 ea = el_bin(OPcall, TYvoid, ea, el_params(el_long(TYint, loc.linnum), efilename, emsg, null)); | |
230 } | |
231 else | |
232 { | |
233 ea = el_var(rtlsym[RTLSYM_DASSERT]); | |
234 ea = el_bin(OPcall, TYvoid, ea, el_param(el_long(TYint, loc.linnum), efilename)); | |
235 } | |
236 } | |
237 else | |
238 { | |
239 sassert = m.toModuleAssert(); | |
240 ea = el_bin(OPcall,TYvoid,el_var(sassert), | |
241 el_long(TYint, loc.linnum)); | |
242 } | |
243 e = el_bin(OPoror,TYvoid,e,ea); | |
244 } | |
245 } | |
246 else | |
247 { | |
248 // BUG: should replace assert(0); with a HLT instruction | |
249 e = el_long(TYint, 0); | |
250 } | |
251 el_setLoc(e,loc); | |
252 | |
253 return e; | |
254 } | |
255 } | |
256 |