Allow returning something of type void in a function that returns void
[delight/core.git] / dmd2 / root.h
blob13d47a5b9db8ca62effd702cb362575a321927f4
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.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, September 2004
17 #ifndef ROOT_H
18 #define ROOT_H
20 #include <stdlib.h>
21 #include <stdarg.h>
23 #if __DMC__
24 #pragma once
25 #endif
27 typedef size_t hash_t;
29 #include "dchar.h"
31 char *wchar2ascii(wchar_t *);
32 int wcharIsAscii(wchar_t *);
33 char *wchar2ascii(wchar_t *, unsigned len);
34 int wcharIsAscii(wchar_t *, unsigned len);
36 int bstrcmp(unsigned char *s1, unsigned char *s2);
37 char *bstr2str(unsigned char *b);
38 #ifndef GCC_SAFE_DMD
39 void error(const char *format, ...);
40 void error(const wchar_t *format, ...);
41 void warning(const char *format, ...);
42 #endif
44 #ifndef TYPEDEFS
45 #define TYPEDEFS
47 #if _MSC_VER
48 typedef __int64 longlong;
49 typedef unsigned __int64 ulonglong;
50 #else
51 typedef long long longlong;
52 typedef unsigned long long ulonglong;
53 #endif
55 #endif
57 longlong randomx();
60 * Root of our class library.
63 struct OutBuffer;
64 struct Array;
66 struct Object
68 Object() { }
69 virtual ~Object() { }
71 virtual int equals(Object *o);
73 /**
74 * Returns a hash code, useful for things like building hash tables of Objects.
76 virtual hash_t hashCode();
78 /**
79 * Return <0, ==0, or >0 if this is less than, equal to, or greater than obj.
80 * Useful for sorting Objects.
82 virtual int compare(Object *obj);
84 /**
85 * Pretty-print an Object. Useful for debugging the old-fashioned way.
87 virtual void print();
89 virtual char *toChars();
90 virtual dchar *toDchars();
91 virtual void toBuffer(OutBuffer *buf);
93 /**
94 * Used as a replacement for dynamic_cast. Returns a unique number
95 * defined by the library user. For Object, the return value is 0.
97 virtual int dyncast();
99 /**
100 * Marks pointers for garbage collector by calling mem.mark() for all pointers into heap.
102 /*virtual*/ // not used, disable for now
103 void mark();
106 struct String : Object
108 int ref; // != 0 if this is a reference to someone else's string
109 char *str; // the string itself
111 String(char *str, int ref = 1);
113 ~String();
115 static hash_t calcHash(const char *str, size_t len);
116 static hash_t calcHash(const char *str);
117 hash_t hashCode();
118 unsigned len();
119 int equals(Object *obj);
120 int compare(Object *obj);
121 char *toChars();
122 void print();
123 void mark();
126 struct FileName : String
128 FileName(char *str, int ref);
129 FileName(char *path, char *name);
130 hash_t hashCode();
131 int equals(Object *obj);
132 int compare(Object *obj);
133 static int absolute(const char *name);
134 static char *ext(const char *);
135 char *ext();
136 static char *removeExt(const char *str);
137 static char *name(const char *);
138 char *name();
139 static char *path(const char *);
140 static char *replaceName(char *path, char *name);
142 static char *combine(char *path, char *name);
143 static Array *splitPath(const char *path);
144 static FileName *defaultExt(const char *name, const char *ext);
145 static FileName *forceExt(const char *name, const char *ext);
146 int equalsExt(const char *ext);
148 void CopyTo(FileName *to);
149 static char *searchPath(Array *path, char *name, int cwd);
150 static int exists(const char *name);
151 static void ensurePathExists(const char *path);
154 struct File : Object
156 int ref; // != 0 if this is a reference to someone else's buffer
157 unsigned char *buffer; // data for our file
158 unsigned len; // amount of data in buffer[]
159 void *touchtime; // system time to use for file
161 FileName *name; // name of our file
163 File(char *);
164 File(FileName *);
165 ~File();
167 void mark();
169 char *toChars();
171 /* Read file, return !=0 if error
174 int read();
176 /* Write file, either succeed or fail
177 * with error message & exit.
180 void readv();
182 /* Read file, return !=0 if error
185 int mmread();
187 /* Write file, either succeed or fail
188 * with error message & exit.
191 void mmreadv();
193 /* Write file, return !=0 if error
196 int write();
198 /* Write file, either succeed or fail
199 * with error message & exit.
202 void writev();
204 /* Return !=0 if file exists.
205 * 0: file doesn't exist
206 * 1: normal file
207 * 2: directory
210 /* Append to file, return !=0 if error
213 int append();
215 /* Append to file, either succeed or fail
216 * with error message & exit.
219 void appendv();
221 /* Return !=0 if file exists.
222 * 0: file doesn't exist
223 * 1: normal file
224 * 2: directory
227 int exists();
229 /* Given wildcard filespec, return an array of
230 * matching File's.
233 static Array *match(char *);
234 static Array *match(FileName *);
236 // Compare file times.
237 // Return <0 this < f
238 // =0 this == f
239 // >0 this > f
240 int compareTime(File *f);
242 // Read system file statistics
243 void stat();
245 /* Set buffer
248 void setbuffer(void *buffer, unsigned len)
250 this->buffer = (unsigned char *)buffer;
251 this->len = len;
254 void checkoffset(size_t offset, size_t nbytes);
256 void remove(); // delete file
259 struct OutBuffer : Object
261 unsigned char *data;
262 unsigned offset;
263 unsigned size;
265 OutBuffer();
266 ~OutBuffer();
267 void *extractData();
268 void mark();
270 void reserve(unsigned nbytes);
271 void setsize(unsigned size);
272 void reset();
273 void write(const void *data, unsigned nbytes);
274 void writebstring(unsigned char *string);
275 void writestring(const char *string);
276 void writedstring(const char *string);
277 void writedstring(const wchar_t *string);
278 void prependstring(char *string);
279 void writenl(); // write newline
280 void writeByte(unsigned b);
281 void writebyte(unsigned b) { writeByte(b); }
282 void writeUTF8(unsigned b);
283 void writedchar(unsigned b);
284 void prependbyte(unsigned b);
285 void writeword(unsigned w);
286 void writeUTF16(unsigned w);
287 void write4(unsigned w);
288 void write(OutBuffer *buf);
289 void write(Object *obj);
290 void fill0(unsigned nbytes);
291 void align(unsigned size);
292 void vprintf(const char *format, va_list args);
293 void printf(const char *format, ...);
294 #if M_UNICODE
295 void vprintf(const unsigned short *format, va_list args);
296 void printf(const unsigned short *format, ...);
297 #endif
298 void bracket(char left, char right);
299 unsigned bracket(unsigned i, char *left, unsigned j, char *right);
300 void spread(unsigned offset, unsigned nbytes);
301 unsigned insert(unsigned offset, const void *data, unsigned nbytes);
302 void remove(unsigned offset, unsigned nbytes);
303 char *toChars();
304 char *extractString();
307 struct Array : Object
309 unsigned dim;
310 unsigned allocdim;
311 void **data;
313 Array();
314 ~Array();
315 void mark();
316 char *toChars();
318 void reserve(unsigned nentries);
319 void setDim(unsigned newdim);
320 void fixDim();
321 void push(void *ptr);
322 void *pop();
323 void shift(void *ptr);
324 void insert(unsigned index, void *ptr);
325 void insert(unsigned index, Array *a);
326 void append(Array *a);
327 void remove(unsigned i);
328 void zero();
329 void *tos();
330 void sort();
331 Array *copy();
334 struct Bits : Object
336 unsigned bitdim;
337 unsigned allocdim;
338 unsigned *data;
340 Bits();
341 ~Bits();
342 void mark();
344 void resize(unsigned bitdim);
346 void set(unsigned bitnum);
347 void clear(unsigned bitnum);
348 int test(unsigned bitnum);
350 void set();
351 void clear();
352 void copy(Bits *from);
353 Bits *clone();
355 void sub(Bits *b);
358 #endif