doccomments are parsed in very strange ways in libidl. Replicate the quirks for the moment.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Mon, 16 Jun 2008 10:13:21 -0400
changeset 9 521ac1e42cbb
parent 8 ea4b1c101668
child 10 3394439f0ddc
push id8
push userbsmedberg@mozilla.com
push dateMon, 16 Jun 2008 14:13:35 +0000
doccomments are parsed in very strange ways in libidl. Replicate the quirks for the moment.
header.py
xpidl.py
--- a/header.py
+++ b/header.py
@@ -311,49 +311,45 @@ def write_interface(iface, fd):
             write_method_decl(member)
         elif isinstance(member, xpidl.CDATA):
             fd.write("  %s" % member.data)
         else:
             raise Exception("Unexpected interface member: %s" % member)
 
     fd.write(iface_epilog % names)
 
-    written = False
     for member in iface.members:
         if isinstance(member, xpidl.Attribute):
             fd.write("\\\n  %s; " % attributeAsNative(member, True))
             if not member.readonly:
                 fd.write("\\\n  %s; " % attributeAsNative(member, False))
-            written = True
         elif isinstance(member, xpidl.Method):
             fd.write("\\\n  %s; " % methodAsNative(member))
-            written = True
-    if not written:
-        fd.write('\\')
+    if len(iface.members) == 0 or \
+       not member.kind in ('attribute', 'method'):
+       fd.write('\\')
 
     fd.write(iface_forward % names)
 
     def emitTemplate(tmpl):
-        written = False
         for member in iface.members:
             if isinstance(member, xpidl.Attribute):
                 fd.write(tmpl % {'asNative': attributeAsNative(member, True),
                                  'nativeName': attributeNativeName(member, True),
                                  'paramList': attributeParamName(member)})
                 if not member.readonly:
                     fd.write(tmpl % {'asNative': attributeAsNative(member, False),
                                      'nativeName': attributeNativeName(member, False),
                                      'paramList': attributeParamName(member)})
-                written = True
             elif isinstance(member, xpidl.Method):
                 fd.write(tmpl % {'asNative': methodAsNative(member),
                                  'nativeName': methodNativeName(member),
                                  'paramList': paramlistNames(member.params, member.realtype, member.notxpcom)})
-                written = True
-        if not written:
+        if len(iface.members) == 0 or \
+           not member.kind in ('attribute', 'method'):
             fd.write('\\')
 
     emitTemplate("\\\n  %(asNative)s { return _to %(nativeName)s(%(paramList)s); } ")
 
     fd.write(iface_forward_safe % names)
 
     emitTemplate("\\\n  %(asNative)s { return !_to ? NS_ERROR_NULL_POINTER : _to->%(nativeName)s(%(paramList)s); } ")
 
--- a/xpidl.py
+++ b/xpidl.py
@@ -192,16 +192,29 @@ class Include(object):
                 parent.setName(type)
             return
 
         raise IDLError("File '%s' not found" % self.filename, self.location)
 
 class IDL(object):
     def __init__(self, productions):
         self.productions = productions
+        # Hack alert: libidl parses doccomments on the non-first interface
+        # incorrectly, assigning them to the first member of the interface
+        # instead of the interface itself. Good god.
+        
+        found = False
+        for p in productions:
+            if p.kind == 'interface':
+                dc = p.doccomments
+                p.doccomments = []
+                if len(p.members):
+                    p.members[0].doccomments[0:0] = dc
+
+            if p.kind in ('interface', 'cdata'): found = True
 
     def setName(self, object):
         self.namemap.set(object)
 
     def getName(self, id, location):
         try:
             return self.namemap[id]
         except KeyError:
@@ -669,34 +682,35 @@ class Param(object):
         kwargs = {}
         if self.shared: kwargs['shared'] = True
         if self.const: kwargs['const'] = True
 
         try:
             return self.realtype.nativeType(self.paramtype, **kwargs)
         except IDLError, e:
             raise IDLError(e.message, self.location)
-        except TypeError, e:
-            raise IDLError("Unexpected paramater attribute", self.location)
+        # except TypeError, e:
+        #     raise IDLError("Unexpected parameter attribute", self.location)
 
     def toIDL(self):
         return "%s%s %s %s" % (paramAttlistToIDL(self.attlist),
                                self.paramtype,
                                self.type,
                                self.name)
 
 class Array(object):
     def __init__(self, basetype):
         self.type = basetype
 
     def isScriptable(self):
         return self.type.isScriptable()
 
-    def nativeType(self, calltype):
-        return self.type.nativeType(calltype) + "*"
+    def nativeType(self, calltype, const=False):
+        return "%s%s*" % (const and 'const ' or '',
+                          self.type.nativeType(calltype))
 
 class IDLParser(object):
     keywords = {
         'const': 'CONST',
         'interface': 'INTERFACE',
         'in': 'IN',
         'inout': 'INOUT',
         'out': 'OUT',