コード例 #1
0
ファイル: interp_cppyy.py プロジェクト: charred/pypy
    def _build_methods(self):
        assert len(self.methods) == 0
        methods_temp = {}
        for i in range(capi.c_num_methods(self.space, self)):
            idx = capi.c_method_index_at(self.space, self, i)
            pyname = helper.map_operator_name(self.space,
                capi.c_method_name(self.space, self, idx),
                capi.c_method_num_args(self.space, self, idx),
                capi.c_method_result_type(self.space, self, idx))
            cppmethod = self._make_cppfunction(pyname, idx)
            methods_temp.setdefault(pyname, []).append(cppmethod)
        # the following covers the case where the only kind of operator[](idx)
        # returns are the ones that produce non-const references; these can be
        # used for __getitem__ just as much as for __setitem__, though
        if not "__getitem__" in methods_temp:
            try:
                for m in methods_temp["__setitem__"]:
                    cppmethod = self._make_cppfunction("__getitem__", m.index)
                    methods_temp.setdefault("__getitem__", []).append(cppmethod)
            except KeyError:
                pass          # just means there's no __setitem__ either

        # create the overload methods from the method sets
        for pyname, methods in methods_temp.iteritems():
            CPPMethodSort(methods).sort()
            overload = W_CPPOverload(self.space, self, methods[:])
            self.methods[pyname] = overload
コード例 #2
0
ファイル: interp_cppyy.py プロジェクト: MichaelBlume/pypy
 def _make_cppfunction(self, method_index):
     num_args = capi.c_method_num_args(self, method_index)
     args_required = capi.c_method_req_args(self, method_index)
     arg_defs = []
     for i in range(num_args):
         arg_type = capi.c_method_arg_type(self, method_index, i)
         arg_dflt = capi.c_method_arg_default(self, method_index, i)
         arg_defs.append((arg_type, arg_dflt))
     return CPPFunction(self.space, self, method_index, arg_defs, args_required)
コード例 #3
0
ファイル: interp_cppyy.py プロジェクト: MichaelBlume/pypy
 def _make_cppfunction(self, method_index):
     num_args = capi.c_method_num_args(self, method_index)
     args_required = capi.c_method_req_args(self, method_index)
     arg_defs = []
     for i in range(num_args):
         arg_type = capi.c_method_arg_type(self, method_index, i)
         arg_dflt = capi.c_method_arg_default(self, method_index, i)
         arg_defs.append((arg_type, arg_dflt))
     if capi.c_is_constructor(self, method_index):
         cls = CPPConstructor
     elif capi.c_is_staticmethod(self, method_index):
         cls = CPPFunction
     else:
         cls = CPPMethod
     return cls(self.space, self, method_index, arg_defs, args_required)
コード例 #4
0
ファイル: interp_cppyy.py プロジェクト: MichaelBlume/pypy
 def _find_methods(self):
     num_methods = capi.c_num_methods(self)
     args_temp = {}
     for i in range(num_methods):
         method_name = capi.c_method_name(self, i)
         pymethod_name = helper.map_operator_name(
             method_name, capi.c_method_num_args(self, i), capi.c_method_result_type(self, i)
         )
         if not pymethod_name in self.methods:
             cppfunction = self._make_cppfunction(i)
             overload = args_temp.setdefault(pymethod_name, [])
             overload.append(cppfunction)
     for name, functions in args_temp.iteritems():
         overload = W_CPPOverload(self.space, self, functions[:])
         self.methods[name] = overload
コード例 #5
0
ファイル: interp_cppyy.py プロジェクト: charred/pypy
 def _make_cppfunction(self, pyname, index):
     num_args = capi.c_method_num_args(self.space, self, index)
     args_required = capi.c_method_req_args(self.space, self, index)
     arg_defs = []
     for i in range(num_args):
         arg_type = capi.c_method_arg_type(self.space, self, index, i)
         arg_dflt = capi.c_method_arg_default(self.space, self, index, i)
         arg_defs.append((arg_type, arg_dflt))
     if capi.c_is_constructor(self.space, self, index):
         cppfunction = CPPConstructor(self.space, self, index, arg_defs, args_required)
         if args_required == 0:
             self.default_constructor = cppfunction
     elif capi.c_method_is_template(self.space, self, index):
         templ_args = capi.c_template_args(self.space, self, index)
         cppfunction = CPPTemplatedCall(self.space, templ_args, self, index, arg_defs, args_required)
     elif capi.c_is_staticmethod(self.space, self, index):
         cppfunction = CPPFunction(self.space, self, index, arg_defs, args_required)
     elif pyname == "__setitem__":
         cppfunction = CPPSetItem(self.space, self, index, arg_defs, args_required)
     else:
         cppfunction = CPPMethod(self.space, self, index, arg_defs, args_required)
     return cppfunction