Mercurial > projects > ldc
annotate dmd/root/root.h @ 1641:00cd99bedf06
Add missing files for the new frontend spell checker
author | Kelly Wilson <wilsonk cpsc.ucalgary.ca> |
---|---|
date | Mon, 08 Mar 2010 17:41:36 -0700 |
parents | 9bf06e02070b |
children |
rev | line source |
---|---|
1 | 1 |
2 | |
1640 | 3 // Copyright (c) 1999-2010 by Digital Mars |
1 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
1640 | 6 // http://www.digitalmars.com |
1 | 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); |
1640 | 159 static char *safeSearchPath(Array *path, const char *name); |
1 | 160 static int exists(const char *name); |
161 static void ensurePathExists(const char *path); | |
1640 | 162 static char *canonicalName(const char *name); |
1 | 163 }; |
164 | |
165 struct File : Object | |
166 { | |
167 int ref; // != 0 if this is a reference to someone else's buffer | |
168 unsigned char *buffer; // data for our file | |
169 unsigned len; // amount of data in buffer[] | |
170 void *touchtime; // system time to use for file | |
171 | |
172 FileName *name; // name of our file | |
173 | |
174 File(char *); | |
175 File(FileName *); | |
176 ~File(); | |
177 | |
178 void mark(); | |
179 | |
180 char *toChars(); | |
181 | |
182 /* Read file, return !=0 if error | |
183 */ | |
184 | |
185 int read(); | |
186 | |
187 /* Write file, either succeed or fail | |
188 * with error message & exit. | |
189 */ | |
190 | |
191 void readv(); | |
192 | |
193 /* Read file, return !=0 if error | |
194 */ | |
195 | |
196 int mmread(); | |
197 | |
198 /* Write file, either succeed or fail | |
199 * with error message & exit. | |
200 */ | |
201 | |
202 void mmreadv(); | |
203 | |
204 /* Write file, return !=0 if error | |
205 */ | |
206 | |
207 int write(); | |
208 | |
209 /* Write file, either succeed or fail | |
210 * with error message & exit. | |
211 */ | |
212 | |
213 void writev(); | |
214 | |
215 /* Return !=0 if file exists. | |
216 * 0: file doesn't exist | |
217 * 1: normal file | |
218 * 2: directory | |
219 */ | |
220 | |
221 /* Append to file, return !=0 if error | |
222 */ | |
223 | |
224 int append(); | |
225 | |
226 /* Append to file, either succeed or fail | |
227 * with error message & exit. | |
228 */ | |
229 | |
230 void appendv(); | |
231 | |
232 /* Return !=0 if file exists. | |
233 * 0: file doesn't exist | |
234 * 1: normal file | |
235 * 2: directory | |
236 */ | |
237 | |
238 int exists(); | |
239 | |
240 /* Given wildcard filespec, return an array of | |
241 * matching File's. | |
242 */ | |
243 | |
244 static Array *match(char *); | |
245 static Array *match(FileName *); | |
246 | |
247 // Compare file times. | |
248 // Return <0 this < f | |
249 // =0 this == f | |
250 // >0 this > f | |
251 int compareTime(File *f); | |
252 | |
253 // Read system file statistics | |
254 void stat(); | |
255 | |
256 /* Set buffer | |
257 */ | |
258 | |
259 void setbuffer(void *buffer, unsigned len) | |
260 { | |
261 this->buffer = (unsigned char *)buffer; | |
262 this->len = len; | |
263 } | |
264 | |
265 void checkoffset(size_t offset, size_t nbytes); | |
266 | |
267 void remove(); // delete file | |
268 }; | |
269 | |
270 struct OutBuffer : Object | |
271 { | |
272 unsigned char *data; | |
273 unsigned offset; | |
274 unsigned size; | |
275 | |
276 OutBuffer(); | |
277 ~OutBuffer(); | |
278 void *extractData(); | |
279 void mark(); | |
280 | |
281 void reserve(unsigned nbytes); | |
282 void setsize(unsigned size); | |
283 void reset(); | |
284 void write(const void *data, unsigned nbytes); | |
285 void writebstring(unsigned char *string); | |
336 | 286 void writestring(const char *string); |
1 | 287 void writedstring(const char *string); |
288 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
|
289 void prependstring(const char *string); |
1 | 290 void writenl(); // write newline |
291 void writeByte(unsigned b); | |
292 void writebyte(unsigned b) { writeByte(b); } | |
293 void writeUTF8(unsigned b); | |
294 void writedchar(unsigned b); | |
295 void prependbyte(unsigned b); | |
296 void writeword(unsigned w); | |
297 void writeUTF16(unsigned w); | |
298 void write4(unsigned w); | |
299 void write(OutBuffer *buf); | |
300 void write(Object *obj); | |
301 void fill0(unsigned nbytes); | |
302 void align(unsigned size); | |
303 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
|
304 void printf(const char *format, ...) IS_PRINTF(2); |
1 | 305 #if M_UNICODE |
306 void vprintf(const unsigned short *format, va_list args); | |
307 void printf(const unsigned short *format, ...); | |
308 #endif | |
309 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
|
310 unsigned bracket(unsigned i, const char *left, unsigned j, const char *right); |
1 | 311 void spread(unsigned offset, unsigned nbytes); |
312 unsigned insert(unsigned offset, const void *data, unsigned nbytes); | |
313 void remove(unsigned offset, unsigned nbytes); | |
314 char *toChars(); | |
315 char *extractString(); | |
316 }; | |
317 | |
318 struct Array : Object | |
319 { | |
320 unsigned dim; | |
321 unsigned allocdim; | |
322 void **data; | |
323 | |
324 Array(); | |
325 ~Array(); | |
326 void mark(); | |
327 char *toChars(); | |
328 | |
329 void reserve(unsigned nentries); | |
330 void setDim(unsigned newdim); | |
331 void fixDim(); | |
332 void push(void *ptr); | |
333 void *pop(); | |
334 void shift(void *ptr); | |
335 void insert(unsigned index, void *ptr); | |
336 void insert(unsigned index, Array *a); | |
337 void append(Array *a); | |
338 void remove(unsigned i); | |
339 void zero(); | |
340 void *tos(); | |
341 void sort(); | |
342 Array *copy(); | |
343 }; | |
344 | |
345 struct Bits : Object | |
346 { | |
347 unsigned bitdim; | |
348 unsigned allocdim; | |
349 unsigned *data; | |
350 | |
351 Bits(); | |
352 ~Bits(); | |
353 void mark(); | |
354 | |
355 void resize(unsigned bitdim); | |
356 | |
357 void set(unsigned bitnum); | |
358 void clear(unsigned bitnum); | |
359 int test(unsigned bitnum); | |
360 | |
361 void set(); | |
362 void clear(); | |
363 void copy(Bits *from); | |
364 Bits *clone(); | |
365 | |
366 void sub(Bits *b); | |
367 }; | |
368 | |
369 #endif |