Class: FFI::Clang::Cursor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ffi/clang/cursor.rb

Defined Under Namespace

Classes: PlatformAvailability

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cxcursor, translation_unit) ⇒ Cursor

Returns a new instance of Cursor.



41
42
43
44
# File 'lib/ffi/clang/cursor.rb', line 41

def initialize(cxcursor, translation_unit)
	@cursor = cxcursor
	@translation_unit = translation_unit
end

Instance Attribute Details

#cursorObject (readonly)

Returns the value of attribute cursor.



29
30
31
# File 'lib/ffi/clang/cursor.rb', line 29

def cursor
  @cursor
end

#translation_unitObject (readonly)

Returns the value of attribute translation_unit.



30
31
32
# File 'lib/ffi/clang/cursor.rb', line 30

def translation_unit
  @translation_unit
end

Class Method Details

.kind_spelling(kind) ⇒ Object

this function is categorized as “Debugging facilities”



37
38
39
# File 'lib/ffi/clang/cursor.rb', line 37

def self.kind_spelling(kind)
	Lib.extract_string Lib.get_cursor_kind_spelling(kind)
end

.null_cursorObject



32
33
34
# File 'lib/ffi/clang/cursor.rb', line 32

def self.null_cursor
	Cursor.new Lib.get_null_cursor, nil
end

Instance Method Details

#abstract?Boolean

Returns:

  • (Boolean)


488
489
490
# File 'lib/ffi/clang/cursor.rb', line 488

def abstract?
	Lib.is_abstract(@cursor) != 0
end

#access_specifierObject



269
270
271
# File 'lib/ffi/clang/cursor.rb', line 269

def access_specifier
	Lib.get_cxx_access_specifier @cursor
end

#ancestors_by_kind(*kinds) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/ffi/clang/cursor.rb', line 301

def ancestors_by_kind(*kinds)
  result = Array.new

  parent = self
  while parent != self.semantic_parent
    parent = self.semantic_parent
    if kinds.include?(parent.kind)
      result << parent
    end
  end
  result
end

#anonymous?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ffi/clang/cursor.rb', line 66

def anonymous?
	Lib.cursor_is_anonymous(@cursor) != 0
end

#anonymous_record_declaration?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/ffi/clang/cursor.rb', line 70

def anonymous_record_declaration?
	Lib.cursor_is_anonymous_record_decl(@cursor) != 0
end

#argument(i) ⇒ Object



418
419
420
# File 'lib/ffi/clang/cursor.rb', line 418

def argument(i)
	Cursor.new Lib.cursor_get_argument(@cursor, i), @translation_unit
end

#attribute?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/ffi/clang/cursor.rb', line 90

def attribute?
	Lib.is_attribute(kind) != 0
end

#availabilityObject



344
345
346
# File 'lib/ffi/clang/cursor.rb', line 344

def availability
	Lib.get_cursor_availability(@cursor)
end

#bitfield?Boolean

Returns:

  • (Boolean)


398
399
400
# File 'lib/ffi/clang/cursor.rb', line 398

def bitfield?
	Lib.is_bit_field(@cursor) != 0
end

#bitwidthObject



402
403
404
# File 'lib/ffi/clang/cursor.rb', line 402

def bitwidth
	Lib.get_field_decl_bit_width(@cursor)
end

#canonicalObject



230
231
232
# File 'lib/ffi/clang/cursor.rb', line 230

def canonical
	Cursor.new Lib.get_canonical_cursor(@cursor), @translation_unit
end

#commentObject



54
55
56
# File 'lib/ffi/clang/cursor.rb', line 54

def comment
	Comment.build_from Lib.cursor_get_parsed_comment(@cursor)
end

#comment_rangeObject



58
59
60
# File 'lib/ffi/clang/cursor.rb', line 58

def comment_range
	SourceRange.new(Lib.cursor_get_comment_range(@cursor))
end

#completionObject



62
63
64
# File 'lib/ffi/clang/cursor.rb', line 62

def completion
	CodeCompletion::String.new Lib.get_cursor_completion_string(@cursor)
end

#const?Boolean

Returns:

  • (Boolean)


496
497
498
# File 'lib/ffi/clang/cursor.rb', line 496

def const?
	Lib.is_const(@cursor) != 0
end

#converting_constructor?Boolean

