diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2010-09-07 19:36:58 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2010-09-07 20:03:59 -0400 |
commit | da89c092c5bac56524bd2b60c0f261b9fa3b91be (patch) | |
tree | 323ea9fd72a99b8ec13b514658f3d8987252097f /giscanner/transformer.py | |
parent | cd0de25d5971a34f49830668337af96b15fed4b4 (diff) | |
download | gobject-introspection-da89c092c5bac56524bd2b60c0f261b9fa3b91be.tar.gz |
Handle casing better for constants
Instead of handling constants by lower-casing them, stripping the
lower-case prefix and upper-casing them again, leave them in the
original case and check against upper-cased versions of
namespace.symbol_prefixes.
Wwe detect what version to test against by looking at the first character
of the identifier, so we assume that --symbol-prefix options are always
in lowercase. If that needs to be relaxed, then we'll have to check all
symbols against both sets of prefixes.
Add tests for constants to Regress.h and fix tests/warn/unresolved-type.h
for a warning message that improved with this change.
https://bugzilla.gnome.org/show_bug.cgi?id=629007
Diffstat (limited to 'giscanner/transformer.py')
-rw-r--r-- | giscanner/transformer.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 8a80e23f..6526c53c 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -20,7 +20,6 @@ import os import sys -import re from . import ast from . import glibast @@ -47,8 +46,6 @@ _xdg_data_dirs = [x for x in os.environ.get('XDG_DATA_DIRS', '').split(':') \ class Transformer(object): namespace = property(lambda self: self._namespace) - UCASE_CONSTANT_RE = re.compile(r'[_A-Z0-9]+') - def __init__(self, namespace, accept_unprefixed=False): self._cachestore = CacheStore() self._accept_unprefixed = accept_unprefixed @@ -204,6 +201,8 @@ currently-scanned namespace is first.""" for ns in self._iter_namespaces(): if is_identifier: prefixes = ns.identifier_prefixes + elif name[0].isupper(): + prefixes = ns._ucase_symbol_prefixes else: prefixes = ns.symbol_prefixes if prefixes: @@ -268,11 +267,8 @@ raise ValueError.""" ident, ns.name, )) return None - def _strip_symbol(self, symbol, is_constant=False): + def _strip_symbol(self, symbol): ident = symbol.ident - if is_constant: - # Temporarily lowercase - ident = ident.lower() hidden = ident.startswith('_') if hidden: ident = ident[1:] @@ -283,8 +279,6 @@ raise ValueError.""" if ns != self._namespace: raise TransformerException( "Skipping foreign symbol from namespace %s" % (ns.name, )) - if is_constant: - name = name.upper() if hidden: return '_' + name return name @@ -351,7 +345,7 @@ raise ValueError.""" # among them, so let's just remove the global namespace # prefix. try: - name = self._strip_symbol(child, is_constant=True) + name = self._strip_symbol(child) except TransformerException, e: message.warn_symbol(symbol, e) return None @@ -582,11 +576,8 @@ raise ValueError.""" if (symbol.source_filename is None or not symbol.source_filename.endswith('.h')): return None - # ignore non-uppercase defines - if not self.UCASE_CONSTANT_RE.match(symbol.ident): - return None try: - name = self._strip_symbol(symbol, is_constant=True) + name = self._strip_symbol(symbol) except TransformerException, e: message.warn_symbol(symbol, e) return None |