Exemple #1
0
            res.append(self.make_getter_wrapper(n.name(), t))
            res.append(self.make_setter_wrapper(n.name(), t))
            res.append(self.make_dynamic_getter_wrapper(n.name(), t))
            res.append(self.make_dynamic_setter_wrapper(n.name(), t))
        
        return res
    
    FuncDef make_getter_wrapper(self, str name, Type typ):
        """Create a getter wrapper for a data attribute.

        The getter will be of this form:
        
        . int $name*(C self):
        .     return self.name!
        """
        member_expr = MemberExpr(self_expr(), name, direct=True)
        ret = ReturnStmt(member_expr)

        wrapper_name = '$' + name
        selft = self_type(self.tf.type_context())            
        sig = Callable([selft], [nodes.ARG_POS], [None], typ, False)
        return FuncDef(wrapper_name,
                       [Var('self')],
                       [nodes.ARG_POS],
                       [None],
                       Block([ret]), sig)
    
    FuncDef make_dynamic_getter_wrapper(self, str name, Type typ):
        """Create a dynamically-typed getter wrapper for a data attribute.

        The getter will be of this form: