aboutsummaryrefslogtreecommitdiff
path: root/libxcb/xcb-proto/xcbgen
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-07-25 10:26:41 +0000
committermarha <marha@users.sourceforge.net>2009-07-25 10:26:41 +0000
commit1dad159fe09ac3a88b21b98544880e5ecc0e8d54 (patch)
tree00297a0e4602eb3fda6bd602e585ceab8c9f1024 /libxcb/xcb-proto/xcbgen
parent87db695311f33c4ff560b2cafdbd1d2e421f29bb (diff)
downloadvcxsrv-1dad159fe09ac3a88b21b98544880e5ecc0e8d54.tar.gz
vcxsrv-1dad159fe09ac3a88b21b98544880e5ecc0e8d54.tar.bz2
vcxsrv-1dad159fe09ac3a88b21b98544880e5ecc0e8d54.zip
Added xcb-proto-1.5.tar.gz. Removed old files.
Diffstat (limited to 'libxcb/xcb-proto/xcbgen')
-rw-r--r--libxcb/xcb-proto/xcbgen/Makefile.am3
-rw-r--r--libxcb/xcb-proto/xcbgen/Makefile.in329
-rw-r--r--libxcb/xcb-proto/xcbgen/__init__.py1
-rw-r--r--libxcb/xcb-proto/xcbgen/error.py5
-rw-r--r--libxcb/xcb-proto/xcbgen/expr.py88
-rw-r--r--libxcb/xcb-proto/xcbgen/matcher.py112
-rw-r--r--libxcb/xcb-proto/xcbgen/state.py166
-rw-r--r--libxcb/xcb-proto/xcbgen/xtypes.py491
8 files changed, 1195 insertions, 0 deletions
diff --git a/libxcb/xcb-proto/xcbgen/Makefile.am b/libxcb/xcb-proto/xcbgen/Makefile.am
new file mode 100644
index 000000000..110a992f1
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/Makefile.am
@@ -0,0 +1,3 @@
+pkgpythondir = $(pythondir)/xcbgen
+
+pkgpython_PYTHON = __init__.py error.py expr.py matcher.py state.py xtypes.py
diff --git a/libxcb/xcb-proto/xcbgen/Makefile.in b/libxcb/xcb-proto/xcbgen/Makefile.in
new file mode 100644
index 000000000..14d4ba311
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/Makefile.in
@@ -0,0 +1,329 @@
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+subdir = xcbgen
+DIST_COMMON = $(pkgpython_PYTHON) $(srcdir)/Makefile.am \
+ $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_CLEAN_FILES =
+SOURCES =
+DIST_SOURCES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(pkgpythondir)"
+pkgpythonPYTHON_INSTALL = $(INSTALL_DATA)
+py_compile = $(top_srcdir)/py-compile
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+XMLLINT = @XMLLINT@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+am__leading_dot = @am__leading_dot@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build_alias = @build_alias@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host_alias = @host_alias@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = $(pythondir)/xcbgen
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+xcbincludedir = @xcbincludedir@
+pkgpython_PYTHON = __init__.py error.py expr.py matcher.py state.py xtypes.py
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign xcbgen/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --foreign xcbgen/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-pkgpythonPYTHON: $(pkgpython_PYTHON)
+ @$(NORMAL_INSTALL)
+ test -z "$(pkgpythondir)" || $(MKDIR_P) "$(DESTDIR)$(pkgpythondir)"
+ @list='$(pkgpython_PYTHON)'; dlist=''; for p in $$list; do\
+ if test -f "$$p"; then b=; else b="$(srcdir)/"; fi; \
+ if test -f $$b$$p; then \
+ f=$(am__strip_dir) \
+ dlist="$$dlist $$f"; \
+ echo " $(pkgpythonPYTHON_INSTALL) '$$b$$p' '$(DESTDIR)$(pkgpythondir)/$$f'"; \
+ $(pkgpythonPYTHON_INSTALL) "$$b$$p" "$(DESTDIR)$(pkgpythondir)/$$f"; \
+ else :; fi; \
+ done; \
+ if test -n "$$dlist"; then \
+ if test -z "$(DESTDIR)"; then \
+ PYTHON=$(PYTHON) $(py_compile) --basedir "$(pkgpythondir)" $$dlist; \
+ else \
+ PYTHON=$(PYTHON) $(py_compile) --destdir "$(DESTDIR)" --basedir "$(pkgpythondir)" $$dlist; \
+ fi; \
+ else :; fi
+
+uninstall-pkgpythonPYTHON:
+ @$(NORMAL_UNINSTALL)
+ @list='$(pkgpython_PYTHON)'; dlist=''; for p in $$list; do\
+ f=$(am__strip_dir) \
+ rm -f "$(DESTDIR)$(pkgpythondir)/$$f"; \
+ rm -f "$(DESTDIR)$(pkgpythondir)/$${f}c"; \
+ rm -f "$(DESTDIR)$(pkgpythondir)/$${f}o"; \
+ done
+tags: TAGS
+TAGS:
+
+ctags: CTAGS
+CTAGS:
+
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile
+installdirs:
+ for dir in "$(DESTDIR)$(pkgpythondir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-generic
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am: install-pkgpythonPYTHON
+
+install-dvi: install-dvi-am
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pkgpythonPYTHON
+
+.MAKE: install-am install-strip
+
+.PHONY: all all-am check check-am clean clean-generic distclean \
+ distclean-generic distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-pkgpythonPYTHON install-ps \
+ install-ps-am install-strip installcheck installcheck-am \
+ installdirs maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \
+ uninstall-am uninstall-pkgpythonPYTHON
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libxcb/xcb-proto/xcbgen/__init__.py b/libxcb/xcb-proto/xcbgen/__init__.py
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/__init__.py
@@ -0,0 +1 @@
+
diff --git a/libxcb/xcb-proto/xcbgen/error.py b/libxcb/xcb-proto/xcbgen/error.py
new file mode 100644
index 000000000..bbcd5013d
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/error.py
@@ -0,0 +1,5 @@
+class ResolveException(Exception):
+ '''
+ Gets thrown when a type doesn't resolve in the XML.
+ '''
+ pass
diff --git a/libxcb/xcb-proto/xcbgen/expr.py b/libxcb/xcb-proto/xcbgen/expr.py
new file mode 100644
index 000000000..522e17d09
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/expr.py
@@ -0,0 +1,88 @@
+'''
+This module contains helper classes for structure fields and length expressions.
+'''
+class Field(object):
+ '''
+ Represents a field of a structure.
+
+ type is the datatype object for the field.
+ field_type is the name of the type (string tuple)
+ field_name is the name of the structure field.
+ visible is true iff the field should be in the request API.
+ wire is true iff the field should be in the request structure.
+ auto is true iff the field is on the wire but not in the request API (e.g. opcode)
+ '''
+ def __init__(self, type, field_type, field_name, visible, wire, auto):
+ self.type = type
+ self.field_type = field_type
+ self.field_name = field_name
+ self.visible = visible
+ self.wire = wire
+ self.auto = auto
+
+
+class Expression(object):
+ '''
+ Represents a mathematical expression for a list length or exprfield.
+
+ Public fields:
+ op is the operation (text +,*,/,<<) or None.
+ lhs and rhs are the sub-Expressions if op is set.
+ lenfield_name is the name of the length field, or None for request lists.
+ lenfield is the Field object for the length field, or None.
+ bitfield is True if the length field is a bitmask instead of a number.
+ nmemb is the fixed size (value)of the expression, or None
+ '''
+ def __init__(self, elt, parent):
+ self.parent = parent
+
+ self.nmemb = None
+
+ self.lenfield_name = None
+ self.lenfield_type = None
+ self.lenfield = None
+ self.lenwire = False
+ self.bitfield = False
+
+ self.op = None
+ self.lhs = None
+ self.rhs = None
+
+ if elt.tag == 'list':
+ # List going into a request, which has no length field (inferred by server)
+ self.lenfield_name = elt.get('name') + '_len'
+ self.lenfield_type = 'CARD32'
+
+ elif elt.tag == 'fieldref':
+ # Standard list with a fieldref
+ self.lenfield_name = elt.text
+
+ elif elt.tag == 'valueparam':
+ # Value-mask. The length bitmask is described by attributes.
+ self.lenfield_name = elt.get('value-mask-name')
+ self.lenfield_type = elt.get('value-mask-type')
+ self.lenwire = True
+ self.bitfield = True
+
+ elif elt.tag == 'op':
+ # Op field. Need to recurse.
+ self.op = elt.get('op')
+ self.lhs = Expression(list(elt)[0], parent)
+ self.rhs = Expression(list(elt)[1], parent)
+
+ # Hopefully we don't have two separate length fields...
+ self.lenfield_name = self.lhs.lenfield_name
+ if self.lenfield_name == None:
+ self.lenfield_name = self.rhs.lenfield_name
+
+ elif elt.tag == 'value':
+ # Constant expression
+ self.nmemb = int(elt.text)
+
+ else:
+ # Notreached
+ raise Exception('XXX')
+
+
+ def fixed_size(self):
+ return self.nmemb != None
diff --git a/libxcb/xcb-proto/xcbgen/matcher.py b/libxcb/xcb-proto/xcbgen/matcher.py
new file mode 100644
index 000000000..e7958fa44
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/matcher.py
@@ -0,0 +1,112 @@
+'''
+XML parser. One function for each top-level element in the schema.
+
+Most functions just declare a new object and add it to the module.
+For typedefs, eventcopies, xidtypes, and other aliases though,
+we do not create a new type object, we just record the existing one under a new name.
+'''
+
+from os.path import join
+from xml.etree.cElementTree import parse
+
+import state
+from xtypes import *
+
+def import_(node, module, namespace):
+ '''
+ For imports, we load the file, create a new namespace object,
+ execute recursively, then record the import (for header files, etc.)
+ '''
+ new_file = join(namespace.dir, '%s.xml' % node.text)
+ new_root = parse(new_file).getroot()
+ new_namespace = state.Namespace(new_file)
+ execute(module, new_namespace)
+ if not module.has_import(node.text):
+ module.add_import(node.text, new_namespace)
+
+def typedef(node, module, namespace):
+ id = node.get('newname')
+ name = namespace.prefix + (id,)
+ type = module.get_type(node.get('oldname'))
+ module.add_type(id, namespace.ns, name, type)
+
+def xidtype(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ type = module.get_type('CARD32')
+ module.add_type(id, namespace.ns, name, type)
+
+def xidunion(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ type = module.get_type('CARD32')
+ module.add_type(id, namespace.ns, name, type)
+
+def enum(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ type = Enum(name, node)
+ module.add_type(id, namespace.ns, name, type)
+
+def struct(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ type = Struct(name, node)
+ module.add_type(id, namespace.ns, name, type)
+
+def union(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ type = Union(name, node)
+ module.add_type(id, namespace.ns, name, type)
+
+def request(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ type = Request(name, node)
+ module.add_request(id, name, type)
+
+def event(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ event = Event(name, node)
+ event.add_opcode(node.get('number'), name, True)
+ module.add_event(id, name, event)
+
+def eventcopy(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ event = module.get_event(node.get('ref'))
+ event.add_opcode(node.get('number'), name, False)
+ module.add_event(id, name, event)
+
+def error(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ error = Error(name, node)
+ error.add_opcode(node.get('number'), name, True)
+ module.add_error(id, name, error)
+
+def errorcopy(node, module, namespace):
+ id = node.get('name')
+ name = namespace.prefix + (id,)
+ error = module.get_error(node.get('ref'))
+ error.add_opcode(node.get('number'), name, False)
+ module.add_error(id, name, error)
+
+funcs = {'import' : import_,
+ 'typedef' : typedef,
+ 'xidtype' : xidtype,
+ 'xidunion' : xidunion,
+ 'enum' : enum,
+ 'struct' : struct,
+ 'union' : union,
+ 'request' : request,
+ 'event' : event,
+ 'eventcopy' : eventcopy,
+ 'error' : error,
+ 'errorcopy' : errorcopy}
+
+def execute(module, namespace):
+ for elt in list(namespace.root):
+ funcs[elt.tag](elt, module, namespace)
diff --git a/libxcb/xcb-proto/xcbgen/state.py b/libxcb/xcb-proto/xcbgen/state.py
new file mode 100644
index 000000000..51efc9480
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/state.py
@@ -0,0 +1,166 @@
+'''
+This module contains the namespace class and the singleton module class.
+'''
+from os.path import dirname, basename
+from xml.etree.cElementTree import parse
+
+import matcher
+from error import *
+from xtypes import *
+
+import __main__
+
+class Namespace(object):
+ '''
+ Contains the naming information for an extension.
+
+ Public fields:
+
+ header is the header attribute ("header file" name).
+ is_ext is true for extensions, false for xproto.
+ major_version and minor_version are extension version info.
+ ext_xname is the X extension name string.
+ ext_name is the XCB extension name prefix.
+ '''
+ def __init__(self, filename):
+ # Path info
+ self.path = filename
+ self.dir = dirname(filename)
+ self.file = basename(filename)
+
+ # Parse XML
+ self.root = parse(filename).getroot()
+ self.header = self.root.get('header')
+ self.ns = self.header + ':'
+
+ # Get root element attributes
+ if self.root.get('extension-xname', False):
+ self.is_ext = True
+ self.major_version = self.root.get('major-version')
+ self.minor_version = self.root.get('minor-version')
+ self.ext_xname = self.root.get('extension-xname')
+ self.ext_name = self.root.get('extension-name')
+ self.prefix = ('xcb', self.ext_name)
+ else:
+ self.is_ext = False
+ self.ext_name = ''
+ self.prefix = ('xcb',)
+
+
+class Module(object):
+ '''
+ This is the grand, encompassing class that represents an entire XCB specification.
+ Only gets instantiated once, in the main() routine.
+
+ Don't need to worry about this much except to declare it and to get the namespace.
+
+ Public fields:
+ namespace contains the namespace info for the spec.
+ '''
+ open = __main__.output['open']
+ close = __main__.output['close']
+
+ def __init__(self, filename, output):
+ self.namespace = Namespace(filename)
+ self.output = output
+
+ self.imports = []
+ self.types = {}
+ self.events = {}
+ self.errors = {}
+ self.all = []
+
+ # Register some common types
+ self.add_type('CARD8', '', ('uint8_t',), tcard8)
+ self.add_type('CARD16', '', ('uint16_t',), tcard16)
+ self.add_type('CARD32', '', ('uint32_t',), tcard32)
+ self.add_type('INT8', '', ('int8_t',), tint8)
+ self.add_type('INT16', '', ('int16_t',), tint16)
+ self.add_type('INT32', '', ('int32_t',), tint32)
+ self.add_type('BYTE', '', ('uint8_t',), tcard8)
+ self.add_type('BOOL', '', ('uint8_t',), tcard8)
+ self.add_type('char', '', ('char',), tchar)
+ self.add_type('float', '', ('float',), tfloat)
+ self.add_type('double', '', ('double',), tdouble)
+ self.add_type('void', '', ('void',), tcard8)
+
+ # This goes out and parses the rest of the XML
+ def register(self):
+ matcher.execute(self, self.namespace)
+
+ # Recursively resolve all types
+ def resolve(self):
+ for (name, item) in self.all:
+ item.resolve(self)
+
+ # Call all the output methods
+ def generate(self):
+ self.open()
+
+ for (name, item) in self.all:
+ item.out(name)
+
+ self.close()
+
+ # Keeps track of what's been imported so far.
+ def add_import(self, name, namespace):
+ self.imports.append((name, namespace.header))
+
+ def has_import(self, name):
+ for (name_, header) in self.imports:
+ if name_ == name:
+ return True
+ return False
+
+ # Keeps track of non-request/event/error datatypes
+ def add_type(self, id, ns, name, item):
+ key = ns + id
+ if key in self.types:
+ return
+ self.types[key] = (name, item)
+ if name[:-1] == self.namespace.prefix:
+ self.all.append((name, item))
+
+ def get_type_impl(self, id, idx):
+ key = id
+ if key in self.types:
+ return self.types[key][idx]
+
+ key = self.namespace.ns + id
+ if key in self.types:
+ return self.types[key][idx]
+
+ for key in self.types.keys():
+ if key.rpartition(':')[2] == id:
+ return self.types[key][idx]
+
+ raise ResolveException('Type %s not found' % id)
+
+ def get_type(self, id):
+ return self.get_type_impl(id, 1)
+
+ def get_type_name(self, id):
+ return self.get_type_impl(id, 0)
+
+ # Keeps track of request datatypes
+ def add_request(self, id, name, item):
+ if name[:-1] == self.namespace.prefix:
+ self.all.append((name, item))
+
+ # Keeps track of event datatypes
+ def add_event(self, id, name, item):
+ self.events[id] = (name, item)
+ if name[:-1] == self.namespace.prefix:
+ self.all.append((name, item))
+
+ def get_event(self, id):
+ return self.events[id][1]
+
+ # Keeps track of error datatypes
+ def add_error(self, id, name, item):
+ self.errors[id] = (name, item)
+ if name[:-1] == self.namespace.prefix:
+ self.all.append((name, item))
+
+ def get_error(self, id):
+ return self.errors[id][1]
diff --git a/libxcb/xcb-proto/xcbgen/xtypes.py b/libxcb/xcb-proto/xcbgen/xtypes.py
new file mode 100644
index 000000000..30617b8f4
--- /dev/null
+++ b/libxcb/xcb-proto/xcbgen/xtypes.py
@@ -0,0 +1,491 @@
+'''
+This module contains the classes which represent XCB data types.
+'''
+from expr import Field, Expression
+import __main__
+
+class Type(object):
+ '''
+ Abstract base class for all XCB data types.
+ Contains default fields, and some abstract methods.
+ '''
+ def __init__(self, name):
+ '''
+ Default structure initializer. Sets up default fields.
+
+ Public fields:
+ name is a tuple of strings specifying the full type name.
+ size is the size of the datatype in bytes, or None if variable-sized.
+ nmemb is 1 for non-list types, None for variable-sized lists, otherwise number of elts.
+ booleans for identifying subclasses, because I can't figure out isinstance().
+ '''
+ self.name = name
+ self.size = None
+ self.nmemb = None
+ self.resolved = False
+
+ # Screw isinstance().
+ self.is_simple = False
+ self.is_list = False
+ self.is_expr = False
+ self.is_container = False
+ self.is_reply = False
+ self.is_union = False
+ self.is_pad = False
+
+ def resolve(self, module):
+ '''
+ Abstract method for resolving a type.
+ This should make sure any referenced types are already declared.
+ '''
+ raise Exception('abstract resolve method not overridden!')
+
+ def out(self, name):
+ '''
+ Abstract method for outputting code.
+ These are declared in the language-specific modules, and
+ there must be a dictionary containing them declared when this module is imported!
+ '''
+ raise Exception('abstract out method not overridden!')
+
+ def fixed_size(self):
+ '''
+ Abstract method for determining if the data type is fixed-size.
+ '''
+ raise Exception('abstract fixed_size method not overridden!')
+
+ def make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto):
+ '''
+ Default method for making a data type a member of a structure.
+ Extend this if the data type needs to add an additional length field or something.
+
+ module is the global module object.
+ complex_type is the structure object.
+ see Field for the meaning of the other parameters.
+ '''
+ new_field = Field(self, field_type, field_name, visible, wire, auto)
+
+ # We dump the _placeholder_byte if any fields are added.
+ for (idx, field) in enumerate(complex_type.fields):
+ if field == _placeholder_byte:
+ complex_type.fields[idx] = new_field
+ return
+
+ complex_type.fields.append(new_field)
+
+class SimpleType(Type):
+ '''
+ Derived class which represents a cardinal type like CARD32 or char.
+ Any type which is typedef'ed to cardinal will be one of these.
+
+ Public fields added:
+ none
+ '''
+ def __init__(self, name, size):
+ Type.__init__(self, name)
+ self.is_simple = True
+ self.size = size
+ self.nmemb = 1
+
+ def resolve(self, module):
+ self.resolved = True
+
+ def fixed_size(self):
+ return True
+
+ out = __main__.output['simple']
+
+
+# Cardinal datatype globals. See module __init__ method.
+tcard8 = SimpleType(('uint8_t',), 1)
+tcard16 = SimpleType(('uint16_t',), 2)
+tcard32 = SimpleType(('uint32_t',), 4)
+tint8 = SimpleType(('int8_t',), 1)
+tint16 = SimpleType(('int16_t',), 2)
+tint32 = SimpleType(('int32_t',), 4)
+tchar = SimpleType(('char',), 1)
+tfloat = SimpleType(('float',), 4)
+tdouble = SimpleType(('double',), 8)
+
+
+class Enum(SimpleType):
+ '''
+ Derived class which represents an enum. Fixed-size.
+
+ Public fields added:
+ values contains a list of (name, value) tuples. value is empty, or a number.
+ bits contains a list of (name, bitnum) tuples. items only appear if specified as a bit. bitnum is a number.
+ '''
+ def __init__(self, name, elt):
+ SimpleType.__init__(self, name, 4)
+ self.values = []
+ self.bits = []
+ for item in list(elt):
+ # First check if we're using a default value
+ if len(list(item)) == 0:
+ self.values.append((item.get('name'), ''))
+ continue
+
+ # An explicit value or bit was specified.
+ value = list(item)[0]
+ if value.tag == 'value':
+ self.values.append((item.get('name'), value.text))
+ elif value.tag == 'bit':
+ self.values.append((item.get('name'), '%u' % (1 << int(value.text))))
+ self.bits.append((item.get('name'), value.text))
+
+ def resolve(self, module):
+ self.resolved = True
+
+ def fixed_size(self):
+ return True
+
+ out = __main__.output['enum']
+
+
+class ListType(Type):
+ '''
+ Derived class which represents a list of some other datatype. Fixed- or variable-sized.
+
+ Public fields added:
+ member is the datatype of the list elements.
+ parent is the structure type containing the list.
+ expr is an Expression object containing the length information, for variable-sized lists.
+ '''
+ def __init__(self, elt, member, parent):
+ Type.__init__(self, member.name)
+ self.is_list = True
+ self.member = member
+ self.parent = parent
+
+ if elt.tag == 'list':
+ elts = list(elt)
+ self.expr = Expression(elts[0] if len(elts) else elt, self)
+ elif elt.tag == 'valueparam':
+ self.expr = Expression(elt, self)
+
+ self.size = member.size if member.fixed_size() else None
+ self.nmemb = self.expr.nmemb if self.expr.fixed_size() else None
+
+ def make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto):
+ if not self.fixed_size():
+ # We need a length field.
+ # Ask our Expression object for it's name, type, and whether it's on the wire.
+ lenfid = self.expr.lenfield_type
+ lenfield_name = self.expr.lenfield_name
+ lenwire = self.expr.lenwire
+ needlen = True
+
+ # See if the length field is already in the structure.
+ for field in self.parent.fields:
+ if field.field_name == lenfield_name:
+ needlen = False
+
+ # It isn't, so we need to add it to the structure ourself.
+ if needlen:
+ type = module.get_type(lenfid)
+ lenfield_type = module.get_type_name(lenfid)
+ type.make_member_of(module, complex_type, lenfield_type, lenfield_name, True, lenwire, False)
+
+ # Add ourself to the structure by calling our original method.
+ Type.make_member_of(self, module, complex_type, field_type, field_name, visible, wire, auto)
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+ self.member.resolve(module)
+
+ # Find my length field again. We need the actual Field object in the expr.
+ # This is needed because we might have added it ourself above.
+ if not self.fixed_size():
+ for field in self.parent.fields:
+ if field.field_name == self.expr.lenfield_name and field.wire:
+ self.expr.lenfield = field
+ break
+
+ self.resolved = True
+
+ def fixed_size(self):
+ return self.member.fixed_size() and self.expr.fixed_size()
+
+class ExprType(Type):
+ '''
+ Derived class which represents an exprfield. Fixed size.
+
+ Public fields added:
+ expr is an Expression object containing the value of the field.
+ '''
+ def __init__(self, elt, member, parent):
+ Type.__init__(self, member.name)
+ self.is_expr = True
+ self.member = member
+ self.parent = parent
+
+ self.expr = Expression(list(elt)[0], self)
+
+ self.size = member.size
+ self.nmemb = 1
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+ self.member.resolve(module)
+ self.resolved = True
+
+ def fixed_size(self):
+ return True
+
+class SizedPadType(Type):
+ '''
+ Derived class which represents a padding field of given size.
+ '''
+ def __init__(self, size):
+ Type.__init__(self, tcard8.name)
+ self.is_pad = True
+ self.size = 1
+ self.nmemb = int(size)
+
+ def resolve(self, module):
+ self.resolved = True
+
+ def fixed_size(self):
+ return True
+
+class PadType(SizedPadType):
+ '''
+ Derived class which represents a padding field of given type.
+ '''
+ def __init__(self, elt):
+ self.nmemb = "1" if (elt == None) else elt.get('bytes')
+ SizedPadType.__init__(self, self.nmemb)
+
+class ComplexType(Type):
+ '''
+ Derived class which represents a structure. Base type for all structure types.
+
+ Public fields added:
+ fields is an array of Field objects describing the structure fields.
+ '''
+ def __init__(self, name, elt):
+ Type.__init__(self, name)
+ self.is_container = True
+ self.elt = elt
+ self.fields = []
+ self.nmemb = 1
+ self.size = 0
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+ pads = 0
+
+ # Resolve all of our field datatypes.
+ for child in list(self.elt):
+ value_mask_pad = None
+ if child.tag == 'pad':
+ field_name = 'pad' + str(pads)
+ fkey = 'CARD8'
+ type = PadType(child)
+ pads = pads + 1
+ visible = False
+ elif child.tag == 'field':
+ field_name = child.get('name')
+ fkey = child.get('type')
+ type = module.get_type(fkey)
+ visible = True
+ elif child.tag == 'exprfield':
+ field_name = child.get('name')
+ fkey = child.get('type')
+ type = ExprType(child, module.get_type(fkey), self)
+ visible = False
+ elif child.tag == 'list':
+ field_name = child.get('name')
+ fkey = child.get('type')
+ type = ListType(child, module.get_type(fkey), self)
+ visible = True
+ elif child.tag == 'valueparam':
+ field_name = child.get('value-list-name')
+ fkey = 'CARD32'
+ type = ListType(child, module.get_type(fkey), self)
+ visible = True
+ value_mask_pad = child.get('value-mask-pad')
+ else:
+ # Hit this on Reply
+ continue
+
+ # Get the full type name for the field
+ field_type = module.get_type_name(fkey)
+ # Add the field to ourself
+ type.make_member_of(module, self, field_type, field_name, visible, True, False)
+ # Recursively resolve the type (could be another structure, list)
+ type.resolve(module)
+
+ # Add a value-mask-pad if necessary
+ if value_mask_pad != None:
+ vmp_field_name = 'pad' + str(pads)
+ vmp_fkey = 'CARD8'
+ vmp_type = SizedPadType(value_mask_pad)
+ pads = pads + 1
+ vmp_visible = False
+ vmp_field_type = module.get_type_name(vmp_fkey)
+ vmp_type.make_member_of(module, self, vmp_field_type, vmp_field_name, vmp_visible, True, False)
+ vmp_type.resolve(module)
+
+ self.calc_size() # Figure out how big we are
+ self.resolved = True
+
+ def calc_size(self):
+ self.size = 0
+ for m in self.fields:
+ if not m.wire:
+ continue
+ if m.type.fixed_size():
+ self.size = self.size + (m.type.size * m.type.nmemb)
+ else:
+ self.size = None
+ break
+
+ def fixed_size(self):
+ for m in self.fields:
+ if not m.type.fixed_size():
+ return False
+ return True
+
+
+class Struct(ComplexType):
+ '''
+ Derived class representing a struct data type.
+ '''
+ out = __main__.output['struct']
+
+
+class Union(ComplexType):
+ '''
+ Derived class representing a union data type.
+ '''
+ def __init__(self, name, elt):
+ ComplexType.__init__(self, name, elt)
+ self.is_union = True
+
+ out = __main__.output['union']
+
+
+class Reply(ComplexType):
+ '''
+ Derived class representing a reply. Only found as a field of Request.
+ '''
+ def __init__(self, name, elt):
+ ComplexType.__init__(self, name, elt)
+ self.is_reply = True
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+ # Add the automatic protocol fields
+ self.fields.append(Field(tcard8, tcard8.name, 'response_type', False, True, True))
+ self.fields.append(_placeholder_byte)
+ self.fields.append(Field(tcard16, tcard16.name, 'sequence', False, True, True))
+ self.fields.append(Field(tcard32, tcard32.name, 'length', False, True, True))
+ ComplexType.resolve(self, module)
+
+
+class Request(ComplexType):
+ '''
+ Derived class representing a request.
+
+ Public fields added:
+ reply contains the reply datatype or None for void requests.
+ opcode contains the request number.
+ '''
+ def __init__(self, name, elt):
+ ComplexType.__init__(self, name, elt)
+ self.reply = None
+ self.opcode = elt.get('opcode')
+
+ for child in list(elt):
+ if child.tag == 'reply':
+ self.reply = Reply(name, child)
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+ # Add the automatic protocol fields
+ if module.namespace.is_ext:
+ self.fields.append(Field(tcard8, tcard8.name, 'major_opcode', False, True, True))
+ self.fields.append(Field(tcard8, tcard8.name, 'minor_opcode', False, True, True))
+ self.fields.append(Field(tcard16, tcard16.name, 'length', False, True, True))
+ ComplexType.resolve(self, module)
+ else:
+ self.fields.append(Field(tcard8, tcard8.name, 'major_opcode', False, True, True))
+ self.fields.append(_placeholder_byte)
+ self.fields.append(Field(tcard16, tcard16.name, 'length', False, True, True))
+ ComplexType.resolve(self, module)
+
+ if self.reply:
+ self.reply.resolve(module)
+
+ out = __main__.output['request']
+
+
+class Event(ComplexType):
+ '''
+ Derived class representing an event data type.
+
+ Public fields added:
+ opcodes is a dictionary of name -> opcode number, for eventcopies.
+ '''
+ def __init__(self, name, elt):
+ ComplexType.__init__(self, name, elt)
+ self.opcodes = {}
+
+ tmp = elt.get('no-sequence-number')
+ self.has_seq = (tmp == None or tmp.lower() == 'false' or tmp == '0')
+
+ def add_opcode(self, opcode, name, main):
+ self.opcodes[name] = opcode
+ if main:
+ self.name = name
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+
+ # Add the automatic protocol fields
+ self.fields.append(Field(tcard8, tcard8.name, 'response_type', False, True, True))
+ if self.has_seq:
+ self.fields.append(_placeholder_byte)
+ self.fields.append(Field(tcard16, tcard16.name, 'sequence', False, True, True))
+ ComplexType.resolve(self, module)
+
+ out = __main__.output['event']
+
+
+class Error(ComplexType):
+ '''
+ Derived class representing an error data type.
+
+ Public fields added:
+ opcodes is a dictionary of name -> opcode number, for errorcopies.
+ '''
+ def __init__(self, name, elt):
+ ComplexType.__init__(self, name, elt)
+ self.opcodes = {}
+
+ def add_opcode(self, opcode, name, main):
+ self.opcodes[name] = opcode
+ if main:
+ self.name = name
+
+ def resolve(self, module):
+ if self.resolved:
+ return
+
+ # Add the automatic protocol fields
+ self.fields.append(Field(tcard8, tcard8.name, 'response_type', False, True, True))
+ self.fields.append(Field(tcard8, tcard8.name, 'error_code', False, True, True))
+ self.fields.append(Field(tcard16, tcard16.name, 'sequence', False, True, True))
+ ComplexType.resolve(self, module)
+
+ out = __main__.output['error']
+
+_placeholder_byte = Field(PadType(None), tcard8.name, 'pad0', False, True, False)