def isVector(cxx_type): if isinstance(cxx_type, bc.ParmVarDecl): cxx_type = cxx_type.type is_lvalue = False is_const = False if isinstance(cxx_type, bc.ElaboratedType): is_const = is_const or cxx_type.isConstQualified cxx_type = cxx_type.namedType if isinstance(cxx_type, bc.LValueReferenceType): is_lvalue = True 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 # print type(cxx_type), cxx_type # print (isinstance(cxx_type, bc.TemplateSpecializationType) and # bc.is_std_vector(cxx_type.sugar.decl)) # print ((isinstance(cxx_type, bc.TemplateSpecializationType) and # bc.is_std_vector(cxx_type.sugar.decl) and # isinstance(cxx_type.args[0].type, bc.RecordType))) if (isinstance(cxx_type, bc.TemplateSpecializationType) and bc.is_std_vector(cxx_type.sugar.decl) and isinstance(base.eraseTypedef(cxx_type.args[0].type), bc.RecordType)): is_const = is_const or cxx_type.isConstQualified if is_lvalue and not is_const: return False return base.eraseTypedef(cxx_type.args[0].type), is_const, is_lvalue return False
def check(klass, creator, cxx_type, func_conv): if isinstance(cxx_type, bc.BuiltinType): k = creator.getClass(cxx_type) if isinstance(k, BuiltinClass) or isinstance(k, BuiltinInterface): return klass(creator, cxx_type, func_conv) elif (isinstance(cxx_type, bc.LValueReferenceType) and isinstance( base.eraseTypedef(cxx_type.pointeeType), bc.BuiltinType) and cxx_type.pointeeType.isConstQualified): pt = base.eraseTypedef(cxx_type.pointeeType) k = creator.getClass(pt) if isinstance(k, BuiltinClass) or isinstance(k, BuiltinInterface): return klass(creator, pt, func_conv)
def isVector(cxx_type): # print "-" * 100 # print type(cxx_type), cxx_type if isinstance(cxx_type, bc.LValueReferenceType): cxx_type = cxx_type.pointeeType if isinstance(cxx_type, bc.ElaboratedType): cxx_type = cxx_type.namedType # print type(cxx_type), cxx_type # print (isinstance(cxx_type, bc.TemplateSpecializationType) and # cxx_type.sugar.decl.path == 'std::vector') # print ((isinstance(cxx_type, bc.TemplateSpecializationType) and # cxx_type.sugar.decl.path == 'std::vector' and # isinstance(cxx_type.args[0].type, bc.RecordType))) # if isinstance(cxx_type, bc.TemplateSpecializationType): # cxx_type.show() # if (isinstance(cxx_type, bc.TemplateSpecializationType) and # cxx_type.sugar.decl.path == 'std::vector'): # print "-" * 100 # print cxx_type # print cxx_type.args[0].type # print string_plugin.isString(cxx_type.args[0].type) # print base.eraseTypedef(cxx_type.args[0].type) if (isinstance(cxx_type, bc.TemplateSpecializationType) and cxx_type.sugar.decl.path == 'std::vector' and string_plugin.isString(base.eraseTypedef(cxx_type.args[0].type))): return True return False
def isVector(cxx_type): if isinstance(cxx_type, bc.ParmVarDecl): cxx_type = cxx_type.type is_lvalue = False is_const = False if isinstance(cxx_type, bc.ElaboratedType): is_const = is_const or cxx_type.isConstQualified cxx_type = cxx_type.namedType if isinstance(cxx_type, bc.LValueReferenceType): is_lvalue = True 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 if (isinstance(cxx_type, bc.TemplateSpecializationType) and (bc.is_std_vector(cxx_type.sugar.decl))): is_const = is_const or cxx_type.isConstQualified if is_lvalue and not is_const: return False, None, None t = base.eraseTypedef(cxx_type.args[0].type) return string_plugin.getString(t), is_const, is_lvalue return False, None, None
def getVectorElem(cxx_type): if isinstance(cxx_type, bc.LValueReferenceType): cxx_type = cxx_type.pointeeType if isinstance(cxx_type, bc.ElaboratedType): cxx_type = cxx_type.namedType if (isinstance(cxx_type, bc.TemplateSpecializationType) and cxx_type.sugar.decl.path == 'std::vector' and string_plugin.isString(base.eraseTypedef(cxx_type.args[0].type))): return cxx_type.args[0].type
def _getAllBases(decl): s = set() for i in decl.bases: if i.access == "public": t = base.eraseTypedef(i.type) if isinstance(t, bc.TemplateSpecializationType): t = t.sugar d = t.decl s.add(d) s.update(_getAllBases(d)) return s
def listBases(self, decl, with_declared=True): l = [decl] res = [] while l: d = l.pop() for b in d.bases: if b.access == 'public': t = base.eraseTypedef(b.type) if isinstance(t, bc.TemplateSpecializationType): t = t.sugar ct = t.decl if (not with_declared) and ct in self.declared_classes: continue l.append(ct) res.append(ct) return res
def isVector(cxx_type): if isinstance(cxx_type, bc.ParmVarDecl): cxx_type = cxx_type.type is_lvalue = False is_const = False if isinstance(cxx_type, bc.ElaboratedType): is_const = is_const or cxx_type.isConstQualified cxx_type = cxx_type.namedType if isinstance(cxx_type, bc.LValueReferenceType): is_lvalue = True 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 # print type(cxx_type), cxx_type # print (isinstance(cxx_type, bc.TemplateSpecializationType) and # cxx_type.sugar.decl.path == 'std::vector') # print ((isinstance(cxx_type, bc.TemplateSpecializationType) and # cxx_type.sugar.decl.path == 'std::vector' and # isinstance(cxx_type.args[0].type, bc.RecordType))) if (isinstance(cxx_type, bc.TemplateSpecializationType) and (bc.is_std_vector(cxx_type.sugar.decl))): # print "=" * 80 # print cxx_type # print cxx_type.args[0].type # print "=" * 80 if isinstance(cxx_type.args[0].type, bc.BuiltinType): raise Exception() elif isinstance(cxx_type.args[0].type, bc.PointerType): return False, None, None is_const = is_const or cxx_type.isConstQualified if is_lvalue and not is_const: return False, None, None t = base.eraseTypedef(cxx_type.args[0].type) if isinstance(t, bc.TemplateSpecializationType): return False, None, None return t, is_const, is_lvalue return False, None, None
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