Commits

mart...@fra-win8.dcl.hpi.uni-potsdam.de  committed a76d665 Draft

Generate vtable calls.

  • Participants
  • Parent commits aa03ed9
  • Branches win8app

Comments (0)

Files changed (2)

File PCbuild/genrtwrappers.py

     return (((b0 & 0x3f) << 24) + (s[1]<<16) +
             (s[2] << 8) + s[3]), s[4:]
 
-class BasicType:
+class RTType:
+    def is_void(self):
+        return False
+
+    def is_array(self):
+        return False
+
+class BasicType(RTType):
     def __init__(self, kind):
         self.kind = kind
 
         return tnames[self.kind] + " " + var + ";"
 
     def decl_ptr(self, var):
-        return tname[self.kind] + " *" + var + ";"
+        return tnames[self.kind] + " *" + var + ";"
+
+    def is_void(self):
+        return self.kind == ELEMENT_TYPE_VOID
 
 builtin_types = {
     'IUnknown':'IUnknown',
     'Windows.Foundation.EventRegistrationToken':'EventRegistrationToken',
     'Windows.Foundation.AsyncStatus':'AsyncStatus',
+    'Windows.Foundation.IAsyncInfo':'IAsyncInfo',
+    'Windows.Foundation.HResult':'HRESULT',
     'Windows.Foundation.Uri':'__x_ABI_CWindows_CFoundation_CIUriRuntimeClass',
     'System.Guid':'GUID',
     }
 
-class NamedType:
+unsupported_types = {
+    # no C type
+    'Windows.Foundation.WwwFormUrlDecoder',
+    'Windows.Graphics.Printing.PrintTaskOptions',
+    'Windows.Media.MediaProperties.MediaPropertySet',
+    'Windows.Networking.Sockets.IWebSocket',
+    'Windows.Networking.Sockets.MessageWebSocketInformation',
+    'Windows.Networking.Sockets.StreamWebSocketInformation',
+    'Windows.Networking.Connectivity.IPInformation',
+    'Windows.Security.Authentication.OnlineId.SignOutUserOperation',
+    'Windows.Security.Cryptography.Core.CryptographicHash',
+    'Windows.Storage.Streams.DataReaderLoadOperation',
+    'Windows.Storage.Streams.DataWriterStoreOperation',
+    'Windows.Storage.AccessCache.AccessListEntryView',
+    'Windows.Storage.FileProperties.StorageItemThumbnail',
+    'Windows.UI.ApplicationSettings.SettingsCommand',
+    'Windows.UI.Xaml.Media.Animation.TimelineCollection',
+    'Windows.UI.Xaml.Media.Animation.DoubleKeyFrameCollection',
+    }
+
+class NamedType(RTType):
     def __init__(self, name, isclass):
+        if name in unsupported_types:
+            raise NotImplementedError
         self.name = name
+        self.isclass = isclass
+        self.ptr = ''
+        if self.isclass:
+            self.ptr = '*'
         try:
             self.tname = builtin_types[name]
         except KeyError:
             self.tname = '_C'.join(comp)
 
     def decl_var(self, var):
-        return "/*%s*/%s %s;" % (self.name, self.tname, var)
+        return "/*%s*/%s %s%s;" % (self.name, self.tname, self.ptr, var)
 
-    def dec_ptr(self, var):
-        return "%s *%s;" % (self.tname, var)
+    def decl_ptr(self, var):
+        return "%s %s*%s;" % (self.tname, self.ptr, var)
 
-class SZArray:
+class SZArray(RTType):
     def __init__(self, elemtype):
         self.elemtype = elemtype
 
     def decl_var(self, var):
         return self.elemtype.decl_ptr(var)
 
+    def is_array(self):
+        return True
+
 def decode_type(s):
     b0 = s[0]
     s = s[1:]
             c, s = parse_custom_mod(s)
         t, s = decode_type(s)
         # XXX consider c
-        return t, s
+        return SZArray(t), s
     if b0 == ELEMENT_TYPE_VAR:
         raise NotImplementedError
         param, s = decompress_integer(s)
     else:
         return decode_type(s)
 
