Class: FFI::Clang::DiagnosticSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ffi/clang/diagnostic_set.rb

Overview

Represents a set of child diagnostics from a parent Diagnostic.

This is not an AutoPointer because the CXDiagnosticSet pointer is owned by the parent Diagnostic. Per the libclang docs: “This CXDiagnosticSet does not need to be released by clang_disposeDiagnosticSet.”

Individual diagnostics obtained from the set DO need disposal via clang_disposeDiagnostic, which is handled by the Diagnostic AutoPointer. Diagnostics are cached on construction so that repeated iteration does not create duplicate AutoPointers that would double-free.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer, translation_unit) ⇒ DiagnosticSet

Initialize a diagnostic set from a CXDiagnosticSet pointer.



32
33
34
35
36
37
# File 'lib/ffi/clang/diagnostic_set.rb', line 32

def initialize(pointer, translation_unit)
	@size = Lib.get_num_diagnostics_in_set(pointer)
	@diagnostics = @size.times.map do |i|
		Diagnostic.new(translation_unit, Lib.get_diagnostic_in_set(pointer, i))
	end
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



27
28
29
# File 'lib/ffi/clang/diagnostic_set.rb', line 27

def size
  @size
end

Instance Method Details

#each(&block) ⇒ Object

Iterate over each diagnostic.



43
44
45
46
47
48
49
# File 'lib/ffi/clang/diagnostic_set.rb', line 43

def each(&block)
	return to_enum(__method__) unless block_given?
	
	@diagnostics.each(&block)
	
	self
end