Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/giscanner/transformer.py
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-03-16 22:25:19 (GMT)
committer Colin Walters <walters@verbum.org>2009-03-17 15:10:04 (GMT)
commite9dcc3cfb985292b5ff96772b73029a32b18ff11 (patch)
tree7c235feb39b547a3829c12f64972b071d93dd7fa /giscanner/transformer.py
parent1d1cc8c35364f9da12620c1925483b61dc688718 (diff)
Bug 575613 - Enum stripping with common prefix, also use "_" consistently
Some enums have members which have a common prefix which doesn't match that of the enum name, but it also longer than the global namespace prefix. Instead, try stripping the common prefix first, and only if that fails fall back to the global strip. Also, for glib-registered enums we were using the nick, which typically has "-" as a separator. Replace that with "_" for consistency between unregistered enums and registered. utils.py:strip_common_prefix is now unused, delete.
Diffstat (limited to 'giscanner/transformer.py')
-rw-r--r--giscanner/transformer.py41
1 files changed, 38 insertions, 3 deletions
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 9aebbd8..2746b6e 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -37,7 +37,7 @@ from .sourcescanner import (
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]
@@ -208,11 +208,46 @@ class Transformer(object):
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))