Class: FFI::Clang::Index
- Inherits:
-
AutoPointer
- Object
- AutoPointer
- FFI::Clang::Index
- 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_translation_unit(ast_filename) ⇒ Object
Create a translation unit from a precompiled AST file.
-
#initialize(exclude_declarations = true, display_diagnostics = false) ⇒ Index
constructor
Initialize a new index for managing translation units.
-
#parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) ⇒ Object
Parse a source file and create a translation unit.
Constructor Details
#initialize(exclude_declarations = true, display_diagnostics = false) ⇒ Index
Initialize a new index for managing translation units.
23 24 25 |
# File 'lib/ffi/clang/index.rb', line 23 def initialize(exclude_declarations = true, display_diagnostics = false) super Lib.create_index(exclude_declarations ? 1 : 0, display_diagnostics ? 1 : 0) end |
Class Method Details
.release(pointer) ⇒ Object
Release the index pointer.
29 30 31 |
# File 'lib/ffi/clang/index.rb', line 29 def self.release(pointer) Lib.dispose_index(pointer) end |
Instance Method Details
#create_translation_unit(ast_filename) ⇒ Object
Create a translation unit from a precompiled AST file.
61 62 63 64 65 |
# File 'lib/ffi/clang/index.rb', line 61 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 |
#parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) ⇒ Object
Parse a source file and create a translation unit.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ffi/clang/index.rb', line 40 def parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) command_line_args = Array(command_line_args) unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved) translation_unit_pointer_out = FFI::MemoryPointer.new(:pointer) error_code = Lib.parse_translation_unit2(self, source_file, args_pointer_from(command_line_args), command_line_args.size, unsaved_files, unsaved.length, (opts), translation_unit_pointer_out) if error_code != :cx_error_success error_name = Lib::ErrorCodes.from_native(error_code, nil) = "Error parsing file. Code: #{error_name}. File: #{source_file.inspect}" raise(Error, ) end translation_unit_pointer = translation_unit_pointer_out.read_pointer TranslationUnit.new translation_unit_pointer, self end |