コード例 #1
0
ファイル: typedef_plugin.py プロジェクト: s1s5/cxx_decls
    def getArgConverter(self, arg_decl, func_decl):
        cxx_type = arg_decl.type
        is_l = False
        is_c = cxx_type.isConstQualified
        if isinstance(cxx_type, bc.LValueReferenceType):
            cxx_type = cxx_type.pointeeType
            is_l = True
            is_c = is_c or cxx_type.isConstQualified
        if isinstance(cxx_type, bc.ElaboratedType):
            cxx_type = cxx_type.namedType
            is_c = is_c or cxx_type.isConstQualified
        # print arg_decl, isinstance(
        # arg_decl.type, bc.TypedefType), type(arg_decl.type)
        if not isinstance(cxx_type, bc.TypedefType):
            return

        if is_l:
            t, c = _get(cxx_type)
            t = t.shallowCopy()
            t.isConstQualified = t.isConstQualified or is_c or c
            cxx_type = bc.LValueReferenceType(t)
        else:
            t, c = _get(cxx_type)
            t = t.shallowCopy()
            t.isConstQualified = t.isConstQualified or is_c or c
            cxx_type = t

        arg_decl = bc.ParmVarDecl(arg_decl.name,
                                  cxx_type,
                                  hasDefaultArg=arg_decl.hasDefaultArg)
        return self.creator.getArgConverter(arg_decl, func_decl)
コード例 #2
0
ファイル: class_vector_plugin.py プロジェクト: s1s5/cxx_decls
 def __init__(self, *args, **kw):
     super(ArgConverter, self).__init__(*args, **kw)
     d, ic, il = isVector(self.arg)
     self.d = d
     self.ic = ic
     self.il = il
     self.c = self.creator.getArgConverter(bc.ParmVarDecl("_e_", self.d),
                                           self.func_conv)
コード例 #3
0
ファイル: class_plugin.py プロジェクト: s1s5/cxx_decls
 def setter(self, class_decl, decl, const):
     if const:
         return []
     name = decl.path
     n = name.split('::')
     name = 'set_' + n[-1]
     if len(n) > 1:
         name = '::'.join(n[:-1] + [name])
     arg_type = decl.type
     if isinstance(arg_type, bc.SubstTemplateTypeParmType):
         arg_type = arg_type.sugar
     arg_type = arg_type.shallowCopy()
     arg_type.isConstQualified = True
     l = []
     l.append(
         CXXSetterDecl(name, None, bc.BuiltinType("void"),
                       [bc.ParmVarDecl("var", arg_type)], class_decl))
     if not isinstance(arg_type, bc.LValueReferenceType):
         arg_type = bc.LValueReferenceType(arg_type)
         l.append(
             CXXSetterDecl(name, None, bc.BuiltinType("void"),
                           [bc.ParmVarDecl("var", arg_type)], class_decl))
     return l
コード例 #4
0
    def dumpCCallPre(self, source):
        return_type = self.creator.resolveClass(self.cxx_type.returnType)
        args = []
        for i in self.cxx_type.param_types:
            args.append(self.creator.resolveClass(i))

        def _type_str(x):
            if x[0]:
                return '{} *'.format(x[1])
            return x[1]

        fdecl = "{}(^{}_objc)({})".format(
            _type_str(return_type), self.getArgName(),
            ', '.join(_type_str(x) for x in args))

        source << "{0} = [{1} copy];".format(fdecl, self.getArgName())
        source << "auto {arg_name}_ = [{arg_name}_objc]({arg_string}){brace}".format(
            arg_name=self.getArgName(),
            arg_string=', '.join(
                'auto arg{}'.format(x)
                for x in range(len(self.cxx_type.param_types))),
            brace='{')

        for param_idx, param_type in enumerate(self.cxx_type.param_types):
            c = self.creator.getReturnConverter(param_type, self)
            source << "%s objc_arg%d = [](auto x) {" % (c.getObjCType(),
                                                        param_idx)
            c.dumpCCallPre(source)
            c.dumpCCall(source, 'x')
            c.dumpCCallPost(source)
            c.dumpCReturn(source)
            source << "}(arg%d);" % param_idx

        call_string = "{}_objc({})".format(
            self.getArgName(),
            ', '.join('objc_arg{}'.format(x)
                      for x in range(len(self.cxx_type.param_types))))
        if (isinstance(self.cxx_type.returnType, bc.BuiltinType)
                and self.cxx_type.returnType.spelling == 'void'):
            source << "{};".format(call_string)
        else:
            source << "auto _ret = {};".format(call_string)
            ac = self.creator.getArgConverter(
                bc.ParmVarDecl(name='_ret', type=self.cxx_type.returnType),
                self)
            ac.dumpCCallPre(source)
            source << "auto _ret_c = {};".format(ac.getCCall())
            ac.dumpCCallPost(source)
            source << "return _ret_c;"
        source << "};"
