annotate dmd/AssertExp.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents 25ede4f66bda
children e3afd1303184
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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 super(loc, TOK.TOKassert, AssertExp.sizeof, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 this.msg = msg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
57 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
59 AssertExp ae = new AssertExp(loc, e1.syntaxCopy(),
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
60 msg ? msg.syntaxCopy() : null);
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 22
diff changeset
61 return ae;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
64 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 printf("AssertExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 UnaExp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 // BUG: see if we can do compile time elimination of the Assert
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 e1 = e1.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 e1 = e1.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 if (msg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 msg = msg.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 msg = resolveProperties(sc, msg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 msg = msg.implicitCastTo(sc, Type.tchar.constOf().arrayOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 msg = msg.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 if (e1.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 fd.hasReturnExp |= 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 if (!global.params.useAssert)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
87 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 Expression e = new HaltExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
97 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
102 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 version (DMDV2) {
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
108 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 /* assert()s are non-recoverable errors, so functions that
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 * use them can be considered "nothrow"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 */
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
113 return false; //(global.params.useAssert != 0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
116 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
118 buf.writestring("assert(");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
119 expToCBuffer(buf, hgs, e1, PREC.PREC_assign);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
120 if (msg)
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
121 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
122 buf.writeByte(',');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
123 expToCBuffer(buf, hgs, msg, PREC_assign);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
124 }
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
125 buf.writeByte(')');
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
128 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 return 1 + e1.inlineCost(ics) + (msg ? msg.inlineCost(ics) : 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
133 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 AssertExp ae = cast(AssertExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 ae.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (msg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 ae.msg = msg.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 return ae;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
143 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 if (msg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 msg = msg.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
150
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 static private void* castToVoid(int i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 return cast(void*)i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
156 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 elem* ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 Type t1 = e1.type.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 //printf("AssertExp.toElem() %s\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 if (global.params.useAssert)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 e = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 InvariantDeclaration inv = cast(InvariantDeclaration)castToVoid(1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 // If e1 is a class object, call the class invariant on it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 if (global.params.useInvariants && t1.ty == Tclass &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 !(cast(TypeClass)t1).sym.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
173 version (POSIX) {///TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 e = el_bin(OPcall, TYvoid, el_var(rtlsym[RTLSYM__DINVARIANT]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 } else {
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 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 // If e1 is a struct object, call the struct invariant on it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 else if (global.params.useInvariants &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 t1.ty == Tpointer &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 t1.nextOf().ty == Tstruct &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 (inv = (cast(TypeStruct)t1.nextOf()).sym.inv) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 e = callfunc(loc, irs, 1, inv.type.nextOf(), e, e1.type, inv, inv.type, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 // Construct: (e1 || ModuleAssert(line))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 Symbol* sassert;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 Module m = irs.blx.module_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 string mname = m.srcfile.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 //printf("filename = '%s'\n", loc.filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 //printf("module = '%s'\n", m.srcfile.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 /* If the source file name has changed, probably due
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 * to a #line directive.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 if (loc.filename && (msg || loc.filename != mname))
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
201 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 elem* efilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 /* Cache values.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 */
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
206 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
207 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
208 Module assertexp_mn = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 if (!assertexp_sfilename || loc.filename != assertexp_name || assertexp_mn != m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 dt_t* dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 string id = loc.filename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 int len = id.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 dtdword(&dt, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 dtabytes(&dt,TYnptr, 0, len + 1, toStringz(id));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 assertexp_sfilename = symbol_generate(SCstatic,type_fake(TYdarray));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 assertexp_sfilename.Sdt = dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 assertexp_sfilename.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 version (ELFOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
223 assertexp_sfilename.Sseg = Segment.CDATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 version (MACHOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 0
diff changeset
226 assertexp_sfilename.Sseg = Segment.DATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 outdata(assertexp_sfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 assertexp_mn = m;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 assertexp_name = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 efilename = el_var(assertexp_sfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 if (msg)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
237 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 elem* emsg = msg.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 ea = el_var(rtlsym[RTLSYM_DASSERT_MSG]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 ea = el_bin(OPcall, TYvoid, ea, el_params(el_long(TYint, loc.linnum), efilename, emsg, null));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 ea = el_var(rtlsym[RTLSYM_DASSERT]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 ea = el_bin(OPcall, TYvoid, ea, el_param(el_long(TYint, loc.linnum), efilename));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 sassert = m.toModuleAssert();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 ea = el_bin(OPcall,TYvoid,el_var(sassert),
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 el_long(TYint, loc.linnum));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 e = el_bin(OPoror,TYvoid,e,ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 165
diff changeset
258 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 // BUG: should replace assert(0); with a HLT instruction
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 e = el_long(TYint, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 el_setLoc(e,loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267