Beispiel #1
0
    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)
 def resolveInterfacePath(self, decl_or_type):
     name = builtin_plugin.getJavaBuiltinType(self.target_info,
                                              decl_or_type.pointeeType)
     cname = 'Const' + name[0].upper() + name[1:]
     vname = 'C' + name[0].upper() + name[1:]
     cpath = jpath.JPath(("primitives", cname, 'Ptr'))
     vpath = jpath.JPath(("primitives", vname, 'Ptr'))
     if decl_or_type.pointeeType.isConstQualified:
         name = cname
         klass = jclass.Interface
         self.creator.setNamespace(jclass.Class, vpath)
     else:
         name = vname
         klass = jclass.Class
         self.creator.setNamespace(jclass.Interface,
                                   jpath.JPath((
                                       "primitives",
                                       cname,
                                   )))
         self.creator.setNamespace(jclass.Interface, cpath)
     if decl_or_type.pointeeType.spelling != "void":
         self.creator.getClass(
             bc.LValueReferenceType(
                 bc.BuiltinType(decl_or_type.pointeeType.spelling)))
         self.creator.resolveInterfacePath(
             bc.PointerType(bc.BuiltinType("void")))
         self.creator.getClass(bc.PointerType(bc.BuiltinType("void")))
     self.creator.setNamespace(jclass.Interface,
                               jpath.JPath((
                                   "primitives",
                                   name,
                               )))
     pjp = jpath.JPath(("primitives", name, 'Ptr'))
     self.classes[decl_or_type.pointeeType.spelling] = cpath, vpath
     return klass, pjp
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
 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
Beispiel #6
0
 def getter(self, class_decl, decl, const):
     if const is None:
         return (self.getter(class_decl, decl, False) +
                 self.getter(class_decl, decl, True))
     name = decl.path
     if const:
         n = name.split('::')
         name = 'get_' + n[-1]
         if len(n) > 1:
             name = '::'.join(n[:-1] + [name])
     ret_type = decl.type
     if isinstance(ret_type, bc.SubstTemplateTypeParmType):
         ret_type = ret_type.sugar
     ret_type = ret_type.shallowCopy()
     ret_type.isConstQualified = const
     l = []
     if const:
         l.append(
             CXXGetterDecl(name + "_copy", None, ret_type, [], class_decl))
     if not isinstance(ret_type, bc.LValueReferenceType):
         ret_type = bc.LValueReferenceType(ret_type)
     l.append(CXXGetterDecl(name, None, ret_type, [], class_decl))
     return l
Beispiel #7
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
Beispiel #8
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)
Beispiel #9
0
 def getElemType(self):
     et, is_const, size = parseType(self.cxx_type)
     return bc.LValueReferenceType(et, isConstQualified=is_const)
Beispiel #10
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
Beispiel #11
0
 def getElemType(self):
     return bc.LValueReferenceType(getBuiltinType(self.cxx_type))
    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)