2008-08-09 Johan Dahlin <johan@gnome.org>
+ * giscanner/__init__.py:
+ * giscanner/ast.py:
+ * giscanner/cgobject.py:
+ * giscanner/gidlparser.py:
+ * giscanner/gidlwriter.py:
+ * giscanner/girparser.py:
+ * giscanner/girwriter.py:
+ * giscanner/glibast.py:
+ * giscanner/glibtransformer.py:
+ * giscanner/odict.py:
+ * giscanner/sourcescanner.py:
+ * giscanner/transformer.py:
+ * giscanner/utils.py:
+ * giscanner/xmlwriter.py:
+ * tools/g-ir-scanner:
+
+ PEP8ify
+
+2008-08-09 Johan Dahlin <johan@gnome.org>
+
* relaxng/api.xml:
* relaxng/c-types.xml:
* relaxng/g-types.xml:
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
-
##
# Basic types
-TYPE_INT8 = 'int8'
-TYPE_UINT8 = 'uint8'
-TYPE_INT16 = 'int16'
-TYPE_UINT16 = 'uint16'
-TYPE_INT32 = 'int32'
-TYPE_UINT32 = 'uint32'
-TYPE_INT64 = 'int64'
-TYPE_UINT64 = 'uint64'
-TYPE_LONG = 'long'
-TYPE_ULONG = 'ulong'
+TYPE_INT8 = 'int8'
+TYPE_UINT8 = 'uint8'
+TYPE_INT16 = 'int16'
+TYPE_UINT16 = 'uint16'
+TYPE_INT32 = 'int32'
+TYPE_UINT32 = 'uint32'
+TYPE_INT64 = 'int64'
+TYPE_UINT64 = 'uint64'
+TYPE_LONG = 'long'
+TYPE_ULONG = 'ulong'
# Floating-point
-TYPE_FLOAT = 'float'
-TYPE_DOUBLE = 'double'
+TYPE_FLOAT = 'float'
+TYPE_DOUBLE = 'double'
# Higher-level data types
-TYPE_NONE = 'none'
-TYPE_ANY = 'any' # CORBA Any/Variant/GValue, holds anything.
-TYPE_BOOLEAN = 'boolean' # True/False
-TYPE_STRING = 'string' # Sequence of characters
+TYPE_NONE = 'none'
+TYPE_ANY = 'any' # CORBA Any/Variant/GValue, holds anything.
+TYPE_BOOLEAN = 'boolean' # True/False
+TYPE_STRING = 'string' # Sequence of characters
TYPE_SEQUENCE = 'sequence' # Sequence of something
-TYPE_CHAR = 'char' # Character
-TYPE_UCHAR = 'uchar' # Unsigned Character
-TYPE_SIZE = 'size' # Size type (memory, buffer etc)
-TYPE_SSIZE = 'ssize'
+TYPE_CHAR = 'char' # Character
+TYPE_UCHAR = 'uchar' # Unsigned Character
+TYPE_SIZE = 'size' # Size type (memory, buffer etc)
+TYPE_SSIZE = 'ssize'
# Wide/Unicode
-TYPE_UCHAR = 'uchar'
-TYPE_USTRING = 'ustring'
+TYPE_UCHAR = 'uchar'
+TYPE_USTRING = 'ustring'
# Domain specific, but practically useful
TYPE_FILENAME = 'filename'
class Namespace(Node):
+
def __init__(self, name):
Node.__init__(self, name)
self.nodes = []
return '%s(%r, %r)' % (self.__class__.__name__, self.name,
self.nodes)
+
class Function(Node):
+
def __init__(self, name, retval, parameters, symbol):
Node.__init__(self, name)
self.retval = retval
class Type(Node):
+
def __init__(self, name, ctype=None):
Node.__init__(self, name)
self.ctype = ctype
class Parameter(Node):
+
def __init__(self, name, typenode):
Node.__init__(self, name)
self.type = typenode
class Enum(Node):
+
def __init__(self, name, symbol, members):
Node.__init__(self, name)
self.symbol = symbol
class Member(Node):
+
def __init__(self, name, value, symbol):
Node.__init__(self, name)
self.value = value
class Struct(Node):
+
def __init__(self, name, symbol):
Node.__init__(self, name)
self.fields = []
class Field(Node):
+
def __init__(self, name, typenode, symbol):
Node.__init__(self, name)
self.type = typenode
class Return(Node):
+
def __init__(self, rtype):
Node.__init__(self)
self.type = rtype
self.transfer = False
def __repr__(self):
- return 'Return(%r)' % (self.type,)
+ return 'Return(%r)' % (self.type, )
class Class(Node):
+
def __init__(self, name, parent):
Node.__init__(self, name)
self.ctype = name
class Interface(Node):
+
def __init__(self, name):
Node.__init__(self, name)
self.methods = []
class Constant(Node):
+
def __init__(self, name, type_name, value):
Node.__init__(self, name)
self.type = Type(type_name)
class Property(Node):
+
def __init__(self, name, type_name, ctype=None):
Node.__init__(self, name)
self.type = Type(type_name, ctype)
# FIXME: Inherit from Function
+
+
class Callback(Node):
+
def __init__(self, name, retval, parameters):
Node.__init__(self, name)
self.retval = retval
class Sequence(Type):
# Subclass, because a Sequence is a kind of Type
+
def __init__(self, name, ctype, element_type):
Type.__init__(self, name, ctype)
self.element_type = element_type
self.transfer = False
-
# Structs
+
class GTypeClass(ctypes.Structure):
_fields_ = [('g_type', GType)]
class GEnumClass(ctypes.Structure):
- _fields_ = [('g_type_class', GTypeClass),
+ _fields_ = [('g_type_class', GTypeClass),
('minimum', ctypes.c_int),
('maximum', ctypes.c_int),
('n_values', ctypes.c_uint),
# Functions
_gobj.g_type_name.restype = ctypes.c_char_p
+
+
def type_name(type_id):
return _gobj.g_type_name(type_id)
_gobj.g_type_from_name.argtypes = [ctypes.c_char_p]
+
+
def type_from_name(name):
return _gobj.g_type_from_name(name)
+
def type_fundamental(type_id):
return _gobj.g_type_fundamental(type_id)
+
def type_parent(type_id):
return _gobj.g_type_parent(type_id)
_gobj.g_type_class_ref.restype = ctypes.POINTER(GTypeClass)
+
+
def type_class_ref(type_id):
fundamental_type = type_fundamental(type_id)
if fundamental_type == TYPE_INVALID:
_gobj.g_object_class_list_properties.restype = ctypes.POINTER(
ctypes.POINTER(GParamSpec))
+
+
def object_class_list_properties(type_id):
klass = _gobj.g_type_class_ref(type_id)
n = ctypes.c_uint()
_gobj.g_object_interface_list_properties.restype = ctypes.POINTER(
ctypes.POINTER(GParamSpec))
+
+
def object_interface_list_properties(type_id):
iface = _gobj.g_type_default_interface_ref(type_id)
n = ctypes.c_uint()
yield ctypes.cast(pspecs[i], ctypes.POINTER(GParamSpec)).contents
_gobj.g_type_interfaces.restype = ctypes.POINTER(ctypes.c_int)
+
+
def type_interfaces(type_id):
n = ctypes.c_uint()
type_ids = _gobj.g_type_interfaces(type_id, ctypes.byref(n))
yield type_ids[i]
_gobj.g_type_interface_prerequisites.restype = ctypes.POINTER(ctypes.c_int)
+
+
def type_interface_prerequisites(type_id):
n = ctypes.c_uint()
type_ids = _gobj.g_type_interface_prerequisites(type_id, ctypes.byref(n))
yield type_ids[i]
_gobj.g_signal_list_ids.restype = ctypes.POINTER(ctypes.c_int)
+
+
def signal_list(type_id):
n = ctypes.c_uint()
signal_ids = _gobj.g_signal_list_ids(type_id, ctypes.byref(n))
class GIDLParser(object):
+
def __init__(self, filename):
self._nodes = []
self._namespace_name = None
if child.tag == 'object':
self._parse_object(child)
else:
- print 'PARSER: Unhandled %s' % (child.tag,)
+ print 'PARSER: Unhandled %s' % (child.tag, )
def _parse_object(self, node):
gobj = GLibObject(node.attrib['name'],
class GIDLWriter(XMLWriter):
+
def __init__(self, namespace):
super(GIDLWriter, self).__init__()
self._write_api(namespace)
CORE_NS = "http://www.gtk.org/introspection/core/1.0"
GLIB_NS = "http://www.gtk.org/introspection/glib/1.0"
+
def _corens(tag):
return '{%s}%s' % (CORE_NS, tag)
+
def _glibns(tag):
return '{%s}%s' % (GLIB_NS, tag)
class GIRParser(object):
+
def __init__(self, filename):
self._nodes = []
self._namespace_name = None
]:
continue
else:
- print 'PARSER: Unhandled %s' % (child.tag,)
+ print 'PARSER: Unhandled %s' % (child.tag, )
def _parse_object(self, node):
gobj = GLibObject(node.attrib['name'],
class GIRWriter(XMLWriter):
+
def __init__(self, namespace):
super(GIRWriter, self).__init__()
self._write_repository(namespace)
with self.tagcontext('glib:signal', attrs):
self._write_return_type(signal.retval)
self._write_parameters(signal.parameters)
-
type_names['gsize'] = TYPE_SIZE
type_names['gssize'] = TYPE_SSIZE
+
class GLibEnum(Enum):
+
def __init__(self, name, type_name, members, get_type):
Enum.__init__(self, name, type_name, members)
self.ctype = type_name
class GLibEnumMember(Member):
+
def __init__(self, name, value, symbol, nick):
Member.__init__(self, name, value, symbol)
self.nick = nick
class GLibObject(Class):
+
def __init__(self, name, parent, type_name, get_type):
Class.__init__(self, name, parent)
self.ctype = type_name
self.get_type = get_type
self.signals = []
+
class GLibBoxed(Struct):
+
def __init__(self, name, type_name, get_type):
Struct.__init__(self, name, get_type)
self.ctype = name
class GLibInterface(Interface):
+
def __init__(self, name, type_name, get_type):
Interface.__init__(self, name)
self.ctype = type_name
class GLibSignal(Node):
+
def __init__(self, name, retval):
Node.__init__(self, name)
self.retval = retval
class GLibTransformer(object):
+
def __init__(self, transformer):
self._transformer = transformer
self._namespace_name = None
elif fundamental_type_id == cgobject.TYPE_BOXED:
self._introspect_boxed(type_id, symbol)
else:
- print 'unhandled GType: %s' % (cgobject.type_name(type_id),)
+ print 'unhandled GType: %s' % (cgobject.type_name(type_id), )
def _introspect_enum(self, ftype_id, type_id, symbol):
type_class = cgobject.type_class_ref(type_id)
if i == 0:
name = 'object'
else:
- name = 'p%s' % (i-1,)
+ name = 'p%s' % (i-1, )
ptype = self._create_type(parameter)
param = Parameter(name, ptype)
signal.parameters.append(param)
class odict(DictMixin):
+
def __init__(self):
self._items = {}
self._keys = []
UNARY_BITWISE_COMPLEMENT,
UNARY_LOGICAL_NEGATION) = range(6)
+
def symbol_type_name(symbol_type):
return {
CSYMBOL_TYPE_INVALID: 'invalid',
CSYMBOL_TYPE_MEMBER: 'member',
}.get(symbol_type)
+
def ctype_name(ctype):
return {
CTYPE_INVALID: 'invalid',
CTYPE_ENUM: 'enum',
CTYPE_POINTER: 'pointer',
CTYPE_ARRAY: 'array',
- CTYPE_FUNCTION: 'function'
+ CTYPE_FUNCTION: 'function',
}.get(ctype)
class SourceType(object):
__members__ = ['type', 'base_type', 'name', 'child_list']
+
def __init__(self, scanner, stype):
self._scanner = scanner
self._stype = stype
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
class SourceScanner(object):
+
def __init__(self):
self._scanner = _giscanner.SourceScanner()
self._filenames = []
- self._cpp_options = []
+ self._cpp_options = []
# Public API
def _parse(self, filenames):
if not filenames:
return
-
+
cpp_args = [
'cpp',
'-C',
proc = subprocess.Popen(cpp_args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
-
+
for filename in filenames:
filename = os.path.abspath(filename)
- proc.stdin.write('#include <%s>\n' % (filename,))
+ proc.stdin.write('#include <%s>\n' % (filename, ))
proc.stdin.close()
tmp = tempfile.mktemp()
class Transformer(object):
+
def __init__(self, generator, namespace_name):
self.generator = generator
self._namespace = Namespace(namespace_name)
pass
else:
raise NotImplementedError(
- 'Transformer: unhandled symbol: %r' % (symbol,))
+ 'Transformer: unhandled symbol: %r' % (symbol, ))
def _create_enum(self, symbol):
members = []
def _create_function(self, symbol):
directives = symbol.directives()
- parameters = list(self._create_parameters(symbol.base_type, directives))
+ parameters = list(self._create_parameters(
+ symbol.base_type, directives))
return_ = self._create_return(symbol.base_type.base_type,
directives.get('return', []))
name = self._remove_prefix(symbol.ident)
value = self._create_source_type(source_type.base_type) + '*'
else:
print 'TRANSFORMER: Unhandled source type %r' % (
- source_type,)
+ source_type, )
value = '???'
return value
ftype = self._create_type(symbol.base_type)
node = Field(symbol.ident, ftype, symbol.ident)
return node
-
+
def _create_typedef(self, symbol):
ctype = symbol.base_type.type
if (ctype == CTYPE_POINTER and
param.allow_none = True
else:
print 'Unhandled parameter annotation option: %s' % (
- option,)
+ option, )
return param
def _create_return(self, source_type, options=None):
return_.type = seq
else:
print 'Unhandled parameter annotation option: %s' % (
- option,)
+ option, )
return return_
def _create_typedef_struct(self, symbol):
type_name = ptype.name
ptype.name = self._resolve_type_name(type_name)
return ptype
-
_upperstr_pat2 = re.compile(r'([A-Z][A-Z])([A-Z][0-9a-z])')
_upperstr_pat3 = re.compile(r'^([A-Z])([A-Z])')
+
def to_underscores(name):
"""Converts a typename to the equivalent underscores name.
This is used to form the type conversion macros and enum/flag
_libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n")
+
def resolve_libtool(libname):
data = open(libname).read()
filename = _libtool_pat.search(data).groups()[0]
'.libs', filename)
return libname
+
def strip_common_prefix(first, second):
first_underscore = to_underscores(first)
for i, c in enumerate(first_underscore.upper()):
if c != second[i]:
break
return second[i:]
-
class XMLWriter(object):
+
def __init__(self):
self._data = StringIO()
self._tag_stack = []
for attr, value in attributes:
if value is None:
raise ValueError(
- "value for attribute %r cannot be None" % (attr,))
+ "value for attribute %r cannot be None" % (attr, ))
attr_length += 2 + len(attr) + len(quoteattr(value))
return attr_length + indent + self._indent
attr_value += '\n%s' % (self._indent_char * indent_len)
if value is None:
raise ValueError(
- "value for attribute %r cannot be None" % (attr,))
+ "value for attribute %r cannot be None" % (attr, ))
attr_value += ' %s=%s' % (attr, quoteattr(value))
if first:
first = False
self.write_line('<%s%s>' % (tag_name, attrs))
def _close_tag(self, tag_name):
- self.write_line('</%s>' % (tag_name,))
+ self.write_line('</%s>' % (tag_name, ))
# Public API
def write_tag(self, tag_name, attributes, data=None):
if attributes is None:
attributes = []
- prefix = '<%s' % (tag_name,)
+ prefix = '<%s' % (tag_name, )
if data is not None:
suffix = '>%s</%s>' % (data, tag_name)
else:
('value', '7'),
('c:identifier', 'GTK_ANCHOR_WEST'),
('glib:nick', 'west')])
-
+
w.pop_tag()
w.pop_tag()
w.pop_tag()
return parser
+
def _error(msg):
- raise SystemExit('ERROR: %s' % (msg,))
+ raise SystemExit('ERROR: %s' % (msg, ))
+
def main(args):
parser = _get_option_parser()
elif options.format == 'gidl':
from giscanner.gidlwriter import GIDLWriter as Writer
else:
- _error("Unknown format: %s" % (options.format,))
+ _error("Unknown format: %s" % (options.format, ))
for package in options.packages:
- output = commands.getoutput('pkg-config --cflags %s' % (package,))
+ output = commands.getoutput('pkg-config --cflags %s' % (package, ))
pkg_options, unused = parser.parse_args(output.split())
options.cpp_includes.extend(pkg_options.cpp_includes)
options.cpp_defines.extend(pkg_options.cpp_defines)
if (arg.endswith('.c') or
arg.endswith('.h')):
if not os.path.exists(arg):
- _error('%s: no such a file or directory' % (arg,))
+ _error('%s: no such a file or directory' % (arg, ))
filenames.append(arg)
# Run the preprocessor, tokenize and construct simple