From eeac05d5cbd42308c33e777aecbf00595256519d Mon Sep 17 00:00:00 2001 From: Paul Pogonyshev Date: Mon, 14 Jul 2008 18:19:25 +0000 Subject: New class. (MethodDefBase.__init__): Make 'self.ret' a 'ReturnType' 2008-07-14 Paul Pogonyshev * 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 --- codegen/definitions.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'codegen/definitions.py') 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': -- cgit