Returns:

  • (Boolean)


448
449
450
# File 'lib/ffi/clang/cursor.rb', line 448

def converting_constructor?
	Lib.is_converting_constructor(@cursor) != 0
end

#copy_assignment_operator?Boolean

Returns:

  • (Boolean)


476
477
478
# File 'lib/ffi/clang/cursor.rb', line 476

def copy_assignment_operator?
	Lib.is_copy_assignment_operator(@cursor) != 0
end

#copy_constructor?Boolean

Returns:

  • (Boolean)


452
453
454
# File 'lib/ffi/clang/cursor.rb', line 452

def copy_constructor?
	Lib.is_copy_constructor(@cursor) != 0
end

#declaration?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/ffi/clang/cursor.rb', line 74

def declaration?
	Lib.is_declaration(kind) != 0
end

#default_constructor?Boolean

Returns:

  • (Boolean)


456
457
458
# File 'lib/ffi/clang/cursor.rb', line 456

def default_constructor?
	Lib.is_default_constructor(@cursor) != 0
end

#defaulted?Boolean

Returns:

  • (Boolean)


468
469
470
# File 'lib/ffi/clang/cursor.rb', line 468

def defaulted?
	Lib.is_defaulted(@cursor) != 0
end

#definitionObject



234
235
236
# File 'lib/ffi/clang/cursor.rb', line 234

def definition
	Cursor.new Lib.get_cursor_definition(@cursor), @translation_unit
end

#definition?Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/ffi/clang/cursor.rb', line 198

def definition?
	Lib.is_definition(@cursor) != 0
end

#deleted?Boolean

Returns:

  • (Boolean)


472
473
474
# File 'lib/ffi/clang/cursor.rb', line 472

def deleted?
	Lib.is_deleted(@cursor) != 0
end

#display_nameObject



143
144
145
# File 'lib/ffi/clang/cursor.rb', line 143

def display_name
	Lib.extract_string Lib.get_cursor_display_name(@cursor)
end

#dynamic_call?Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/ffi/clang/cursor.rb', line 190

def dynamic_call?
	Lib.is_dynamic_call(@cursor) != 0
end

#each(recurse = true, &block) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/ffi/clang/cursor.rb', line 281

def each(recurse = true, &block)
	return to_enum(:each, recurse) unless block_given?

	adapter = Proc.new do |cxcursor, parent_cursor, unused|
		# Call the block and capture the result. This lets advanced users
		# modify the recursion on a case by case basis if needed
		result = block.call Cursor.new(cxcursor, @translation_unit), Cursor.new(parent_cursor, @translation_unit)
		case result
			when :continue
				:continue
			when :recurse
				:recurse
			else
				recurse ? :recurse : :continue
		end
	end

	Lib.visit_children(@cursor, adapter, nil)
end

#enum_scoped?Boolean

Returns:

  • (Boolean)


492
493
494
# File 'lib/ffi/clang/cursor.rb', line 492

def enum_scoped?
	Lib.is_enum_scoped(@cursor) != 0
end

#enum_typeObject



222
223
224
# File 'lib/ffi/clang/cursor.rb', line 222

def enum_type
	Types::Type.create Lib.get_enum_decl_integer_type(@cursor), @translation_unit
end

#enum_unsigned_valueObject



218
219
220
# File 'lib/ffi/clang/cursor.rb', line 218

def enum_unsigned_value
	Lib.get_enum_unsigned_value @cursor
end

#enum_valueObject



214
215
216
# File 'lib/ffi/clang/cursor.rb', line 214

def enum_value
	Lib.get_enum_value @cursor
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


426
427
428
# File 'lib/ffi/clang/cursor.rb', line 426

def eql?(other)
	Lib.are_equal(@cursor, other.cursor) != 0
end

#expansion_locationObject Also known as: location



122
123
124
# File 'lib/ffi/clang/cursor.rb', line 122

def expansion_location
	ExpansionLocation.new(Lib.get_cursor_location(@cursor))
end

#explicit?Boolean

Returns:

  • (Boolean)


484
485
486
# File 'lib/ffi/clang/cursor.rb', line 484

def explicit?
	Lib.is_explicit(@cursor) != 0
end

#expression?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/ffi/clang/cursor.rb', line 82

def expression?
	Lib.is_expression(kind) != 0
