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