summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2010-09-07 19:36:58 -0400
committerOwen W. Taylor <otaylor@fishsoup.net>2010-09-07 20:03:59 -0400
commitda89c092c5bac56524bd2b60c0f261b9fa3b91be (patch)
tree323ea9fd72a99b8ec13b514658f3d8987252097f /giscanner
parentcd0de25d5971a34f49830668337af96b15fed4b4 (diff)
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')
-rw-r--r--giscanner/ast.py2
-rw-r--r--giscanner/scannermain.py5
-rw-r--r--giscanner/transformer.py19
3 files changed, 12 insertions, 14 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index b03d43f..ada6412 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 630acb6..0333dee 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 8a80e23..6526c53 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