Class: FFI::Clang::TranslationUnit
- Inherits:
-
AutoPointer
- Object
- AutoPointer
- FFI::Clang::TranslationUnit
- Defined in:
- lib/ffi/clang/translation_unit.rb
Overview
Represents a single translation unit (a compiled source file with its dependencies).
Defined Under Namespace
Classes: ResourceUsage
Class Method Summary collapse
-
.default_editing_translation_unit_options ⇒ Object
Get the default editing translation unit options.
-
.release(pointer) ⇒ Object
Release the translation unit pointer.
Instance Method Summary collapse
-
#all_skipped_ranges ⇒ Object
Get all skipped preprocessor ranges in this translation unit.
-
#code_complete(source_file, line, column, unsaved = [], opts = nil) ⇒ Object
Perform code completion at a specific location.
-
#cursor(location = nil) ⇒ Object
Get a cursor for the translation unit or at a specific location.
-
#default_reparse_options ⇒ Object
Get the default reparse options for this translation unit.
-
#default_save_options ⇒ Object
Get the default save options for this translation unit.
-
#diagnostics ⇒ Object
Get all diagnostics for this translation unit.
-
#file(file_name = nil) ⇒ Object
Get a file object from this translation unit.
-
#inclusions(&block) ⇒ Object
Iterate over all file inclusions in this translation unit.
-
#initialize(pointer, index) ⇒ TranslationUnit
constructor
Initialize a translation unit with a pointer and parent index.
-
#location(file, line, column) ⇒ Object
Get a source location by file, line, and column.
-
#location_offset(file, offset) ⇒ Object
Get a source location by file and byte offset.
-
#reparse(unsaved = [], opts = nil) ⇒ Object
Reparse the translation unit with updated file contents.
-
#resource_usage ⇒ Object
Get resource usage information for this translation unit.
-
#save(filename, opts = nil) ⇒ Object
Save the translation unit to a file.
-
#skipped_ranges(file) ⇒ Object
Get skipped preprocessor ranges for a file in this translation unit.
-
#spelling ⇒ Object
Get the spelling (filename) of this translation unit.
-
#suspend ⇒ Object
Suspend this translation unit to free memory.
-
#target_pointer_width ⇒ Object
Get the pointer width for the target of this translation unit.
-
#target_triple ⇒ Object
Get the target triple for this translation unit.
-
#tokenize(range) ⇒ Object
Tokenize a source range.
Constructor Details
#initialize(pointer, index) ⇒ TranslationUnit
Initialize a translation unit with a pointer and parent index.
28 29 30 31 |
# File 'lib/ffi/clang/translation_unit.rb', line 28 def initialize(pointer, index) super pointer @index = index end |
Class Method Details
.default_editing_translation_unit_options ⇒ Object
Get the default editing translation unit options.
41 42 43 44 |
# File 'lib/ffi/clang/translation_unit.rb', line 41 def self. bitmask = Lib. Lib.opts_from Lib::TranslationUnitFlags, bitmask end |
.release(pointer) ⇒ Object
Release the translation unit pointer.
35 36 37 |
# File 'lib/ffi/clang/translation_unit.rb', line 35 def self.release(pointer) Lib.dispose_translation_unit(pointer) end |
Instance Method Details
#all_skipped_ranges ⇒ Object
Get all skipped preprocessor ranges in this translation unit.
154 155 156 |
# File 'lib/ffi/clang/translation_unit.rb', line 154 def all_skipped_ranges SourceRange.from_source_range_list(Lib.get_all_skipped_ranges(self)) end |
#code_complete(source_file, line, column, unsaved = [], opts = nil) ⇒ Object
Perform code completion at a specific location.
187 188 189 190 191 192 193 |
# File 'lib/ffi/clang/translation_unit.rb', line 187 def code_complete(source_file, line, column, unsaved = [], opts = nil) opts = CodeCompletion. if opts.nil? unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved) option_bitmask = Lib.bitmask_from(Lib::CodeCompleteFlags, opts) ptr = Lib.code_complete_at(self, source_file, line, column, unsaved_files, unsaved.length, option_bitmask) CodeCompletion::Results.new ptr, self end |
#cursor(location = nil) ⇒ Object
Get a cursor for the translation unit or at a specific location.
109 110 111 112 113 114 115 |
# File 'lib/ffi/clang/translation_unit.rb', line 109 def cursor(location = nil) if location.nil? Cursor.new Lib.get_translation_unit_cursor(self), self else Cursor.new Lib.get_cursor(self, location.location), self end end |
#default_reparse_options ⇒ Object
Get the default reparse options for this translation unit.
73 74 75 76 |
# File 'lib/ffi/clang/translation_unit.rb', line 73 def bitmask = Lib.(self) Lib.opts_from Lib::ReparseFlags, bitmask end |
#default_save_options ⇒ Object
Get the default save options for this translation unit.
48 49 50 51 |
# File 'lib/ffi/clang/translation_unit.rb', line 48 def bitmask = Lib.(self) Lib.opts_from Lib::SaveTranslationUnitFlags, bitmask end |
#diagnostics ⇒ Object
Get all diagnostics for this translation unit.
98 99 100 101 102 103 104 |
# File 'lib/ffi/clang/translation_unit.rb', line 98 def diagnostics n = Lib.get_num_diagnostics(self) n.times.map do |i| Diagnostic.new(self, Lib.get_diagnostic(self, i)) end end |
#file(file_name = nil) ⇒ Object
Get a file object from this translation unit.
137 138 139 140 141 142 143 |
# File 'lib/ffi/clang/translation_unit.rb', line 137 def file(file_name = nil) if file_name.nil? File.new(Lib.get_file(self, spelling), self) else File.new(Lib.get_file(self, file_name), self) end end |
#inclusions(&block) ⇒ Object
Iterate over all file inclusions in this translation unit.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/ffi/clang/translation_unit.rb', line 199 def inclusions(&block) adapter = Proc.new do |included_file, inclusion_stack, include_len, unused| file = Lib.extract_string Lib.get_file_name(included_file) cur_ptr = inclusion_stack inclusions = [] include_len.times do inclusions << SourceLocation.new(Lib::CXSourceLocation.new(cur_ptr)) cur_ptr += Lib::CXSourceLocation.size end block.call file, inclusions end Lib.get_inclusions(self, adapter, nil) end |
#location(file, line, column) ⇒ Object
Get a source location by file, line, and column.
122 123 124 |
# File 'lib/ffi/clang/translation_unit.rb', line 122 def location(file, line, column) ExpansionLocation.new Lib.get_location(self, file, line, column) end |
#location_offset(file, offset) ⇒ Object
Get a source location by file and byte offset.
130 131 132 |
# File 'lib/ffi/clang/translation_unit.rb', line 130 def location_offset(file, offset) ExpansionLocation.new Lib.get_location_offset(self, file, offset) end |
#reparse(unsaved = [], opts = nil) ⇒ Object
Reparse the translation unit with updated file contents.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ffi/clang/translation_unit.rb', line 82 def reparse(unsaved = [], opts = nil) unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved) option_bitmask = if opts.nil? Lib.(self) else Lib.bitmask_from(Lib::ReparseFlags, opts) end if Lib.reparse_translation_unit(self, unsaved.size, unsaved_files, option_bitmask) != 0 raise Error, "reparse error" end end |
#resource_usage ⇒ Object
Get resource usage information for this translation unit.
166 167 168 |
# File 'lib/ffi/clang/translation_unit.rb', line 166 def resource_usage FFI::Clang::TranslationUnit::ResourceUsage.new Lib.resource_usage(self) end |
#save(filename, opts = nil) ⇒ Object
Save the translation unit to a file.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ffi/clang/translation_unit.rb', line 57 def save(filename, opts = nil) option_bitmask = if opts.nil? Lib.(self) else Lib.bitmask_from(Lib::SaveTranslationUnitFlags, opts) end ret = Lib.save_translation_unit(self, filename, option_bitmask) sym = Lib::SaveError[ret] raise Error, "unknown return values: #{ret} #{sym.inspect}" unless sym raise Error, "save error: #{sym.inspect}, filename: #{filename}" if sym != :none end |
#skipped_ranges(file) ⇒ Object
Get skipped preprocessor ranges for a file in this translation unit.
148 149 150 |
# File 'lib/ffi/clang/translation_unit.rb', line 148 def skipped_ranges(file) SourceRange.from_source_range_list(Lib.get_skipped_ranges(self, file)) end |
#spelling ⇒ Object
Get the spelling (filename) of this translation unit.
160 161 162 |
# File 'lib/ffi/clang/translation_unit.rb', line 160 def spelling Lib.extract_string Lib.get_translation_unit_spelling(self) end |
#suspend ⇒ Object
Suspend this translation unit to free memory.
234 235 236 |
# File 'lib/ffi/clang/translation_unit.rb', line 234 def suspend Lib.suspend_translation_unit(self) != 0 end |
#target_pointer_width ⇒ Object
Get the pointer width for the target of this translation unit.
225 226 227 228 229 230 |
# File 'lib/ffi/clang/translation_unit.rb', line 225 def target_pointer_width target_info = Lib.get_translation_unit_target_info(self) width = Lib.target_info_get_pointer_width(target_info) Lib.target_info_dispose(target_info) width end |
#target_triple ⇒ Object
Get the target triple for this translation unit.
216 217 218 219 220 221 |
# File 'lib/ffi/clang/translation_unit.rb', line 216 def target_triple target_info = Lib.get_translation_unit_target_info(self) triple = Lib.extract_string Lib.target_info_get_triple(target_info) Lib.target_info_dispose(target_info) triple end |
#tokenize(range) ⇒ Object
Tokenize a source range.
173 174 175 176 177 178 |
# File 'lib/ffi/clang/translation_unit.rb', line 173 def tokenize(range) token_ptr = MemoryPointer.new :pointer uint_ptr = MemoryPointer.new :uint Lib.tokenize(self, range.range, token_ptr, uint_ptr) Tokens.new(token_ptr.get_pointer(0), uint_ptr.get_uint(0), self) end |