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);
}
;
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,
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):
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
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):
def __init__(self):
self._scanner = _giscanner.SourceScanner()
self._filenames = []
- self._cpp_options = []
+ self._cpp_options = []
# Public API
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):
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 = []
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()
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):
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
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
elif ctype in (CTYPE_TYPEDEF,
CTYPE_POINTER,
CTYPE_BASIC_TYPE,
- CTYPE_UNION):
+ CTYPE_UNION,
+ CTYPE_VOID):
return
else:
raise NotImplementedError(
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)