end

#extentObject



139
140
141
# File 'lib/ffi/clang/cursor.rb', line 139

def extent
	SourceRange.new(Lib.get_cursor_extent(@cursor))
end

#file_locationObject



135
136
137
# File 'lib/ffi/clang/cursor.rb', line 135

def file_location
	FileLocation.new(Lib.get_cursor_location(@cursor))
end

#find_by_kind(recurse, *kinds) ⇒ Object



314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/ffi/clang/cursor.rb', line 314

def find_by_kind(recurse, *kinds)
     unless (recurse == nil || recurse == true || recurse == false)
       raise("Recurse parameter must be nil or a boolean value. Value was: #{recurse}")
     end

	result = Array.new
	self.each(recurse) do |child, parent|
		if kinds.include?(child.kind)
			result << child
		end
	end
	result
end

#find_references_in_file(file = nil, &block) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
# File 'lib/ffi/clang/cursor.rb', line 328

def find_references_in_file(file = nil, &block)
	file ||= Lib.extract_string Lib.get_translation_unit_spelling(@translation_unit)

	visit_adapter = Proc.new do |unused, cxcursor, cxsource_range|
		block.call Cursor.new(cxcursor, @translation_unit), SourceRange.new(cxsource_range)
	end
	visitor = FFI::Clang::Lib::CXCursorAndRangeVisitor.new
	visitor[:visit] = visit_adapter

	Lib.find_references_in_file(@cursor, Lib.get_file(@translation_unit, file), visitor)
end

#forward_declaration?Boolean

Returns:

  • (Boolean)


243
244
245
246
247
248
249
250
251
# File 'lib/ffi/clang/cursor.rb', line 243

def forward_declaration?
	# Is this a forward declaration for a definition contained in the same translation_unit?
	# https://joshpeterson.github.io/identifying-a-forward-declaration-with-libclang
	#
	# Possible alternate implementations?
	# self.declaration? && !self.definition? && self.definition
	# !self.definition? && self.definition
	self.declaration? && !self.eql?(self.definition) && !self.definition.invalid?
end

#hashObject



431
432
433
# File 'lib/ffi/clang/cursor.rb', line 431

def hash
	Lib.get_cursor_hash(@cursor)
end

#included_fileObject



348
349
350
# File 'lib/ffi/clang/cursor.rb', line 348

def included_file
	File.new Lib.get_included_file(@cursor), @translation_unit
end

#invalid?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/ffi/clang/cursor.rb', line 106

def invalid?
	Lib.is_invalid(kind) != 0
end

#kindObject



166
167
168
# File 'lib/ffi/clang/cursor.rb', line 166

def kind
	@cursor ? @cursor[:kind] : nil
end

#kind_spellingObject



170
171
172
# File 'lib/ffi/clang/cursor.rb', line 170

def kind_spelling
	Cursor.kind_spelling @cursor[:kind]
end

#languageObject



273
274
275
# File 'lib/ffi/clang/cursor.rb', line 273

def language
	Lib.get_language @cursor
end

#lexical_parentObject



261
262
263
# File 'lib/ffi/clang/cursor.rb', line 261

def lexical_parent
	Cursor.new Lib.get_cursor_lexical_parent(@cursor), @translation_unit
end

#linkageObject



340
341
342
# File 'lib/ffi/clang/cursor.rb', line 340

def linkage
	Lib.get_cursor_linkage(@cursor)
end

#move_assignment_operator?Boolean

Returns:

  • (Boolean)


480
481
482
# File 'lib/ffi/clang/cursor.rb', line 480

def move_assignment_operator?
	Lib.is_move_assignment_operator(@cursor) != 0
end

#move_constructor?Boolean

Returns:

  • (Boolean)


460
461
462
# File 'lib/ffi/clang/cursor.rb', line 460

def move_constructor?
	Lib.is_move_constructor(@cursor) != 0
end

#mutable?Boolean

Returns:

  • (Boolean)


464
465
466
# File 'lib/ffi/clang/cursor.rb', line 464

def mutable?
	Lib.is_mutable(@cursor) != 0
end

#null?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ffi/clang/cursor.rb', line 46

def null?
	Lib.cursor_is_null(@cursor) != 0
end

#num_argsObject



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

def num_args
	Lib.get_num_args @cursor
