[Xcb-commit] 4 commits - xcb-proto
Jamey Sharp
jamey at kemper.freedesktop.org
Wed Jun 14 16:46:35 PDT 2006
xcb-proto/src/import.py | 68 ++++++++++++++++++++++++++++++++++++++++++++
xcb-proto/src/size.py | 57 ++++++++++++++++++++++--------------
xcb-proto/src/type.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 176 insertions(+), 23 deletions(-)
New commits:
diff-tree 5e1ff70281f82b4124ed00529b78782922779811 (from c294fa82080193009eead8d1e19393f334add699)
Author: Jamey Sharp <jamey at minilop.net>
Date: Wed Jun 14 16:45:24 2006 -0700
Bugfix for size.py: count padding in struct size.
diff --git a/xcb-proto/src/size.py b/xcb-proto/src/size.py
index 885c1ae..8376833 100755
--- a/xcb-proto/src/size.py
+++ b/xcb-proto/src/size.py
@@ -36,6 +36,10 @@ class AnnotateSize(XMLFilterBase):
elif self.union is not None:
self.totalsize = max(self.totalsize, size)
attrs = AttributesUnion(attrs, bytes=str(size))
+ elif name == 'pad':
+ assert self.union is None
+ if self.struct is not None:
+ self.totalsize += int(attrs['bytes'])
elif name == 'xidtype':
self.setTypeSize(attrs['name'], 4)
elif name == 'typedef':
diff-tree c294fa82080193009eead8d1e19393f334add699 (from ba18d38cb536e51efe27f623a0277d3828bab035)
Author: Jamey Sharp <jamey at minilop.net>
Date: Wed Jun 14 14:18:49 2006 -0700
type.py qualifies all type names with the header in which they are defined.
Update size.py to quit doing a bad job at the same task.
Suggested usage is now:
./import.py extensions/composite.xml | ./type.py | ./size.py
diff --git a/xcb-proto/src/size.py b/xcb-proto/src/size.py
index 07e2f27..885c1ae 100755
--- a/xcb-proto/src/size.py
+++ b/xcb-proto/src/size.py
@@ -12,21 +12,17 @@ def AttributesUnion(base, **values):
class AnnotateSize(XMLFilterBase):
types = {
- 'BYTE': 1,
- 'BOOL': 1,
- 'CARD8': 1,
- 'CARD16': 2,
- 'CARD32': 4,
- 'INT8': 1,
- 'INT16': 2,
- 'INT32': 4,
- 'float': 4,
- 'double': 8,
+ 'BYTE': 1, 'BOOL': 1,
+ 'CARD8': 1, 'CARD16': 2, 'CARD32': 4,
+ 'INT8': 1, 'INT16': 2, 'INT32': 4,
+ 'char': 1, 'void': 1,
+ 'float': 4, 'double': 8,
+ 'XID': 4,
}
header = []
def setTypeSize(self, name, size):
+ assert not self.types.has_key(name)
self.types[name] = size
- self.types[self.header[0] + ':' + name] = size
struct = None
union = None
@@ -49,7 +45,7 @@ class AnnotateSize(XMLFilterBase):
setattr(self, name, attrs['name'])
self.totalsize = 0
- if len(self.header) == 1:
+ if len(self.header) == 1 or name == 'xcb':
XMLFilterBase.startElement(self, name, attrs)
def characters(self, content):
@@ -57,7 +53,7 @@ class AnnotateSize(XMLFilterBase):
XMLFilterBase.characters(self, content)
def endElement(self, name):
- if len(self.header) == 1:
+ if len(self.header) == 1 or name == 'xcb':
XMLFilterBase.endElement(self, name)
if name == 'xcb':
diff --git a/xcb-proto/src/type.py b/xcb-proto/src/type.py
new file mode 100755
index 0000000..c2f3cdf
--- /dev/null
+++ b/xcb-proto/src/type.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+from xml.sax.saxutils import XMLFilterBase, XMLGenerator
+from xml.sax.xmlreader import AttributesImpl
+from xml.sax import make_parser
+import sys
+
+def AttributesUnion(base, **values):
+ baseitems = dict(base)
+ baseitems.update(values)
+ return AttributesImpl(baseitems)
+
+class AnnotateType(XMLFilterBase):
+ scopes = []
+ map = dict([(name, [name]) for name in [
+ 'BOOL', 'BYTE',
+ 'CARD8', 'CARD16', 'CARD32',
+ 'INT8', 'INT16', 'INT32',
+ 'char', 'void',
+ 'float', 'double',
+ 'XID',
+ ]])
+ def startScope(self, name):
+ self.scopes.insert(0, name)
+ def declareType(self, name):
+ assert ':' not in name
+ qname = self.scopes[0] + ':' + name
+ self.map.setdefault(name, []).append(qname)
+ def getQualifiedType(self, name):
+ if ':' in name:
+ return name
+ names = self.map.get(name, [])
+ return names[0]
+ def endScope(self):
+ self.scopes.pop(0)
+
+ def startElement(self, name, attrs):
+ attnames = []
+ if name == 'xcb':
+ self.startScope(attrs['header'])
+ elif name in ['struct', 'union', 'xidtype', 'enum', 'event', 'eventcopy', 'error', 'errorcopy']:
+ self.declareType(attrs['name'])
+ attnames = ['name']
+ if name.endswith('copy'):
+ attnames.append('ref')
+ elif name == 'typedef':
+ self.declareType(attrs['newname'])
+ attnames = ['oldname', 'newname']
+ elif name == 'valueparam':
+ attnames = ['value-mask-type']
+ elif attrs.has_key('type'):
+ attnames = ['type']
+ newattrs = {}
+ for attname in attnames:
+ newattrs[attname] = self.getQualifiedType(attrs[attname])
+ if newattrs:
+ attrs = AttributesUnion(attrs, **newattrs)
+ XMLFilterBase.startElement(self, name, attrs)
+
+ def endElement(self, name):
+ XMLFilterBase.endElement(self, name)
+ if name == 'xcb':
+ self.endScope()
+
+annotator = AnnotateType(make_parser())
+annotator.setContentHandler(XMLGenerator())
+if len(sys.argv) > 1:
+ annotator.parse(sys.argv[1])
+else:
+ annotator.parse(sys.stdin)
+
+for name,names in annotator.map.iteritems():
+ if len(names) != 1:
+ print "<!-- warning:", name, "has the following definitions:", names, "-->"
diff-tree ba18d38cb536e51efe27f623a0277d3828bab035 (from fc7d662f70879c0ef0587ad047307d6d884f02e0)
Author: Jamey Sharp <jamey at minilop.net>
Date: Tue Jun 13 17:23:03 2006 -0700
Process <import> directives with a new import.py tool.
Update size.py to accept all the data it needs in one file or stdin.
diff --git a/xcb-proto/src/import.py b/xcb-proto/src/import.py
new file mode 100755
index 0000000..63cba99
--- /dev/null
+++ b/xcb-proto/src/import.py
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+
+from xml.sax.saxutils import XMLFilterBase, XMLGenerator
+from xml.sax import make_parser
+import sys, os
+
+path = [os.path.curdir, 'extensions']
+def find_file_on_path(name):
+ for d in path:
+ test = os.path.join(d, name)
+ if os.path.isfile(test):
+ return test
+ raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), name)
+
+seen = {}
+
+class ProcessImports(XMLFilterBase):
+ def setContentHandler(self, handler):
+ self.handler = handler
+ XMLFilterBase.setContentHandler(self, handler)
+
+ def ensure(self, name):
+ if not seen.has_key(name):
+ child = ProcessImports(make_parser())
+ child.setContentHandler(self.handler)
+ child.parse(find_file_on_path(name + '.xml'))
+
+ def startDocument(self):
+ pass
+ def endDocument(self):
+ pass
+
+ inimport = None
+
+ def startElement(self, name, attrs):
+ assert self.inimport is None
+ if name == 'import':
+ self.inimport = ""
+ return
+ XMLFilterBase.startElement(self, name, attrs)
+ if name == 'xcb':
+ seen[attrs['header']] = True
+ if attrs['header'] != 'xcb_types':
+ self.ensure('xcb_types')
+ self.ensure('xproto')
+
+ def characters(self, content):
+ if self.inimport is not None:
+ self.inimport += content
+ else:
+ XMLFilterBase.characters(self, content)
+
+ def endElement(self, name):
+ if name == 'import':
+ self.ensure(self.inimport)
+ self.inimport = None
+ return
+ XMLFilterBase.endElement(self, name)
+
+out = XMLGenerator()
+importer = ProcessImports(make_parser())
+importer.setContentHandler(out)
+out.startDocument()
+if len(sys.argv) > 1:
+ importer.parse(sys.argv[1])
+else:
+ importer.parse(sys.stdin)
+out.endDocument()
diff --git a/xcb-proto/src/size.py b/xcb-proto/src/size.py
index 2e1c403..07e2f27 100755
--- a/xcb-proto/src/size.py
+++ b/xcb-proto/src/size.py
@@ -23,16 +23,16 @@ class AnnotateSize(XMLFilterBase):
'float': 4,
'double': 8,
}
- header = None
+ header = []
def setTypeSize(self, name, size):
self.types[name] = size
- self.types[self.header + ':' + name] = size
+ self.types[self.header[0] + ':' + name] = size
struct = None
union = None
def startElement(self, name, attrs):
if name == 'xcb':
- self.header = attrs['header']
+ self.header.insert(0, attrs['header'])
elif name == 'field':
size = self.types.get(attrs['type'], 0)
if self.struct is not None:
@@ -48,17 +48,29 @@ class AnnotateSize(XMLFilterBase):
assert self.struct is None and self.union is None
setattr(self, name, attrs['name'])
self.totalsize = 0
- XMLFilterBase.startElement(self, name, attrs)
+
+ if len(self.header) == 1:
+ XMLFilterBase.startElement(self, name, attrs)
+
+ def characters(self, content):
+ if len(self.header) == 1:
+ XMLFilterBase.characters(self, content)
def endElement(self, name):
- if name == 'struct' or name == 'union':
+ if len(self.header) == 1:
+ XMLFilterBase.endElement(self, name)
+
+ if name == 'xcb':
+ self.header.pop(0)
+ elif name == 'struct' or name == 'union':
assert getattr(self, name) is not None
self.setTypeSize(getattr(self, name), self.totalsize)
setattr(self, name, None)
del self.totalsize
- XMLFilterBase.endElement(self, name)
annotator = AnnotateSize(make_parser())
annotator.setContentHandler(XMLGenerator())
-for f in sys.argv[1:]:
- annotator.parse(f)
+if len(sys.argv) > 1:
+ annotator.parse(sys.argv[1])
+else:
+ annotator.parse(sys.stdin)
diff-tree fc7d662f70879c0ef0587ad047307d6d884f02e0 (from 5dfad53a67c8c49c9c1561bce9cbac95b6274d0b)
Author: Jamey Sharp <jamey at minilop.net>
Date: Tue Jun 13 17:11:56 2006 -0700
Simpler implementation of AttributesUnion for XML processing.
diff --git a/xcb-proto/src/size.py b/xcb-proto/src/size.py
index 907f2b5..2e1c403 100755
--- a/xcb-proto/src/size.py
+++ b/xcb-proto/src/size.py
@@ -5,11 +5,10 @@ from xml.sax.xmlreader import Attributes
from xml.sax import make_parser
import sys
-class AttributesUnion(AttributesImpl):
- def __init__(self, base, **values):
- baseitems = dict(base)
- baseitems.update(values)
- AttributesImpl.__init__(self, baseitems)
+def AttributesUnion(base, **values):
+ baseitems = dict(base)
+ baseitems.update(values)
+ return AttributesImpl(baseitems)
class AnnotateSize(XMLFilterBase):
types = {
More information about the xcb-commit
mailing list