コード例 #5
0
 def linkEnd(self):
     if not self.__flag:
         return
     klass = self.creator.getClass(STRING_REF_CLASS_PATH)
     f = StringRefGetDecl("StringRef::get", None,
                          STRING_TYPE, [], bc.CXXRecordDecl("int"))
     conv = self.creator.getFunctionConverter(f)
     klass.addFunction(conv)
     f = StringRefSetDecl("StringRef::set", None,
                          bc.BuiltinType("void"), [
                              bc.ParmVarDecl("arg", STRING_TYPE)],
                          bc.CXXRecordDecl("int"))
     conv = self.creator.getFunctionConverter(f)
     klass.addFunction(conv)
コード例 #6
0
 def linkEnd(self):
     for i in self.classes:
         decl = self.classes[i].pointeeType.decl
         isConstQualified = self.classes[i].pointeeType.isConstQualified
         c = self.creator.getClass(self.classes[i])
         intf = self.creator.getInterface(self.classes[i].pointeeType)
         intf2 = self.creator.getClass(self.classes[i].pointeeType)
         # print ">>", i, self.classes[i]
         fn = 'at'
         if isConstQualified:
             fn = 'cAt'
         f = PointerAtDecl(
             decl.name + "::" + fn,
             None,
             bc.LValueReferenceType(
                 bc.RecordType(decl, isConstQualified=isConstQualified)),
             [bc.ParmVarDecl(
                 "index",
                 bc.BuiltinType("int"),
             )],
             decl,
             isConstQualified=isConstQualified)
         conv = self.creator.getFunctionConverter(f)
         c.addFunction(conv)
         fn = 'ref'
         if isConstQualified:
             fn = 'cref'
         f = getPointerFunctionDecl(
             decl.name + "::" + fn, None,
             bc.PointerType(
                 bc.RecordType(decl, isConstQualified=isConstQualified)),
             [], decl)
         conv = self.creator.getFunctionConverter(f)
         # print intf, intf2, conv
         intf.addFunction(conv)
         intf2.addFunction(conv)
         if not isConstQualified:
             d = self.creator.getClass(
                 bc.PointerType(bc.RecordType(decl, isConstQualified=True)))
             c.setBaseClass(d)
