summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2010-09-08 11:31:02 -0400
committerColin Walters <walters@verbum.org>2010-09-08 14:40:16 -0400
commit35d349b232d80f40242dc45aa90e5ed3eab42c68 (patch)
treebe0a6c33f1c4e77b735cbedf231eccd0f074c738 /giscanner
parent5140ec172415192af4f406b1fd5ff4615caf1386 (diff)
scanner: Kill glibast
It was a stupid abstraction split, we only support GObject. * Clean up how we handle c:type - we only set it if we've actually seen a corresponding structure. * Add a warning if we don't see the structure typedef for an interface, since that's pretty bogus. (And fix regress.h to have one) * Rename the "type_name" attribute internally to "gtype_name" for clarity.
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/Makefile.am1
-rw-r--r--giscanner/ast.py201
-rw-r--r--giscanner/gdumpparser.py110
-rw-r--r--giscanner/girparser.py96
-rw-r--r--giscanner/girwriter.py144
-rw-r--r--giscanner/glibast.py161
-rw-r--r--giscanner/introspectablepass.py7
-rw-r--r--giscanner/maintransformer.py35
-rw-r--r--giscanner/transformer.py16
9 files changed, 355 insertions, 416 deletions
diff --git a/giscanner/Makefile.am b/giscanner/Makefile.am
index a2044cf..6fee40d 100644
--- a/giscanner/Makefile.am
+++ b/giscanner/Makefile.am
@@ -42,7 +42,6 @@ pkgpyexec_PYTHON = \
introspectablepass.py \
girparser.py \
girwriter.py \
- glibast.py \
gdumpparser.py \
libtoolimporter.py \
odict.py \
diff --git a/giscanner/ast.py b/giscanner/ast.py
index ada6412..6e9dc89 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -357,11 +357,10 @@ returned."""
raise ValueError("Namespace conflict: %r" % (node, ))
self.remove(previous)
# A layering violation...but oh well.
- from .glibast import GLibBoxed
if isinstance(node, Alias):
self._aliases[node.name] = node
- elif isinstance(node, (GLibBoxed, Interface, Class)):
- self._type_names[node.type_name] = node
+ elif isinstance(node, Registered) and node.gtype_name is not None:
+ self._type_names[node.gtype_name] = node
elif isinstance(node, Function):
self._symbols[node.symbol] = node
assert isinstance(node, Node)
@@ -374,11 +373,10 @@ returned."""
self._ctypes[node.symbol] = node
def remove(self, node):
- from .glibast import GLibBoxed
if isinstance(node, Alias):
del self._aliases[node.name]
- elif isinstance(node, (GLibBoxed, Interface, Class)):
- del self._type_names[node.type_name]
+ elif isinstance(node, Registered) and node.gtype_name is not None:
+ del self._type_names[node.gtype_name]
del self._names[node.name]
node.namespace = None
if hasattr(node, 'ctype'):
@@ -503,6 +501,16 @@ GIName. It's possible for nodes to contain or point to other nodes."""
def _walk(self, callback, chain):
pass
+
+class Registered:
+ """A node that (possibly) has gtype_name and get_type."""
+ def __init__(self, gtype_name, get_type):
+ assert (gtype_name is None and get_type is None) or \
+ (gtype_name is not None and get_type is not None)
+ self.gtype_name = gtype_name
+ self.get_type = get_type
+
+
class Callable(Node):
def __init__(self, name, retval, parameters, throws):
@@ -661,44 +669,72 @@ class Return(TypeContainer):
self.direction = PARAM_DIRECTION_OUT
-class Enum(Node):
+class Enum(Node, Registered):
- def __init__(self, name, symbol, members):
+ def __init__(self, name, ctype,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None,
+ members=None):
Node.__init__(self, name)
- self.symbol = symbol
+ Registered.__init__(self, gtype_name, get_type)
+ self.c_symbol_prefix = c_symbol_prefix
+ self.ctype = ctype
self.members = members
+ # Associated error quark
+ self.error_quark = None
-class Bitfield(Node):
+class Bitfield(Node, Registered):
- def __init__(self, name, symbol, members):
+ def __init__(self, name, ctype,
+ gtype_name=None,
+ c_symbol_prefix=None,
+ get_type=None,
+ members=None):
Node.__init__(self, name)
- self.symbol = symbol
+ Registered.__init__(self, gtype_name, get_type)
+ self.ctype = ctype
+ self.c_symbol_prefix = c_symbol_prefix
self.members = members
class Member(Annotated):
- def __init__(self, name, value, symbol):
+ def __init__(self, name, value, symbol, nick):
Annotated.__init__(self)
self.name = name
self.value = value
self.symbol = symbol
+ self.nick = nick
def __cmp__(self, other):
return cmp(self.name, other.name)
-class Record(Node):
- def __init__(self, name, symbol, disguised=False):
+class Compound(Node, Registered):
+ def __init__(self, name,
+ ctype=None,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None,
+ disguised=False):
Node.__init__(self, name)
+ Registered.__init__(self, gtype_name, get_type)
+ self.ctype = ctype
+ self.methods = []
+ self.static_methods = []
self.fields = []
self.constructors = []
- self.symbol = symbol
self.disguised = disguised
- self.methods = []
- self.static_methods = []
+ self.gtype_name = gtype_name
+ self.get_type = get_type
+ self.c_symbol_prefix = c_symbol_prefix
+
+ def add_gtype(self, gtype_name, get_type):
+ self.gtype_name = gtype_name
+ self.get_type = get_type
def _walk(self, callback, chain):
for ctor in self.constructors:
@@ -711,7 +747,6 @@ class Record(Node):
if field.anonymous_node is not None:
field.anonymous_node.walk(callback, chain)
-
class Field(Annotated):
def __init__(self, name, typenode, readable, writable, bits=None,
@@ -729,13 +764,91 @@ class Field(Annotated):
return cmp(self.name, other.name)
-class Class(Node):
+class Record(Compound):
- def __init__(self, name, parent, is_abstract):
+ def __init__(self, name,
+ ctype=None,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None,
+ disguised=False):
+ Compound.__init__(self, name,
+ ctype=ctype,
+ gtype_name=gtype_name,
+ get_type=get_type,
+ c_symbol_prefix=c_symbol_prefix,
+ disguised=disguised)
+ # If non-None, this record defines the FooClass C structure
+ # for some Foo GObject (or similar for GInterface)
+ self.is_gtype_struct_for = None
+
+
+class Union(Compound):
+
+ def __init__(self, name,
+ ctype=None,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None,
+ disguised=False):
+ Compound.__init__(self, name,
+ ctype=ctype,
+ gtype_name=gtype_name,
+ get_type=get_type,
+ c_symbol_prefix=c_symbol_prefix,
+ disguised=disguised)
+
+
+class Boxed(Node, Registered):
+ """A boxed type with no known associated structure/union."""
+ def __init__(self, name,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None):
+ assert gtype_name is not None
+ assert get_type is not None
Node.__init__(self, name)
- self.ctype = name
- self.c_symbol_prefix = None
+ Registered.__init__(self, gtype_name, get_type)
+ if get_type is not None:
+ assert c_symbol_prefix is not None
+ self.c_symbol_prefix = c_symbol_prefix
+ self.constructors = []
+ self.methods = []
+ self.static_methods = []
+
+ def _walk(self, callback, chain):
+ for ctor in self.constructors:
+ ctor.walk(callback, chain)
+ for meth in self.methods:
+ meth.walk(callback, chain)
+ for meth in self.static_methods:
+ meth.walk(callback, chain)
+
+
+class Signal(Callable):
+
+ def __init__(self, name, retval, parameters):
+ Callable.__init__(self, name, retval, parameters, False)
+
+
+class Class(Node, Registered):
+
+ def __init__(self, name, parent,
+ ctype=None,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None,
+ is_abstract=False):
+ Node.__init__(self, name)
+ Registered.__init__(self, gtype_name, get_type)
+ self.ctype = ctype
+ self.c_symbol_prefix = c_symbol_prefix
self.parent = parent
+ self.fundamental = False
+ self.unref_func = None
+ self.ref_func = None
+ self.set_value_func = None
+ self.get_value_func = None
# When we're in the scanner, we keep around a list
# of parents so that we can transparently fall back
# if there are 'hidden' parents
@@ -749,6 +862,7 @@ class Class(Node):
self.constructors = []
self.properties = []
self.fields = []
+ self.signals = []
def _walk(self, callback, chain):
for meth in self.methods:
@@ -762,15 +876,25 @@ class Class(Node):
for field in self.fields:
if field.anonymous_node:
field.anonymous_node.walk(callback, chain)
+ for sig in self.signals:
+ sig.walk(callback, chain)
+
-class Interface(Node):
+class Interface(Node, Registered):
- def __init__(self, name, parent):
+ def __init__(self, name, parent,
+ ctype=None,
+ gtype_name=None,
+ get_type=None,
+ c_symbol_prefix=None):
Node.__init__(self, name)
- self.c_symbol_prefix = None
+ Registered.__init__(self, gtype_name, get_type)
+ self.ctype = ctype
+ self.c_symbol_prefix = c_symbol_prefix
self.parent = parent
self.parent_chain = []
self.methods = []
+ self.signals = []
self.static_methods = []
self.virtual_methods = []
self.glib_type_struct = None
@@ -788,6 +912,9 @@ class Interface(Node):
for field in self.fields:
if field.anonymous_node:
field.anonymous_node.walk(callback, chain)
+ for sig in self.signals:
+ sig.walk(callback, chain)
+
class Constant(Node):
@@ -815,25 +942,3 @@ class Callback(Callable):
def __init__(self, name, retval, parameters, throws, ctype=None):
Callable.__init__(self, name, retval, parameters, throws)
self.ctype = ctype
-
-
-class Union(Node):
-
- def __init__(self, name, symbol):
- Node.__init__(self, name)
- self.fields = []
- self.constructors = []
- self.methods = []
- self.static_methods = []
- self.symbol = symbol
-
- def _walk(self, callback, chain):
- for ctor in self.constructors:
- ctor.walk(callback, chain)
- for meth in self.methods:
- meth.walk(callback, chain)
- for meth in self.static_methods:
- meth.walk(callback, chain)
- for field in self.fields:
- if field.anonymous_node:
- field.anonymous_node.walk(callback, chain)
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index 6c0e444..ed62dfa 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -26,7 +26,6 @@ import subprocess
from xml.etree.cElementTree import parse
from . import ast
-from . import glibast
from . import message
from .transformer import TransformerException
@@ -119,8 +118,7 @@ class GDumpParser(object):
# Anyone who wants them can get them from the ast.Class/Interface/Boxed
to_remove = []
for name, node in self._namespace.iteritems():
- if isinstance(node, (ast.Class, ast.Interface, glibast.GLibBoxed,
- glibast.GLibEnum, glibast.GLibFlags)):
+ if isinstance(node, ast.Registered) and node.get_type is not None:
get_type_name = node.get_type
if get_type_name == 'intern':
continue
@@ -172,7 +170,11 @@ blob containing data gleaned from GObject's primitive introspection."""
symbol = 'g_initially_unowned_get_type'
else:
assert False
- gnode = glibast.GLibObject(node.name, parent_gitype, type_name, symbol, 'object', True)
+ gnode = ast.Class(node.name, parent_gitype,
+ gtype_name=type_name,
+ get_type=symbol,
+ c_symbol_prefix='object',
+ is_abstract=True)
if type_name == 'GObject':
gnode.fields.extend(node.fields)
else:
@@ -243,24 +245,33 @@ blob containing data gleaned from GObject's primitive introspection."""
else:
raise ValueError("Unhandled introspection XML tag %s", xmlnode.tag)
- def _introspect_enum(self, node):
+ def _introspect_enum(self, xmlnode):
members = []
- for member in node.findall('member'):
+ for member in xmlnode.findall('member'):
# Keep the name closer to what we'd take from C by default;
# see http://bugzilla.gnome.org/show_bug.cgi?id=575613
name = member.attrib['nick'].replace('-', '_')
- members.append(glibast.GLibEnumMember(name,
- member.attrib['value'],
- member.attrib['name'],
- member.attrib['nick']))
+ members.append(ast.Member(name,
+ member.attrib['value'],
+ member.attrib['name'],
+ member.attrib['nick']))
- klass = (glibast.GLibFlags if node.tag == 'flags' else glibast.GLibEnum)
- type_name = node.attrib['name']
+
+ if xmlnode.tag == 'flags':
+ klass = ast.Bitfield
+ else:
+ klass = ast.Enum
+ type_name = xmlnode.attrib['name']
+ (get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
try:
enum_name = self._transformer.strip_identifier(type_name)
except TransformerException, e:
message.fatal(e)
- node = klass(enum_name, type_name, members, node.attrib['get-type'])
+ node = klass(enum_name, type_name,
+ gtype_name=type_name,
+ c_symbol_prefix=c_symbol_prefix,
+ members=members,
+ get_type=xmlnode.attrib['get-type'])
self._namespace.append(node, replace=True)
def _split_type_and_symbol_prefix(self, xmlnode):
@@ -284,8 +295,11 @@ blob containing data gleaned from GObject's primitive introspection."""
object_name = self._transformer.strip_identifier(type_name)
except TransformerException, e:
message.fatal(e)
- node = glibast.GLibObject(object_name, None, type_name,
- get_type, c_symbol_prefix, is_abstract)
+ node = ast.Class(object_name, None,
+ gtype_name=type_name,
+ get_type=get_type,
+ c_symbol_prefix=c_symbol_prefix,
+ is_abstract=is_abstract)
self._parse_parents(xmlnode, node)
self._introspect_properties(node, xmlnode)
self._introspect_signals(node, xmlnode)
@@ -301,14 +315,23 @@ blob containing data gleaned from GObject's primitive introspection."""
interface_name = self._transformer.strip_identifier(type_name)
except TransformerException, e:
message.fatal(e)
- node = glibast.GLibInterface(interface_name, None, type_name,
- get_type, c_symbol_prefix)
+ node = ast.Interface(interface_name, None,
+ gtype_name=type_name,
+ get_type=get_type,
+ c_symbol_prefix=c_symbol_prefix)
self._introspect_properties(node, xmlnode)
self._introspect_signals(node, xmlnode)
for child in xmlnode.findall('prerequisite'):
name = child.attrib['name']
prereq = ast.Type.create_from_gtype_name(name)
node.prerequisites.append(prereq)
+
+ record = self._namespace.get(node.name)
+ if isinstance(record, ast.Record):
+ node.ctype = record.ctype
+ else:
+ message.warn_node(node, "Couldn't find associated structure for '%r'" % (node.name, ))
+
# GtkFileChooserEmbed is an example of a private interface, we
# just filter them out
if xmlnode.attrib['get-type'].startswith('_'):
@@ -318,11 +341,17 @@ blob containing data gleaned from GObject's primitive introspection."""
def _introspect_boxed(self, xmlnode):
type_name = xmlnode.attrib['name']
+ try:
+ name = self._transformer.strip_identifier(type_name)
+ except TransformerException, e:
+ message.fatal(e)
# This one doesn't go in the main namespace; we associate it with
# the struct or union
(get_type, c_symbol_prefix) = self._split_type_and_symbol_prefix(xmlnode)
- node = glibast.GLibBoxed(type_name, get_type, c_symbol_prefix)
- self._boxed_types[node.type_name] = node
+ node = ast.Boxed(name, gtype_name=type_name,
+ get_type=get_type,
+ c_symbol_prefix=c_symbol_prefix)
+ self._boxed_types[node.gtype_name] = node
def _introspect_implemented_interfaces(self, node, xmlnode):
gt_interfaces = []
@@ -363,7 +392,7 @@ blob containing data gleaned from GObject's primitive introspection."""
param = ast.Parameter(argname, ptype)
param.transfer = ast.PARAM_TRANSFER_NONE
parameters.append(param)
- signal = glibast.GLibSignal(signal_info.attrib['name'], return_, parameters)
+ signal = ast.Signal(signal_info.attrib['name'], return_, parameters)
node.signals.append(signal)
node.signals = node.signals
@@ -393,8 +422,11 @@ blob containing data gleaned from GObject's primitive introspection."""
message.warn(e)
return
- node = glibast.GLibObject(fundamental_name, None, type_name,
- get_type, c_symbol_prefix, is_abstract)
+ node = ast.Class(fundamental_name, None,
+ gtype_name=type_name,
+ get_type=get_type,
+ c_symbol_prefix=c_symbol_prefix,
+ is_abstract=is_abstract)
self._parse_parents(xmlnode, node)
node.fundamental = True
self._introspect_implemented_interfaces(node, xmlnode)
@@ -407,6 +439,7 @@ blob containing data gleaned from GObject's primitive introspection."""
record = self._namespace.get(node.name)
if not isinstance(record, ast.Record):
return
+ node.ctype = record.ctype
node.fields = record.fields
for field in node.fields:
if isinstance(field, ast.Field):
@@ -416,29 +449,22 @@ blob containing data gleaned from GObject's primitive introspection."""
def _pair_boxed_type(self, boxed):
try:
- name = self._transformer.strip_identifier(boxed.type_name)
+ name = self._transformer.strip_identifier(boxed.gtype_name)
except TransformerException, e:
message.fatal(e)
pair_node = self._namespace.get(name)
if not pair_node:
- boxed_item = glibast.GLibBoxedOther(name, boxed.type_name,
- boxed.get_type,
- boxed.c_symbol_prefix)
- elif isinstance(pair_node, ast.Record):
- boxed_item = glibast.GLibBoxedStruct(pair_node.name, boxed.type_name,
- boxed.get_type,
- boxed.c_symbol_prefix)
- boxed_item.inherit_file_positions(pair_node)
- boxed_item.fields = pair_node.fields
- elif isinstance(pair_node, ast.Union):
- boxed_item = glibast.GLibBoxedUnion(pair_node.name, boxed.type_name,
- boxed.get_type,
- boxed.c_symbol_prefix)
- boxed_item.inherit_file_positions(pair_node)
- boxed_item.fields = pair_node.fields
+ # Keep the "bare" boxed instance
+ self._namespace.append(boxed)
+ elif isinstance(pair_node, (ast.Record, ast.Union)):
+ pair_node.add_gtype(boxed.gtype_name, boxed.get_type)
+ assert boxed.c_symbol_prefix is not None
+ pair_node.c_symbol_prefix = boxed.c_symbol_prefix
+ # Quick hack - reset the disguised flag; we're setting it
+ # incorrectly in the scanner
+ pair_node.disguised = False
else:
return False
- self._namespace.append(boxed_item, replace=True)
def _strip_class_suffix(self, name):
if (name.endswith('Class') or
@@ -461,8 +487,6 @@ blob containing data gleaned from GObject's primitive introspection."""
if not (pair_record and isinstance(pair_record, ast.Record)):
return
- gclass_struct = glibast.GLibRecord.from_record(pair_record)
- self._namespace.append(gclass_struct, replace=True)
- cls.glib_type_struct = gclass_struct.create_type()
+ cls.glib_type_struct = pair_record.create_type()
cls.inherit_file_positions(pair_record)
- gclass_struct.is_gtype_struct_for = cls.create_type()
+ pair_record.is_gtype_struct_for = cls.create_type()
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 2fc0a35..5c54dbe 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -23,7 +23,6 @@ import os
from xml.etree.cElementTree import parse
from . import ast
-from . import glibast
from .girwriter import COMPATIBLE_GIR_VERSION
CORE_NS = "http://www.gtk.org/introspection/core/1.0"
@@ -205,21 +204,22 @@ class GIRParser(object):
parent_type = None
ctor_args = [node.attrib['name'],
- parent_type,
- node.attrib[_glibns('type-name')],
- node.attrib[_glibns('get-type')],
- node.attrib.get(_cns('symbol-prefix'))]
+ parent_type]
+ ctor_kwargs = {'gtype_name': node.attrib[_glibns('type-name')],
+ 'get_type': node.attrib[_glibns('get-type')],
+ 'c_symbol_prefix': node.attrib.get(_cns('symbol-prefix')),
+ 'ctype': node.attrib.get(_cns('type'))}
if node.tag == _corens('interface'):
- klass = glibast.GLibInterface
+ klass = ast.Interface
elif node.tag == _corens('class'):
- klass = glibast.GLibObject
+ klass = ast.Class
is_abstract = node.attrib.get('abstract')
is_abstract = is_abstract and is_abstract != '0'
- ctor_args.append(is_abstract)
+ ctor_kwargs['is_abstract'] = is_abstract
else:
raise AssertionError(node)
- obj = klass(*ctor_args)
+ obj = klass(*ctor_args, **ctor_kwargs)
self._parse_generic_attribs(node, obj)
type_struct = node.attrib.get(_glibns('type-struct'))
if type_struct:
@@ -331,22 +331,15 @@ class GIRParser(object):
return res
def _parse_record(self, node, anonymous=False):
- if _glibns('type-name') in node.attrib:
- struct = glibast.GLibBoxedStruct(node.attrib['name'],
- node.attrib[_glibns('type-name')],
- node.attrib[_glibns('get-type')],
- node.attrib.get(_cns('symbol-prefix')),
- node.attrib.get(_cns('type')))
- elif _glibns('is-gtype-struct-for') in node.attrib:
- struct = glibast.GLibRecord(node.attrib['name'],
- node.attrib.get(_cns('type')),
- disguised=node.attrib.get('disguised') == '1')
- is_gtype_struct_for = node.attrib[_glibns('is-gtype-struct-for')]
- struct.is_gtype_struct_for = self._namespace.type_from_name(is_gtype_struct_for)
- else:
- struct = ast.Record(node.attrib.get('name'),
+ struct = ast.Record(node.attrib.get('name'),
node.attrib.get(_cns('type')),
- disguised=node.attrib.get('disguised') == '1')
+ disguised=node.attrib.get('disguised') == '1',
+ gtype_name=node.attrib.get(_glibns('type-name')),
+ get_type=node.attrib.get(_glibns('get-type')),
+ c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
+ is_gtype_struct_for = node.attrib.get(_glibns('is-gtype-struct-for'))
+ if is_gtype_struct_for is not None:
+ struct.is_gtype_struct_for = self._namespace.type_from_name(is_gtype_struct_for)
if node.attrib.get('foreign') == '1':
struct.foreign = True
self._parse_generic_attribs(node, struct)
@@ -366,15 +359,11 @@ class GIRParser(object):
return struct
def _parse_union(self, node, anonymous=False):
- if _glibns('type-name') in node.attrib:
- union = glibast.GLibBoxedUnion(node.attrib['name'],
- node.attrib[_glibns('type-name')],
- node.attrib[_glibns('get-type')],
- node.attrib.get(_cns('symbol-prefix')),
- node.attrib.get(_cns('type')))
- else:
- union = ast.Union(node.attrib.get('name'),
- node.attrib.get(_cns('type')))
+ union = ast.Union(node.attrib.get('name'),
+ node.attrib.get(_cns('type')),
+ gtype_name=node.attrib.get(_glibns('type-name')),
+ get_type=node.attrib.get(_glibns('get-type')),
+ c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
if not anonymous:
self._namespace.append(union)
@@ -464,10 +453,10 @@ class GIRParser(object):
typeval.length_param_name = parent.parameters[idx].argname
def _parse_boxed(self, node):
- obj = glibast.GLibBoxedOther(node.attrib[_glibns('name')],
- node.attrib[_glibns('type-name')],
- node.attrib[_glibns('get-type')],
- node.attrib.get(_cns('symbol-prefix')))
+ obj = ast.Boxed(node.attrib[_glibns('name')],
+ gtype_name=node.attrib[_glibns('type-name')],
+ get_type=node.attrib[_glibns('get-type')],
+ c_symbol_prefix=node.attrib.get(_cns('symbol-prefix')))
self._parse_generic_attribs(node, obj)
self._namespace.append(obj)
for method in self._find_children(node, _corens('method')):
@@ -520,10 +509,10 @@ class GIRParser(object):
return prop
def _parse_member(self, node):
- member = glibast.GLibEnumMember(node.attrib['name'],
- node.attrib['value'],
- node.attrib.get(_cns('identifier')),
- node.attrib.get(_glibns('nick')))
+ member = ast.Member(node.attrib['name'],
+ node.attrib['value'],
+ node.attrib.get(_cns('identifier')),
+ node.attrib.get(_glibns('nick')))
self._parse_generic_attribs(node, member)
return member
@@ -541,24 +530,17 @@ class GIRParser(object):
get_type = node.attrib.get(_glibns('get-type'))
type_name = node.attrib.get(_glibns('type-name'))
glib_error_quark = node.attrib.get(_glibns('error-quark'))
- if get_type or glib_error_quark:
- if node.tag == _corens('bitfield'):
- klass = glibast.GLibFlags
- else:
- klass = glibast.GLibEnum
+ if node.tag == _corens('bitfield'):
+ klass = ast.Bitfield
else:
- if node.tag == _corens('bitfield'):
- klass = ast.Bitfield
- else:
- klass = ast.Enum
- type_name = ctype
+ klass = ast.Enum
members = []
- if klass in (ast.Enum, ast.Bitfield):
- obj = klass(name, type_name, members)
- else:
- obj = klass(name, type_name, members, get_type)
- obj.error_quark = glib_error_quark
- obj.ctype = ctype
+ obj = klass(name, ctype,
+ members=members,
+ gtype_name=type_name,
+ get_type=get_type)
+ obj.error_quark = glib_error_quark
+ obj.ctype = ctype
self._parse_generic_attribs(node, obj)
self._namespace.append(obj)
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 883e4e3..a450bb1 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -21,12 +21,7 @@
from __future__ import with_statement
-from .ast import (Alias, Array, Bitfield, Callback, Class, Constant, Enum,
- Function, Interface, List, Map, Member, Record, Union,
- Varargs, Type)
-from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember,
- GLibFlags, GLibObject, GLibInterface,
- GLibRecord)
+from . import ast
from .xmlwriter import XMLWriter
# Bump this for *incompatible* changes to the .gir.
@@ -92,12 +87,12 @@ and/or use gtk-doc annotations. ''')
# we want aliases to be first. They're a bit
# special because the typelib compiler expands them.
def nscmp(a, b):
- if isinstance(a, Alias):
- if isinstance(b, Alias):
+ if isinstance(a, ast.Alias):
+ if isinstance(b, ast.Alias):
return cmp(a.name, b.name)
else:
return -1
- elif isinstance(b, Alias):
+ elif isinstance(b, ast.Alias):
return 1
else:
return cmp(a, b)
@@ -105,28 +100,28 @@ and/or use gtk-doc annotations. ''')
self._write_node(node)
def _write_node(self, node):
- if isinstance(node, Function):
+ if isinstance(node, ast.Function):
self._write_function(node)
- elif isinstance(node, Enum):
+ elif isinstance(node, ast.Enum):
self._write_enum(node)
- elif isinstance(node, Bitfield):
+ elif isinstance(node, ast.Bitfield):
self._write_bitfield(node)
- elif isinstance(node, (Class, Interface)):
+ elif isinstance(node, (ast.Class, ast.Interface)):
self._write_class(node)
- elif isinstance(node, Callback):
+ elif isinstance(node, ast.Callback):
self._write_callback(node)
- elif isinstance(node, Record):
+ elif isinstance(node, ast.Record):
self._write_record(node)
- elif isinstance(node, Union):
+ elif isinstance(node, ast.Union):
self._write_union(node)
- elif isinstance(node, GLibBoxed):
+ elif isinstance(node, ast.Boxed):
self._write_boxed(node)
- elif isinstance(node, Member):
+ elif isinstance(node, ast.Member):
# FIXME: atk_misc_instance singleton
pass
- elif isinstance(node, Alias):
+ elif isinstance(node, ast.Alias):
self._write_alias(node)
- elif isinstance(node, Constant):
+ elif isinstance(node, ast.Constant):
self._write_constant(node)
else:
print 'WRITER: Unhandled node', node
@@ -245,15 +240,15 @@ and/or use gtk-doc annotations. ''')
return typeval.target_giname
def _write_type(self, ntype, relation=None, function=None):
- assert isinstance(ntype, Type), ntype
+ assert isinstance(ntype, ast.Type), ntype
attrs = []
if ntype.ctype:
attrs.append(('c:type', ntype.ctype))
- if isinstance(ntype, Varargs):
+ if isinstance(ntype, ast.Varargs):
with self.tagcontext('varargs', []):
pass
- elif isinstance(ntype, Array):
- if ntype.array_type != Array.C:
+ elif isinstance(ntype, ast.Array):
+ if ntype.array_type != ast.Array.C:
attrs.insert(0, ('name', ntype.array_type))
if not ntype.zeroterminated:
attrs.insert(0, ('zero-terminated', '0'))
@@ -266,12 +261,12 @@ and/or use gtk-doc annotations. ''')
with self.tagcontext('array', attrs):
self._write_type(ntype.element_type)
- elif isinstance(ntype, List):
+ elif isinstance(ntype, ast.List):
if ntype.name:
attrs.insert(0, ('name', ntype.name))
with self.tagcontext('type', attrs):
self._write_type(ntype.element_type)
- elif isinstance(ntype, Map):
+ elif isinstance(ntype, ast.Map):
attrs.insert(0, ('name', 'GLib.HashTable'))
with self.tagcontext('type', attrs):
self._write_type(ntype.key_type)
@@ -287,17 +282,19 @@ and/or use gtk-doc annotations. ''')
attrs.insert(0, ('foreign', '1'))
self.write_tag('type', attrs)
+ def _append_registered(self, node, attrs):
+ assert isinstance(node, ast.Registered)
+ if node.get_type:
+ attrs.extend([('glib:type-name', node.gtype_name),
+ ('glib:get-type', node.get_type)])
+
def _write_enum(self, enum):
attrs = [('name', enum.name)]
self._append_version(enum, attrs)
self._append_node_generic(enum, attrs)
- if isinstance(enum, GLibEnum):
- attrs.extend([('glib:type-name', enum.type_name),
- ('glib:get-type', enum.get_type),
- ('c:type', enum.ctype)])
- else:
- attrs.append(('c:type', enum.symbol))
- if hasattr(enum, 'error_quark') and enum.error_quark:
+ self._append_registered(enum, attrs)
+ attrs.append(('c:type', enum.ctype))
+ if enum.error_quark:
attrs.append(('glib:error-quark', enum.error_quark))
with self.tagcontext('enumeration', attrs):
@@ -309,12 +306,8 @@ and/or use gtk-doc annotations. ''')
attrs = [('name', bitfield.name)]
self._append_version(bitfield, attrs)
self._append_node_generic(bitfield, attrs)
- if isinstance(bitfield, GLibFlags):
- attrs.extend([('glib:type-name', bitfield.type_name),
- ('glib:get-type', bitfield.get_type),
- ('c:type', bitfield.ctype)])
- else:
- attrs.append(('c:type', bitfield.symbol))
+ self._append_registered(bitfield, attrs)
+ attrs.append(('c:type', bitfield.ctype))
with self.tagcontext('bitfield', attrs):
self._write_generic(bitfield)
for member in bitfield.members:
@@ -324,7 +317,7 @@ and/or use gtk-doc annotations. ''')
attrs = [('name', member.name),
('value', str(member.value)),
('c:identifier', member.symbol)]
- if isinstance(member, GLibEnumMember):
+ if member.nick is not None:
attrs.append(('glib:nick', member.nick))
self.write_tag('member', attrs)
@@ -339,7 +332,7 @@ and/or use gtk-doc annotations. ''')
('c:type', node.ctype)]
self._append_version(node, attrs)
self._append_node_generic(node, attrs)
- if isinstance(node, Class):
+ if isinstance(node, ast.Class):
tag_name = 'class'
if node.parent is not None:
attrs.append(('parent',
@@ -347,15 +340,15 @@ and/or use gtk-doc annotations. ''')
if node.is_abstract:
attrs.append(('abstract', '1'))
else:
+ assert isinstance(node, ast.Interface)
tag_name = 'interface'
- if isinstance(node, (GLibObject, GLibInterface)):
- attrs.append(('glib:type-name', node.type_name))
- if node.get_type:
- attrs.append(('glib:get-type', node.get_type))
- if node.glib_type_struct:
- attrs.append(('glib:type-struct',
- self._type_to_name(node.glib_type_struct)))
- if isinstance(node, GLibObject):
+ attrs.append(('glib:type-name', node.gtype_name))
+ if node.get_type is not None:
+ attrs.append(('glib:get-type', node.get_type))
+ if node.glib_type_struct is not None:
+ attrs.append(('glib:type-struct',
+ self._type_to_name(node.glib_type_struct)))
+ if isinstance(node, ast.Class):
if node.fundamental:
attrs.append(('glib:fundamental', '1'))
if node.ref_func:
@@ -368,18 +361,18 @@ and/or use gtk-doc annotations. ''')
attrs.append(('glib:get-value-func', node.get_value_func))
with self.tagcontext(tag_name, attrs):
self._write_generic(node)
- if isinstance(node, GLibObject):
+ if isinstance(node, ast.Class):
for iface in sorted(node.interfaces):
self.write_tag('implements',
[('name', self._type_to_name(iface))])
- if isinstance(node, Interface):
+ if isinstance(node, ast.Interface):
for iface in sorted(node.prerequisites):
self.write_tag('prerequisite',
[('name', self._type_to_name(iface))])
- if isinstance(node, Class):
+ if isinstance(node, ast.Class):
for method in sorted(node.constructors):
self._write_constructor(method)
- if isinstance(node, (Class, Interface)):
+ if isinstance(node, (ast.Class, ast.Interface)):
for method in sorted(node.static_methods):
self._write_static_method(method)
for vfunc in sorted(node.virtual_methods):
@@ -394,9 +387,10 @@ and/or use gtk-doc annotations. ''')
self._write_signal(signal)
def _write_boxed(self, boxed):
- attrs = [('c:type', boxed.ctype),
- ('glib:name', boxed.name)]
- attrs.extend(self._boxed_attrs(boxed))
+ attrs = [('glib:name', boxed.name)]
+ if boxed.c_symbol_prefix is not None:
+ attrs.append(('c:symbol-prefix', boxed.c_symbol_prefix))
+ self._append_registered(boxed, attrs)
with self.tagcontext('glib:boxed', attrs):
self._write_generic(boxed)
for method in sorted(boxed.constructors):
@@ -437,31 +431,26 @@ and/or use gtk-doc annotations. ''')
attrs.append(('c:type', callback.c_name))
self._write_callable(callback, 'callback', attrs)
- def _boxed_attrs(self, boxed):
- return [('glib:type-name', boxed.type_name),
- ('glib:get-type', boxed.get_type),
- ('c:symbol-prefix', boxed.c_symbol_prefix)]
-
def _write_record(self, record, extra_attrs=[]):
is_gtype_struct = False
attrs = list(extra_attrs)
if record.name is not None:
attrs.append(('name', record.name))
- if record.symbol is not None: # the record might be anonymous
- attrs.append(('c:type', record.symbol))
+ if record.ctype is not None: # the record might be anonymous
+ attrs.append(('c:type', record.ctype))
if record.disguised:
attrs.append(('disguised', '1'))
if record.foreign:
attrs.append(('foreign', '1'))
- if isinstance(record, GLibRecord):
- if record.is_gtype_struct_for:
- is_gtype_struct = True
- attrs.append(('glib:is-gtype-struct-for',
- self._type_to_name(record.is_gtype_struct_for)))
+ if record.is_gtype_struct_for is not None:
+ is_gtype_struct = True
+ attrs.append(('glib:is-gtype-struct-for',
+ self._type_to_name(record.is_gtype_struct_for)))
self._append_version(record, attrs)
self._append_node_generic(record, attrs)
- if isinstance(record, GLibBoxed):
- attrs.extend(self._boxed_attrs(record))
+ self._append_registered(record, attrs)
+ if record.c_symbol_prefix:
+ attrs.append(('c:symbol-prefix', record.c_symbol_prefix))
with self.tagcontext('record', attrs):
self._write_generic(record)
if record.fields:
@@ -478,12 +467,13 @@ and/or use gtk-doc annotations. ''')
attrs = []
if union.name is not None:
attrs.append(('name', union.name))
- if union.symbol is not None: # the union might be anonymous
- attrs.append(('c:type', union.symbol))
+ if union.ctype is not None: # the union might be anonymous
+ attrs.append(('c:type', union.ctype))
self._append_version(union, attrs)
self._append_node_generic(union, attrs)
- if isinstance(union, GLibBoxed):
- attrs.extend(self._boxed_attrs(union))
+ self._append_registered(union, attrs)
+ if union.c_symbol_prefix:
+ attrs.append(('c:symbol-prefix', union.c_symbol_prefix))
with self.tagcontext('union', attrs):
self._write_generic(union)
if union.fields:
@@ -498,14 +488,14 @@ and/or use gtk-doc annotations. ''')
def _write_field(self, field, is_gtype_struct=False):
if field.anonymous_node:
- if isinstance(field.anonymous_node, Callback):
+ if isinstance(field.anonymous_node, ast.Callback):
attrs = [('name', field.name)]
self._append_node_generic(field, attrs)
with self.tagcontext('field', attrs):
self._write_callback(field.anonymous_node)
- elif isinstance(field.anonymous_node, Record):
+ elif isinstance(field.anonymous_node, ast.Record):
self._write_record(field.anonymous_node)
- elif isinstance(field.anonymous_node, Union):
+ elif isinstance(field.anonymous_node, ast.Union):
self._write_union(field.anonymous_node)
else:
raise AssertionError("Unknown field anonymous: %r" \
diff --git a/giscanner/glibast.py b/giscanner/glibast.py
deleted file mode 100644
index 85092b8..0000000
--- a/giscanner/glibast.py
+++ /dev/null
@@ -1,161 +0,0 @@
-# -*- Mode: Python -*-
-# GObject-Introspection - a framework for introspecting GObject libraries
-# Copyright (C) 2008 Johan Dahlin
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-#
-
-from . import ast
-
-class GLibRecord(ast.Record):
- def __init__(self, *args, **kwargs):
- ast.Record.__init__(self, *args, **kwargs)
-
- @classmethod
- def from_record(cls, record):
- obj = cls(record.name, record.symbol)
- obj.fields = record.fields
- obj.constructors = record.constructors
- obj.disguised = record.disguised
- obj.doc = record.doc
- obj.methods = record.methods
- # If true, this record defines the FooClass C structure
- # for some Foo GObject (or similar for GInterface)
- obj.is_gtype_struct_for = False
- return obj
-
-class GLibEnum(ast.Enum):
-
- def __init__(self, name, type_name, members, get_type):
- ast.Enum.__init__(self, name, type_name, members)
- self.ctype = type_name
- self.type_name = type_name
- self.get_type = get_type
- self.error_quark = None
-
- def __repr__(self):
- return 'GlibEnum(%r, %r, %r)' % (self.name, self.members,
- self.get_type)
-
-
-class GLibFlags(ast.Bitfield):
-
- def __init__(self, name, type_name, members, get_type):
- ast.Bitfield.__init__(self, name, type_name, members)
- self.ctype = type_name
- self.type_name = type_name
- self.get_type = get_type
-
- def __repr__(self):
- return 'GlibFlags(%r, %r, %r)' % (self.name, self.members,
- self.get_type)
-
-
-class GLibEnumMember(ast.Member):
-
- def __init__(self, name, value, symbol, nick):
- ast.Member.__init__(self, name, value, symbol)
- self.nick = nick
-
-
-class GLibObject(ast.Class):
-
- def __init__(self, name, parent, type_name, get_type,
- c_symbol_prefix, is_abstract, ctype=None):
- ast.Class.__init__(self, name, parent, is_abstract)
- self.type_name = type_name
- self.get_type = get_type
- self.c_symbol_prefix = c_symbol_prefix
- self.fundamental = False
- self.unref_func = None
- self.ref_func = None
- self.set_value_func = None
- self.get_value_func = None
- self.signals = []
- self.ctype = ctype or type_name
-
- def _walk(self, callback, chain):
- super(GLibObject, self)._walk(callback, chain)
- for sig in self.signals:
- sig.walk(callback, chain)
-
-
-class GLibBoxed:
-
- def __init__(self, type_name, get_type, c_symbol_prefix):
- self.type_name = type_name
- self.get_type = get_type
- self.c_symbol_prefix = c_symbol_prefix
-
-
-class GLibBoxedStruct(ast.Record, GLibBoxed):
-
- def __init__(self, name, type_name, get_type, c_symbol_prefix, ctype=None):
- ast.Record.__init__(self, name, ctype or type_name)
- GLibBoxed.__init__(self, type_name, get_type, c_symbol_prefix)
-
-
-class GLibBoxedUnion(ast.Union, GLibBoxed):
-
- def __init__(self, name, type_name, get_type, c_symbol_prefix, ctype=None):
- ast.Union.__init__(self, name, ctype or type_name)
- GLibBoxed.__init__(self, type_name, get_type, c_symbol_prefix)
-
-
-class GLibBoxedOther(ast.Node, GLibBoxed):
-
- def __init__(self, name, type_name, get_type, c_symbol_prefix):
- ast.Node.__init__(self, name)
- GLibBoxed.__init__(self, type_name, get_type, c_symbol_prefix)
- self.constructors = []
- self.methods = []
- self.static_methods = []
- self.ctype = type_name
- self.doc = None
-
- def _walk(self, callback, chain):
- for ctor in self.constructors:
- ctor.walk(callback, chain)
- for meth in self.methods:
- meth.walk(callback, chain)
- for meth in self.static_methods:
- meth.walk(callback, chain)
-
-
-class GLibInterface(ast.Interface):
-
- def __init__(self, name, parent, type_name, get_type,
- c_symbol_prefix, ctype=None):
- ast.Interface.__init__(self, name, parent)
- self.type_name = type_name
- self.get_type = get_type
- self.c_symbol_prefix = c_symbol_prefix
- self.signals = []
- self.ctype = ctype or type_name
-
- def _walk(self, callback, chain):
- super(GLibInterface, self)._walk(callback, chain)
- for sig in self.signals:
- sig.walk(callback, chain)
-
-class GLibProperty(ast.Property):
- pass
-
-
-class GLibSignal(ast.Callable):
-
- def __init__(self, name, retval, parameters):
- ast.Callable.__init__(self, name, retval, parameters, False)
diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
index 290f1d2..1432a10 100644
--- a/giscanner/introspectablepass.py
+++ b/giscanner/introspectablepass.py
@@ -18,7 +18,6 @@
#
from . import ast
-from . import glibast
from . import message
class IntrospectablePass(object):
@@ -37,7 +36,7 @@ class IntrospectablePass(object):
self._namespace.walk(self._introspectable_pass3)
def _interface_vfunc_check(self, node, stack):
- if isinstance(node, glibast.GLibInterface):
+ if isinstance(node, ast.Interface):
for vfunc in node.virtual_methods:
if not vfunc.invoker:
message.warn_node(vfunc,
@@ -100,8 +99,8 @@ class IntrospectablePass(object):
if (is_return
and isinstance(target, (ast.Record, ast.Union))
- and not target.foreign
- and not isinstance(target, glibast.GLibBoxed)):
+ and target.get_type is None
+ and not target.foreign):
if node.transfer != ast.PARAM_TRANSFER_NONE:
self._parameter_warning(parent, node,
"Invalid non-constant return of bare structure or union; register as boxed type or (skip)")
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index a9f43a3..01bc7b4 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -20,7 +20,6 @@
import re
from . import ast
-from . import glibast
from . import message
from .annotationparser import (TAG_VFUNC, TAG_SINCE, TAG_DEPRECATED, TAG_RETURNS,
TAG_ATTRIBUTES, TAG_RENAME_TO, TAG_TYPE, TAG_TRANSFER,
@@ -74,7 +73,7 @@ class MainTransformer(object):
# Generate a reverse mapping "bar_baz" -> BarBaz
for node in self._namespace.itervalues():
- if isinstance(node, (ast.Class, ast.Interface, glibast.GLibBoxed)):
+ if isinstance(node, ast.Registered) and node.get_type is not None:
self._uscore_type_names[node.c_symbol_prefix] = node
elif isinstance(node, (ast.Record, ast.Union)):
uscored = to_underscores_noprefix(node.name).lower()
@@ -96,7 +95,7 @@ class MainTransformer(object):
self._namespace.walk(self._pass3)
# TODO - merge into pass3
- self._resolve_quarks()
+ self._pair_quarks_with_enums()
# Private
@@ -150,7 +149,7 @@ class MainTransformer(object):
self._apply_annotations_callable(node, chain, block)
def _pass_callable_defaults(self, node, chain):
- if isinstance(node, (ast.Callable, glibast.GLibSignal)):
+ if isinstance(node, (ast.Callable, ast.Signal)):
for param in node.parameters:
if param.transfer is None:
param.transfer = self._get_transfer_default(node, param)
@@ -343,7 +342,8 @@ class MainTransformer(object):
target = self._transformer.lookup_typenode(typeval)
if isinstance(target, ast.Alias):
return self._get_transfer_default_returntype_basic(target.target)
- elif isinstance(target, glibast.GLibBoxed):
+ elif (isinstance(target, ast.Boxed)
+ or (isinstance(target, (ast.Record, ast.Union)) and target.gtype_name is not None)):
return ast.PARAM_TRANSFER_FULL
elif isinstance(target, (ast.Enum, ast.Bitfield)):
return ast.PARAM_TRANSFER_NONE
@@ -564,7 +564,7 @@ class MainTransformer(object):
field.type = self._transformer.create_type_from_user_string(t.one())
def _apply_annotations_property(self, parent, prop):
- block = self._blocks.get('%s:%s' % (parent.type_name, prop.name))
+ block = self._blocks.get('%s:%s' % (parent.c_name, prop.name))
self._apply_annotations_annotated(prop, block)
if not block:
return
@@ -578,7 +578,7 @@ class MainTransformer(object):
prop.type = self._resolve(type_tag.value, prop.type)
def _apply_annotations_signal(self, parent, signal):
- block = self._blocks.get('%s::%s' % (parent.type_name, signal.name))
+ block = self._blocks.get('%s::%s' % (parent.c_name, signal.name))
self._apply_annotations_annotated(signal, block)
# We're only attempting to name the signal parameters if
# the number of parameter tags (@foo) is the same or greater
@@ -683,7 +683,7 @@ the ones that failed to resolve removed."""
node.prerequisites = self._resolve_and_filter_type_list(node.prerequisites)
return True
- def _resolve_quarks(self):
+ def _pair_quarks_with_enums(self):
# self._uscore_type_names is an authoritative mapping of types
# to underscored versions, since it is based on get_type() methods;
# but only covers enums that are registered as GObject enums.
@@ -692,7 +692,7 @@ the ones that failed to resolve removed."""
for enum in self._namespace.itervalues():
if not isinstance(enum, ast.Enum):
continue
- type_name = enum.symbol
+ type_name = enum.ctype
uscored = to_underscores(type_name).lower()
uscore_enums[uscored] = enum
@@ -773,7 +773,7 @@ method or constructor of some type."""
target = self._transformer.lookup_typenode(first.type)
if not isinstance(target, (ast.Class, ast.Interface,
ast.Record, ast.Union,
- glibast.GLibBoxedOther)):
+ ast.Boxed)):
return False
if target.namespace != self._namespace:
return False
@@ -801,12 +801,12 @@ method or constructor of some type."""
(node, funcname) = split
# We actually should treat static methods on a wider class of objects:
- # ast.Class, ast.Interface, ast.Record, ast.Union, glibast.GLibBoxedOther
- # But we stick to GLibObject for now for compatibility with existing code.
+ # ast.Class, ast.Interface, ast.Record, ast.Union, ast.Boxed
+ # But we stick to ast.Class for now for compatibility with existing code.
#
# See https://bugzilla.gnome.org/show_bug.cgi?id=572408
#
- if not isinstance(node, glibast.GLibObject):
+ if not isinstance(node, ast.Class):
return False
self._namespace.float(func)
@@ -817,7 +817,9 @@ method or constructor of some type."""
if not (func.symbol.find('_new_') >= 0 or func.symbol.endswith('_new')):
return False
target = self._transformer.lookup_typenode(func.retval.type)
- if not isinstance(target, (ast.Class, glibast.GLibBoxed)):
+ if not (isinstance(target, ast.Class)
+ or (isinstance(target, (ast.Record, ast.Union, ast.Boxed))
+ and target.get_type is not None)):
return False
split = self._split_uscored_by_type(subsymbol)
@@ -827,9 +829,10 @@ method or constructor of some type."""
"Can't find matching type for constructor; symbol=%r" % (func.symbol, ))
return False
(origin_node, funcname) = split
-
# Some sanity checks; only objects and boxeds can have ctors
- if not isinstance(origin_node, (ast.Class, glibast.GLibBoxed)):
+ if not (isinstance(origin_node, ast.Class)
+ or (isinstance(origin_node, (ast.Record, ast.Union, ast.Boxed))
+ and origin_node.get_type is not None)):
return False
# Verify the namespace - don't want to append to foreign namespaces!
if origin_node.namespace != self._namespace:
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 6526c53..328d29e 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -22,7 +22,6 @@ import os
import sys
from . import ast
-from . import glibast
from . import message
from .cachestore import CacheStore
from .config import DATADIR, GIR_DIR, GIR_SUFFIX
@@ -351,7 +350,8 @@ raise ValueError."""
return None
members.append(ast.Member(name.lower(),
child.const_int,
- child.ident))
+ child.ident,
+ None))
try:
enum_name = self.strip_identifier(symbol.ident)
@@ -362,7 +362,7 @@ raise ValueError."""
klass = ast.Bitfield
else:
klass = ast.Enum
- node = klass(enum_name, symbol.ident, members)
+ node = klass(enum_name, symbol.ident, members=members)
node.add_symbol_reference(symbol)
return node
@@ -603,7 +603,7 @@ raise ValueError."""
except TransformerException, e:
message.warn_symbol(symbol, e)
return None
- struct = ast.Record(name, symbol.ident, disguised)
+ struct = ast.Record(name, symbol.ident, disguised=disguised)
self._parse_fields(symbol, struct)
struct.add_symbol_reference(symbol)
self._typedefs_ns[symbol.ident] = struct
@@ -756,12 +756,10 @@ Note that type resolution may not succeed."""
assert typeval.gtype_name is not None
for ns in self._iter_namespaces():
for node in ns.itervalues():
- if not isinstance(node, (ast.Class, ast.Interface,
- glibast.GLibBoxed,
- glibast.GLibEnum,
- glibast.GLibFlags)):
+ if not (isinstance(node, (ast.Class, ast.Interface))
+ or (isinstance(node, ast.Registered) and node.get_type is not None)):
continue
- if node.type_name == typeval.gtype_name:
+ if node.gtype_name == typeval.gtype_name:
typeval.target_giname = '%s.%s' % (ns.name, node.name)
return True
return False