diff options
author | Giovanni Campagna <gcampagna@src.gnome.org> | 2014-02-25 18:55:37 +0100 |
---|---|---|
committer | Giovanni Campagna <gcampagna@src.gnome.org> | 2014-02-26 17:27:08 +0100 |
commit | 6432c9213bff425d7d0f2be39df59337588caff3 (patch) | |
tree | 071456aeb8251cbdfba7fc0b2a1612386540bef4 /giscanner | |
parent | 63022d4290264182d1d41cffc9bf12f202931379 (diff) | |
download | gobject-introspection-6432c9213bff425d7d0f2be39df59337588caff3.tar.gz |
maintransformer: don't pair methods if the symbol prefix does not match with a final underscore
In cases like g_resources_register() and gdk_events_get_angle(),
the c_symbol_prefix of the first parameter (resp. g_resource and
gdk_event) is a prefix of the symbol, but the next character is
not _, so that should not be considered a method.
For backward compatibility reasons, we still generate one, but
then it's not included in the documentation (because of moved_to)
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/maintransformer.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index e6f04684..d9811cfb 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -1023,15 +1023,35 @@ method or constructor of some type.""" uscored_prefix = self._get_uscored_prefix(func, subsymbol) target = self._transformer.lookup_typenode(func.parameters[0].type) - func.instance_parameter = func.parameters.pop(0) - self._namespace.float(func) - - if not func.is_method: + if not func.is_method and not subsymbol.startswith(uscored_prefix + '_'): + # Uh oh! This function starts with uscored_prefix, but not + # uscored_prefix + '_', so if we split, we're splitting on something + # which is not _ + # Examples of this are g_resources_register() (splits as + # g_resource + _register) and gdk_events_get_angle() (splits as + # gdk_event + _get_angle). + # As the C name suggests, these are not methods, but for backward + # compatibility reasons we need to create a method with the old + # name, and a moved-to annotation pointing to the new variant. + + newfunc = func.clone() + newfunc.moved_to = func.name + newfunc.instance_parameter = newfunc.parameters.pop(0) subsym_idx = func.symbol.find(subsymbol) - func.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):] - func.is_method = True + newfunc.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):] + newfunc.is_method = True + + target.methods.append(newfunc) + else: + func.instance_parameter = func.parameters.pop(0) + self._namespace.float(func) + + if not func.is_method: + subsym_idx = func.symbol.find(subsymbol) + func.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):] + func.is_method = True - target.methods.append(func) + target.methods.append(func) def _get_uscored_prefix(self, func, subsymbol): # Here we check both the c_symbol_prefix and (if that fails), |