コード例 #7
0
ファイル: class_plugin.py プロジェクト: s1s5/cxx_decls
    def declare(self, decl):
        if not isinstance(decl, bc.RecordDecl):
            return False
        if decl.access != "public" and decl.access != "none":
            return False
        # print decl, "!" * 10
        # decl.show()
        if decl.describedClassTemplate is not None:
            return False

        self.classes.add(decl)
        for i in self.listBases(decl):
            self.classes.add(i)

        cc = bc.RecordType(decl, isConstQualified=True)
        nc = bc.RecordType(decl, isConstQualified=False)
        cls = [
            self.creator.getInterface(cc),
            self.creator.getInterface(nc),
            self.creator.getClass(nc),
        ]

        cls[2].is_valid = not decl.isAbstract

        cls[1].addBase(cls[0])
        cls[2].addBase(cls[1])

        # for i in self.listMethods(decl, const=True):
        for i in self.listAllMethods(decl, const=True):
            conv = self.creator.getFunctionConverter(i, decl)
            if not conv.isStatic():
                cls[0].addFunction(conv)
            # cls[2].addFunction(conv)
        # for i in self.listMethods(decl, const=False):
        for i in self.listAllMethods(decl, const=False):
            conv = self.creator.getFunctionConverter(i, decl)
            if not conv.isStatic():
                cls[1].addFunction(conv)
            # cls[2].addFunction(conv)

        if not decl.isAbstract:
            for i in self.listAllMethods(decl):
                conv = self.creator.getFunctionConverter(i, decl)
                cls[2].addFunction(conv)
            for i in self.listConstructors(decl):
                conv = self.creator.getFunctionConverter(i, decl)
                cls[2].addFunction(conv)

        if self.hasCopyConstructor(decl):
            f = CXXCopyDecl(decl.cname() + "::__copy__", None,
                            bc.RecordType(decl), [], decl)
            conv = self.creator.getFunctionConverter(f, decl)
            cls[0].addFunction(conv)
            if not decl.isAbstract:
                cls[2].addFunction(conv)
            f = CXXAssignOperatorDecl(
                decl.cname() + "::__assign__", None, bc.BuiltinType("void"), [
                    bc.ParmVarDecl(
                        "arg",
                        bc.LValueReferenceType(
                            bc.RecordType(decl, isConstQualified=True)),
                    ),
                ], decl)
            conv = self.creator.getFunctionConverter(f, decl)
            cls[1].addFunction(conv)
            if not decl.isAbstract:
                cls[2].addFunction(conv)
        return True
コード例 #8
0
ファイル: class_plugin.py プロジェクト: s1s5/cxx_decls
 def __init__(self, creator, decl, func_conv):
     arg = bc.ParmVarDecl("_this",
                          bc.LValueReferenceType(bc.RecordType(decl)))
     super(InstanceArgConverter, self).__init__(creator, arg, func_conv)
コード例 #9
0
    def declare(self, decl):
        # print("!" * 80)
        # print("field !!")
        # print(decl)
        # print(isinstance(decl, bc.RecordDecl))

        if not isinstance(decl, bc.RecordDecl):
            return False
        # print("decl.describedClassTemplate: ", decl.describedClassTemplate)
        # TODO: bug fix,,,
        # if decl.describedClassTemplate is not None:
        #     return False
        # print("access = ", decl.access)
        if decl.access != "public" and decl.access != "none":
            return False

        cc = bc.RecordType(decl, isConstQualified=True)
        nc = bc.RecordType(decl, isConstQualified=False)
        cc = self.creator.getClass(cc)
        nc = self.creator.getClass(nc)

        cc.setImpl(decl)
        nc.addBase(cc)
        nc.priority = 10

        for i in self.listAllMethods(decl, const=True):
            conv = self.creator.getFunctionConverter(i)
            cc.addFunction(conv)

        for i in self.listAllMethods(decl, const=False):
            conv = self.creator.getFunctionConverter(i)
            nc.addFunction(conv)

        # print("=" * 80)
        # print("field !!")
        # print(decl)
        for field in self.listAllFields(decl):
            # print(field)
            ft = field.type
            if isinstance(ft, bc.SubstTemplateTypeParmType):
                ft = ft.sugar

            if (isinstance(base.eraseTypedef(ft), bc.BuiltinType)
                    or isinstance(base.eraseTypedef(ft), bc.EnumType)):
                rt = ft
            else:
                rt = bc.LValueReferenceType(ft, isConstQualified=True)

            f = CXXGetterDecl("%s::get_%s" % (decl.path, field.name), None, rt,
                              [], decl)
            f.field_name = field.name
            gconv = CXXGetterConverter(self.creator, f)
            cc.addFunction(gconv)

            if not (isinstance(base.eraseTypedef(ft), bc.BuiltinType)
                    or isinstance(base.eraseTypedef(ft), bc.EnumType)):
                rt = bc.LValueReferenceType(ft, isConstQualified=False)

                f = CXXGetterDecl("%s::get_%s" % (decl.path, field.name), None,
                                  rt, [], decl)
                f.field_name = field.name
                gconv = CXXGetterConverter(self.creator, f)
                nc.addFunction(gconv)

            f = CXXSetterDecl("%s::set_%s" % (decl.path, field.name), None,
                              bc.BuiltinType("void"), [
                                  bc.ParmVarDecl("arg", ft),
                              ], decl)

            f.field_name = field.name
            sconv = CXXSetterConverter(self.creator, f)
            nc.addFunction(sconv)
            t = gconv.return_converter.getObjCType()
            if not gconv.return_converter.isValid():
                continue

            if gconv.isValid():
                cc.addProperty(
                    objc_class.Property(t,
                                        field.name,
                                        getter=gconv.getName(),
                                        other_attribs='assign, nonatomic'))
                gname = gconv.getName()
            else:
                gname = None

            if sconv.isValid():
                # t = sconv.arg_converters[0].getObjCType()
                t = gconv.return_converter.getObjCType()
                nc.addProperty(
                    objc_class.Property(t,
                                        field.name,
                                        getter=gname,
                                        setter=sconv.getName(),
                                        other_attribs='assign, nonatomic'))

        if False and self.hasCopyConstructor(decl):
            f = CXXCopyDecl(decl.path + "::__copy__", None,
                            bc.RecordType(decl), [], decl)
            conv = self.creator.getFunctionConverter(f)
            cc.addFunction(conv)
            f = CXXAssignOperatorDecl(
                decl.path + "::__assign__", None, bc.BuiltinType("void"), [
                    bc.ParmVarDecl(
                        "arg",
                        bc.LValueReferenceType(
                            bc.RecordType(decl, isConstQualified=True)),
                    ),
                ], decl)
            conv = self.creator.getFunctionConverter(f)
            nc.addFunction(conv)
        return True