end

#num_argumentsObject



422
423
424
# File 'lib/ffi/clang/cursor.rb', line 422

def num_arguments
	Lib.cursor_get_num_arguments(@cursor)
end

#num_overloaded_declsObject



410
411
412
# File 'lib/ffi/clang/cursor.rb', line 410

def num_overloaded_decls
	Lib.get_num_overloaded_decls(@cursor)
end

#objc_type_encodingObject



414
415
416
# File 'lib/ffi/clang/cursor.rb', line 414

def objc_type_encoding
	Lib.extract_string Lib.get_decl_objc_type_encoding(@cursor)
end

#opaque_declaration?Boolean

Returns:

  • (Boolean)


238
239
240
241
# File 'lib/ffi/clang/cursor.rb', line 238

def opaque_declaration?
	# Is this a declaration that does not have a definition in the translation unit
	self.declaration? && !self.definition? && self.definition.invalid?
end

#overloaded_decl(i) ⇒ Object



406
407
408
# File 'lib/ffi/clang/cursor.rb', line 406

def overloaded_decl(i)
	Cursor.new Lib.get_overloaded_decl(@cursor, i), @translation_unit
end

#overriddensObject



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/ffi/clang/cursor.rb', line 382

def overriddens
	cursor_ptr = FFI::MemoryPointer.new :pointer
	num_ptr = FFI::MemoryPointer.new :uint
	Lib.get_overridden_cursors(@cursor, cursor_ptr, num_ptr)
	num = num_ptr.get_uint(0)
	cur_ptr = cursor_ptr.get_pointer(0)

	overriddens = []
	num.times {
		overriddens << Cursor.new(cur_ptr, @translation_unit)
		cur_ptr += Lib::CXCursor.size
	}
	Lib.dispose_overridden_cursors(cursor_ptr.get_pointer(0)) if num != 0
	overriddens
end

#platform_availability(max_availability_size = 4) ⇒ Object



352
353
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
# File 'lib/ffi/clang/cursor.rb', line 352

def platform_availability(max_availability_size = 4)
	availability_ptr = FFI::MemoryPointer.new(Lib::CXPlatformAvailability, max_availability_size)
	always_deprecated_ptr = FFI::MemoryPointer.new :int
	always_unavailable_ptr = FFI::MemoryPointer.new :int
	deprecated_message_ptr = FFI::MemoryPointer.new Lib::CXString
	unavailable_message_ptr = FFI::MemoryPointer.new Lib::CXString

	actual_availability_size = Lib.get_cursor_platform_availability(
		@cursor,
		always_deprecated_ptr, deprecated_message_ptr,
		always_unavailable_ptr, unavailable_message_ptr,
		availability_ptr, max_availability_size)

	availability = []
	cur_ptr = availability_ptr
	[actual_availability_size, max_availability_size].min.times {
		availability << PlatformAvailability.new(cur_ptr)
		cur_ptr += Lib::CXPlatformAvailability.size
	}

	# return as Hash
	{
		always_deprecated: always_deprecated_ptr.get_int(0),
		always_unavailable: always_unavailable_ptr.get_int(0),
		deprecated_message: Lib.extract_string(Lib::CXString.new(deprecated_message_ptr)),
		unavailable_message: Lib.extract_string(Lib::CXString.new(unavailable_message_ptr)),
		availability: availability
	}
end

#preprocessing?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/ffi/clang/cursor.rb', line 114

def preprocessing?
	Lib.is_preprocessing(kind) != 0
end

#presumed_locationObject



127
128
129
# File 'lib/ffi/clang/cursor.rb', line 127

def presumed_location
	PresumedLocation.new(Lib.get_cursor_location(@cursor))
end

#printing_policyObject



158
159
160
# File 'lib/ffi/clang/cursor.rb', line 158

def printing_policy
	PrintingPolicy.new(cursor)
end

#private?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/ffi/clang/cursor.rb', line 98

def private?
	Lib.cxx_get_access_specifier(@cursor) == :private
end

#protected?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/ffi/clang/cursor.rb', line 102

def protected?
	Lib.cxx_get_access_specifier(@cursor) == :protected
end

#public?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/ffi/clang/cursor.rb', line 94

def public?
	Lib.cxx_get_access_specifier(@cursor) == :public
