diff options
author | Torsten Schönfeld <kaffeetisch@gmx.de> | 2011-08-13 12:00:00 +0200 |
---|---|---|
committer | Torsten Schönfeld <kaffeetisch@gmx.de> | 2011-08-13 14:59:24 +0200 |
commit | c47a10f867da52695a5c5b5bf7e0a22dddc0b085 (patch) | |
tree | 21ad6c167d702881598c6edb577f47acfd6d287b /giscanner | |
parent | d437ae4ae95bada1305c6b720bb7eb207c7122bf (diff) | |
download | gobject-introspection-c47a10f867da52695a5c5b5bf7e0a22dddc0b085.tar.gz |
scanner: handle static methods on all types
Instead of just handling static methods for classes, handle them for:
- Records and boxed
- Unions
- Interfaces
Based on a patch by Owen Taylor.
https://bugzilla.gnome.org/show_bug.cgi?id=572408
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/ast.py | 9 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 38 |
2 files changed, 36 insertions, 11 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py index bd56aef3..8ca3a4dd 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -19,6 +19,8 @@ # Boston, MA 02111-1307, USA. # +import copy + from .message import Position from .odict import odict from .utils import to_underscores @@ -568,6 +570,13 @@ class Function(Callable): self.shadowed_by = None # C symbol string self.shadows = None # C symbol string + def clone(self): + clone = copy.copy(self) + # copy the parameters array so a change to self.parameters does not + # influence clone.parameters. + clone.parameters = self.parameters[:] + return clone + class ErrorQuarkFunction(Function): diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index d2d1f2d8..40dda294 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -993,19 +993,35 @@ method or constructor of some type.""" if split is None: return False (node, funcname) = split - - # We actually should treat static methods on a wider class of objects: - # ast.Class, ast.Interface, ast.Record, ast.Union, ast.Boxed - # But we stick to ast.Class for now for compatibility with existing code. - # - # See https://bugzilla.gnome.org/show_bug.cgi?id=572408 - # - if not isinstance(node, ast.Class): + if funcname == '': return False - self._namespace.float(func) - func.name = funcname - node.static_methods.append(func) + if isinstance(node, ast.Class): + self._namespace.float(func) + func.name = funcname + node.static_methods.append(func) + return True + elif isinstance(node, (ast.Interface, ast.Record, ast.Union, + ast.Boxed)): + # prior to the introduction of this part of the code, only + # ast.Class could have static methods. so for backwards + # compatibility, instead of removing the func from the namespace, + # leave it there and get a copy instead. modify the copy and push + # it onto static_methods. we need to copy the parameters list + # separately, because in the third pass functions are flagged as + # 'throws' depending on the presence of a GError parameter which is + # then removed from the parameters list. without the explicit + # copy, only one of the two functions would thus get flagged as + # 'throws'. clone() does this for us. + new_func = func.clone() + new_func.name = funcname + node.static_methods.append(new_func) + # TODO: flag func as a backwards-comptability kludge (and maybe + # prune it in the introspectable pass if we would have + # introspectable=0 anyway). + return True + + return False def _set_up_constructor(self, func, subsymbol): self._namespace.float(func) |