def _introspect_enum(self, node):
members = []
for member in node.findall('member'):
- members.append(GLibEnumMember(member.attrib['nick'],
+ # 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(GLibEnumMember(name,
member.attrib['value'],
member.attrib['name'],
member.attrib['nick']))
CSYMBOL_TYPE_ENUM, CSYMBOL_TYPE_UNION, CSYMBOL_TYPE_OBJECT,
CSYMBOL_TYPE_MEMBER, CSYMBOL_TYPE_ELLIPSIS, CSYMBOL_TYPE_CONST,
TYPE_QUALIFIER_CONST)
-from .utils import strip_common_prefix, to_underscores
+from .utils import to_underscores
_xdg_data_dirs = [x for x in os.environ.get('XDG_DATA_DIRS', '').split(':') \
+ [DATADIR, '/usr/share'] if x]
raise NotImplementedError(
'Transformer: unhandled symbol: %r' % (symbol, ))
+ def _enum_common_prefix(self, symbol):
+ def common_prefix(a, b):
+ alen = len(a)
+ blen = len(b)
+ l = min(alen, blen)
+ for i in xrange(l):
+ if a[i] != b[i]:
+ return a[:i]
+ if alen > blen:
+ return b
+ return a
+ # Nothing less than 2 has a common prefix
+ if len(list(symbol.base_type.child_list)) < 2:
+ return None
+ prefix = None
+ for child in symbol.base_type.child_list:
+ if prefix is None:
+ prefix = child.ident
+ else:
+ prefix = common_prefix(prefix, child.ident)
+ if prefix == '':
+ return None
+ return prefix
+
def _create_enum(self, symbol):
+ prefix = self._enum_common_prefix(symbol)
+ if prefix:
+ prefixlen = len(prefix)
+ else:
+ prefixlen = 0
members = []
for child in symbol.base_type.child_list:
- name = strip_common_prefix(symbol.ident, child.ident).lower()
- members.append(Member(name,
+ if prefixlen > 0:
+ name = child.ident[prefixlen:]
+ else:
+ # Ok, the enum members don't have a consistent prefix
+ # among them, so let's just remove the global namespace
+ # prefix.
+ name = self.remove_prefix(child.ident)
+ members.append(Member(name.lower(),
child.const_int,
child.ident))
# and pre-2.2. Johan 2008-10-21
libname = libname.replace('.libs/.libs', '.libs')
return libname
-
-
-def strip_common_prefix(first, second):
- max_index = second.rfind('_')
- second_len = len(second)
- second = second.replace('_', '')
- max_index -= second_len - len(second) - 1
- for i, c in enumerate(first.upper()):
- if i >= len(second) or c != second[i] or i == max_index:
- return second[i:]
- return second[i + 1:]
<alias name="List" target="GLib.SList" c:type="FooList"/>
<alias name="ObjectCookie" target="any" c:type="FooObjectCookie"/>
<alias name="XEvent" target="none" c:type="FooXEvent"/>
+ <enumeration name="ASingle" c:type="FooASingle">
+ <member name="some_single_enum"
+ value="0"
+ c:identifier="FOO_SOME_SINGLE_ENUM"/>
+ </enumeration>
<record name="BRect"
c:type="FooBRect"
glib:type-name="FooBRect"
<constant name="SUCCESS_INT" value="4408">
<type name="int"/>
</constant>
+ <enumeration name="StackLayer" c:type="FooStackLayer">
+ <member name="desktop" value="0" c:identifier="FOO_LAYER_DESKTOP"/>
+ <member name="bottom" value="1" c:identifier="FOO_LAYER_BOTTOM"/>
+ <member name="normal" value="2" c:identifier="FOO_LAYER_NORMAL"/>
+ <member name="top" value="4" c:identifier="FOO_LAYER_TOP"/>
+ <member name="dock" value="4" c:identifier="FOO_LAYER_DOCK"/>
+ <member name="fullscreen" value="5" c:identifier="FOO_LAYER_FULLSCREEN"/>
+ <member name="focused_window"
+ value="6"
+ c:identifier="FOO_LAYER_FOCUSED_WINDOW"/>
+ <member name="override_redirect"
+ value="7"
+ c:identifier="FOO_LAYER_OVERRIDE_REDIRECT"/>
+ <member name="last" value="8" c:identifier="FOO_LAYER_LAST"/>
+ </enumeration>
<record name="Struct" c:type="FooStruct">
<field name="priv" writable="1">
<type name="StructPrivate" c:type="FooStructPrivate*"/>
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
<namespace name="foo" version="1.0" shared-library="foo">
+ <enumeration name="ASingle">
+ <member name="some_single_enum" value="0"/>
+ </enumeration>
<record name="BRect" glib:type-name="FooBRect" glib:get-type="foo_brect_get_type">
<field name="x" writable="1">
<type name="double"/>
<constant name="SUCCESS_INT" value="4408">
<type name="int"/>
</constant>
+ <enumeration name="StackLayer">
+ <member name="desktop" value="0"/>
+ <member name="bottom" value="1"/>
+ <member name="normal" value="2"/>
+ <member name="top" value="4"/>
+ <member name="dock" value="4"/>
+ <member name="fullscreen" value="5"/>
+ <member name="focused_window" value="6"/>
+ <member name="override_redirect" value="7"/>
+ <member name="last" value="8"/>
+ </enumeration>
<record name="Struct">
<field name="priv" writable="1">
<type name="StructPrivate"/>
GQuark foo_error_quark (void);
+typedef enum
+{
+ FOO_LAYER_DESKTOP = 0,
+ FOO_LAYER_BOTTOM = 1,
+ FOO_LAYER_NORMAL = 2,
+ FOO_LAYER_TOP = 4, /* Same as DOCK; see EWMH and bug 330717 */
+ FOO_LAYER_DOCK = 4,
+ FOO_LAYER_FULLSCREEN = 5,
+ FOO_LAYER_FOCUSED_WINDOW = 6,
+ FOO_LAYER_OVERRIDE_REDIRECT = 7,
+ FOO_LAYER_LAST = 8
+} FooStackLayer;
+
+typedef enum
+{
+ FOO_SOME_SINGLE_ENUM
+} FooASingle;
+
/* Should be skipped */
void foo_some_variant (guint x, va_list args);
void foo_some_variant_ptr (guint x, va_list *args);