FFI::ClangSourceFFIClangLib

module Lib

Nested

Definitions

CUSOR_TRANSLATION_UNIT = Clang.clang_version < Gem::Version.new("15.0.0") ? 300 : 350

In Clang 15 the enum value changed from 300 to 350!

def self.extract_string(cxstring)

Extract a Ruby string from a CXString and dispose of the CXString.

Signature

parameter cxstring CXString

The CXString to extract from.

returns String

The extracted string.

Implementation

def self.extract_string(cxstring)
	result = get_string(cxstring)
	dispose_string cxstring
	
	return result
end

def self.bitmask_from(enum, opts)

Convert an options hash to a bitmask for libclang enums.

Signature

parameter enum FFI::Enum

The enum type.

parameter opts Array(Symbol)

The array of option symbols.

returns Integer

The bitmask representing the options.

raises Error

If an unknown option is provided.

Implementation

def self.bitmask_from(enum, opts)
	bitmask = 0
	
	opts.each do |symbol|
		if int = enum[symbol]
			bitmask |= int
		else
			raise Error, "unknown option: #{symbol}, expected one of #{enum.symbols}"
		end
	end
	
	bitmask
end

def self.opts_from(enum, bitmask)

Convert a bitmask to an array of option symbols.

Signature

parameter enum FFI::Enum

The enum type.

parameter bitmask Integer

The bitmask to convert.

returns Array(Symbol)

The array of option symbols.

raises Error

If unknown bits are set in the bitmask.

Implementation

def self.opts_from(enum, bitmask)
	bit = 1
	result = []
	while bitmask != 0
		if bitmask & 1
			if symbol = enum[bit]
				result << symbol
			else
				raise(Error, "unknown values: #{bit}, expected one of #{enum.symbols}")
			end
		end
		bitmask >>= 1
		bit <<= 1
	end
	result
end