FFI::ClangSourceFFIClangDiagnostic

class Diagnostic

Represents a diagnostic message from the compiler.

Definitions

def self.default_display_opts

Get the default diagnostic display options.

Signature

returns Array(Symbol)

The default display options.

Implementation

def self.default_display_opts
	Lib.opts_from(Lib::DiagnosticDisplayOptions, Lib.default_diagnostic_display_options)
end

def initialize(translation_unit, pointer)

Initialize a diagnostic.

Signature

parameter translation_unit TranslationUnit

The parent translation unit.

parameter pointer FFI::Pointer

The diagnostic pointer.

Implementation

def initialize(translation_unit, pointer)
	super pointer
	
	@translation_unit = translation_unit
end

def self.release(pointer)

Release the diagnostic pointer.

Signature

parameter pointer FFI::Pointer

The pointer to release.

Implementation

def self.release(pointer)
	Lib.dispose_diagnostic(pointer)
end

def format(opts = {})

Format the diagnostic as a string.

Signature

parameter opts Hash

Display options.

returns String

The formatted diagnostic.

Implementation

def format(opts = {})
	cxstring = Lib.format_diagnostic(self, display_opts(opts))
	Lib.extract_string cxstring
end

def severity

Get the severity of the diagnostic.

Signature

returns Symbol

The severity level.

Implementation

def severity
	Lib.get_diagnostic_severity self
end

def spelling

Get the diagnostic message text.

Signature

returns String

The diagnostic spelling.

Implementation

def spelling
	Lib.get_string Lib.get_diagnostic_spelling(self)
end

def location

Get the source location of the diagnostic.

Signature

returns ExpansionLocation

The diagnostic location.

Implementation

def location
	sl = Lib.get_diagnostic_location(self)
	ExpansionLocation.new sl
end

def fixits

Get fix-it hints for the diagnostic.

Signature

returns Array(Hash)

Array of fix-its with :text and :range keys.

Implementation

def fixits
	n = Lib.get_diagnostic_num_fix_its(self)
	n.times.map {|i|
		ptr = MemoryPointer.new Lib::CXSourceRange
		replace_text = Lib.extract_string(Lib.get_diagnostic_fix_it(self, i, ptr))
		{text: replace_text, range: SourceRange.new(ptr)}
	}
end

def ranges

Get the source ranges associated with the diagnostic.

Signature

returns Array(SourceRange)

Array of source ranges.

Implementation

def ranges
	n = Lib.get_diagnostic_num_ranges(self)
	
	n.times.map {|i| SourceRange.new Lib.get_diagnostic_range(self, i)}
end

def children

Get child diagnostics.

Signature

returns Array(Diagnostic)

Array of child diagnostics.

Implementation

def children
	diagnostic_set = Lib.get_child_diagnostics(self)
	num_diagnostics = Lib.get_num_diagnostics_in_set(diagnostic_set)
	num_diagnostics.times.map {|i|
		Diagnostic.new(@translation_unit, Lib.get_diagnostic_in_set(diagnostic_set, i))
	}
end

def enable_option

Get the compiler option that enables this diagnostic.

Signature

returns String

The enable option.

Implementation

def enable_option
	Lib.extract_string Lib.get_diagnostic_option(self, nil)
end

def disable_option

Get the compiler option that disables this diagnostic.

Signature

returns String

The disable option.

Implementation

def disable_option
	ptr = MemoryPointer.new Lib::CXString
	Lib.get_diagnostic_option(self, ptr)
	Lib.extract_string ptr
end

def category

Get the category text for the diagnostic.

Signature

returns String

The category text.

Implementation

def category
	Lib.extract_string Lib.get_diagnostic_category_text(self)
end

def category_id

Get the category ID for the diagnostic.

Signature

returns Integer

The category ID.

Implementation

def category_id
	Lib.get_diagnostic_category(self)
end

def inspect

Get a string representation of the diagnostic.

Signature

returns String

The diagnostic string.

Implementation

def inspect
	"#{self.location}: #{self.format}"
end

def display_opts(opts)

  • private

Signature

private

Implementation

def display_opts(opts)
	if opts.empty?
		Lib.default_diagnostic_display_options
	else
		Lib.bitmask_from(Lib::DiagnosticDisplayOptions, opts)
	end
end