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