annotate dmd/AssertExp.d @ 178:e3afd1303184

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