gobject-introspection r222 - in trunk: . giscanner
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r222 - in trunk: . giscanner
- Date: Wed, 23 Apr 2008 02:28:27 +0100 (BST)
Author: johan
Date: Wed Apr 23 01:28:27 2008
New Revision: 222
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=222&view=rev
Log:
2008-04-22 Johan Dahlin <jdahlin async com br>
* giscanner/gidlwriter.py:
* giscanner/girwriter.py:
* giscanner/gobjecttreebuilder.py:
* giscanner/treebuilder.py:
Add support for Callbacks
Modified:
trunk/ChangeLog
trunk/TODO
trunk/giscanner/gidlwriter.py
trunk/giscanner/girwriter.py
trunk/giscanner/gobjecttreebuilder.py
trunk/giscanner/treebuilder.py
Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Wed Apr 23 01:28:27 2008
@@ -32,7 +32,6 @@
Scanner
------
-- Callbacks
- Virtual functions
- Signals
- Property.readable/writable, GLibProperty.blurb/nick
Modified: trunk/giscanner/gidlwriter.py
==============================================================================
--- trunk/giscanner/gidlwriter.py (original)
+++ trunk/giscanner/gidlwriter.py Wed Apr 23 01:28:27 2008
@@ -2,7 +2,7 @@
from .gobjecttreebuilder import (GLibBoxed, GLibEnum, GLibEnumMember,
GLibFlags, GLibObject, GLibInterface)
-from .treebuilder import Class, Enum, Function, Interface
+from .treebuilder import Callback, Class, Enum, Function, Interface
from .xmlwriter import XMLWriter
@@ -29,6 +29,8 @@
self._write_class(node)
elif isinstance(node, GLibBoxed):
self._write_boxed(node)
+ elif isinstance(node, Callback):
+ self._write_callback(node)
else:
print 'WRITER: Unhandled node', node
@@ -116,3 +118,9 @@
attrs = [('name', prop.name),
('prop', prop.type)]
self.write_tag('property', attrs)
+
+ def _write_callback(self, func):
+ attrs = [('name', func.name)]
+ with self.tagcontext('callback', attrs):
+ self._write_return_type(func.retval)
+ self._write_parameters(func.parameters)
Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py (original)
+++ trunk/giscanner/girwriter.py Wed Apr 23 01:28:27 2008
@@ -2,7 +2,7 @@
from .gobjecttreebuilder import (GLibBoxed, GLibEnum, GLibEnumMember,
GLibFlags, GLibObject, GLibInterface)
-from .treebuilder import Class, Enum, Function, Interface
+from .treebuilder import Callback, Class, Enum, Function, Interface
from .xmlwriter import XMLWriter
@@ -35,6 +35,8 @@
self._write_class(node)
elif isinstance(node, GLibBoxed):
self._write_boxed(node)
+ elif isinstance(node, Callback):
+ self._write_callback(node)
else:
print 'WRITER: Unhandled node', node
@@ -125,3 +127,10 @@
attrs = [('name', prop.name),
('prop', prop.type)]
self.write_tag('property', attrs)
+
+
+ def _write_callback(self, callback):
+ attrs = [('name', callback.name)]
+ with self.tagcontext('callback', attrs):
+ self._write_return_type(callback.retval)
+ self._write_parameters(callback.parameters)
Modified: trunk/giscanner/gobjecttreebuilder.py
==============================================================================
--- trunk/giscanner/gobjecttreebuilder.py (original)
+++ trunk/giscanner/gobjecttreebuilder.py Wed Apr 23 01:28:27 2008
@@ -4,8 +4,8 @@
from . import cgobject
from .odict import odict
-from .treebuilder import (Class, Enum, Function, Interface, Member, Property,
- Struct)
+from .treebuilder import (Callback, Class, Enum, Function, Interface,
+ Member, Property, Struct)
# Copied from h2defs.py
_upperstr_pat1 = re.compile(r'([^A-Z])([A-Z])')
@@ -166,8 +166,10 @@
self._parse_function(node)
elif isinstance(node, Struct):
self._parse_struct(node)
+ elif isinstance(node, Callback):
+ self._parse_callback(node)
else:
- print 'Unhandled node:', node
+ print 'GOBJECT BUILDER: Unhandled node:', node
def _parse_enum(self, enum):
enum.name = self._strip_namespace_object(enum.name)
@@ -263,6 +265,9 @@
return
self._add_attribute(struct)
+ def _parse_callback(self, callback):
+ self._add_attribute(callback)
+
def _introspect_type(self, type_id, symbol):
fundamental_type_id = cgobject.type_fundamental(type_id)
if (fundamental_type_id == cgobject.TYPE_ENUM or
Modified: trunk/giscanner/treebuilder.py
==============================================================================
--- trunk/giscanner/treebuilder.py (original)
+++ trunk/giscanner/treebuilder.py Wed Apr 23 01:28:27 2008
@@ -108,6 +108,17 @@
self.name, self.type, self.value)
+class Callback(Node):
+ def __init__(self, name, retval, parameters):
+ self.name = name
+ self.retval = retval
+ self.parameters = parameters
+
+ def __repr__(self):
+ return 'Callback(%r, %r, %r)' % (
+ self.name, self.retval, self.parameters)
+
+
class TreeBuilder(object):
def __init__(self, generator):
self.generator = generator
@@ -134,7 +145,11 @@
if stype == giscanner.CSYMBOL_TYPE_FUNCTION:
return self._create_function(symbol)
elif stype == giscanner.CSYMBOL_TYPE_TYPEDEF:
- return self._traverse_one(symbol, symbol.base_type.type)
+ if (symbol.base_type.type == giscanner.CTYPE_POINTER and
+ symbol.base_type.base_type.type == giscanner.CTYPE_FUNCTION):
+ return self._create_callback(symbol)
+ else:
+ return self._traverse_one(symbol, symbol.base_type.type)
elif stype == giscanner.CSYMBOL_TYPE_STRUCT:
return self._create_struct(symbol)
elif stype == giscanner.CSYMBOL_TYPE_ENUM:
@@ -151,12 +166,9 @@
return Enum(symbol.ident, members)
def _create_function(self, symbol):
- parameters = []
- for child in symbol.base_type.child_list:
- parameters.append(self._create_parameter(child))
-
+ parameters = self._create_parameters(symbol.base_type)
retval = Return(self._create_source_type(symbol.base_type.base_type))
- return Function(symbol.ident, retval, parameters, symbol.ident)
+ return Function(symbol.ident, retval, list(parameters), symbol.ident)
def _create_source_type(self, source_type):
if source_type.type == giscanner.CTYPE_VOID:
@@ -172,6 +184,10 @@
value = '???'
return value
+ def _create_parameters(self, base_type):
+ for child in base_type.child_list:
+ yield self._create_parameter(child)
+
def _create_parameter(self, symbol):
return Parameter(symbol.ident,
self._create_source_type(symbol.base_type))
@@ -179,3 +195,7 @@
def _create_struct(self, symbol):
return Struct(symbol.ident)
+ def _create_callback(self, symbol):
+ parameters = self._create_parameters(symbol.base_type.base_type)
+ retval = Return(self._create_source_type(symbol.base_type.base_type.base_type))
+ return Callback(symbol.ident, retval, list(parameters))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]