gobject-introspection r281 - in trunk: . giscanner tests/parser
- From: johan svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r281 - in trunk: . giscanner tests/parser
- Date: Sat, 31 May 2008 23:20:57 +0000 (UTC)
Author: johan
Date: Sat May 31 23:20:56 2008
New Revision: 281
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=281&view=rev
Log:
2008-05-31 Johan Dahlin <jdahlin async com br>
* giscanner/scannerparser.y:
* giscanner/sourcescanner.h:
* giscanner/sourcescanner.py:
Add a new source type enum for member.
Use __repr__ for improved debugging
* giscanner/girparser.py:
Ignore some more
* giscanner/transformer.py:
Improve parsing of struct members.
* tests/parser/foo-object.h:
Add a new testcase
Modified:
trunk/ChangeLog
trunk/giscanner/girparser.py
trunk/giscanner/scannerparser.y
trunk/giscanner/sourcescanner.h
trunk/giscanner/sourcescanner.py
trunk/giscanner/transformer.py
trunk/tests/parser/Foo-expected.gir
trunk/tests/parser/foo-object.h
Modified: trunk/giscanner/girparser.py
==============================================================================
--- trunk/giscanner/girparser.py (original)
+++ trunk/giscanner/girparser.py Sat May 31 23:20:56 2008
@@ -50,7 +50,9 @@
self._parse_object(child)
elif child.tag in [_corens('callback'),
_corens('function'),
- _corens('record')]:
+ _corens('record'),
+ _corens('enumeration'),
+ ]:
continue
else:
print 'PARSER: Unhandled %s' % (child.tag,)
Modified: trunk/giscanner/scannerparser.y
==============================================================================
--- trunk/giscanner/scannerparser.y (original)
+++ trunk/giscanner/scannerparser.y Sat May 31 23:20:56 2008
@@ -728,17 +728,19 @@
struct_declaration
: specifier_qualifier_list struct_declarator_list ';'
{
- GList *l;
- $$ = NULL;
- for (l = $2; l != NULL; l = l->next) {
- GISourceSymbol *sym = l->data;
- if ($1->storage_class_specifier & STORAGE_CLASS_TYPEDEF) {
- sym->type = CSYMBOL_TYPE_TYPEDEF;
- }
- gi_source_symbol_merge_type (sym, gi_source_type_copy ($1));
- $$ = g_list_append ($$, sym);
- }
- ctype_free ($1);
+ GList *l;
+ $$ = NULL;
+ for (l = $2; l != NULL; l = l->next)
+ {
+ GISourceSymbol *sym = l->data;
+ if ($1->storage_class_specifier & STORAGE_CLASS_TYPEDEF)
+ sym->type = CSYMBOL_TYPE_TYPEDEF;
+ else
+ sym->type = CSYMBOL_TYPE_MEMBER;
+ gi_source_symbol_merge_type (sym, gi_source_type_copy ($1));
+ $$ = g_list_append ($$, sym);
+ }
+ ctype_free ($1);
}
;
Modified: trunk/giscanner/sourcescanner.h
==============================================================================
--- trunk/giscanner/sourcescanner.h (original)
+++ trunk/giscanner/sourcescanner.h Sat May 31 23:20:56 2008
@@ -42,7 +42,8 @@
CSYMBOL_TYPE_STRUCT,
CSYMBOL_TYPE_UNION,
CSYMBOL_TYPE_ENUM,
- CSYMBOL_TYPE_TYPEDEF
+ CSYMBOL_TYPE_TYPEDEF,
+ CSYMBOL_TYPE_MEMBER
} GISourceSymbolType;
typedef enum
Modified: trunk/giscanner/sourcescanner.py
==============================================================================
--- trunk/giscanner/sourcescanner.py (original)
+++ trunk/giscanner/sourcescanner.py Sat May 31 23:20:56 2008
@@ -31,7 +31,8 @@
CSYMBOL_TYPE_STRUCT,
CSYMBOL_TYPE_UNION,
CSYMBOL_TYPE_ENUM,
- CSYMBOL_TYPE_TYPEDEF) = range(8)
+ CSYMBOL_TYPE_TYPEDEF,
+ CSYMBOL_TYPE_MEMBER) = range(9)
(CTYPE_INVALID,
CTYPE_VOID,
@@ -75,7 +76,8 @@
CSYMBOL_TYPE_STRUCT: 'struct',
CSYMBOL_TYPE_UNION: 'union',
CSYMBOL_TYPE_ENUM: 'enum',
- CSYMBOL_TYPE_TYPEDEF: 'typedef'
+ CSYMBOL_TYPE_TYPEDEF: 'typedef',
+ CSYMBOL_TYPE_MEMBER: 'member',
}.get(symbol_type)
def ctype_name(ctype):
@@ -94,10 +96,17 @@
class SourceType(object):
+ __members__ = ['type', 'base_type', 'name', 'child_list']
def __init__(self, scanner, stype):
self._scanner = scanner
self._stype = stype
+ def __repr__(self):
+ return '<%s type=%r name=%r>' % (
+ self.__class__.__name__,
+ ctype_name(self.type),
+ self.name)
+
@property
def type(self):
return self._stype.type
@@ -120,10 +129,17 @@
class SourceSymbol(object):
+ __members__ = ['const_int', 'ident', 'type', 'base_type']
def __init__(self, scanner, symbol):
self._scanner = scanner
self._symbol = symbol
+ def __repr__(self):
+ return '<%s type=%r ident=%r>' % (
+ self.__class__.__name__,
+ symbol_type_name(self.type),
+ self.ident)
+
def directives(self):
mapping = {}
for directive in self._scanner.get_directives(self._symbol.ident):
@@ -152,7 +168,7 @@
def __init__(self):
self._scanner = _giscanner.SourceScanner()
self._filenames = []
- self._cpp_options = []
+ self._cpp_options = []
# Public API
Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py (original)
+++ trunk/giscanner/transformer.py Sat May 31 23:20:56 2008
@@ -22,11 +22,11 @@
Parameter, Return, Sequence, Struct, Type)
from giscanner.sourcescanner import (
SourceSymbol, ctype_name, symbol_type_name, CTYPE_POINTER,
- CTYPE_BASIC_TYPE, CTYPE_UNION,
+ CTYPE_BASIC_TYPE, CTYPE_UNION, CTYPE_ARRAY,
CTYPE_TYPEDEF, CTYPE_VOID, CTYPE_BASIC_TYPE, CTYPE_ENUM,
CTYPE_FUNCTION, CTYPE_STRUCT, CSYMBOL_TYPE_FUNCTION,
CSYMBOL_TYPE_TYPEDEF, CSYMBOL_TYPE_STRUCT, CSYMBOL_TYPE_ENUM,
- CSYMBOL_TYPE_UNION, CSYMBOL_TYPE_OBJECT)
+ CSYMBOL_TYPE_UNION, CSYMBOL_TYPE_OBJECT, CSYMBOL_TYPE_MEMBER)
class Transformer(object):
@@ -113,13 +113,14 @@
return self._create_enum(symbol)
elif stype == CSYMBOL_TYPE_OBJECT:
return self._create_object(symbol)
+ elif stype == CSYMBOL_TYPE_MEMBER:
+ return self._create_member(symbol)
elif stype == CSYMBOL_TYPE_UNION:
# Unions are not supported
pass
else:
raise NotImplementedError(
- 'Transformer: unhandled symbol: %r of type %s'
- % (symbol.ident, symbol_type_name(stype)))
+ 'Transformer: unhandled symbol: %r' % (symbol,))
def _create_enum(self, symbol):
members = []
@@ -131,7 +132,7 @@
return Enum(name, symbol.ident, members)
def _create_object(self, symbol):
- return Member(symbol.ident, symbol.base_type.name)
+ return self._create_member(symbol)
def _create_function(self, symbol):
directives = symbol.directives()
@@ -140,7 +141,6 @@
directives.get('return', []))
name = self._remove_prefix(symbol.ident)
name = self._strip_namespace_func(name)
-
return Function(name, return_, parameters, symbol.ident)
def _create_source_type(self, source_type):
@@ -152,11 +152,13 @@
value = source_type.name
elif source_type.type == CTYPE_TYPEDEF:
value = source_type.name
+ elif source_type.type == CTYPE_ARRAY:
+ return self._create_source_type(source_type.base_type)
elif source_type.type == CTYPE_POINTER:
value = self._create_source_type(source_type.base_type) + '*'
else:
- print 'BUILDER: Unhandled source type %s' % (
- ctype_name(source_type.type),)
+ print 'TRANSFORMER: Unhandled source type %r' % (
+ source_type,)
value = '???'
return value
@@ -167,6 +169,15 @@
yield self._create_parameter(
child, options.get(child.ident, []))
+ def _create_member(self, symbol):
+ ctype = symbol.base_type.type
+ if (ctype == CTYPE_POINTER and
+ symbol.base_type.base_type.type == CTYPE_FUNCTION):
+ node = self._create_callback(symbol)
+ else:
+ node = Member(symbol.ident, self._create_source_type(symbol))
+ return node
+
def _create_typedef(self, symbol):
ctype = symbol.base_type.type
if (ctype == CTYPE_POINTER and
@@ -179,7 +190,8 @@
elif ctype in (CTYPE_TYPEDEF,
CTYPE_POINTER,
CTYPE_BASIC_TYPE,
- CTYPE_UNION):
+ CTYPE_UNION,
+ CTYPE_VOID):
return
else:
raise NotImplementedError(
@@ -241,13 +253,7 @@
struct = Struct(name, symbol.ident)
for child in symbol.base_type.child_list:
- # FIXME: This is obviously wrong, we're sending in data
- # of the wrong type to _traverse_one
- try:
- field = self._traverse_one(child, child.base_type.type)
- except NotImplementedError:
- continue
-
+ field = self._traverse_one(child)
if field:
struct.fields.append(field)
Modified: trunk/tests/parser/Foo-expected.gir
==============================================================================
--- trunk/tests/parser/Foo-expected.gir (original)
+++ trunk/tests/parser/Foo-expected.gir Sat May 31 23:20:56 2008
@@ -280,8 +280,15 @@
</parameters>
</callback>
<record name="FooStruct" c:type="FooStruct">
+ <field name="priv" value="FooStructPrivate*"/>
<field name="member" value="int"/>
</record>
<record name="FooStructPrivate" c:type="FooStructPrivate"/>
+ <record name="FooRectangle" c:type="FooRectangle">
+ <field name="x" value="gint"/>
+ <field name="y" value="gint"/>
+ <field name="width" value="gint"/>
+ <field name="height" value="gint"/>
+ </record>
</namespace>
</repository>
Modified: trunk/tests/parser/foo-object.h
==============================================================================
--- trunk/tests/parser/foo-object.h (original)
+++ trunk/tests/parser/foo-object.h Sat May 31 23:20:56 2008
@@ -129,5 +129,15 @@
FooStructPrivate *priv;
int member;
};
-
+
+typedef struct _FooRectangle FooRectangle;
+
+struct _FooRectangle
+{
+ gint x;
+ gint y;
+ gint width;
+ gint height;
+};
+
#endif /* __FOO_OBJECT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]