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
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
import os
import sys
-import re
from . import ast
from . import glibast
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
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:
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:]
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
# 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
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
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">
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;