diff options
author | Paul Pogonyshev <pogonyshev@gmx.net> | 2008-07-14 18:19:25 +0000 |
---|---|---|
committer | Paul Pogonyshev <paulp@src.gnome.org> | 2008-07-14 18:19:25 +0000 |
commit | eeac05d5cbd42308c33e777aecbf00595256519d (patch) | |
tree | 3400ea9d0fb8e6b62fe317a5e77424164433d221 /codegen/definitions.py | |
parent | 5905589cd3e35d4e1fe11f60d56560936be7ae8c (diff) | |
download | pygobject-eeac05d5cbd42308c33e777aecbf00595256519d.tar.gz pygobject-eeac05d5cbd42308c33e777aecbf00595256519d.tar.xz pygobject-eeac05d5cbd42308c33e777aecbf00595256519d.zip |
New class. (MethodDefBase.__init__): Make 'self.ret' a 'ReturnType'
2008-07-14 Paul Pogonyshev <pogonyshev@gmx.net>
* codegen/definitions.py (ReturnType): New class.
(MethodDefBase.__init__): Make 'self.ret' a 'ReturnType' instance,
not string. Accept 'optional' flag.
* codegen/argtypes.py (ArgMatcher.get_reverse_ret): Test if
'ptype' has true 'optional' attribute and copy it to 'props' then.
* codegen/reversewrapper.py (ReturnType.support_optional): New
class field, False by default.
(GObjectReturn.support_optional, GObjectReturn.write_decl)
(GObjectReturn.write_conversion): Support optional return.
svn path=/trunk/; revision=796
Diffstat (limited to 'codegen/definitions.py')
-rw-r--r-- | codegen/definitions.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/codegen/definitions.py b/codegen/definitions.py index 617bcbe..5da488b 100644 --- a/codegen/definitions.py +++ b/codegen/definitions.py @@ -31,6 +31,17 @@ class Parameter(object): if old.pnull is not None: self.pnull = old.pnull +# We currently subclass 'str' to make impact on the rest of codegen as +# little as possible. Later we can subclass 'object' instead, but +# then we must find and adapt all places which expect return types to +# be strings. +class ReturnType(str): + def __new__(cls, *args, **kwds): + return str.__new__(cls, *args[:1]) + def __init__(self, type_name, optional=False): + str.__init__(self, type_name) + self.optional = optional + # Parameter for property based constructors class Property(object): def __init__(self, pname, optional, argname): @@ -297,7 +308,12 @@ class MethodDefBase(Definition): elif arg[0] == 'gtype-id': self.typecode = arg[1] elif arg[0] == 'return-type': - self.ret = arg[1] + type_name = arg[1] + optional = False + for prop in arg[2:]: + if prop[0] == 'optional': + optional = True + self.ret = ReturnType(type_name, optional) elif arg[0] == 'caller-owns-return': self.caller_owns_return = arg[1] in ('t', '#t') elif arg[0] == 'unblock-threads': |