def build_ctype(self, name, decl): which = decl.getitem(String(u"type")) if isinstance(which, String) and which.string == u"cfunc": restype = decl.getitem(String(u'restype')) argtypes_list = decl.getitem(String(u'argtypes')) if not isinstance(argtypes_list, List): raise Error(u"incorrect function record") restype = self.lookup_type(restype) argtypes = [] for argtype in argtypes_list.contents: argtypes.append(self.lookup_type(argtype)) return ffi.CFunc(restype, argtypes) if isinstance(which, String) and which.string == u"union": if decl in self.cycle_catch: return self.cycle_catch[decl] fields = decl.getitem(String(u"fields")) self.cycle_catch[decl] = ctype = ffi.Union(None, name) ctype.declare(self.parse_fields(name, fields)) return ctype if isinstance(which, String) and which.string == u"struct": if decl in self.cycle_catch: return self.cycle_catch[decl] fields = decl.getitem(String(u"fields")) self.cycle_catch[decl] = ctype = ffi.Struct(None, name) ctype.declare(self.parse_fields(name, fields)) return ctype if isinstance(which, String) and which.string == u"opaque": return ffi.Struct(None, name) if isinstance(which, String) and which.string == u"array": ctype = self.lookup_type(decl.getitem(String(u'ctype'))) length = decl.getitem(String(u"length")) if length is null: return ffi.Array(ctype) elif isinstance(length, Integer): return ffi.Array(ctype, length.value) else: raise Error(name + u": incorrect length value: %s" % length.repr()) if isinstance(which, String) and which.string == u"pointer": to = self.lookup_type(decl.getitem(String(u'to'))) return ffi.Pointer(to) raise Error(name + u": no ctype builder for " + which.repr())
def build_ctype_raw(self, name, decl): which = decl.getitem(String(u"type")) if isinstance(which, String) and which.string == u"cfunc": restype = decl.getitem(String(u'restype')) argtypes_list = decl.getitem(String(u'argtypes')) if not isinstance(argtypes_list, List): raise OldError(u"incorrect function record") restype = self.lookup_type(restype) argtypes = [] for argtype in argtypes_list.contents: argtypes.append(self.lookup_type(argtype)) return ffi.CFunc(restype, argtypes) if isinstance(which, String) and which.string == u"union": if decl in self.cycle_catch: return self.cycle_catch[decl] fields = decl.getitem(String(u"fields")) self.cycle_catch[decl] = ctype = ffi.Union(None, name) ctype.declare(self.parse_fields(name, fields)) return ctype if isinstance(which, String) and which.string == u"struct": if decl in self.cycle_catch: return self.cycle_catch[decl] fields = decl.getitem(String(u"fields")) self.cycle_catch[decl] = ctype = ffi.Struct(None, name) ctype.declare(self.parse_fields(name, fields)) return ctype if isinstance(which, String) and which.string == u"opaque": return ffi.Struct(None, name) if isinstance(which, String) and which.string == u"array": ctype = self.lookup_type(decl.getitem(String(u'ctype'))) length = decl.getitem(String(u"length")) if length is null: return ffi.Array(ctype) elif isinstance(length, Integer): return ffi.Array(ctype, length.value) else: raise OldError(name + u": incorrect length value: %s" % length.repr()) if isinstance(which, String) and which.string == u"pointer": to_obj = decl.getitem(String(u'to')) # A little hack to name common opaque pointers. if isinstance(to_obj, Dict): to = self.build_ctype(name, to_obj) else: to = self.lookup_type(to_obj) return ffi.Pointer(to) if isinstance(which, String) and which.string == u"enum": ctype = self.lookup_type(decl.getitem(String(u'ctype'))) constants = decl.getitem(String(u"constants")) if not isinstance(constants, Dict): raise unwind( LTypeError(name + u": expected constant table to be dictionary")) table = {} for name_, const in constants.data.iteritems(): if not isinstance(name_, String): raise unwind( LTypeError( name + u": expected constants table key to be string")) if not isinstance(const, Integer): raise unwind( LTypeError( name + u": expected constants table value to be integer")) table[name_.string] = const.value return ffi.Bitmask(ffi.to_type(ctype), table, multichoice=False) if isinstance(which, String) and which.string == u"bitmask": ctype = self.lookup_type(decl.getitem(String(u'ctype'))) constants = decl.getitem(String(u"constants")) if not isinstance(constants, Dict): raise unwind( LTypeError(name + u": expected constant table to be dictionary")) table = {} for name_, const in constants.data.iteritems(): if not isinstance(name_, String): raise unwind( LTypeError( name + u": expected constants table key to be string")) if not isinstance(const, Integer): raise unwind( LTypeError( name + u": expected constants table value to be integer")) table[name_.string] = const.value return ffi.Bitmask(ffi.to_type(ctype), table, multichoice=True) raise OldError(name + u": no ctype builder for " + which.repr())