Class: FFI::Clang::Diagnostic

Inherits:
AutoPointer
  • Object
show all
Defined in:
lib/ffi/clang/diagnostic.rb

Overview

Represents a diagnostic message from the compiler.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(translation_unit, pointer) ⇒ Diagnostic

Initialize a diagnostic.



27
28
29
30
31
# File 'lib/ffi/clang/diagnostic.rb', line 27

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

Class Method Details

.default_display_optsObject

Get the default diagnostic display options.



20
21
22
# File 'lib/ffi/clang/diagnostic.rb', line 20

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

.release(pointer) ⇒ Object

Release the diagnostic pointer.



35
36
37
# File 'lib/ffi/clang/diagnostic.rb', line 35

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

Instance Method Details

#categoryObject

Get the category text for the diagnostic.



107
108
109
# File 'lib/ffi/clang/diagnostic.rb', line 107

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

#category_idObject

Get the category ID for the diagnostic.



113
114
115
# File 'lib/ffi/clang/diagnostic.rb', line 113

def category_id
	Lib.get_diagnostic_category(self)
end

#childrenObject

Get child diagnostics.



87
88
89
# File 'lib/ffi/clang/diagnostic.rb', line 87

def children
	@children ||= DiagnosticSet.new(Lib.get_child_diagnostics(self), @translation_unit)
end

#disable_optionObject

Get the compiler option that disables this diagnostic.



99
100
101
102
103
# File 'lib/ffi/clang/diagnostic.rb', line 99

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

#enable_optionObject

Get the compiler option that enables this diagnostic.



93
94
95
# File 'lib/ffi/clang/diagnostic.rb', line 93

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

#fixitsObject

Get fix-it hints for the diagnostic.



68
69
70
71
72
73
74
75
# File 'lib/ffi/clang/diagnostic.rb', line 68

def fixits
	n = Lib.get_diagnostic_num_fix_its(self)
	n.times.map do |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
end

#format(opts = {}) ⇒ Object

Format the diagnostic as a string.



42
43
44
45
# File 'lib/ffi/clang/diagnostic.rb', line 42

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

#inspectObject

Get a string representation of the diagnostic.



119
120
121
# File 'lib/ffi/clang/diagnostic.rb', line 119

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

#locationObject

Get the source location of the diagnostic.



61
62
63
64
# File 'lib/ffi/clang/diagnostic.rb', line 61

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

#rangesObject

Get the source ranges associated with the diagnostic.



79
80
81
82
83
# File 'lib/ffi/clang/diagnostic.rb', line 79

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

#severityObject

Get the severity of the diagnostic.



49
50
51
# File 'lib/ffi/clang/diagnostic.rb', line 49

def severity
	Lib.get_diagnostic_severity self
end

#spellingObject

Get the diagnostic message text.



55
56
57
# File 'lib/ffi/clang/diagnostic.rb', line 55

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