コード例 #10
0
    def linkEnd(self):
        for spelling, (cpath, vpath) in self.classes.items():
            if spelling == 'void':
                void_ptr = cpath, vpath

        for spelling, (cpath, vpath) in self.classes.items():
            # print spelling, cpath, vpath
            cklass = self.creator.getInterface(cpath)
            klass = self.creator.getClass(vpath)
            klass.addBase(cklass)

            if spelling == 'void':
                t = builtin_reference_plugin.builtin_class_wrapper[spelling]
                f = WrapVoidPtrDecl(
                    "wrap",
                    None,
                    bc.PointerType(bc.BuiltinType("void")),
                    [WrapVoidPtrArg(
                        "ptr",
                        bc.BuiltinType("void"),
                    )],
                    t,
                    isStatic=True)
                conv = self.creator.getFunctionConverter(f)
                klass.addFunction(conv)
            else:
                klass.setBaseClass(self.creator.getClass(void_ptr[1]))
                t = builtin_reference_plugin.builtin_class_wrapper[spelling]
                f = PointerAtDecl(
                    "at", None,
                    bc.LValueReferenceType(bc.BuiltinType(spelling)),
                    [bc.ParmVarDecl(
                        "index",
                        bc.BuiltinType("int"),
                    )], t)
                conv = self.creator.getFunctionConverter(f)
                klass.addFunction(conv)

                f = PointerCAtDecl(
                    "cAt",
                    None,
                    bc.LValueReferenceType(
                        bc.BuiltinType(spelling, isConstQualified=True)),
                    [bc.ParmVarDecl("index", bc.BuiltinType("int"))],
                    t,
                    isConstQualified=True)
                conv = self.creator.getFunctionConverter(f)
                cklass.addFunction(conv)
                klass.addFunction(conv)

                f = WrapArrayDecl(
                    "wrap",
                    None,
                    bc.PointerType(bc.BuiltinType(spelling)),
                    # f = WrapArrayDecl(t, bc.BuiltinType("void"),
                    [
                        WrapArrayArg(
                            "arg",
                            bc.PointerType(bc.BuiltinType(spelling)),
                        )
                    ],
                    t,
                    isStatic=True)
                conv = self.creator.getFunctionConverter(f)
                klass.addFunction(conv)
コード例 #11
0
 def __init__(self, creator, decl, func_conv):
     arg = bc.ParmVarDecl("_this",
                          bc.PointerType(bc.BuiltinType(decl.name)))
     super(InstanceArgConverter, self).__init__(creator, arg, func_conv)
コード例 #12
0
ファイル: memory_plugin.py プロジェクト: s1s5/cxx_decls
 def getBridgeArgConverters(self):
     return [ArgConverter(self.creator, bc.ParmVarDecl(), self.decl)]