-def parse_sig(s, name):
+def parse_sig(this, s, name):
     # 22.2.3 StandAloneMethodSig
     s0 = s[0]
     s = s[1:]
     nparams, s = decompress_integer(s)
     try:
         rtype, s = decode_type(s)
+        if rtype.is_void():
+            rtype = None
         params = []
         for i in range(nparams):
             t, s = parse_param(s)
             params.append(t)
     except NotImplementedError:
         params = None
-    outfile.write('static PyObject*\n%s_%s(PyObject *_this, PyObject *args)\n{\n' %
+    outfile.write('static PyObject*\n%s_%s(PyObject *_self, PyObject *args)\n{\n' %
                   (cname, name))
     if params is None:
         outfile.write('  PyErr_SetString(PyExc_NotImplementedError, "signature is unsupported");\n')
         outfile.write('  return NULL;\n')
     else:
+        outfile.write('  RTObject* self = (RTObject*)_self;\n')
+        outfile.write('  %s *_this = (%s*)self->_com;\n' % (this.tname, this.tname))
+        if rtype:
+            if rtype.is_array():
+                outfile.write('  UINT32 result_size;\n')
+            outfile.write('  %s\n' % rtype.decl_var('result'))
+        outfile.write('  HRESULT hres;\n')
         for i, p in enumerate(params):
+            if p.is_array():
+                outfile.write("  UINT32 param%d_size;\n" % i)
             outfile.write("  %s\n" % p.decl_var("param%d" % i))
+        outfile.write("  hres = _this->lpVtbl->%s(_this" % name)
+        for i, p in enumerate(params):
+            if p.is_array():
+                outfile.write(", param%d_size" % i)
+            outfile.write(", param%d" % i)
+        if rtype:
+            if rtype.is_array():
+                outfile.write(', &result_size')
+            outfile.write(', &result')
+        outfile.write(');\n')
     outfile.write('}\n\n')
 
 # No header file for these namespaces
 # skip for now
 skipped_types = {
     'Windows.Devices.Enumeration.DeviceThumbnail',
+    'Windows.ApplicationModel.Background.IBackgroundTaskBuilder',
+    'Windows.ApplicationModel.Background.IPushNotificationTriggerFactory',
+    'Windows.Devices.Sms.ISmsDevice',
+    'Windows.Management.Deployment.IPackageManager',
+    'Windows.UI.Xaml.Media.Animation.IStoryboard',
+    # no this type
+    'Windows.ApplicationModel.Background.BackgroundExecutionManager',
     }
 skipped_namespaces = {
     'Windows.Foundation.Metadata', # no header file
         include(namespace)
     for typedef in mdi.EnumTypeDefs(None, 1000):
         tname, flags, base = mdi.GetTypeDefProps(typedef)
+        if not (flags & 0x20):
+            # skip non-interface types for now
+            continue
         if '`' in tname:
             # XXX generics
             continue
         namespace = tname.rsplit('.', 1)[0]
         if namespace in skipped_namespaces:
             continue
+        try:
+            this = NamedType(tname, True)
+        except NotImplementedError:
+            continue
         outfile.write("/******* %s ********/\n" % tname)
         cname = tname.replace('.', '_')
-        methods = []
-        classes.append(cname)
+        methods = set()
+        overloaded = set()
+        # skip over overloaded methods
         for md in mdi.EnumMethods(None, typedef, 100):
             mt, name, flags, sig, flags = mdi.GetMethodProps(md)
             if name in methods:
+                overloaded.add(name)
+            methods.add(name)
+        classes.append(cname)
+        methods = set()
+        for md in mdi.EnumMethods(None, typedef, 100):
+            mt, name, flags, sig, flags = mdi.GetMethodProps(md)
+            if name in overloaded:
                 # XXX resolve overloading somehow
                 continue
             if name == '.ctor':
                 # XXX ctor methods
                 continue
-            methods.append(name)
-            parse_sig(sig, name)
+            parse_sig(this, sig, name)
+            methods.add(name)
         print_type()
 
 outfile.write('''