diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2021-10-08 12:01:57 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2021-10-08 12:01:57 +0100 |
commit | 995a141b378030110202483b9f8f9c91a3e785aa (patch) | |
tree | 9b489634dffb74e97974d81d7abb95627e4e2e1d /giscanner | |
parent | 24d6578b4aaa0280cf0ad5ee410425894507c803 (diff) | |
download | gobject-introspection-pointer-aliases.tar.gz |
scanner: Aliases of gpointer are pointerspointer-aliases
If we have a type alias defined as:
typedef gpointer FooPointer
and we use it inside our API like:
Bar* foo_pointer_get_bar (FooPointer self)
then we want `foo_pointer_get_bar` to be detected as a method of
`FooPointer`, instead of a global function that takes a `FooPointer` as
its only argument.
This requires checking if the first argument is a pointer type *or* an
alias to `gpointer`.
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/maintransformer.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 0f1ea9b6..ea2865f2 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -1147,6 +1147,21 @@ method or constructor of some type.""" name = typeval.get_giname() return to_underscores_noprefix(name).lower() + def _is_instance_pointer(self, typeval): + pointer_types = ( + ast.Boxed, + ast.Class, + ast.Interface, + ast.Record, + ast.Union, + ) + if isinstance(typeval, pointer_types): + return True + # Aliases to gpointer are also pointers + if isinstance(typeval, ast.Alias) and typeval.target.is_equiv(ast.TYPE_ANY): + return True + return False + def _is_method(self, func, subsymbol): if not func.parameters: if func.is_method: @@ -1155,9 +1170,7 @@ method or constructor of some type.""" return False first = func.parameters[0] target = self._transformer.lookup_typenode(first.type) - if not isinstance(target, (ast.Class, ast.Interface, - ast.Record, ast.Union, - ast.Boxed)): + if not self._is_instance_pointer(target): if func.is_method: message.warn_node(func, '%s: Methods must have a pointer as their first ' |