Class: FFI::Clang::IndexAction

Inherits:
AutoPointer
  • Object
show all
Includes:
InvocationSupport
Defined in:
lib/ffi/clang/index_action.rb

Overview

Represents a reusable libclang indexing session.

Defined Under Namespace

Classes: CallbackAdapter, Container, Declaration, Diagnostic, Entity, EntityReference, ImportedASTFile, IncludedFile

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ IndexAction

Initialize an index action for the given index.



270
271
272
273
# File 'lib/ffi/clang/index_action.rb', line 270

def initialize(index)
	super Lib.create_index_action(index)
	@index = index
end

Class Method Details

.release(pointer) ⇒ Object

Release the underlying index action pointer.



277
278
279
# File 'lib/ffi/clang/index_action.rb', line 277

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

Instance Method Details

#index_source_file(source_file, command_line_args = nil, unsaved = [], index_opts = [], translation_unit_opts = [], &block) ⇒ Object

Index a source file and yield indexing events. Event payloads:

  • ‘:diagnostic` => `Array(Diagnostic)`

  • ‘:entered_main_file` => `FFI::Clang::File`

  • ‘:included_file` => `IncludedFile`

  • ‘:imported_ast_file` => `ImportedASTFile`

  • ‘:started_translation_unit` => `nil`

  • ‘:declaration` => `Declaration`

  • ‘:reference` => `EntityReference`

If the block returns ‘:abort`, libclang stops the next time it polls `abortQuery`, so a few more callbacks may be delivered before control returns.



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/ffi/clang/index_action.rb', line 303

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?
	
	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_out = MemoryPointer.new(:pointer)
	adapter = CallbackAdapter.new(nil, &block)
	
	error_code = Lib.index_source_file(
		self,
		nil,
		adapter.callbacks,
		adapter.callbacks.size,
		index_options_bitmask_from(index_opts),
		source_file,
		args_pointer,
		command_line_args.length,
		unsaved_files,
		unsaved.length,
		translation_unit_pointer_out,
		translation_unit_options_bitmask_from(translation_unit_opts)
	)
	
	return nil if adapter.aborted?
	
	translation_unit_from_indexing_result(error_code, source_file, translation_unit_pointer_out)
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 including argv. Event payloads:

  • ‘:diagnostic` => `Array(Diagnostic)`

  • ‘:entered_main_file` => `FFI::Clang::File`

  • ‘:included_file` => `IncludedFile`

  • ‘:imported_ast_file` => `ImportedASTFile`

  • ‘:started_translation_unit` => `nil`

  • ‘:declaration` => `Declaration`

  • ‘:reference` => `EntityReference`

If the block returns ‘:abort`, libclang stops the next time it polls `abortQuery`, so a few more callbacks may be delivered before control returns.



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/ffi/clang/index_action.rb', line 354

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?
	
	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_out = MemoryPointer.new(:pointer)
	adapter = CallbackAdapter.new(nil, &block)
	
	error_code = Lib.index_source_file_full_argv(
		self,
		nil,
		adapter.callbacks,
		adapter.callbacks.size,
		index_options_bitmask_from(index_opts),
		source_file,
		args_pointer,
		command_line_args.length,
		unsaved_files,
		unsaved.length,
		translation_unit_pointer_out,
		translation_unit_options_bitmask_from(translation_unit_opts)
	)
	
	return nil if adapter.aborted?
	
	translation_unit_from_indexing_result(error_code, source_file, translation_unit_pointer_out)
end

#index_translation_unit(translation_unit, index_opts = [], &block) ⇒ Object

Index an existing translation unit and yield indexing events. Event payloads:

  • ‘:diagnostic` => `Array(Diagnostic)`

  • ‘:entered_main_file` => `FFI::Clang::File`

  • ‘:included_file` => `IncludedFile`

  • ‘:imported_ast_file` => `ImportedASTFile`

  • ‘:started_translation_unit` => `nil`

  • ‘:declaration` => `Declaration`

  • ‘:reference` => `EntityReference`

If the block returns ‘:abort`, libclang stops the next time it polls `abortQuery`, so a few more callbacks may be delivered before control returns.



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/ffi/clang/index_action.rb', line 402

def index_translation_unit(translation_unit, index_opts = [], &block)
	return to_enum(__method__, translation_unit, index_opts) unless block_given?
	
	adapter = CallbackAdapter.new(translation_unit, &block)
	error_code = Lib.index_translation_unit(
		self,
		nil,
		adapter.callbacks,
		adapter.callbacks.size,
		index_options_bitmask_from(index_opts),
		translation_unit
	)
	
	return nil if adapter.aborted?
	
	raise_indexing_error(error_code, translation_unit.spelling) unless error_code == :cx_error_success
	
	translation_unit
end