def Variable(self, attrs): name = attrs["name"] if name.startswith("cpp_sym_"): # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx fix me! name = name[len("cpp_sym_"):] init = attrs.get("init", None) typ = attrs["type"] return typedesc.Variable(name, typ, init)
def VAR_DECL(self, cursor): """Handles Variable declaration.""" # get the name name = self.get_unique_name(cursor) log.debug('VAR_DECL: name: %s', name) # Check for a previous declaration in the register if self.is_registered(name): return self.get_registered(name) # get the typedesc object _type = self._VAR_DECL_type(cursor) # transform the ctypes values into ctypeslib init_value = self._VAR_DECL_value(cursor, _type) # finished log.debug('VAR_DECL: _type:%s', _type.name) log.debug('VAR_DECL: _init:%s', init_value) log.debug('VAR_DECL: location:%s', getattr(cursor, 'location')) obj = self.register(name, typedesc.Variable(name, _type, init_value)) self.set_location(obj, cursor) self.set_comment(obj, cursor) return True
def VAR_DECL(self, cursor): """Handles Variable declaration.""" # get the name name = self.get_unique_name(cursor) # double declaration ? if self.is_registered(name): return self.get_registered(name) # Get the type _ctype = cursor.type.get_canonical() # FIXME: Need working int128, long_double, etc... if self.is_fundamental_type(_ctype): ctypesname = self.get_ctypes_name(_ctype.kind) _type = typedesc.FundamentalType(ctypesname, 0, 0) # FIXME: because c_long_double_t or c_unint128 are not real ctypes # we can make variable with them. # just write the value as-is. ### if literal_kind != CursorKind.DECL_REF_EXPR: ### init_value = '%s(%s)'%(ctypesname, init_value) elif self.is_unexposed_type(_ctype): # string are not exposed # FIXME recurse on child log.error('PATCH NEEDED: %s type is not exposed by clang' % (name)) raise RuntimeError('') ctypesname = self.get_ctypes_name(TypeKind.UCHAR) _type = typedesc.FundamentalType(ctypesname, 0, 0) elif self.is_array_type(_ctype) or _ctype.kind == TypeKind.RECORD: _type = self.parse_cursor_type(_ctype) elif self.is_pointer_type(_ctype): # extern Function pointer if self.is_unexposed_type(_ctype.get_pointee()): _type = self.parse_cursor_type( _ctype.get_canonical().get_pointee()) elif _ctype.get_pointee().kind == TypeKind.FUNCTIONPROTO: # Function pointers # cursor.type.get_pointee().kind == TypeKind.UNEXPOSED BUT # cursor.type.get_canonical().get_pointee().kind == TypeKind.FUNCTIONPROTO _type = self.parse_cursor_type(_ctype.get_pointee()) #_type = mth(_ctype.get_pointee()) else: # Fundamental types, structs.... _type = self.parse_cursor_type(_ctype) else: # What else ? raise NotImplementedError('What other type of variable? %s' % (_ctype.kind)) ## get the init_value and special cases init_value = self._get_var_decl_init_value(cursor.type, list(cursor.get_children())) if self.is_unexposed_type(_ctype): # string are not exposed init_value = '%s # UNEXPOSED TYPE. PATCH NEEDED.' % (init_value) elif (self.is_pointer_type(_ctype) and _ctype.get_pointee().kind == TypeKind.FUNCTIONPROTO): # Function pointers argument are handled inside if type(init_value) != list: init_value = [init_value] _type.arguments = init_value init_value = _type # finished log.debug('VAR_DECL: %s _ctype:%s _type:%s _init:%s location:%s' % (name, _ctype.kind.name, _type.name, init_value, getattr(cursor, 'location'))) obj = self.register(name, typedesc.Variable(name, _type, init_value)) self.set_location(obj, cursor) self.set_comment(obj, cursor) return True # dont parse literals again