#
import os
+import sys
from .ast import (Bitfield, Callback, Enum, Function, Namespace, Member,
Parameter, Return, Struct, Field,
class SkipError(Exception):
pass
+class VaListSkipError(SkipError):
+ pass
class Names(object):
names = property(lambda self: self._names)
def get_includes(self):
return self._includes
+ def set_strip_suffix(self, strip_suffix):
+ self._strip_suffix = strip_suffix
+
def set_strip_prefix(self, strip_prefix):
self._strip_prefix = strip_prefix
path = os.path.join(d, girname)
if os.path.exists(path):
return path
- raise ValueError("Couldn't find include %r (search path: %r)"\
+ sys.stderr.write("Couldn't find include %r (search path: %r)\n"\
% (girname, searchdirs))
+ sys.exit(1)
def _parse_include(self, filename):
parser = self._cachestore.load(filename)
# when --strip-prefix=g:
# GHashTable -> HashTable
# g_hash_table_new -> hash_table_new
+ stripped = False
prefix = self._strip_prefix.lower()
- if isfunction:
+
+ if isfunction and '_' in name:
prefix += '_'
if len(name) > len(prefix) and name.lower().startswith(prefix):
name = name[len(prefix):]
+ stripped = True
while name.startswith('_'):
name = name[1:]
+
+ if (stripped and self._strip_suffix and
+ len(name) > len(self._strip_suffix) and
+ name.endswith(self._strip_suffix)
+ name = name[:-1*len(self._strip_suffix)]
+
return name
def _traverse_one(self, symbol, stype=None):
if not self._type_is_callback(param.type):
continue
+ # set a default scope
+ if param.scope is None:
+ param.scope = 'call'
+
# j is the index where we look for closure/destroy to
# group with the callback param
j = i + 1
source_type = symbol.base_type
if (source_type.type == CTYPE_POINTER and
symbol.base_type.base_type.type == CTYPE_FUNCTION):
- node = self._create_callback(symbol)
+ try:
+ node = self._create_callback(symbol)
+ except VaListSkipError:
+ #this handles va_list members, and converts them
+ #to unwritable, unreadable void*
+ ftype = Type("any", "void*")
+ ftype = self.resolve_param_type(ftype)
+ node = Field(symbol.ident, ftype, ftype.name,
+ readable=False, writable=False, bits=symbol.const_int)
+
+
elif source_type.type == CTYPE_STRUCT and source_type.name is None:
node = self._create_struct(symbol, anonymous=True)
elif source_type.type == CTYPE_UNION and source_type.name is None:
if (ctype == CTYPE_POINTER and
symbol.base_type.base_type.type == CTYPE_FUNCTION):
node = self._create_typedef_callback(symbol)
+ if (ctype == CTYPE_FUNCTION):
+ node = self._create_typedef_callback(symbol)
elif (ctype == CTYPE_POINTER and
symbol.base_type.base_type.type == CTYPE_STRUCT):
node = self._create_typedef_struct(symbol, disguised=True)
name = self.remove_prefix(symbol.ident)
if symbol.base_type.name:
target = self.remove_prefix(symbol.base_type.name)
+ elif (ctype == CTYPE_POINTER and
+ symbol.base_type.base_type.name):
+ target = self.remove_prefix(
+ symbol.base_type.base_type.name) + '*'
+ elif (ctype == CTYPE_POINTER and
+ symbol.base_type.base_type.type == CTYPE_VOID):
+ target = 'any'
else:
target = 'none'
if name in type_names:
def _create_type(self, source_type, is_param, is_retval):
ctype = self._create_source_type(source_type)
if ctype.startswith('va_list'):
- raise SkipError()
+ raise VaListSkipError()
# FIXME: FILE* should not be skipped, it should be handled
# properly instead
elif ctype == 'FILE*':
else:
break
return type_name
+
+ def iter_enums(self):
+ for node in self._namespace.nodes:
+ if isinstance(node, Enum):
+ yield node