FFI::ClangSourceFFIClangLibCXIndexOptions

class CXIndexOptions

FFI struct for index creation options (libclang 17.0.0+).

The C struct uses bitfields for ExcludeDeclarationsFromPCH (bit 0), DisplayDiagnostics (bit 1), and StorePreamblesInMemory (bit 2). FFI doesn't support bitfields, so these are packed into a single field. Use the helper methods to set them.

On Windows, libclang packs the unsigned bitfields into a 4-byte uint with alignment padding, making the struct 32 bytes. On Linux/macOS, they pack into 2 bytes after the uchars (24 bytes total).

Definitions

def initialize(*args)

Create a new CXIndexOptions with size pre-populated.

Implementation

def initialize(*args)
	super
	self[:size] = self.class.size
	@string_fields = {}
end

def thread_background_priority_for_indexing=(value)

Set the indexing background thread priority policy.

Signature

parameter value Symbol

The CXChoice value.

Implementation

def thread_background_priority_for_indexing=(value)
	self[:thread_background_priority_for_indexing] = value
end

def thread_background_priority_for_editing=(value)

Set the editing background thread priority policy.

Signature

parameter value Symbol

The CXChoice value.

Implementation

def thread_background_priority_for_editing=(value)
	self[:thread_background_priority_for_editing] = value
end

def exclude_declarations_from_pch=(value)

Set whether to exclude declarations from PCH.

Signature

parameter value Boolean

True to exclude.

Implementation

def exclude_declarations_from_pch=(value)
	set_bitfield(0, value)
end

def display_diagnostics=(value)

Set whether to display diagnostics.

Signature

parameter value Boolean

True to display.

Implementation

def display_diagnostics=(value)
	set_bitfield(1, value)
end

def store_preambles_in_memory=(value)

Set whether to store preambles in memory.

Signature

parameter value Boolean

True to store in memory.

Implementation

def store_preambles_in_memory=(value)
	set_bitfield(2, value)
end

def preamble_storage_path=(value)

Set the preamble storage path.

Signature

parameter value String | Nil

The directory path.

Implementation

def preamble_storage_path=(value)
	store_string(:preamble_storage_path, value)
end

def invocation_emission_path=(value)

Set the invocation emission path.

Signature

parameter value String | Nil

The directory path.

Implementation

def invocation_emission_path=(value)
	store_string(:invocation_emission_path, value)
end

def set_bitfield(bit, value)

Set a single bit in the bitfields.

Signature

parameter bit Integer

The bit position.

parameter value Boolean

The value to set.

Implementation

def set_bitfield(bit, value)
	if value
		self[:bitfields] |= (1 << bit)
	else
		self[:bitfields] &= ~(1 << bit)
	end
end

def store_string(field, value)

Keep backing string memory alive for pointer fields.

Signature

parameter field Symbol

The struct field.

parameter value String | Nil

The string value.

Implementation

def store_string(field, value)
	if value
		@string_fields[field] = MemoryPointer.from_string(value)
		self[field] = @string_fields[field]
	else
		@string_fields.delete(field)
		self[field] = nil
	end
end