Class: FFI::Clang::Index
- Inherits:
-
AutoPointer
- Object
- AutoPointer
- FFI::Clang::Index
- Includes:
- InvocationSupport
- Defined in:
- lib/ffi/clang/index.rb
Overview
Represents a libclang index that manages translation units and provides a top-level context for parsing.
Class Method Summary collapse
-
.release(pointer) ⇒ Object
Release the index pointer.
Instance Method Summary collapse
-
#create_action ⇒ Object
Create a reusable indexing action for this index.
-
#create_translation_unit(ast_filename) ⇒ Object
Create a translation unit from a precompiled AST file.
-
#create_translation_unit2(ast_filename) ⇒ Object
Create a translation unit from a precompiled AST file with detailed error reporting.
-
#create_translation_unit_from_source_file(source_file, command_line_args = nil, unsaved = []) ⇒ Object
Create a translation unit directly from source and compiler arguments.
-
#global_options ⇒ Object
Get the global index options.
-
#global_options=(options) ⇒ Object
Set the global index options.
-
#index_source_file(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) ⇒ Object
Index a source file using a temporary index action.
-
#index_source_file_with_invocation(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) ⇒ Object
Index a source file using a full compiler command line and a temporary index action.
-
#index_translation_unit(translation_unit, index_opts = [], &block) ⇒ Object
Index an existing translation unit using a temporary index action.
-
#initialize(exclude_declarations_from_pch: true, display_diagnostics: false, store_preambles_in_memory: false, thread_background_priority_for_indexing: :default, thread_background_priority_for_editing: :default, preamble_storage_path: nil, invocation_emission_path: nil) ⇒ Index
constructor
Initialize a new index for managing translation units.
-
#invocation_emission_path=(path) ⇒ Object
Set the invocation emission path for this index.
-
#parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) ⇒ Object
Parse a source file and create a translation unit.
-
#parse_translation_unit_with_invocation(source_file, command_line_args = nil, unsaved = [], opts = {}) ⇒ Object
Parse a source file using a full compiler command line including argv.
Constructor Details
#initialize(exclude_declarations_from_pch: true, display_diagnostics: false, store_preambles_in_memory: false, thread_background_priority_for_indexing: :default, thread_background_priority_for_editing: :default, preamble_storage_path: nil, invocation_emission_path: nil) ⇒ Index
Initialize a new index for managing translation units.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ffi/clang/index.rb', line 32 def initialize( exclude_declarations_from_pch: true, display_diagnostics: false, store_preambles_in_memory: false, thread_background_priority_for_indexing: :default, thread_background_priority_for_editing: :default, preamble_storage_path: nil, invocation_emission_path: nil ) pointer = create_index_pointer(exclude_declarations_from_pch:, display_diagnostics:, store_preambles_in_memory:, thread_background_priority_for_indexing:, thread_background_priority_for_editing:, preamble_storage_path:, invocation_emission_path:) super pointer end |
Class Method Details
.release(pointer) ⇒ Object
Release the index pointer.
47 48 49 |
# File 'lib/ffi/clang/index.rb', line 47 def self.release(pointer) Lib.dispose_index(pointer) end |
Instance Method Details
#create_action ⇒ Object
Create a reusable indexing action for this index.
130 131 132 |
# File 'lib/ffi/clang/index.rb', line 130 def create_action IndexAction.new(self) end |
#create_translation_unit(ast_filename) ⇒ Object
Create a translation unit from a precompiled AST file.
95 96 97 98 99 |
# File 'lib/ffi/clang/index.rb', line 95 def create_translation_unit(ast_filename) translation_unit_pointer = Lib.create_translation_unit(self, ast_filename) raise Error, "error parsing #{ast_filename.inspect}" if translation_unit_pointer.null? TranslationUnit.new translation_unit_pointer, self end |
#create_translation_unit2(ast_filename) ⇒ Object
Create a translation unit from a precompiled AST file with detailed error reporting.
105 106 107 108 109 |
# File 'lib/ffi/clang/index.rb', line 105 def create_translation_unit2(ast_filename) translation_unit_pointer_out = MemoryPointer.new(:pointer) error_code = Lib.create_translation_unit2(self, ast_filename, translation_unit_pointer_out) translation_unit_from_error_code(error_code, ast_filename, translation_unit_pointer_out) end |
#create_translation_unit_from_source_file(source_file, command_line_args = nil, unsaved = []) ⇒ Object
Create a translation unit directly from source and compiler arguments.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ffi/clang/index.rb', line 117 def create_translation_unit_from_source_file(source_file, command_line_args = nil, unsaved = []) command_line_args = normalized_command_line_args(command_line_args) args_pointer, _strings = args_pointer_from(command_line_args) unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved) translation_unit_pointer = Lib.create_translation_unit_from_source_file(self, source_file, command_line_args.length, args_pointer, unsaved.length, unsaved_files) raise Error, "error parsing #{source_file.inspect}" if translation_unit_pointer.null? TranslationUnit.new translation_unit_pointer, self end |
#global_options ⇒ Object
Get the global index options.
53 54 55 |
# File 'lib/ffi/clang/index.rb', line 53 def Lib.opts_from(Lib::GlobalOptFlags, Lib.(self)) end |
#global_options=(options) ⇒ Object
Set the global index options.
59 60 61 |
# File 'lib/ffi/clang/index.rb', line 59 def () Lib.(self, Lib.bitmask_from(Lib::GlobalOptFlags, )) end |
#index_source_file(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) ⇒ Object
Index a source file using a temporary index action.
145 146 147 148 149 |
# File 'lib/ffi/clang/index.rb', line 145 def index_source_file(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) return to_enum(__method__, source_file, command_line_args, unsaved, index_opts, translation_unit_opts) unless block_given? create_action.index_source_file(source_file, command_line_args, unsaved, index_opts, translation_unit_opts, &block) end |
#index_source_file_with_invocation(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) ⇒ Object
Index a source file using a full compiler command line and a temporary index action.
162 163 164 165 166 |
# File 'lib/ffi/clang/index.rb', line 162 def index_source_file_with_invocation(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) return to_enum(__method__, source_file, command_line_args, unsaved, index_opts, translation_unit_opts) unless block_given? create_action.index_source_file_with_invocation(source_file, command_line_args, unsaved, index_opts, translation_unit_opts, &block) end |
#index_translation_unit(translation_unit, index_opts = [], &block) ⇒ Object
Index an existing translation unit using a temporary index action.
176 177 178 179 180 |
# File 'lib/ffi/clang/index.rb', line 176 def index_translation_unit(translation_unit, index_opts = [], &block) return to_enum(__method__, translation_unit, index_opts) unless block_given? create_action.index_translation_unit(translation_unit, index_opts, &block) end |
#invocation_emission_path=(path) ⇒ Object
Set the invocation emission path for this index.
65 66 67 |
# File 'lib/ffi/clang/index.rb', line 65 def invocation_emission_path=(path) Lib.set_invocation_emission_path_option(self, path) end |
#parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) ⇒ Object
Parse a source file and create a translation unit.
76 77 78 |
# File 'lib/ffi/clang/index.rb', line 76 def parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) parse_translation_unit_with(:parse_translation_unit2, source_file, command_line_args, unsaved, opts) end |
#parse_translation_unit_with_invocation(source_file, command_line_args = nil, unsaved = [], opts = {}) ⇒ Object
Parse a source file using a full compiler command line including argv.
87 88 89 |
# File 'lib/ffi/clang/index.rb', line 87 def parse_translation_unit_with_invocation(source_file, command_line_args = nil, unsaved = [], opts = {}) parse_translation_unit_with(:parse_translation_unit2_full_argv, source_file, command_line_args, unsaved, opts) end |