Comments bad... header.py works on the entire tree! And the shift-reduce conflict is gone!
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 19 Jun 2008 13:58:49 -0400
changeset 12 30574df5c435
parent 11 024b54ccabc6
child 13 f51708e7f0d9
push id9
push userbsmedberg@mozilla.com
push dateThu, 19 Jun 2008 17:57:09 +0000
Comments bad... header.py works on the entire tree! And the shift-reduce conflict is gone!
header.py
xpidl.py
--- a/header.py
+++ b/header.py
@@ -1,14 +1,24 @@
 #!/usr/bin/env python
 
 """Print a C++ header file for the IDL files specified on the command line"""
 
 import sys, os.path, re, xpidl
 
+printdoccomments = False
+
+if printdoccomments:
+    def printComments(fd, clist, indent):
+        for c in clist:
+            fd.write("%s%s\n" % (indent, c))
+else:
+    def printComments(fd, clist, indent):
+        pass
+
 def firstCap(str):
     return str[0].upper() + str[1:]
 
 def attributeParamName(a):
     return "a" + firstCap(a.name)
 
 def attributeNativeName(a, getter):
     binaryname = a.binaryname is not None and a.binaryname or firstCap(a.name)
@@ -132,17 +142,17 @@ def print_header(idl, fd, filename):
 
         if p.kind == 'forward':
             fd.write(forward_decl % {'name': p.name})
             continue
         if p.kind == 'interface':
             write_interface(p, fd)
             continue
         if p.kind == 'typedef':
-            for c in p.doccomments: fd.write("%s\n" % c)
+            printComments(fd, p.doccomments, '')
             fd.write("typedef %s %s;\n\n" % (p.realtype.nativeType('in'),
                                              p.name))
 
     fd.write(footer % {'basename': idl_basename(filename)})
 
 iface_header = r"""
 /* starting interface:    %(name)s */
 #define %(defname)s_IID_STR "%(iid)s"
@@ -231,37 +241,34 @@ iface_template_epilog = """/* End of imp
 
 """
 
 def write_interface(iface, fd):
     if iface.namemap is None:
         raise Exception("Interface was not resolved.")
 
     def write_const_decl(c):
-        for comment in c.doccomments:
-            fd.write("  %s\n" % comment)
+        printComments(fd, c.doccomments, '  ')
 
         basetype = c.basetype
         value = c.getValue()
 
         fd.write("  enum { %(name)s = %(value)s%(signed)s };\n\n" % {
                      'name': c.name,
                      'value': value,
                      'signed': (not basetype.signed) and 'U' or ''})
 
     def write_method_decl(m):
-        for comment in m.doccomments:
-            fd.write("  %s\n" % comment)
+        printComments(fd, m.doccomments, '  ')
 
         fd.write("  /* %s */\n" % m.toIDL())
         fd.write("  %s = 0;\n\n" % methodAsNative(m))
                                                                            
     def write_attr_decl(a):
-        for comment in a.doccomments:
-            fd.write("  %s\n" % comment)
+        printComments(fd, a.doccomments, '  ')
 
         fd.write("  /* %s */\n" % a.toIDL());
 
         fd.write("  %s = 0;\n" % attributeAsNative(a, True))
         if not a.readonly:
             fd.write("  %s = 0;\n" % attributeAsNative(a, False))
         fd.write("\n")
 
@@ -281,18 +288,17 @@ def write_interface(iface, fd):
     names.update({'defname': defname,
                   'macroname': iface.name.upper(),
                   'name': iface.name,
                   'iid': iface.attributes.uuid,
                   'implclass': implclass})
 
     fd.write(iface_header % names)
 
-    for comment in iface.doccomments:
-        fd.write("%s\n" % comment)
+    printComments(fd, iface.doccomments, '')
 
     fd.write("class ")
     foundcdata = False
     for m in iface.members:
         if isinstance(m, xpidl.CDATA):
             foundcdata = True
 
     if not foundcdata:
--- a/xpidl.py
+++ b/xpidl.py
@@ -74,22 +74,25 @@ class Builtin(object):
         self.name = name
         self.nativename = nativename
         self.signed = signed
         self.maybeConst = maybeConst
 
     def isScriptable(self):
         return True
 
-    def nativeType(self, calltype, shared=False):
-        if calltype == 'in' and self.nativename.endswith('*'):
+    def nativeType(self, calltype, shared=False, const=False):
+        if const:
+            print >>sys.stderr, IDLError("[const] doesn't make sense on builtin types.", self.location, warning=True)
+            const = 'const '
+        elif calltype == 'in' and self.nativename.endswith('*'):
             const = 'const '
         elif shared:
             if not self.nativename.endswith('*'):
-                raise XPIDLError("[shared] not applicable to non-pointer types.")
+                raise IDLError("[shared] not applicable to non-pointer types.", self.location)
             const = 'const '
         else:
             const = ''
         return "%s%s %s" % (const, self.nativename,
                             calltype != 'in' and '*' or '')
 
 builtinNames = [
     Builtin('boolean', 'PRBool'),
@@ -861,16 +864,17 @@ class IDLParser(object):
                        Location(lexer=self.lexer,
                                 lineno=self.lexer.lineno,
                                 lexpos=self.lexer.lexpos))
 
     precedence = (
         ('left', '|'),
         ('left', 'LSHIFT', 'RSHIFT'),
         ('left', '+', '-'),
+        ('left', '*'),
         ('left', 'UMINUS'),
     )
 
     def p_idlfile(self, p):
         """idlfile : productions"""
         p[0] = IDL(p[1])
 
     def p_productions_start(self, p):