Mercurial > projects > ldc
annotate dmd/root.h @ 1138:4c8bb03e4fbc
Update DtoConstFP() to be correct after LLVM r67562, which changed the way the
APFloat constructor expects its i80 APInts to be formatted. (They're now
actually consistent with the x87 format)
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Tue, 24 Mar 2009 15:24:59 +0100 |
parents | eeb8b95ea92e |
children |
rev | line source |
---|---|
1 | 1 |
2 | |
3 // Copyright (c) 1999-2006 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #ifndef ROOT_H | |
12 #define ROOT_H | |
13 | |
14 #include <stdlib.h> | |
15 #include <stdarg.h> | |
16 | |
17 #if __DMC__ | |
18 #pragma once | |
19 #endif | |
20 | |
21 typedef size_t hash_t; | |
22 | |
23 #include "dchar.h" | |
24 | |
25 char *wchar2ascii(wchar_t *); | |
26 int wcharIsAscii(wchar_t *); | |
27 char *wchar2ascii(wchar_t *, unsigned len); | |
28 int wcharIsAscii(wchar_t *, unsigned len); | |
29 | |
30 int bstrcmp(unsigned char *s1, unsigned char *s2); | |
31 char *bstr2str(unsigned char *b); | |
32 void error(const char *format, ...); | |
33 void error(const wchar_t *format, ...); | |
34 void warning(const char *format, ...); | |
35 | |
36 #ifndef TYPEDEFS | |
37 #define TYPEDEFS | |
38 | |
39 #if _MSC_VER | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
658
diff
changeset
|
40 #include <float.h> // for _isnan |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
41 #include <malloc.h> // for alloca |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
42 // According to VC 8.0 docs, long double is the same as double |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
43 #define strtold strtod |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
44 #define strtof strtod |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
45 #define isnan _isnan |
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1103
diff
changeset
|
46 |
1 | 47 typedef __int64 longlong; |
48 typedef unsigned __int64 ulonglong; | |
49 #else | |
50 typedef long long longlong; | |
51 typedef unsigned long long ulonglong; | |
52 #endif | |
53 | |
54 #endif | |
55 | |
56 longlong randomx(); | |
57 | |
58 /* | |
59 * Root of our class library. | |
60 */ | |
61 | |
62 struct OutBuffer; | |
63 struct Array; | |
64 | |
65 struct Object | |
66 { | |
67 Object() { } | |
68 virtual ~Object() { } | |
69 | |
70 virtual int equals(Object *o); | |
71 | |
72 /** | |
73 * Returns a hash code, useful for things like building hash tables of Objects. | |
74 */ | |
75 virtual hash_t hashCode(); | |
76 | |
77 /** | |
78 * Return <0, ==0, or >0 if this is less than, equal to, or greater than obj. | |
79 * Useful for sorting Objects. | |
80 */ | |
81 virtual int compare(Object *obj); | |
82 | |
83 /** | |
84 * Pretty-print an Object. Useful for debugging the old-fashioned way. | |
85 */ | |
86 virtual void print(); | |
87 | |
88 virtual char *toChars(); | |
89 virtual dchar *toDchars(); | |
90 virtual void toBuffer(OutBuffer *buf); | |
91 | |
92 /** | |
93 * Used as a replacement for dynamic_cast. Returns a unique number | |
94 * defined by the library user. For Object, the return value is 0. | |
95 */ | |
96 virtual int dyncast(); | |
97 | |
98 /** | |
99 * Marks pointers for garbage collector by calling mem.mark() for all pointers into heap. | |
100 */ | |
101 /*virtual*/ // not used, disable for now | |
102 void mark(); | |
103 }; | |
104 | |
105 struct String : Object | |
106 { | |
107 int ref; // != 0 if this is a reference to someone else's string | |
108 char *str; // the string itself | |
109 | |
110 String(char *str, int ref = 1); | |
111 | |
112 ~String(); | |
113 | |
114 static hash_t calcHash(const char *str, size_t len); | |
115 static hash_t calcHash(const char *str); | |
116 hash_t hashCode(); | |
117 unsigned len(); | |
118 int equals(Object *obj); | |
119 int compare(Object *obj); | |
120 char *toChars(); | |
121 void print(); | |
122 void mark(); | |
123 }; | |
124 | |
125 struct FileName : String | |
126 { | |
127 FileName(char *str, int ref); | |
128 FileName(char *path, char *name); | |
129 hash_t hashCode(); | |
130 int equals(Object *obj); | |
131 int compare(Object *obj); | |
132 static int absolute(const char *name); | |
133 static char *ext(const char *); | |
134 char *ext(); | |
336 | 135 static char *removeExt(const char *str); |
1 | 136 static char *name(const char *); |
137 char *name(); | |
138 static char *path(const char *); | |
139 static char *replaceName(char *path, char *name); | |
140 | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
141 static char *combine(const char *path, const char *name); |
1 | 142 static Array *splitPath(const char *path); |
143 static FileName *defaultExt(const char *name, const char *ext); | |
144 static FileName *forceExt(const char *name, const char *ext); | |
145 int equalsExt(const char *ext); | |
146 | |
147 void CopyTo(FileName *to); | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
148 static char *searchPath(Array *path, const char *name, int cwd); |
1 | 149 static int exists(const char *name); |
150 static void ensurePathExists(const char *path); | |
151 }; | |
152 | |
153 struct File : Object | |
154 { | |
155 int ref; // != 0 if this is a reference to someone else's buffer | |
156 unsigned char *buffer; // data for our file | |
157 unsigned len; // amount of data in buffer[] | |
158 void *touchtime; // system time to use for file | |
159 | |
160 FileName *name; // name of our file | |
161 | |
162 File(char *); | |
163 File(FileName *); | |
164 ~File(); | |
165 | |
166 void mark(); | |
167 | |
168 char *toChars(); | |
169 | |
170 /* Read file, return !=0 if error | |
171 */ | |
172 | |
173 int read(); | |
174 | |
175 /* Write file, either succeed or fail | |
176 * with error message & exit. | |
177 */ | |
178 | |
179 void readv(); | |
180 | |
181 /* Read file, return !=0 if error | |
182 */ | |
183 | |
184 int mmread(); | |
185 | |
186 /* Write file, either succeed or fail | |
187 * with error message & exit. | |
188 */ | |
189 | |
190 void mmreadv(); | |
191 | |
192 /* Write file, return !=0 if error | |
193 */ | |
194 | |
195 int write(); | |
196 | |
197 /* Write file, either succeed or fail | |
198 * with error message & exit. | |
199 */ | |
200 | |
201 void writev(); | |
202 | |
203 /* Return !=0 if file exists. | |
204 * 0: file doesn't exist | |
205 * 1: normal file | |
206 * 2: directory | |
207 */ | |
208 | |
209 /* Append to file, return !=0 if error | |
210 */ | |
211 | |
212 int append(); | |
213 | |
214 /* Append to file, either succeed or fail | |
215 * with error message & exit. | |
216 */ | |
217 | |
218 void appendv(); | |
219 | |
220 /* Return !=0 if file exists. | |
221 * 0: file doesn't exist | |
222 * 1: normal file | |
223 * 2: directory | |
224 */ | |
225 | |
226 int exists(); | |
227 | |
228 /* Given wildcard filespec, return an array of | |
229 * matching File's. | |
230 */ | |
231 | |
232 static Array *match(char *); | |
233 static Array *match(FileName *); | |
234 | |
235 // Compare file times. | |
236 // Return <0 this < f | |
237 // =0 this == f | |
238 // >0 this > f | |
239 int compareTime(File *f); | |
240 | |
241 // Read system file statistics | |
242 void stat(); | |
243 | |
244 /* Set buffer | |
245 */ | |
246 | |
247 void setbuffer(void *buffer, unsigned len) | |
248 { | |
249 this->buffer = (unsigned char *)buffer; | |
250 this->len = len; | |
251 } | |
252 | |
253 void checkoffset(size_t offset, size_t nbytes); | |
254 | |
255 void remove(); // delete file | |
256 }; | |
257 | |
258 struct OutBuffer : Object | |
259 { | |
260 unsigned char *data; | |
261 unsigned offset; | |
262 unsigned size; | |
263 | |
264 OutBuffer(); | |
265 ~OutBuffer(); | |
266 void *extractData(); | |
267 void mark(); | |
268 | |
269 void reserve(unsigned nbytes); | |
270 void setsize(unsigned size); | |
271 void reset(); | |
272 void write(const void *data, unsigned nbytes); | |
273 void writebstring(unsigned char *string); | |
336 | 274 void writestring(const char *string); |
1 | 275 void writedstring(const char *string); |
276 void writedstring(const wchar_t *string); | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
277 void prependstring(const char *string); |
1 | 278 void writenl(); // write newline |
279 void writeByte(unsigned b); | |
280 void writebyte(unsigned b) { writeByte(b); } | |
281 void writeUTF8(unsigned b); | |
282 void writedchar(unsigned b); | |
283 void prependbyte(unsigned b); | |
284 void writeword(unsigned w); | |
285 void writeUTF16(unsigned w); | |
286 void write4(unsigned w); | |
287 void write(OutBuffer *buf); | |
288 void write(Object *obj); | |
289 void fill0(unsigned nbytes); | |
290 void align(unsigned size); | |
291 void vprintf(const char *format, va_list args); | |
292 void printf(const char *format, ...); | |
293 #if M_UNICODE | |
294 void vprintf(const unsigned short *format, va_list args); | |
295 void printf(const unsigned short *format, ...); | |
296 #endif | |
297 void bracket(char left, char right); | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
298 unsigned bracket(unsigned i, const char *left, unsigned j, const char *right); |
1 | 299 void spread(unsigned offset, unsigned nbytes); |
300 unsigned insert(unsigned offset, const void *data, unsigned nbytes); | |
301 void remove(unsigned offset, unsigned nbytes); | |
302 char *toChars(); | |
303 char *extractString(); | |
304 }; | |
305 | |
306 struct Array : Object | |
307 { | |
308 unsigned dim; | |
309 unsigned allocdim; | |
310 void **data; | |
311 | |
312 Array(); | |
313 ~Array(); | |
314 void mark(); | |
315 char *toChars(); | |
316 | |
317 void reserve(unsigned nentries); | |
318 void setDim(unsigned newdim); | |
319 void fixDim(); | |
320 void push(void *ptr); | |
321 void *pop(); | |
322 void shift(void *ptr); | |
323 void insert(unsigned index, void *ptr); | |
324 void insert(unsigned index, Array *a); | |
325 void append(Array *a); | |
326 void remove(unsigned i); | |
327 void zero(); | |
328 void *tos(); | |
329 void sort(); | |
330 Array *copy(); | |
331 }; | |
332 | |
333 struct Bits : Object | |
334 { | |
335 unsigned bitdim; | |
336 unsigned allocdim; | |
337 unsigned *data; | |
338 | |
339 Bits(); | |
340 ~Bits(); | |
341 void mark(); | |
342 | |
343 void resize(unsigned bitdim); | |
344 | |
345 void set(unsigned bitnum); | |
346 void clear(unsigned bitnum); | |
347 int test(unsigned bitnum); | |
348 | |
349 void set(); | |
350 void clear(); | |
351 void copy(Bits *from); | |
352 Bits *clone(); | |
353 | |
354 void sub(Bits *b); | |
355 }; | |
356 | |
357 #endif |