]> git.cworth.org Git - apitrace/blob - windows.py
Rename GL spec parser.
[apitrace] / windows.py
1 ##########################################################################
2 #
3 # Copyright 2008-2009 VMware, Inc.
4 # All Rights Reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26 """windows.h"""
27
28 from base import *
29
30 SHORT = Alias("SHORT", Short)
31 USHORT = Alias("USHORT", UShort)
32 INT = Alias("INT", Int)
33 UINT = Alias("UINT", UInt)
34 LONG = Alias("LONG", Long)
35 ULONG = Alias("ULONG", ULong)
36 LONGLONG = Alias("LONGLONG", LongLong)
37 FLOAT = Alias("FLOAT", Float)
38
39 INT32 = Literal("INT32", "UInt")
40 UINT32 = Literal("UINT32", "UInt")
41
42 BYTE = Literal("BYTE", "UInt", base=16)
43 WORD = Literal("WORD", "UInt", base=16)
44 DWORD = Literal("DWORD", "UInt", base=16)
45
46 BOOL = Alias("BOOL", Bool)
47
48 LPLONG = Pointer(LONG)
49 LPWORD = Pointer(WORD)
50 LPDWORD = Pointer(DWORD)
51 LPBOOL = Pointer(BOOL)
52 LPSIZE = LPDWORD
53
54 LPSTR = CString
55 LPCSTR = Const(CString)
56 LPWSTR = WString
57 LPCWSTR = Const(WString)
58
59 LARGE_INTEGER = Struct("LARGE_INTEGER", [
60     (LONGLONG, 'QuadPart'),
61 ])
62
63 SIZE_T = Alias("SIZE_T", SizeT)
64
65 HRESULT = Alias("HRESULT", Int)
66
67 VOID = Void
68 PVOID = Opaque("PVOID")
69 LPVOID = PVOID
70 HANDLE = Opaque("HANDLE")
71 HWND = Opaque("HWND")
72 HDC = Opaque("HDC")
73 HMONITOR = Opaque("HMONITOR")
74
75 GUID = Struct("GUID", [
76     (DWORD, "Data1"),
77     (WORD, "Data2"),
78     (WORD, "Data3"),
79     (BYTE, "Data4[0]"),
80     (BYTE, "Data4[1]"),
81     (BYTE, "Data4[2]"),
82     (BYTE, "Data4[3]"),
83     (BYTE, "Data4[4]"),
84     (BYTE, "Data4[5]"),
85     (BYTE, "Data4[6]"),
86     (BYTE, "Data4[7]"),
87 ])
88 LPGUID = Pointer(GUID)
89
90 #REFGUID = Alias("REFGUID", Pointer(GUID))
91 REFGUID = Alias("REFGUID", GUID)
92
93 IID = Alias("IID", GUID)
94 #REFIID = Alias("REFIID", Pointer(IID))
95 REFIID = Alias("REFIID", IID)
96
97 CLSID = Alias("CLSID", GUID)
98 #REFCLSID = Alias("REFCLSID", Pointer(CLSID))
99 REFCLSID = Alias("REFCLSID", CLSID)
100
101 LUID = Struct("LUID", [
102     (DWORD, "LowPart"),
103     (LONG, "HighPart"),
104 ])
105
106 POINT = Struct("POINT", (
107   (LONG, "x"),
108   (LONG, "y"),
109 )) 
110 LPPOINT = Pointer(POINT)
111
112 RECT = Struct("RECT", (
113   (LONG, "left"),
114   (LONG, "top"),
115   (LONG, "right"), 
116   (LONG, "bottom"), 
117 )) 
118 LPRECT = Pointer(RECT)
119
120 PALETTEENTRY = Struct("PALETTEENTRY", (
121   (BYTE, "peRed"),
122   (BYTE, "peGreen"),
123   (BYTE, "peBlue"), 
124   (BYTE, "peFlags"), 
125 )) 
126 LPPALETTEENTRY = Pointer(PALETTEENTRY)
127
128
129 RGNDATAHEADER = Struct("RGNDATAHEADER", [
130     (DWORD, "dwSize"),
131     (DWORD, "iType"),
132     (DWORD, "nCount"),
133     (DWORD, "nRgnSize"),
134     (RECT, "rcBound"),
135 ])
136
137 RGNDATA = Struct("RGNDATA", [
138     (RGNDATAHEADER, "rdh"),
139     #(Char, "Buffer[1]"),
140 ])
141 LPRGNDATA = Pointer(RGNDATA)
142
143 HMODULE = Opaque("HMODULE")
144
145 IUnknown = Interface("IUnknown")
146
147 IUnknown.methods = (
148         Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(OpaquePointer(Void)), "ppvObj"))),
149         Method(ULONG, "AddRef", ()),
150         Method(ULONG, "Release", ()),
151 )
152
153
154 class DllFunction(Function):
155
156     def get_true_pointer(self):
157         ptype = self.pointer_type()
158         pvalue = self.pointer_value()
159         print '    if(!g_hDll) {'
160         print '        g_hDll = LoadLibrary(g_szDll);'
161         print '        if(!g_hDll)'
162         self.fail_impl()
163         print '    }'
164         print '    if(!%s) {' % (pvalue,)
165         print '        %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name)
166         print '        if(!%s)' % (pvalue,)
167         self.fail_impl()
168         print '    }'
169
170
171 class Dll:
172
173     def __init__(self, name):
174         self.name = name
175         self.functions = []
176         if self not in towrap:
177             towrap.append(self)
178
179     def wrap_name(self):
180         return "Wrap" + self.name
181
182     def wrap_pre_decl(self):
183         pass
184
185     def wrap_decl(self):
186         print 'static HINSTANCE g_hDll = NULL;'
187         print 'static TCHAR g_szDll[MAX_PATH] = {0};'
188         print
189         print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
190         print
191         for function in self.functions:
192             function.wrap_decl()
193         print
194
195     def wrap_impl(self):
196         print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
197         print r'    switch(fdwReason) {'
198         print r'    case DLL_PROCESS_ATTACH:'
199         print r'        if(!GetSystemDirectory(g_szDll, MAX_PATH))'
200         print r'            return FALSE;'
201         print r'        _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
202         print r'        Log::Open("%s");' % self.name
203         print r'    case DLL_THREAD_ATTACH:'
204         print r'        return TRUE;'
205         print r'    case DLL_THREAD_DETACH:'
206         print r'        return TRUE;'
207         print r'    case DLL_PROCESS_DETACH:'
208         print r'        Log::Close();'
209         print r'        if(g_hDll) {'
210         print r'            FreeLibrary(g_hDll);'
211         print r'            g_hDll = NULL;'
212         print r'        }'
213         print r'        return TRUE;'
214         print r'    }'
215         print r'    (void)hinstDLL;'
216         print r'    (void)lpvReserved;'
217         print r'    return TRUE;'
218         print r'}'
219         print
220         for function in self.functions:
221             function.wrap_impl()
222         print
223