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 | |
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
-rw-r--r-- | giscanner/ast.py | 2 | ||||
-rw-r--r-- | giscanner/scannermain.py | 5 | ||||
-rw-r--r-- | giscanner/transformer.py | 19 | ||||
-rw-r--r-- | tests/scanner/Regress-1.0-expected.gir | 12 | ||||
-rw-r--r-- | tests/scanner/regress.h | 7 | ||||
-rw-r--r-- | tests/warn/unresolved-type.h | 2 |
6 files changed, 32 insertions, 15 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py index b03d43f9..ada6412d 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -311,6 +311,8 @@ class Namespace(object): else: ps = self.identifier_prefixes self.symbol_prefixes = [to_underscores(p).lower() for p in ps] + # cache upper-cased versions + self._ucase_symbol_prefixes = [p.upper() for p in self.symbol_prefixes] self._names = odict() # Maps from GIName -> node self._aliases = {} # Maps from GIName -> GIName self._type_names = {} # Maps from GTName -> node diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 630acb6f..0333dee4 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -263,6 +263,11 @@ def scanner_main(args): else: identifier_prefixes = None if options.symbol_prefixes: + for prefix in options.symbol_prefixes: + # See Transformer._split_c_string_for_namespace_matches() for + # why this check is needed + if prefix.lower() != prefix: + _error("Values for --symbol-prefix must be entirely lowercase") symbol_prefixes = options.symbol_prefixes else: symbol_prefixes = None 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 diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 3fce12b5..6ae7172b 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -15,6 +15,18 @@ and/or use gtk-doc annotations. --> shared-library="libregress.so" c:identifier-prefixes="Regress" c:symbol-prefixes="regress"> + <constant name="DOUBLE_CONSTANT" value="44.220000"> + <type name="gdouble" c:type="gdouble"/> + </constant> + <constant name="INT_CONSTANT" value="4422"> + <type name="gint" c:type="gint"/> + </constant> + <constant name="Mixed_Case_Constant" value="4423"> + <type name="gint" c:type="gint"/> + </constant> + <constant name="STRING_CONSTANT" value="Some String"> + <type name="utf8" c:type="gchar*"/> + </constant> <record name="SkippedStructure" c:type="RegressSkippedStructure" introspectable="0"> diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index 6fed4ca7..c0591f84 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -166,6 +166,13 @@ GType regress_test_flags_get_type (void) G_GNUC_CONST; const gchar * regress_test_enum_param(RegressTestEnum e); +/* constants */ + +#define REGRESS_INT_CONSTANT 4422 +#define REGRESS_DOUBLE_CONSTANT 44.22 +#define REGRESS_STRING_CONSTANT "Some String" +#define REGRESS_Mixed_Case_Constant 4423 + /* structures */ typedef struct _RegressTestStructA RegressTestStructA; typedef struct _RegressTestStructB RegressTestStructB; diff --git a/tests/warn/unresolved-type.h b/tests/warn/unresolved-type.h index 9f1a05cb..a31db5ea 100644 --- a/tests/warn/unresolved-type.h +++ b/tests/warn/unresolved-type.h @@ -16,4 +16,4 @@ typedef enum { MY_ENUM_A = 0 } TestMyEnum2; -// EXPECT:17: Warning: Test: symbol='TestMyEnum2': Unknown namespace for symbol 'my_enum_a' +// EXPECT:17: Warning: Test: symbol='TestMyEnum2': Unknown namespace for symbol 'MY_ENUM_A' |