summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@async.com.br>2008-05-31 23:20:56 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-05-31 23:20:56 +0000
commit04e4dcd86e2318f637c0e9c01cea1da4476c9a58 (patch)
tree7c0fa93890808bc33e67a0376268f56019b0e624
parent7a8c0642f5cc6e80e873f239984beeab7b9ba6ff (diff)
downloadgobject-introspection-04e4dcd86e2318f637c0e9c01cea1da4476c9a58.tar.gz
Add a new source type enum for member. Use __repr__ for improved debugging
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 svn path=/trunk/; revision=281
-rw-r--r--ChangeLog14
-rw-r--r--giscanner/girparser.py4
-rw-r--r--giscanner/scannerparser.y24
-rw-r--r--giscanner/sourcescanner.h3
-rw-r--r--giscanner/sourcescanner.py22
-rw-r--r--giscanner/transformer.py38
-rw-r--r--tests/parser/Foo-expected.gir7
-rw-r--r--tests/parser/foo-object.h12
8 files changed, 91 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 34980bf9..c6b41900 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
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
+
+2008-05-31 Johan Dahlin <jdahlin@async.com.br>
+
* giscanner/xmlwriter.py:
Improve error reporting when trying to quote None.
* giscanner/girparser.py:
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 7858342f..50d21cb1 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -50,7 +50,9 @@ class GIRParser(object):
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,)
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index 45d67891..f21950db 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -728,17 +728,19 @@ struct_declaration_list
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);
}
;
diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h
index b0f4de7c..93fa450e 100644
--- a/giscanner/sourcescanner.h
+++ b/giscanner/sourcescanner.h
@@ -42,7 +42,8 @@ typedef enum
CSYMBOL_TYPE_STRUCT,
CSYMBOL_TYPE_UNION,
CSYMBOL_TYPE_ENUM,
- CSYMBOL_TYPE_TYPEDEF
+ CSYMBOL_TYPE_TYPEDEF,
+ CSYMBOL_TYPE_MEMBER
} GISourceSymbolType;
typedef enum
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index a7226156..f79fe78e 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -31,7 +31,8 @@ from . import _giscanner
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 @@ def symbol_type_name(symbol_type):
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 @@ def ctype_name(ctype):
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 SourceType(object):
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 @@ class SourceScanner(object):
def __init__(self):
self._scanner = _giscanner.SourceScanner()
self._filenames = []
- self._cpp_options = []
+ self._cpp_options = []
# Public API
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 6622602c..f1dd2fa1 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -22,11 +22,11 @@ from giscanner.ast import (Callback, Enum, Function, Namespace, Member,
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 @@ class Transformer(object):
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 @@ class Transformer(object):
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 @@ class Transformer(object):
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 @@ class Transformer(object):
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 @@ class Transformer(object):
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 @@ class Transformer(object):
elif ctype in (CTYPE_TYPEDEF,
CTYPE_POINTER,
CTYPE_BASIC_TYPE,
- CTYPE_UNION):
+ CTYPE_UNION,
+ CTYPE_VOID):
return
else:
raise NotImplementedError(
@@ -241,13 +253,7 @@ class Transformer(object):
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)
diff --git a/tests/parser/Foo-expected.gir b/tests/parser/Foo-expected.gir
index 5bd7ad35..e4561c83 100644
--- a/tests/parser/Foo-expected.gir
+++ b/tests/parser/Foo-expected.gir
@@ -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>
diff --git a/tests/parser/foo-object.h b/tests/parser/foo-object.h
index 2ef8ce6f..cea217ae 100644
--- a/tests/parser/foo-object.h
+++ b/tests/parser/foo-object.h
@@ -129,5 +129,15 @@ struct _FooStruct
FooStructPrivate *priv;
int member;
};
-
+
+typedef struct _FooRectangle FooRectangle;
+
+struct _FooRectangle
+{
+ gint x;
+ gint y;
+ gint width;
+ gint height;
+};
+
#endif /* __FOO_OBJECT_H__ */