annotate src/util.d @ 1:4a9dcbd9e54f

-files of 0.13 beta -fixes so that it now compiles with the current dmd version
author marton@basel.hu
date Tue, 05 Apr 2011 20:44:01 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1 /* Ddbg - Win32 Debugger for the D programming language
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
2 * Copyright (c) 2007 Jascha Wetzel
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
3 * All rights reserved. See LICENSE.TXT for details.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
4 */
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
5
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
6 import std.ctype;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
7 import std.stdio;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
8 import std.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
9 import std.c.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
10 import std.c.stdio;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
11 import std.format;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
12 import std.date : getUTCtime, d_time, TicksPerSecond;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
13 import std.demangle;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
14
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
15 import win32.winbase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
16 import win32.windef;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
17
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
18 import std.typeinfo.ti_AC;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
19 import std.typeinfo.ti_Acdouble;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
20 import std.typeinfo.ti_Acfloat;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
21 import std.typeinfo.ti_Acreal;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
22 import std.typeinfo.ti_Adouble;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
23 import std.typeinfo.ti_Afloat;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
24 import std.typeinfo.ti_Ag;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
25 import std.typeinfo.ti_Aint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
26 import std.typeinfo.ti_Along;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
27 import std.typeinfo.ti_Areal;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
28 import std.typeinfo.ti_Ashort;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
29 import std.typeinfo.ti_byte;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
30 import std.typeinfo.ti_C;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
31 import std.typeinfo.ti_cdouble;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
32 import std.typeinfo.ti_cfloat;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
33 import std.typeinfo.ti_char;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
34 import std.typeinfo.ti_creal;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
35 import std.typeinfo.ti_dchar;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
36 import std.typeinfo.ti_delegate;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
37 import std.typeinfo.ti_double;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
38 import std.typeinfo.ti_float;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
39 import std.typeinfo.ti_idouble;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
40 import std.typeinfo.ti_ifloat;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
41 import std.typeinfo.ti_int;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
42 import std.typeinfo.ti_ireal;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
43 import std.typeinfo.ti_long;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
44 import std.typeinfo.ti_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
45 import std.typeinfo.ti_real;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
46 import std.typeinfo.ti_short;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
47 import std.typeinfo.ti_ubyte;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
48 import std.typeinfo.ti_uint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
49 import std.typeinfo.ti_ulong;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
50 import std.typeinfo.ti_ushort;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
51 import std.typeinfo.ti_void;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
52 import std.typeinfo.ti_wchar;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
53
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
54 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
55
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
56 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
57 T dmax(T)(T a, T b)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
58 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
59 return a<b?b:a;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
60 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
61
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
62 T dmin(T)(T a, T b)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
63 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
64 return a>b?b:a;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
65 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
66
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
67 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
68
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
69 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
70 uint intFromStr(string str)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
71 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
72 uint i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
73 foreach_reverse ( c; str )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
74 i = i<<8 | c;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
75 return i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
76 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
77
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
78 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
79
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
80 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
81 string itoa(uint i)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
82 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
83 if ( i == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
84 return "0";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
85 string str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
86 for ( ; i > 0; i /= 10 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
87 str = "0123456789"[i%10] ~ str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
88 return str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
89 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
90
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
91 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
92
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
93 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
94 string TODO(string file, uint line, string msg)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
95 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
96 return "TODO - "~file~"("~itoa(line)~"): "~msg~"";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
97 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
98
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
99 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
100
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
101 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
102 string formatTicks(ulong ticks)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
103 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
104 SYSTEMTIME stime;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
105 if ( !FileTimeToSystemTime(cast(FILETIME*)&ticks, &stime) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
106 return "invalid";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
107 string str = format("%02d:%02d:%02d.%03d", stime.wHour, stime.wMinute, stime.wSecond, stime.wMilliseconds);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
108 return str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
109 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
110
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
111 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
112 Name lookup for win32 DebugEventCodes.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
113 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
114 string getEventName(uint event)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
115 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
116 switch ( event )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
117 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
118 case EXCEPTION_DEBUG_EVENT : return "EXCEPTION_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
119 case CREATE_THREAD_DEBUG_EVENT : return "CREATE_THREAD_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
120 case CREATE_PROCESS_DEBUG_EVENT : return "CREATE_PROCESS_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
121 case EXIT_THREAD_DEBUG_EVENT : return "EXIT_THREAD_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
122 case EXIT_PROCESS_DEBUG_EVENT : return "EXIT_PROCESS_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
123 case LOAD_DLL_DEBUG_EVENT : return "LOAD_DLL_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
124 case UNLOAD_DLL_DEBUG_EVENT : return "UNLOAD_DLL_DEBUG_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
125 case OUTPUT_DEBUG_STRING_EVENT : return "OUTPUT_DEBUG_STRING_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
126 case RIP_EVENT: return "RIP_EVENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
127 default : break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
128 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
129 return "";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
130 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
131
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
132 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
133 Name lookup for win32 ExceptionCodes.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
134 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
135 string getExceptionName(uint excpt)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
136 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
137 switch ( excpt )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
138 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
139 case EXCEPTION_ACCESS_VIOLATION : return "EXCEPTION_ACCESS_VIOLATION";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
140 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED : return "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
141 case EXCEPTION_BREAKPOINT : return "EXCEPTION_BREAKPOINT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
142 case EXCEPTION_DATATYPE_MISALIGNMENT : return "EXCEPTION_DATATYPE_MISALIGNMENT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
143 case EXCEPTION_FLT_DENORMAL_OPERAND : return "EXCEPTION_FLT_DENORMAL_OPERAND";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
144 case EXCEPTION_FLT_DIVIDE_BY_ZERO : return "EXCEPTION_FLT_DIVIDE_BY_ZERO";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
145 case EXCEPTION_FLT_INEXACT_RESULT : return "EXCEPTION_FLT_INEXACT_RESULT";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
146 case EXCEPTION_FLT_INVALID_OPERATION : return "EXCEPTION_FLT_INVALID_OPERATION";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
147 case EXCEPTION_FLT_OVERFLOW : return "EXCEPTION_FLT_OVERFLOW";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
148 case EXCEPTION_FLT_STACK_CHECK : return "EXCEPTION_FLT_STACK_CHECK";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
149 case EXCEPTION_FLT_UNDERFLOW : return "EXCEPTION_FLT_UNDERFLOW";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
150 case EXCEPTION_ILLEGAL_INSTRUCTION : return "EXCEPTION_ILLEGAL_INSTRUCTION";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
151 case EXCEPTION_IN_PAGE_ERROR : return "EXCEPTION_IN_PAGE_ERROR";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
152 case EXCEPTION_INT_DIVIDE_BY_ZERO : return "EXCEPTION_INT_DIVIDE_BY_ZERO";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
153 case EXCEPTION_INT_OVERFLOW : return "EXCEPTION_INT_OVERFLOW";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
154 case EXCEPTION_INVALID_DISPOSITION : return "EXCEPTION_INVALID_DISPOSITION";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
155 case EXCEPTION_NONCONTINUABLE_EXCEPTION : return "EXCEPTION_NONCONTINUABLE_EXCEPTION";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
156 case EXCEPTION_PRIV_INSTRUCTION : return "EXCEPTION_PRIV_INSTRUCTION";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
157 case EXCEPTION_SINGLE_STEP : return "EXCEPTION_SINGLE_STEP";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
158 case EXCEPTION_STACK_OVERFLOW : return "EXCEPTION_STACK_OVERFLOW";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
159 default : break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
160 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
161 return "";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
162 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
163
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
164 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
165 Wrapper for Win32 GetLastError.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
166 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
167 string lastError()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
168 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
169 char[4096] msg;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
170 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, null, GetLastError(), 0, msg.ptr, msg.length, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
171 return msg[0..strlen(msg.ptr)];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
172 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
173
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
174 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
175 Simplified number parser for prefixes.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
176 Returns: number represented by the prefix of name, 0 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
177 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
178 uint parseNumber(inout string name)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
179 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
180 uint res;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
181 int i;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
182 while ( name.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
183 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
184 if ( !isdigit(name[0]) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
185 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
186 res = res*10+(name[0]-'0');
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
187 name = name[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
188 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
189 return res;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
190 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
191
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
192 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
193
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
194 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
195 string typeFromMangled(string mangled)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
196 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
197 if ( mangled is null || mangled.length < 4 || mangled[0..2] != "_D" || !isdigit(mangled[2]) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
198 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
199 string type = mangled[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
200 // skip symbol name
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
201 while ( type.length > 1 && type[0] == 'D' && isdigit(type[1]) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
202 type = type[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
203 uint len = parseNumber(type);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
204 type = type[len..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
205 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
206 return type;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
207 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
208
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
209 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
210
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
211 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
212 string mangleName(string name)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
213 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
214 string mangled;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
215 string[] idents = split(name, ".");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
216 foreach ( string id; idents )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
217 mangled ~= .toString(id.length)~id;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
218 return mangled;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
219 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
220
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
221 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
222
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
223 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
224 string demangleType(string mangled)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
225 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
226 return demangle("_D0"~mangled);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
227 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
228
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
229 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
230
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
231 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
232 string demangleNameSkip(inout string mangled)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
233 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
234 string name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
235 do {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
236 uint len = parseNumber(mangled);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
237 if ( len <= 0 || len > mangled.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
238 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
239 if ( name.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
240 name ~= ".";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
241 name ~= mangled[0..len];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
242 mangled = mangled[len..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
243 } while ( mangled.length > 0 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
244 return name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
245 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
246
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
247 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
248
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
249 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
250 string demangleName(string mangled)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
251 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
252 string name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
253 if ( mangled.length > 2 && mangled[0..2] == "_D" && isNumeric(mangled[2]) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
254 mangled = mangled[2..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
255 else
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
256 return mangled;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
257 do {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
258 uint len = parseNumber(mangled);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
259 while ( len <= 0 && mangled.length > 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
260 mangled = mangled[1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
261 len = parseNumber(mangled);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
262 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
263 if ( len <= 0 || len > mangled.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
264 return name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
265 if ( name.length > 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
266 name ~= ".";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
267 name ~= mangled[0..len];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
268 mangled = mangled[len..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
269 } while ( mangled.length > 0 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
270 return name;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
271 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
272
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
273 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
274 Wraps win32 stdio functions. Respects io redirection into pipes.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
275 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
276 class DbgIO
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
277 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
278 static HANDLE ddb_read, ddb_write;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
279 static string buffer;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
280
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
281 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
282
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
283 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
284 static this()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
285 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
286 ddb_read = GetStdHandle(STD_INPUT_HANDLE);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
287 ddb_write = GetStdHandle(STD_OUTPUT_HANDLE);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
288 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
289
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
290 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
291
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
292 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
293 static string readln()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
294 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
295 char[128] buf;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
296 uint read;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
297
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
298 int nl_index;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
299 do
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
300 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
301 ReadFile(ddb_read, buf.ptr, buf.length, &read, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
302 buffer ~= buf[0..read];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
303 nl_index = find(buffer, '\n');
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
304 } while ( nl_index < 0 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
305 string ret = buffer[0..nl_index];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
306 buffer = buffer[nl_index+1..$];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
307 return ret;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
308 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
309
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
310 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
311
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
312 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
313 static void print(...)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
314 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
315 string str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
316
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
317 void putc(dchar c)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
318 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
319 str ~= c;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
320 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
321
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
322 doFormat(&putc, _arguments, _argptr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
323 uint written;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
324 WriteFile(ddb_write, str.ptr, str.length, &written, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
325 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
326
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
327 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
328
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
329 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
330 static void println(...)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
331 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
332 string str;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
333
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
334 void putc(dchar c)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
335 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
336 str ~= c;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
337 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
338
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
339 doFormat(&putc, _arguments, _argptr);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
340 uint written;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
341 str ~= '\n';
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
342 WriteFile(ddb_write, str.ptr, str.length, &written, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
343 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
344
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
345 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
346
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
347 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
348 static void write(string str)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
349 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
350 uint written;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
351 WriteFile(ddb_write, str.ptr, str.length, &written, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
352 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
353
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
354 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
355
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
356 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
357 static void writeln(string str)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
358 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
359 uint written;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
360 str ~= "\n";
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
361 WriteFile(ddb_write, str.ptr, str.length, &written, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
362 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
363 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
364
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
365 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
366
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
367 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
368 TypeInfo TypeInfoFromMangled(string mangled)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
369 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
370 TypeInfo res;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
371 TypeInfo* ti = &res;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
372
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
373 for ( uint i=0; ti !is null && i < mangled.length; ++i )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
374 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
375 switch ( mangled[i] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
376 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
377 case 'C':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
378 debug DbgIO.println("TypeInfoFromMangled: classinfos not supported, yet");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
379 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
380 case 'P':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
381 TypeInfo_Pointer tip = new TypeInfo_Pointer;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
382 *ti = tip;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
383 ti = &tip.m_next;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
384 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
385 case 'G':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
386 TypeInfo_StaticArray tia = new TypeInfo_StaticArray;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
387 *ti = tia;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
388 ti = &tia.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
389 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
390 case 'A':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
391 switch ( mangled[i+1] )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
392 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
393 case 'v': *ti = new TypeInfo_Av; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
394 case 'x':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
395 case 'b': *ti = new TypeInfo_Ab; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
396 case 'g': *ti = new TypeInfo_Ag; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
397 case 'h': *ti = new TypeInfo_Ah; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
398 case 's': *ti = new TypeInfo_As; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
399 case 't': *ti = new TypeInfo_At; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
400 case 'i': *ti = new TypeInfo_Ai; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
401 case 'k': *ti = new TypeInfo_Ak; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
402 case 'l': *ti = new TypeInfo_Al; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
403 case 'm': *ti = new TypeInfo_Am; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
404 case 'f': *ti = new TypeInfo_Af; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
405 case 'd': *ti = new TypeInfo_Ad; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
406 case 'e': *ti = new TypeInfo_Ae; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
407 case 'o': *ti = new TypeInfo_Ao; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
408 case 'p': *ti = new TypeInfo_Ap; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
409 case 'j': *ti = new TypeInfo_Aj; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
410 case 'q': *ti = new TypeInfo_Aq; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
411 case 'r': *ti = new TypeInfo_Ar; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
412 case 'c': *ti = new TypeInfo_Ac; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
413 case 'a': *ti = new TypeInfo_Aa; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
414 case 'u': *ti = new TypeInfo_Au; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
415 case 'w': *ti = new TypeInfo_Aw; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
416 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
417 TypeInfo_Array tia = new TypeInfo_Array;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
418 *ti = tia;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
419 ti = &tia.value;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
420 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
421 break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
422 case 'v': *ti = new TypeInfo_v; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
423 case 'x':
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
424 case 'b': *ti = new TypeInfo_b; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
425 case 'g': *ti = new TypeInfo_g; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
426 case 'h': *ti = new TypeInfo_h; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
427 case 's': *ti = new TypeInfo_s; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
428 case 't': *ti = new TypeInfo_t; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
429 case 'i': *ti = new TypeInfo_i; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
430 case 'k': *ti = new TypeInfo_k; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
431 case 'l': *ti = new TypeInfo_l; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
432 case 'm': *ti = new TypeInfo_m; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
433 case 'f': *ti = new TypeInfo_f; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
434 case 'd': *ti = new TypeInfo_d; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
435 case 'e': *ti = new TypeInfo_e; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
436 case 'o': *ti = new TypeInfo_o; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
437 case 'p': *ti = new TypeInfo_p; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
438 case 'j': *ti = new TypeInfo_j; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
439 case 'q': *ti = new TypeInfo_q; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
440 case 'r': *ti = new TypeInfo_r; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
441 case 'c': *ti = new TypeInfo_c; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
442 case 'a': *ti = new TypeInfo_a; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
443 case 'u': *ti = new TypeInfo_u; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
444 case 'w': *ti = new TypeInfo_w; ti = null; break;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
445 default:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
446 debug DbgIO.println("unknown mangled type "~mangled[i]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
447 assert(0);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
448 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
449 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
450
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
451 return res;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
452 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
453
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
454 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
455
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
456 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
457 class DataReader
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
458 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
459 ubyte[] data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
460 uint cursor;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
461
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
462 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
463
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
464 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
465 this(ubyte[] d)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
466 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
467 data = d;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
468 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
469
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
470 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
471
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
472 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
473 void alignCursor(ubyte num)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
474 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
475 cursor += (num + cursor) % num;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
476 assert(cursor<=data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
477 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
478
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
479 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
480
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
481 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
482 bool available()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
483 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
484 return cursor<data.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
485 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
486
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
487 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
488
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
489 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
490 void seek(uint offset)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
491 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
492 cursor=offset;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
493 if ( cursor > data.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
494 throw new Exception("DataReader.seek beyond end of data offset="~.toString(cursor)~", $="~.toString(data.length));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
495 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
496
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
497 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
498
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
499 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
500 void relseek(int offset)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
501 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
502 cursor+=offset;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
503 if ( cursor > data.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
504 throw new Exception("DataReader.seek beyond end of data offset="~.toString(cursor)~", $="~.toString(data.length));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
505 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
506
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
507 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
508
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
509 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
510 void peek(out ubyte val)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
511 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
512 assert(cursor<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
513 val = data[cursor];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
514 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
515
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
516 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
517
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
518 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
519 void read(out ubyte val)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
520 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
521 assert(cursor<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
522 val = data[cursor];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
523 ++cursor;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
524 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
525 void read(out char val) { read(*cast(ubyte*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
526
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
527 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
528
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
529 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
530 void read(out ushort val)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
531 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
532 assert(cursor+1<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
533 val = (cast(ushort[])(data[cursor..cursor+2]))[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
534 cursor+=2;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
535 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
536 void read(out short val) { read(*cast(ushort*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
537
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
538 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
539
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
540 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
541 void read(out uint val)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
542 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
543 assert(cursor+3<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
544 val = (cast(uint[])(data[cursor..cursor+4]))[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
545 cursor+=4;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
546 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
547 void read(out int val) { read(*cast(uint*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
548 void read(out float val) { read(*cast(uint*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
549
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
550 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
551
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
552 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
553 void read(out ulong val)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
554 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
555 assert(cursor+7<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
556 val = (cast(ulong[])(data[cursor..cursor+8]))[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
557 cursor+=8;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
558 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
559 void read(out long val) { read(*cast(ulong*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
560 void read(out double val) { read(*cast(ulong*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
561 void read(out cfloat val) { read(*cast(ulong*)&val); }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
562
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
563 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
564
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
565 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
566 void read(out real val)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
567 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
568 assert(cursor+9<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
569 val = (cast(real[])(data[cursor..cursor+10]))[0];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
570 cursor+=10;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
571 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
572
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
573 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
574
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
575 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
576 void read(out string str)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
577 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
578 assert(cursor<data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
579 ushort len = data[cursor++];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
580 if ( len >= 0xff && data[cursor] == 0 ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
581 ++cursor;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
582 read(len);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
583 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
584
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
585 assert(cursor+len<=data.length, "dr cursor="~.toString(cursor)~" len="~.toString(len));
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
586 str = (cast(string)data)[cursor..cursor+len];
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
587 cursor+=len;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
588 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
589
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
590 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
591
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
592 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
593 void readA(T)(out T[] array, uint length)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
594 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
595 uint size = length*T.sizeof;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
596 assert(cursor<=data.length-size);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
597 array = cast(T[])(data[cursor..cursor+size]);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
598 cursor+=size;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
599 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
600 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
601
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
602 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
603
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
604 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
605 string getFullPath(string filename)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
606 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
607 char[] fullpath;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
608 char* filepart;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
609 fullpath.length = 4096;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
610 int len = GetFullPathName(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
611 toStringz(filename),
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
612 fullpath.length,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
613 fullpath.ptr,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
614 &filepart
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
615 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
616 if ( len <= 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
617 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
618 fullpath.length = len;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
619
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
620 char[] longfullpath;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
621 longfullpath.length = 4096;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
622 len = GetLongPathName(
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
623 toStringz(fullpath),
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
624 longfullpath.ptr,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
625 longfullpath.length
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
626 );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
627 longfullpath.length = len;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
628 return longfullpath;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
629 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
630
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
631 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
632
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
633 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
634 struct DbgTimer
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
635 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
636 d_time time;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
637
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
638 void start()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
639 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
640 time = getUTCtime;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
641 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
642
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
643 string finish()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
644 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
645 time = getUTCtime - time;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
646 return format("%d'%03d", time / TicksPerSecond, time % TicksPerSecond);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
647 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
648 }