summaryrefslogtreecommitdiff
path: root/giscanner/ast.py
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2012-03-06 11:57:01 -0300
committerJohan Dahlin <jdahlin@litl.com>2012-03-06 11:57:22 -0300
commitab8a6d9694ebd79b202b470c3742e8d521faf722 (patch)
tree8a7552e3b24cbf12d8e52e8758b3b79c7e8a5608 /giscanner/ast.py
parentc2fc7cb45243aa9e0e1e5569cc742f69c76a671a (diff)
downloadgobject-introspection-ab8a6d9694ebd79b202b470c3742e8d521faf722.tar.gz
Fix matching of methods named *_get_type()
The code which heuristically turned functions into class methods would always ignore any function called *_get_type or *_get_gtype. However, the code which looked for GI metadata functions to execute them was much more comprehensive, checking not just the name, but also that it had no parameters and that it returned a GType. This change abstracts the more comprehensive check into the Function class, and uses the same check in both places. https://bugzilla.gnome.org/show_bug.cgi?id=671218
Diffstat (limited to 'giscanner/ast.py')
-rw-r--r--giscanner/ast.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 6df356dd..9e9d7c37 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -21,6 +21,8 @@
import copy
+from . import message
+
from .message import Position
from .odict import odict
from .utils import to_underscores
@@ -589,6 +591,25 @@ class Function(Callable):
clone.parameters = self.parameters[:]
return clone
+ def is_type_meta_function(self):
+ # Named correctly
+ if not (self.name.endswith('_get_type') or
+ self.name.endswith('_get_gtype')):
+ return False
+
+ # Doesn't have any parameters
+ if self.parameters:
+ return False
+
+ # Returns GType
+ rettype = self.retval.type
+ if (not rettype.is_equiv(TYPE_GTYPE) and
+ rettype.target_giname != 'Gtk.Type'):
+ message.warn("function '%s' returns '%r', not a GType" %
+ (self.name, rettype))
+ return False
+
+ return True
class ErrorQuarkFunction(Function):