end

#pure_virtual?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/ffi/clang/cursor.rb', line 210

def pure_virtual?
	Lib.cxx_method_is_pure_virtual(@cursor) != 0
end

#qualified_nameObject



147
148
149
150
151
152
# File 'lib/ffi/clang/cursor.rb', line 147

def qualified_name
	if self.kind != :cursor_translation_unit
		result = self.semantic_parent.qualified_name
		result ? "#{result}::#{self.spelling}" : self.spelling
	end
end

#raw_comment_textObject



50
51
52
# File 'lib/ffi/clang/cursor.rb', line 50

def raw_comment_text
	Lib.extract_string Lib.cursor_get_raw_comment_text(@cursor)
end

#reference?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/ffi/clang/cursor.rb', line 78

def reference?
	Lib.is_reference(kind) != 0
end

#referencedObject



253
254
255
# File 'lib/ffi/clang/cursor.rb', line 253

def referenced
	Cursor.new Lib.get_cursor_referenced(@cursor), @translation_unit
end

#references(file = nil) ⇒ Object



439
440
441
442
443
444
445
446
# File 'lib/ffi/clang/cursor.rb', line 439

def references(file = nil)
	refs = []
	self.find_references_in_file(file) do |cursor, unused|
		refs << cursor
		:continue
	end
	refs
end

#result_typeObject



178
179
180
# File 'lib/ffi/clang/cursor.rb', line 178

def result_type
	Types::Type.create Lib.get_cursor_result_type(@cursor), @translation_unit
end

#semantic_parentObject



257
258
259
# File 'lib/ffi/clang/cursor.rb', line 257

def semantic_parent
	Cursor.new Lib.get_cursor_semantic_parent(@cursor), @translation_unit
end

#specialized_templateObject



226
227
228
# File 'lib/ffi/clang/cursor.rb', line 226

def specialized_template
	Cursor.new Lib.get_specialized_cursor_template(@cursor), @translation_unit
end

#spellingObject



154
155
156
# File 'lib/ffi/clang/cursor.rb', line 154

def spelling
	Lib.extract_string Lib.get_cursor_spelling(@cursor)
end

#spelling_locationObject



131
132
133
# File 'lib/ffi/clang/cursor.rb', line 131

def spelling_location
	SpellingLocation.new(Lib.get_cursor_location(@cursor))
end

#statement?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/ffi/clang/cursor.rb', line 86

def statement?
	Lib.is_statement(kind) != 0
end

#static?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/ffi/clang/cursor.rb', line 202

def static?
	Lib.cxx_method_is_static(@cursor) != 0
end

#template_kindObject



265
266
267
# File 'lib/ffi/clang/cursor.rb', line 265

def template_kind
	Lib.get_template_cursor_kind @cursor
end

#to_sObject



435
436
437
# File 'lib/ffi/clang/cursor.rb', line 435

def to_s
	"Cursor <#{self.kind.to_s.gsub(/^cursor_/, '')}: #{self.spelling}>"
end

#translation_unit?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/ffi/clang/cursor.rb', line 110

def translation_unit?
	Lib.is_translation_unit(kind) != 0
end

#typeObject



174
175
176
# File 'lib/ffi/clang/cursor.rb', line 174

def type
	Types::Type.create Lib.get_cursor_type(@cursor), @translation_unit
end

#underlying_typeObject



182
183
184
# File 'lib/ffi/clang/cursor.rb', line 182

def underlying_type
	Types::Type.create Lib.get_typedef_decl_underlying_type(@cursor), @translation_unit
end

#unexposed?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/ffi/clang/cursor.rb', line 118

def unexposed?
	Lib.is_unexposed(kind) != 0
end

#usrObject



162
163
164
# File 'lib/ffi/clang/cursor.rb', line 162

def usr
	Lib.extract_string Lib.get_cursor_usr(@cursor)
end

#variadic?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/ffi/clang/cursor.rb', line 194

def variadic?
	Lib.is_variadic(@cursor) != 0
end

#virtual?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/ffi/clang/cursor.rb', line 206

def virtual?
	Lib.cxx_method_is_virtual(@cursor) != 0
end

#virtual_base?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/ffi/clang/cursor.rb', line 186

def virtual_base?
	Lib.is_virtual_base(@cursor) != 0
end