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.



111
112
113
# File 'lib/ffi/clang/diagnostic.rb', line 111

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

#category_idObject

Get the category ID for the diagnostic.



117
118
119
# File 'lib/ffi/clang/diagnostic.rb', line 117

def category_id
  Lib.get_diagnostic_category(self)
end

#childrenObject

Get child diagnostics.



87
88
89
90
91
92
93
# File 'lib/ffi/clang/diagnostic.rb', line 87

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

#disable_optionObject

Get the compiler option that disables this diagnostic.



103
104
105
106
107
# File 'lib/ffi/clang/diagnostic.rb', line 103

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.



97
98
99
# File 'lib/ffi/clang/diagnostic.rb', line 97

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 {|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

#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.



123
124
125
# File 'lib/ffi/clang/diagnostic.rb', line 123

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.get_string Lib.get_diagnostic_spelling(self)
end