Example #1
0
    def linkEnd(self):
        try:
            self.classes.remove(None)
        except:
            pass

        self.decls = []
        self.decl_indexes = {}
        self.decl_bases = {}
        for decl in sorted(self.classes, key=lambda x: x.path):
            # print type(decl)
            # print decl
            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[1].addBase(cls[0])
            cls[2].addBase(cls[1])

            declared = filter(lambda x: x in self.declared_classes,
                              self.listBases(decl))
            for i in declared:
                cci = bc.RecordType(i, isConstQualified=True)
                nci = bc.RecordType(i, isConstQualified=False)
                cls[0].addBase(self.creator.getInterface(cci))
                cls[1].addBase(self.creator.getInterface(nci))

            self.decl_indexes[decl] = len(self.decls)
            self.decls.append(decl)
            self.decl_bases[decl] = _getAllBases(decl)
Example #2
0
 def __setRecord(self, d):
     decl, is_const = parseType(d)
     if decl is None:
         return
     # print d.name
     self.resolveInterfacePath(
         bc.LValueReferenceType(bc.RecordType(decl, isConstQualified=True)))
     self.resolveInterfacePath(decl)
     self.resolveClassPath(decl)
     self.__addClassDecl(decl)
Example #3
0
 def resolveInterfacePath(self, decl_or_type):
     decl, is_const = parseType(decl_or_type)
     klass, jp = self.creator.resolveInterfacePath(decl_or_type.pointeeType)
     klass = jclass.Class
     if not is_const:
         self.creator.getClass(
             bc.PointerType(bc.RecordType(decl, isConstQualified=True)))
         klass = PointerClass
     njp = jpath.JPath(jp.path + ('Ptr', ))
     self.classes[jp.path] = decl_or_type
     return klass, njp
Example #4
0
def getVectorElem(cxx_type):
    elem_type, is_const, _ = isVector(cxx_type)
    # is_const = False
    # if isinstance(cxx_type, bc.LValueReferenceType):
    #     is_const = is_const or cxx_type.isConstQualified
    #     cxx_type = cxx_type.pointeeType
    # if isinstance(cxx_type, bc.ElaboratedType):
    #     is_const = is_const or cxx_type.isConstQualified
    #     cxx_type = cxx_type.namedType
    # is_const = is_const or cxx_type.isConstQualified
    t = bc.RecordType(elem_type.decl, isConstQualified=is_const)
    return t
Example #5
0
 def resolveClass(self, decl_or_type):
     postfix = ''
     if self.settings['lightweight_generics']:
         elem_type, isc, _ = isVector(decl_or_type)
         if isinstance(elem_type, bc.BuiltinType):
             print decl_or_type
             print elem_type
             raise Exception()
         t = self.creator.resolveClass(
             bc.RecordType(elem_type.decl, isConstQualified=isc))
         postfix = '<%s*>' % t[1]
     return True, "NSArray%s" % postfix
Example #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)
Example #7
0
 def getElemType(self):
     decl, is_const = parseType(self.cxx_type)
     return bc.RecordType(decl, isConstQualified=is_const)
Example #8
0
    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
Example #9
0
 def getReturnConverter(self):
     return CopyReturnConverter(self.creator,
                                bc.RecordType(self.decl.parent), self)
Example #10
0
 def __init__(self, creator, cxx_type, func_conv):
     ty = bc.RecordType(cxx_type.decl)
     super(CopyReturnConverter, self).__init__(creator, ty, func_conv)
Example #11
0
 def __init__(self, creator, decl, func_conv):
     arg = bc.ParmVarDecl("_this",
                          bc.LValueReferenceType(bc.RecordType(decl)))
     super(InstanceArgConverter, self).__init__(creator, arg, func_conv)
Example #12
0
    def linkEnd(self):
        l = sorted(self.classes, key=lambda x: x.path)
        # m = {}
        # for idx, decl in enumerate(l):
        #     m[decl] = idx
        # self.class_indexes = m

        processed = []
        tmp_map = {}
        while True:
            l = list(self.classes.difference(processed))
            if not l:
                break

            # self.class_indexes = {}
            # for decl in l:
            #     self.class_indexes[decl] = len(self.class_indexes)

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

                # print("=" * 80)
                # print(decl)
                # print(cc.funcs)
                # print(nc.funcs)
                if True or cc.funcs:
                    ccp = self.creator.getClass('Api_' + cc.name,
                                                objc_class.ObjCProtocol)
                    map(ccp.addFunction, cc.funcs)
                    cc.addProtocol(ccp)

                else:
                    ccp = None
                if True or nc.funcs:
                    ncp = self.creator.getClass('Api_' + nc.name,
                                                objc_class.ObjCProtocol)
                    map(ncp.addFunction, nc.funcs)
                    nc.addProtocol(ncp)
                else:
                    ncp = None
                tmp_map[decl] = cc, nc, ccp, ncp

                if decl.access != "public" and decl.access != "none":
                    cc.setValid(False)
                    nc.setValid(False)
                if not self.hasPublicDefaultConstructor(decl):
                    cc.hasDelete(False)

                cc.addBase(self.creator.getBaseClass())
                cc.setImpl(decl)
                nc.addBase(cc)
                nc.priority = 10
            processed += l

        for decl in tmp_map:
            bases = self.listBases(decl)
            cc, nc, ccp, ncp = tmp_map[decl]
            for b in bases:
                if b in tmp_map:
                    if tmp_map[b][2]:
                        cc.addProtocol(tmp_map[b][2])
                    if tmp_map[b][3]:
                        nc.addProtocol(tmp_map[b][3])
Example #13
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
Example #14
0
 def dumpCCallPre(self, source):
     decl, is_const = parseType(self.cxx_type)
     ot = self.creator.resolveClass(bc.RecordType(decl))[1]
     source << ("%s* _ret_val = [%s alloc];" % (ot, ot))
Example #15
0
# coding: utf-8
from blueboss import common as bc
import plugin
import string_plugin
import jpath
import jclass
import builtin_reference_plugin


STRING_REF_CLASS_PATH = jpath.JPath(("primitives", "StringRef"))
STRING_TYPE = bc.TemplateSpecializationType()
STRING_TYPE.sugar = bc.RecordType(bc.RecordDecl('std::basic_string'))
STRING_TYPE.args = [
    bc.TemplateArgument()
]
STRING_TYPE.args[0].type = bc.BuiltinType("char")


class StringRefGetDecl(bc.CXXMethodDecl):
    pass


class StringRefSetDecl(bc.CXXMethodDecl):
    pass


class InstanceArgConverter(builtin_reference_plugin.InstanceArgConverter):
    def getCTypeName(self):
        return "std::string"