diff options
author | marha <marha@users.sourceforge.net> | 2011-05-03 15:37:14 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-05-03 15:37:14 +0000 |
commit | e4bd55e182560fa87af77ee3ec49fc1a907ead85 (patch) | |
tree | f77ade9dac153a4f45e08ccaf260de8d8ddbbb17 /libxcb/xcb-proto/xcbgen/matcher.py | |
parent | e8af1ef3142aaaf2d17f2d3710e23eee1baf8a61 (diff) | |
parent | cc93496bdbb3e7aea51033ece75fa85cfb5845d4 (diff) | |
download | vcxsrv-e4bd55e182560fa87af77ee3ec49fc1a907ead85.tar.gz vcxsrv-e4bd55e182560fa87af77ee3ec49fc1a907ead85.tar.bz2 vcxsrv-e4bd55e182560fa87af77ee3ec49fc1a907ead85.zip |
svn merge ^/branches/released .
Diffstat (limited to 'libxcb/xcb-proto/xcbgen/matcher.py')
-rw-r--r-- | libxcb/xcb-proto/xcbgen/matcher.py | 225 |
1 files changed, 113 insertions, 112 deletions
diff --git a/libxcb/xcb-proto/xcbgen/matcher.py b/libxcb/xcb-proto/xcbgen/matcher.py index e7958fa44..c4d99fc57 100644 --- a/libxcb/xcb-proto/xcbgen/matcher.py +++ b/libxcb/xcb-proto/xcbgen/matcher.py @@ -1,112 +1,113 @@ -''' -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) +'''
+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
+
+from xcbgen.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.)
+ '''
+ # To avoid circular import error
+ from xcbgen import state
+ 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)
|