Class: FFI::Clang::Cursor
- Inherits:
-
Object
- Object
- FFI::Clang::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/ffi/clang/cursor.rb,
lib/ffi/clang/overridden_cursors.rb
Overview
Represents a cursor in the abstract syntax tree (AST).
Defined Under Namespace
Classes: ExternalSymbol, OverriddenCursors, PlatformAvailability
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
- #The translation unit this cursor belongs to.(translationunitthiscursorbelongsto.) ⇒ Object readonly
- #The underlying libclang cursor structure.(underlyinglibclangcursorstructure.) ⇒ Object readonly
-
#translation_unit ⇒ Object
readonly
Returns the value of attribute translation_unit.
Class Method Summary collapse
-
.binary_operator_kind_spelling(kind) ⇒ Object
Get the string representation of a binary operator kind.
-
.kind_spelling(kind) ⇒ Object
Get the spelling of a cursor kind.
-
.null_cursor ⇒ Object
Get a null cursor.
-
.unary_operator_kind_spelling(kind) ⇒ Object
Get the string representation of a unary operator kind.
Instance Method Summary collapse
-
#abstract? ⇒ Boolean
Check if this cursor is abstract.
-
#access_specifier ⇒ Object
Get the C++ access specifier.
-
#ancestors_by_kind(*kinds) ⇒ Object
Find ancestors of this cursor by kind.
-
#anonymous? ⇒ Boolean
Check if this cursor is anonymous.
-
#anonymous_record_declaration? ⇒ Boolean
Check if this cursor is an anonymous record declaration.
-
#argument(i) ⇒ Object
Get a function or method argument by index.
-
#attribute? ⇒ Boolean
Check if this cursor is an attribute.
-
#availability ⇒ Object
Get the availability of this cursor.
-
#binary_operator_kind ⇒ Object
Get the binary operator kind for a binary operator cursor.
-
#bitfield? ⇒ Boolean
Check if this cursor represents a bitfield.
-
#bitwidth ⇒ Object
Get the bit width of a bitfield.
-
#brief_comment_text ⇒ Object
Get the brief documentation comment text for this cursor.
-
#canonical ⇒ Object
Get the canonical cursor for this cursor.
-
#comment ⇒ Object
Get the parsed comment associated with this cursor.
-
#comment_range ⇒ Object
Get the source range of the comment.
-
#completion ⇒ Object
Get the code completion string for this cursor.
-
#const? ⇒ Boolean
Check if this cursor is const-qualified.
-
#converting_constructor? ⇒ Boolean
Check if this is a converting constructor.
-
#copy_assignable? ⇒ Boolean
Check if this class/struct is copy-assignable: it has no inaccessible (deleted, private, or protected) copy assignment operator, and every base class is copy-assignable (recursively).
-
#copy_assignment_operator? ⇒ Boolean
Check if this is a copy assignment operator.
-
#copy_constructor? ⇒ Boolean
Check if this is a copy constructor.
-
#copyable? ⇒ Boolean
Check if this class/struct is copyable: it has no inaccessible (deleted, private, or protected) copy constructor, and every base class is copyable (recursively).
-
#cxx_manglings ⇒ Object
Get the C++ mangled symbols for a constructor or destructor cursor.
-
#declaration? ⇒ Boolean
Check if this cursor is a declaration.
-
#default_constructor? ⇒ Boolean
Check if this is a default constructor.
-
#defaulted? ⇒ Boolean
Check if this cursor is defaulted.
-
#definition ⇒ Object
Get the definition cursor for this cursor.
-
#definition? ⇒ Boolean
Check if this cursor is a definition.
-
#deleted? ⇒ Boolean
Check if this cursor is deleted.
-
#display_name ⇒ Object
Get the display name of this cursor.
-
#dynamic_call? ⇒ Boolean
Check if this cursor is a dynamic call.
-
#each(recurse = true, &block) ⇒ Object
Iterate over child cursors.
-
#enum_scoped? ⇒ Boolean
Check if this is a scoped enum.
-
#enum_type ⇒ Object
Get the integer type of an enum declaration.
-
#enum_unsigned_value ⇒ Object
Get the unsigned value of an enum constant.
-
#enum_value ⇒ Object
Get the value of an enum constant.
-
#eql?(other) ⇒ Boolean
(also: #==)
Check if this cursor equals another cursor.
-
#evaluate ⇒ Object
Evaluate this cursor as a compile-time constant.
-
#exception_specification ⇒ Object
Get the exception specification type for this cursor.
-
#expansion_location ⇒ Object
(also: #location)
Get the expansion location of this cursor.
-
#explicit? ⇒ Boolean
Check if this cursor is explicit.
-
#expression? ⇒ Boolean
Check if this cursor is an expression.
-
#extent ⇒ Object
Get the source extent of this cursor.
-
#external_symbol ⇒ Object
Check if this cursor points to a symbol marked with the external_source_symbol attribute.
-
#file_location ⇒ Object
Get the file location of this cursor.
-
#find_by_kind(recurse, *kinds, &block) ⇒ Object
Find child cursors by kind.
-
#find_first_by_kind(recurse, *kinds) ⇒ Object
Find the first child cursor matching any of the given kinds.
-
#find_references_in_file(file = nil, &block) ⇒ Object
Find all references to this cursor in a file.
-
#forward_declaration? ⇒ Boolean
Check if this is a forward declaration.
-
#function_inlined? ⇒ Boolean
Check if this function is declared inline.
-
#has_attrs? ⇒ Boolean
Check if this cursor has any attributes.
-
#has_external_storage? ⇒ Boolean
Check if this variable has external storage.
-
#has_global_storage? ⇒ Boolean
Check if this variable has global or file-scope storage.
-
#hash ⇒ Object
Get the hash code for this cursor.
-
#included_file ⇒ Object
Get the file included by this cursor.
-
#initialize(cxcursor, translation_unit) ⇒ Cursor
constructor
Initialize a cursor with a libclang cursor structure.
-
#inline_namespace? ⇒ Boolean
Check if this namespace is an inline namespace.
-
#invalid? ⇒ Boolean
Check if this cursor is invalid.
-
#invalid_declaration? ⇒ Boolean
Check if this declaration is invalid or incomplete.
-
#kind ⇒ Object
Get the kind of this cursor.
-
#kind_spelling ⇒ Object
Get the spelling of the cursor kind.
-
#language ⇒ Object
Get the programming language of this cursor.
-
#lexical_parent ⇒ Object
Get the lexical parent of this cursor.
-
#linkage ⇒ Object
Get the linkage of this cursor.
-
#macro_builtin? ⇒ Boolean
Check if this macro is a builtin macro.
-
#macro_function_like? ⇒ Boolean
Check if this macro cursor is function-like.
-
#mangling ⇒ Object
Get the C++ mangled name of this cursor.
-
#move_assignment_operator? ⇒ Boolean
Check if this is a move assignment operator.
-
#move_constructor? ⇒ Boolean
Check if this is a move constructor.
-
#mutable? ⇒ Boolean
Check if this cursor is mutable.
-
#null? ⇒ Boolean
Check if this cursor is null.
-
#num_args ⇒ Object
Get the number of arguments for this cursor.
-
#num_arguments ⇒ Object
Get the number of arguments.
-
#num_overloaded_decls ⇒ Object
Get the number of overloaded declarations.
-
#num_template_arguments ⇒ Object
Get the number of template arguments for a template specialization cursor.
-
#objc_type_encoding ⇒ Object
Get the Objective-C type encoding.
-
#offset_of_base(base) ⇒ Object
Get the bit offset of a base class in a record layout.
-
#offset_of_field ⇒ Object
Get the offset of a field in a record, in bits.
-
#opaque_declaration? ⇒ Boolean
Check if this is an opaque declaration without a definition.
-
#overloaded_decl(i) ⇒ Object
Get an overloaded declaration by index.
-
#overriddens ⇒ Object
Get all cursors that this cursor overrides.
-
#platform_availability(max_availability_size = 4) ⇒ Object
Get platform availability information for this cursor.
-
#preprocessing? ⇒ Boolean
Check if this cursor is a preprocessing directive.
-
#presumed_location ⇒ Object
Get the presumed location of this cursor.
-
#printing_policy ⇒ Object
Get the printing policy for this cursor.
-
#private? ⇒ Boolean
Check if this cursor has private access.
-
#protected? ⇒ Boolean
Check if this cursor has protected access.
-
#public? ⇒ Boolean
Check if this cursor has public access.
-
#pure_virtual? ⇒ Boolean
Check if this is a pure virtual method.
-
#qualified_display_name ⇒ Object
Get the qualified display name including parent scope.
-
#qualified_name ⇒ Object
Get the fully qualified name of this cursor.
-
#raw_comment_text ⇒ Object
Get the raw comment text associated with this cursor.
-
#reference? ⇒ Boolean
Check if this cursor is a reference.
-
#reference_name_range(name_flags = [], piece_index = 0) ⇒ Object
Get the source range of a reference name piece.
-
#referenced ⇒ Object
Get the cursor referenced by this cursor.
-
#references(file = nil) ⇒ Object
Find all references to this cursor.
-
#result_type ⇒ Object
Get the result type for a function cursor.
-
#semantic_parent ⇒ Object
Get the semantic parent of this cursor.
-
#specialized_template ⇒ Object
Get the template that this cursor specializes.
-
#spelling ⇒ Object
Get the spelling (name) of this cursor.
-
#spelling_location ⇒ Object
Get the spelling location of this cursor.
-
#spelling_name_range(piece_index = 0) ⇒ Object
Get the source range for a piece of the cursor’s spelling name.
-
#statement? ⇒ Boolean
Check if this cursor is a statement.
-
#static? ⇒ Boolean
Check if this is a static method.
-
#storage_class ⇒ Object
Get the storage class of this declaration.
-
#template_argument_kind(index) ⇒ Object
Get the kind of a template argument for a template specialization cursor.
-
#template_argument_type(index) ⇒ Object
Get the type of a template argument for a template specialization cursor.
-
#template_argument_unsigned_value(index) ⇒ Object
Get the unsigned integral value of a template argument for a template specialization cursor.
-
#template_argument_value(index) ⇒ Object
Get the signed integral value of a template argument for a template specialization cursor.
-
#template_kind ⇒ Object
Get the template cursor kind.
-
#tls_kind ⇒ Object
Get the thread-local storage kind of this cursor.
-
#to_s ⇒ Object
Get a string representation of this cursor.
-
#translation_unit? ⇒ Boolean
Check if this cursor is a translation unit.
-
#type ⇒ Object
Get the type of this cursor.
-
#unary_operator_kind ⇒ Object
Get the unary operator kind for a unary operator cursor.
-
#underlying_type ⇒ Object
Get the underlying type for a typedef cursor.
-
#unexposed? ⇒ Boolean
Check if this cursor is unexposed.
-
#usr ⇒ Object
Get the Unified Symbol Resolution (USR) for this cursor.
-
#var_decl_initializer ⇒ Object
Get the initializer expression of a variable declaration.
-
#variadic? ⇒ Boolean
Check if this cursor is variadic.
-
#virtual? ⇒ Boolean
Check if this is a virtual method.
-
#virtual_base? ⇒ Boolean
Check if this cursor is a virtual base class.
-
#visibility ⇒ Object
Get the visibility of this cursor.
-
#visit_children(&block) ⇒ Object
Visit only direct children without recursing.
Constructor Details
#initialize(cxcursor, translation_unit) ⇒ Cursor
Initialize a cursor with a libclang cursor structure.
81 82 83 84 |
# File 'lib/ffi/clang/cursor.rb', line 81 def initialize(cxcursor, translation_unit) @cursor = cxcursor @translation_unit = translation_unit end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
60 61 62 |
# File 'lib/ffi/clang/cursor.rb', line 60 def cursor @cursor end |
#The translation unit this cursor belongs to.(translationunitthiscursorbelongsto.) ⇒ Object (readonly)
63 |
# File 'lib/ffi/clang/cursor.rb', line 63 attr_reader :translation_unit |
#The underlying libclang cursor structure.(underlyinglibclangcursorstructure.) ⇒ Object (readonly)
60 |
# File 'lib/ffi/clang/cursor.rb', line 60 attr_reader :cursor |
#translation_unit ⇒ Object (readonly)
Returns the value of attribute translation_unit.
63 64 65 |
# File 'lib/ffi/clang/cursor.rb', line 63 def translation_unit @translation_unit end |
Class Method Details
.binary_operator_kind_spelling(kind) ⇒ Object
Get the string representation of a binary operator kind.
892 893 894 |
# File 'lib/ffi/clang/cursor.rb', line 892 def self.binary_operator_kind_spelling(kind) Lib.extract_string Lib.get_binary_operator_kind_spelling(kind) end |
.kind_spelling(kind) ⇒ Object
Get the spelling of a cursor kind.
74 75 76 |
# File 'lib/ffi/clang/cursor.rb', line 74 def self.kind_spelling(kind) Lib.extract_string Lib.get_cursor_kind_spelling(kind) end |
.null_cursor ⇒ Object
Get a null cursor.
67 68 69 |
# File 'lib/ffi/clang/cursor.rb', line 67 def self.null_cursor Cursor.new Lib.get_null_cursor, nil end |
.unary_operator_kind_spelling(kind) ⇒ Object
Get the string representation of a unary operator kind.
905 906 907 |
# File 'lib/ffi/clang/cursor.rb', line 905 def self.unary_operator_kind_spelling(kind) Lib.extract_string Lib.get_unary_operator_kind_spelling(kind) end |
Instance Method Details
#abstract? ⇒ Boolean
Check if this cursor is abstract.
812 813 814 |
# File 'lib/ffi/clang/cursor.rb', line 812 def abstract? Lib.is_abstract(@cursor) != 0 end |
#access_specifier ⇒ Object
Get the C++ access specifier.
481 482 483 |
# File 'lib/ffi/clang/cursor.rb', line 481 def access_specifier Lib.get_cxx_access_specifier @cursor end |
#ancestors_by_kind(*kinds) ⇒ Object
Find ancestors of this cursor by kind.
537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/ffi/clang/cursor.rb', line 537 def ancestors_by_kind(*kinds) result = Array.new parent = self.semantic_parent while parent.kind != :cursor_translation_unit if kinds.include?(parent.kind) result << parent end parent = parent.semantic_parent end result end |
#anonymous? ⇒ Boolean
Check if this cursor is anonymous.
118 119 120 |
# File 'lib/ffi/clang/cursor.rb', line 118 def anonymous? Lib.cursor_is_anonymous(@cursor) != 0 end |
#anonymous_record_declaration? ⇒ Boolean
Check if this cursor is an anonymous record declaration.
124 125 126 |
# File 'lib/ffi/clang/cursor.rb', line 124 def anonymous_record_declaration? Lib.cursor_is_anonymous_record_decl(@cursor) != 0 end |
#argument(i) ⇒ Object
Get a function or method argument by index.
708 709 710 |
# File 'lib/ffi/clang/cursor.rb', line 708 def argument(i) Cursor.new Lib.cursor_get_argument(@cursor, i), @translation_unit end |
#attribute? ⇒ Boolean
Check if this cursor is an attribute.
154 155 156 |
# File 'lib/ffi/clang/cursor.rb', line 154 def attribute? Lib.is_attribute(kind) != 0 end |
#availability ⇒ Object
Get the availability of this cursor.
625 626 627 |
# File 'lib/ffi/clang/cursor.rb', line 625 def availability Lib.get_cursor_availability(@cursor) end |
#binary_operator_kind ⇒ Object
Get the binary operator kind for a binary operator cursor.
885 886 887 |
# File 'lib/ffi/clang/cursor.rb', line 885 def binary_operator_kind Lib.get_cursor_binary_operator_kind(@cursor) end |
#bitfield? ⇒ Boolean
Check if this cursor represents a bitfield.
676 677 678 |
# File 'lib/ffi/clang/cursor.rb', line 676 def bitfield? Lib.is_bit_field(@cursor) != 0 end |
#bitwidth ⇒ Object
Get the bit width of a bitfield.
682 683 684 |
# File 'lib/ffi/clang/cursor.rb', line 682 def bitwidth Lib.get_field_decl_bit_width(@cursor) end |
#brief_comment_text ⇒ Object
Get the brief documentation comment text for this cursor.
1036 1037 1038 |
# File 'lib/ffi/clang/cursor.rb', line 1036 def brief_comment_text Lib.extract_string Lib.cursor_get_brief_comment_text(@cursor) end |
#canonical ⇒ Object
Get the canonical cursor for this cursor.
392 393 394 |
# File 'lib/ffi/clang/cursor.rb', line 392 def canonical Cursor.new Lib.get_canonical_cursor(@cursor), @translation_unit end |
#comment ⇒ Object
Get the parsed comment associated with this cursor.
100 101 102 |
# File 'lib/ffi/clang/cursor.rb', line 100 def comment Comment.build_from Lib.cursor_get_parsed_comment(@cursor) end |
#comment_range ⇒ Object
Get the source range of the comment.
106 107 108 |
# File 'lib/ffi/clang/cursor.rb', line 106 def comment_range SourceRange.new(Lib.cursor_get_comment_range(@cursor)) end |
#completion ⇒ Object
Get the code completion string for this cursor.
112 113 114 |
# File 'lib/ffi/clang/cursor.rb', line 112 def completion CodeCompletion::String.new Lib.get_cursor_completion_string(@cursor) end |
#const? ⇒ Boolean
Check if this cursor is const-qualified.
879 880 881 |
# File 'lib/ffi/clang/cursor.rb', line 879 def const? Lib.is_const(@cursor) != 0 end |
#converting_constructor? ⇒ Boolean
Check if this is a converting constructor.
752 753 754 |
# File 'lib/ffi/clang/cursor.rb', line 752 def converting_constructor? Lib.is_converting_constructor(@cursor) != 0 end |
#copy_assignable? ⇒ Boolean
Check if this class/struct is copy-assignable: it has no inaccessible (deleted, private, or protected) copy assignment operator, and every base class is copy-assignable (recursively). Returns true on cursors that don’t denote a class/struct, since the question doesn’t apply.
A class with no explicit copy assignment operator is treated as copy-assignable — the implicit one is generated. We only flag explicit ‘= delete` or private/protected access.
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 |
# File 'lib/ffi/clang/cursor.rb', line 854 def copy_assignable? return true unless [:cursor_class_decl, :cursor_struct].include?(self.kind) copy_assignment_operators = self.find_by_kind(false, :cursor_cxx_method).select(&:copy_assignment_operator?) copy_assignment_operators.each do |operator| return false if operator.deleted? || operator.private? || operator.protected? end self.find_by_kind(false, :cursor_cxx_base_specifier).each do |base| base_decl = base.type.declaration next if base_decl.kind == :cursor_no_decl_found return false unless base_decl.copy_assignable? end true end |
#copy_assignment_operator? ⇒ Boolean
Check if this is a copy assignment operator.
794 795 796 |
# File 'lib/ffi/clang/cursor.rb', line 794 def copy_assignment_operator? Lib.is_copy_assignment_operator(@cursor) != 0 end |
#copy_constructor? ⇒ Boolean
Check if this is a copy constructor.
758 759 760 |
# File 'lib/ffi/clang/cursor.rb', line 758 def copy_constructor? Lib.is_copy_constructor(@cursor) != 0 end |
#copyable? ⇒ Boolean
Check if this class/struct is copyable: it has no inaccessible (deleted, private, or protected) copy constructor, and every base class is copyable (recursively). Returns true on cursors that don’t denote a class/struct, since the question doesn’t apply.
A class with no explicit copy constructor is treated as copyable —the implicit one is generated. We only flag explicit ‘= delete` or private/protected access.
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/ffi/clang/cursor.rb', line 826 def copyable? return true unless [:cursor_class_decl, :cursor_struct].include?(self.kind) copy_constructors = self.find_by_kind(false, :cursor_constructor).select(&:copy_constructor?) copy_constructors.each do |constructor| return false if constructor.deleted? || constructor.private? || constructor.protected? end self.find_by_kind(false, :cursor_cxx_base_specifier).each do |base| base_decl = base.type.declaration next if base_decl.kind == :cursor_no_decl_found return false unless base_decl.copyable? end true end |
#cxx_manglings ⇒ Object
Get the C++ mangled symbols for a constructor or destructor cursor. The returned set may differ from #mangling, particularly for destructors where some ABIs expose multiple related symbols.
985 986 987 |
# File 'lib/ffi/clang/cursor.rb', line 985 def cxx_manglings StringSet.new(Lib.cursor_get_cxx_manglings(@cursor)) end |
#declaration? ⇒ Boolean
Check if this cursor is a declaration.
130 131 132 |
# File 'lib/ffi/clang/cursor.rb', line 130 def declaration? Lib.is_declaration(kind) != 0 end |
#default_constructor? ⇒ Boolean
Check if this is a default constructor.
764 765 766 |
# File 'lib/ffi/clang/cursor.rb', line 764 def default_constructor? Lib.is_default_constructor(@cursor) != 0 end |
#defaulted? ⇒ Boolean
Check if this cursor is defaulted.
782 783 784 |
# File 'lib/ffi/clang/cursor.rb', line 782 def defaulted? Lib.is_defaulted(@cursor) != 0 end |
#definition ⇒ Object
Get the definition cursor for this cursor.
398 399 400 |
# File 'lib/ffi/clang/cursor.rb', line 398 def definition Cursor.new Lib.get_cursor_definition(@cursor), @translation_unit end |
#definition? ⇒ Boolean
Check if this cursor is a definition.
344 345 346 |
# File 'lib/ffi/clang/cursor.rb', line 344 def definition? Lib.is_definition(@cursor) != 0 end |
#deleted? ⇒ Boolean
Check if this cursor is deleted.
788 789 790 |
# File 'lib/ffi/clang/cursor.rb', line 788 def deleted? Lib.is_deleted(@cursor) != 0 end |
#display_name ⇒ Object
Get the display name of this cursor.
233 234 235 |
# File 'lib/ffi/clang/cursor.rb', line 233 def display_name Lib.extract_string Lib.get_cursor_display_name(@cursor) end |
#dynamic_call? ⇒ Boolean
Check if this cursor is a dynamic call.
332 333 334 |
# File 'lib/ffi/clang/cursor.rb', line 332 def dynamic_call? Lib.is_dynamic_call(@cursor) != 0 end |
#each(recurse = true, &block) ⇒ Object
Iterate over child cursors. The block may return :break, :continue, or :recurse to control traversal.
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/ffi/clang/cursor.rb', line 504 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 :break :break when :continue :continue when :recurse :recurse else recurse ? :recurse : :continue end end Lib.visit_children(@cursor, adapter, nil) end |
#enum_scoped? ⇒ Boolean
Check if this is a scoped enum.
873 874 875 |
# File 'lib/ffi/clang/cursor.rb', line 873 def enum_scoped? Lib.is_enum_scoped(@cursor) != 0 end |
#enum_type ⇒ Object
Get the integer type of an enum declaration.
380 381 382 |
# File 'lib/ffi/clang/cursor.rb', line 380 def enum_type Types::Type.create Lib.get_enum_decl_integer_type(@cursor), @translation_unit end |
#enum_unsigned_value ⇒ Object
Get the unsigned value of an enum constant.
374 375 376 |
# File 'lib/ffi/clang/cursor.rb', line 374 def enum_unsigned_value Lib.get_enum_unsigned_value @cursor end |
#enum_value ⇒ Object
Get the value of an enum constant.
368 369 370 |
# File 'lib/ffi/clang/cursor.rb', line 368 def enum_value Lib.get_enum_value @cursor end |
#eql?(other) ⇒ Boolean Also known as: ==
Check if this cursor equals another cursor.
721 722 723 |
# File 'lib/ffi/clang/cursor.rb', line 721 def eql?(other) Lib.are_equal(@cursor, other.cursor) != 0 end |
#evaluate ⇒ Object
Evaluate this cursor as a compile-time constant.
307 308 309 310 |
# File 'lib/ffi/clang/cursor.rb', line 307 def evaluate result = Lib.cursor_evaluate(@cursor) result.null? ? nil : EvalResult.new(result) end |
#exception_specification ⇒ Object
Get the exception specification type for this cursor.
619 620 621 |
# File 'lib/ffi/clang/cursor.rb', line 619 def exception_specification Lib.get_cursor_exception_specification_type(@cursor) end |
#expansion_location ⇒ Object Also known as: location
Get the expansion location of this cursor.
202 203 204 |
# File 'lib/ffi/clang/cursor.rb', line 202 def expansion_location ExpansionLocation.new(Lib.get_cursor_location(@cursor)) end |
#explicit? ⇒ Boolean
Check if this cursor is explicit.
806 807 808 |
# File 'lib/ffi/clang/cursor.rb', line 806 def explicit? Lib.is_explicit(@cursor) != 0 end |
#expression? ⇒ Boolean
Check if this cursor is an expression.
142 143 144 |
# File 'lib/ffi/clang/cursor.rb', line 142 def expression? Lib.is_expression(kind) != 0 end |
#extent ⇒ Object
Get the source extent of this cursor.
227 228 229 |
# File 'lib/ffi/clang/cursor.rb', line 227 def extent SourceRange.new(Lib.get_cursor_extent(@cursor)) end |
#external_symbol ⇒ Object
Check if this cursor points to a symbol marked with the external_source_symbol attribute.
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'lib/ffi/clang/cursor.rb', line 997 def external_symbol language_str = Lib::CXString.new defined_in_str = Lib::CXString.new is_generated_ptr = MemoryPointer.new(:uint) result = Lib.cursor_is_external_symbol(@cursor, language_str, defined_in_str, is_generated_ptr) return nil if result == 0 ExternalSymbol.new( Lib.extract_string(language_str), Lib.extract_string(defined_in_str), is_generated_ptr.read_uint != 0 ) end |
#file_location ⇒ Object
Get the file location of this cursor.
221 222 223 |
# File 'lib/ffi/clang/cursor.rb', line 221 def file_location FileLocation.new(Lib.get_cursor_location(@cursor)) end |
#find_by_kind(recurse, *kinds, &block) ⇒ Object
Find child cursors by kind.
556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/ffi/clang/cursor.rb', line 556 def find_by_kind(recurse, *kinds, &block) unless (recurse == nil || recurse == true || recurse == false) raise("Recurse parameter must be nil or a boolean value. Value was: #{recurse}") end return enum_for(__method__, recurse, *kinds) unless block_given? kinds_set = kinds.to_set self.each(recurse) do |child, parent| yield child if kinds_set.include?(child.kind) end end |
#find_first_by_kind(recurse, *kinds) ⇒ Object
Find the first child cursor matching any of the given kinds. Short-circuits on first match via :break to terminate traversal early.
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/ffi/clang/cursor.rb', line 576 def find_first_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 = nil kinds_set = kinds.to_set self.each(recurse) do |child, parent| if kinds_set.include?(child.kind) result = child next :break end end result end |
#find_references_in_file(file = nil, &block) ⇒ Object
Find all references to this cursor in a file.
599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/ffi/clang/cursor.rb', line 599 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
Check if this is a forward declaration.
411 412 413 414 415 416 417 418 419 |
# File 'lib/ffi/clang/cursor.rb', line 411 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 |
#function_inlined? ⇒ Boolean
Check if this function is declared inline.
941 942 943 |
# File 'lib/ffi/clang/cursor.rb', line 941 def function_inlined? Lib.cursor_is_function_inlined(@cursor) != 0 end |
#has_attrs? ⇒ Boolean
Check if this cursor has any attributes.
917 918 919 |
# File 'lib/ffi/clang/cursor.rb', line 917 def has_attrs? Lib.cursor_has_attrs(@cursor) != 0 end |
#has_external_storage? ⇒ Boolean
Check if this variable has external storage.
965 966 967 |
# File 'lib/ffi/clang/cursor.rb', line 965 def has_external_storage? Lib.cursor_has_var_decl_external_storage(@cursor) != 0 end |
#has_global_storage? ⇒ Boolean
Check if this variable has global or file-scope storage.
959 960 961 |
# File 'lib/ffi/clang/cursor.rb', line 959 def has_global_storage? Lib.cursor_has_var_decl_global_storage(@cursor) != 0 end |
#hash ⇒ Object
Get the hash code for this cursor.
728 729 730 |
# File 'lib/ffi/clang/cursor.rb', line 728 def hash Lib.get_cursor_hash(@cursor) end |
#included_file ⇒ Object
Get the file included by this cursor.
631 632 633 |
# File 'lib/ffi/clang/cursor.rb', line 631 def included_file File.new Lib.get_included_file(@cursor), @translation_unit end |
#inline_namespace? ⇒ Boolean
Check if this namespace is an inline namespace.
971 972 973 |
# File 'lib/ffi/clang/cursor.rb', line 971 def inline_namespace? Lib.cursor_is_inline_namespace(@cursor) != 0 end |
#invalid? ⇒ Boolean
Check if this cursor is invalid.
178 179 180 |
# File 'lib/ffi/clang/cursor.rb', line 178 def invalid? Lib.is_invalid(kind) != 0 end |
#invalid_declaration? ⇒ Boolean
Check if this declaration is invalid or incomplete.
911 912 913 |
# File 'lib/ffi/clang/cursor.rb', line 911 def invalid_declaration? Lib.is_invalid_declaration(@cursor) != 0 end |
#kind ⇒ Object
Get the kind of this cursor.
289 290 291 |
# File 'lib/ffi/clang/cursor.rb', line 289 def kind @cursor ? @cursor[:kind] : nil end |
#kind_spelling ⇒ Object
Get the spelling of the cursor kind.
295 296 297 |
# File 'lib/ffi/clang/cursor.rb', line 295 def kind_spelling Cursor.kind_spelling @cursor[:kind] end |
#language ⇒ Object
Get the programming language of this cursor.
487 488 489 |
# File 'lib/ffi/clang/cursor.rb', line 487 def language Lib.get_language @cursor end |
#lexical_parent ⇒ Object
Get the lexical parent of this cursor.
435 436 437 |
# File 'lib/ffi/clang/cursor.rb', line 435 def lexical_parent Cursor.new Lib.get_cursor_lexical_parent(@cursor), @translation_unit end |
#linkage ⇒ Object
Get the linkage of this cursor.
613 614 615 |
# File 'lib/ffi/clang/cursor.rb', line 613 def linkage Lib.get_cursor_linkage(@cursor) end |
#macro_builtin? ⇒ Boolean
Check if this macro is a builtin macro.
953 954 955 |
# File 'lib/ffi/clang/cursor.rb', line 953 def macro_builtin? Lib.cursor_is_macro_builtin(@cursor) != 0 end |
#macro_function_like? ⇒ Boolean
Check if this macro cursor is function-like.
947 948 949 |
# File 'lib/ffi/clang/cursor.rb', line 947 def macro_function_like? Lib.cursor_is_macro_function_like(@cursor) != 0 end |
#mangling ⇒ Object
Get the C++ mangled name of this cursor.
977 978 979 |
# File 'lib/ffi/clang/cursor.rb', line 977 def mangling Lib.extract_string Lib.cursor_get_mangling(@cursor) end |
#move_assignment_operator? ⇒ Boolean
Check if this is a move assignment operator.
800 801 802 |
# File 'lib/ffi/clang/cursor.rb', line 800 def move_assignment_operator? Lib.is_move_assignment_operator(@cursor) != 0 end |
#move_constructor? ⇒ Boolean
Check if this is a move constructor.
770 771 772 |
# File 'lib/ffi/clang/cursor.rb', line 770 def move_constructor? Lib.is_move_constructor(@cursor) != 0 end |
#mutable? ⇒ Boolean
Check if this cursor is mutable.
776 777 778 |
# File 'lib/ffi/clang/cursor.rb', line 776 def mutable? Lib.is_mutable(@cursor) != 0 end |
#null? ⇒ Boolean
Check if this cursor is null.
88 89 90 |
# File 'lib/ffi/clang/cursor.rb', line 88 def null? Lib.cursor_is_null(@cursor) != 0 end |
#num_args ⇒ Object
Get the number of arguments for this cursor.
493 494 495 |
# File 'lib/ffi/clang/cursor.rb', line 493 def num_args Lib.get_num_args @cursor end |
#num_arguments ⇒ Object
Get the number of arguments.
714 715 716 |
# File 'lib/ffi/clang/cursor.rb', line 714 def num_arguments Lib.cursor_get_num_arguments(@cursor) end |
#num_overloaded_decls ⇒ Object
Get the number of overloaded declarations.
695 696 697 |
# File 'lib/ffi/clang/cursor.rb', line 695 def num_overloaded_decls Lib.get_num_overloaded_decls(@cursor) end |
#num_template_arguments ⇒ Object
Get the number of template arguments for a template specialization cursor.
447 448 449 |
# File 'lib/ffi/clang/cursor.rb', line 447 def num_template_arguments Lib.cursor_get_num_template_arguments(@cursor) end |
#objc_type_encoding ⇒ Object
Get the Objective-C type encoding.
701 702 703 |
# File 'lib/ffi/clang/cursor.rb', line 701 def objc_type_encoding Lib.extract_string Lib.get_decl_objc_type_encoding(@cursor) end |
#offset_of_base(base) ⇒ Object
Get the bit offset of a base class in a record layout.
1024 1025 1026 |
# File 'lib/ffi/clang/cursor.rb', line 1024 def offset_of_base(base) Lib.get_offset_of_base(@cursor, base.cursor) end |
#offset_of_field ⇒ Object
Get the offset of a field in a record, in bits.
1030 1031 1032 |
# File 'lib/ffi/clang/cursor.rb', line 1030 def offset_of_field Lib.cursor_get_offset_of_field(@cursor) end |
#opaque_declaration? ⇒ Boolean
Check if this is an opaque declaration without a definition.
404 405 406 407 |
# File 'lib/ffi/clang/cursor.rb', line 404 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
Get an overloaded declaration by index.
689 690 691 |
# File 'lib/ffi/clang/cursor.rb', line 689 def overloaded_decl(i) Cursor.new Lib.get_overloaded_decl(@cursor, i), @translation_unit end |
#overriddens ⇒ Object
Get all cursors that this cursor overrides.
670 671 672 |
# File 'lib/ffi/clang/cursor.rb', line 670 def overriddens OverriddenCursors.new(@cursor, @translation_unit) end |
#platform_availability(max_availability_size = 4) ⇒ Object
Get platform availability information for this cursor.
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/ffi/clang/cursor.rb', line 638 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 = FFI::MemoryPointer.new Lib::CXString = FFI::MemoryPointer.new Lib::CXString actual_availability_size = Lib.get_cursor_platform_availability( @cursor, always_deprecated_ptr, , always_unavailable_ptr, , availability_ptr, max_availability_size) availability = [] cur_ptr = availability_ptr [actual_availability_size, max_availability_size].min.times do availability << PlatformAvailability.new(cur_ptr, availability_ptr) cur_ptr += Lib::CXPlatformAvailability.size end # 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()), unavailable_message: Lib.extract_string(Lib::CXString.new()), availability: availability } end |
#preprocessing? ⇒ Boolean
Check if this cursor is a preprocessing directive.
190 191 192 |
# File 'lib/ffi/clang/cursor.rb', line 190 def preprocessing? Lib.is_preprocessing(kind) != 0 end |
#presumed_location ⇒ Object
Get the presumed location of this cursor.
209 210 211 |
# File 'lib/ffi/clang/cursor.rb', line 209 def presumed_location PresumedLocation.new(Lib.get_cursor_location(@cursor)) end |
#printing_policy ⇒ Object
Get the printing policy for this cursor.
277 278 279 |
# File 'lib/ffi/clang/cursor.rb', line 277 def printing_policy PrintingPolicy.new(cursor) end |
#private? ⇒ Boolean
Check if this cursor has private access.
166 167 168 |
# File 'lib/ffi/clang/cursor.rb', line 166 def private? Lib.cxx_get_access_specifier(@cursor) == :private end |
#protected? ⇒ Boolean
Check if this cursor has protected access.
172 173 174 |
# File 'lib/ffi/clang/cursor.rb', line 172 def protected? Lib.cxx_get_access_specifier(@cursor) == :protected end |
#public? ⇒ Boolean
Check if this cursor has public access.
160 161 162 |
# File 'lib/ffi/clang/cursor.rb', line 160 def public? Lib.cxx_get_access_specifier(@cursor) == :public end |
#pure_virtual? ⇒ Boolean
Check if this is a pure virtual method.
362 363 364 |
# File 'lib/ffi/clang/cursor.rb', line 362 def pure_virtual? Lib.cxx_method_is_pure_virtual(@cursor) != 0 end |
#qualified_display_name ⇒ Object
Get the qualified display name including parent scope.
240 241 242 243 244 245 246 247 248 |
# File 'lib/ffi/clang/cursor.rb', line 240 def qualified_display_name if self.kind != :cursor_translation_unit if self.semantic_parent.kind == :cursor_invalid_file raise(ArgumentError, "Invalid semantic parent: #{self}") end result = self.semantic_parent.qualified_display_name result ? "#{result}::#{self.display_name}" : self.display_name end end |
#qualified_name ⇒ Object
Get the fully qualified name of this cursor.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/ffi/clang/cursor.rb', line 253 def qualified_name if self.kind != :cursor_translation_unit if self.semantic_parent.kind == :cursor_invalid_file raise(ArgumentError, "Invalid semantic parent: #{self}") end # Skip cursor_linkage_spec (extern "C" / extern "C++" blocks). # These have empty spellings but are included in the semantic parent chain, # which would otherwise produce invalid names like "::::ushort". if self.kind == :cursor_linkage_spec return self.semantic_parent.qualified_name end result = self.semantic_parent.qualified_name result && !result.empty? ? "#{result}::#{self.spelling}" : self.spelling end end |
#raw_comment_text ⇒ Object
Get the raw comment text associated with this cursor.
94 95 96 |
# File 'lib/ffi/clang/cursor.rb', line 94 def raw_comment_text Lib.extract_string Lib.cursor_get_raw_comment_text(@cursor) end |
#reference? ⇒ Boolean
Check if this cursor is a reference.
136 137 138 |
# File 'lib/ffi/clang/cursor.rb', line 136 def reference? Lib.is_reference(kind) != 0 end |
#reference_name_range(name_flags = [], piece_index = 0) ⇒ Object
Get the source range of a reference name piece.
1016 1017 1018 1019 |
# File 'lib/ffi/clang/cursor.rb', line 1016 def reference_name_range(name_flags = [], piece_index = 0) flags = Lib.bitmask_from(Lib::NameRefFlags, name_flags) SourceRange.new(Lib.get_cursor_reference_name_range(@cursor, flags, piece_index)) end |
#referenced ⇒ Object
Get the cursor referenced by this cursor.
423 424 425 |
# File 'lib/ffi/clang/cursor.rb', line 423 def referenced Cursor.new Lib.get_cursor_referenced(@cursor), @translation_unit end |
#references(file = nil) ⇒ Object
Find all references to this cursor.
741 742 743 744 745 746 747 748 |
# File 'lib/ffi/clang/cursor.rb', line 741 def references(file = nil) refs = [] self.find_references_in_file(file) do |cursor, unused| refs << cursor :continue end refs end |
#result_type ⇒ Object
Get the result type for a function cursor.
314 315 316 |
# File 'lib/ffi/clang/cursor.rb', line 314 def result_type Types::Type.create Lib.get_cursor_result_type(@cursor), @translation_unit end |
#semantic_parent ⇒ Object
Get the semantic parent of this cursor.
429 430 431 |
# File 'lib/ffi/clang/cursor.rb', line 429 def semantic_parent Cursor.new Lib.get_cursor_semantic_parent(@cursor), @translation_unit end |
#specialized_template ⇒ Object
Get the template that this cursor specializes.
386 387 388 |
# File 'lib/ffi/clang/cursor.rb', line 386 def specialized_template Cursor.new Lib.get_specialized_cursor_template(@cursor), @translation_unit end |
#spelling ⇒ Object
Get the spelling (name) of this cursor.
271 272 273 |
# File 'lib/ffi/clang/cursor.rb', line 271 def spelling Lib.extract_string Lib.get_cursor_spelling(@cursor) end |
#spelling_location ⇒ Object
Get the spelling location of this cursor.
215 216 217 |
# File 'lib/ffi/clang/cursor.rb', line 215 def spelling_location SpellingLocation.new(Lib.get_cursor_location(@cursor)) end |
#spelling_name_range(piece_index = 0) ⇒ Object
Get the source range for a piece of the cursor’s spelling name.
1043 1044 1045 |
# File 'lib/ffi/clang/cursor.rb', line 1043 def spelling_name_range(piece_index = 0) SourceRange.new Lib.cursor_get_spelling_name_range(@cursor, piece_index, 0) end |
#statement? ⇒ Boolean
Check if this cursor is a statement.
148 149 150 |
# File 'lib/ffi/clang/cursor.rb', line 148 def statement? Lib.is_statement(kind) != 0 end |
#static? ⇒ Boolean
Check if this is a static method.
350 351 352 |
# File 'lib/ffi/clang/cursor.rb', line 350 def static? Lib.cxx_method_is_static(@cursor) != 0 end |
#storage_class ⇒ Object
Get the storage class of this declaration.
929 930 931 |
# File 'lib/ffi/clang/cursor.rb', line 929 def storage_class Lib.cursor_get_storage_class(@cursor) end |
#template_argument_kind(index) ⇒ Object
Get the kind of a template argument for a template specialization cursor.
454 455 456 |
# File 'lib/ffi/clang/cursor.rb', line 454 def template_argument_kind(index) Lib.cursor_get_template_argument_kind(@cursor, index) end |
#template_argument_type(index) ⇒ Object
Get the type of a template argument for a template specialization cursor.
461 462 463 |
# File 'lib/ffi/clang/cursor.rb', line 461 def template_argument_type(index) Types::Type.create Lib.cursor_get_template_argument_type(@cursor, index), @translation_unit end |
#template_argument_unsigned_value(index) ⇒ Object
Get the unsigned integral value of a template argument for a template specialization cursor.
475 476 477 |
# File 'lib/ffi/clang/cursor.rb', line 475 def template_argument_unsigned_value(index) Lib.cursor_get_template_argument_unsigned_value(@cursor, index) end |
#template_argument_value(index) ⇒ Object
Get the signed integral value of a template argument for a template specialization cursor.
468 469 470 |
# File 'lib/ffi/clang/cursor.rb', line 468 def template_argument_value(index) Lib.cursor_get_template_argument_value(@cursor, index) end |
#template_kind ⇒ Object
Get the template cursor kind.
441 442 443 |
# File 'lib/ffi/clang/cursor.rb', line 441 def template_kind Lib.get_template_cursor_kind @cursor end |
#tls_kind ⇒ Object
Get the thread-local storage kind of this cursor.
935 936 937 |
# File 'lib/ffi/clang/cursor.rb', line 935 def tls_kind Lib.cursor_get_tls_kind(@cursor) end |
#to_s ⇒ Object
Get a string representation of this cursor.
734 735 736 |
# File 'lib/ffi/clang/cursor.rb', line 734 def to_s "Cursor <#{self.kind.to_s.gsub(/^cursor_/, '')}: #{self.spelling}>" end |
#translation_unit? ⇒ Boolean
Check if this cursor is a translation unit.
184 185 186 |
# File 'lib/ffi/clang/cursor.rb', line 184 def translation_unit? Lib.is_translation_unit(kind) != 0 end |
#type ⇒ Object
Get the type of this cursor.
301 302 303 |
# File 'lib/ffi/clang/cursor.rb', line 301 def type Types::Type.create Lib.get_cursor_type(@cursor), @translation_unit end |
#unary_operator_kind ⇒ Object
Get the unary operator kind for a unary operator cursor.
898 899 900 |
# File 'lib/ffi/clang/cursor.rb', line 898 def unary_operator_kind Lib.get_cursor_unary_operator_kind(@cursor) end |
#underlying_type ⇒ Object
Get the underlying type for a typedef cursor.
320 321 322 |
# File 'lib/ffi/clang/cursor.rb', line 320 def Types::Type.create Lib.(@cursor), @translation_unit end |
#unexposed? ⇒ Boolean
Check if this cursor is unexposed.
196 197 198 |
# File 'lib/ffi/clang/cursor.rb', line 196 def unexposed? Lib.is_unexposed(kind) != 0 end |
#usr ⇒ Object
Get the Unified Symbol Resolution (USR) for this cursor.
283 284 285 |
# File 'lib/ffi/clang/cursor.rb', line 283 def usr Lib.extract_string Lib.get_cursor_usr(@cursor) end |
#var_decl_initializer ⇒ Object
Get the initializer expression of a variable declaration.
991 992 993 |
# File 'lib/ffi/clang/cursor.rb', line 991 def var_decl_initializer Cursor.new(Lib.cursor_get_var_decl_initializer(@cursor), @translation_unit) end |
#variadic? ⇒ Boolean
Check if this cursor is variadic.
338 339 340 |
# File 'lib/ffi/clang/cursor.rb', line 338 def variadic? Lib.is_variadic(@cursor) != 0 end |
#virtual? ⇒ Boolean
Check if this is a virtual method.
356 357 358 |
# File 'lib/ffi/clang/cursor.rb', line 356 def virtual? Lib.cxx_method_is_virtual(@cursor) != 0 end |
#virtual_base? ⇒ Boolean
Check if this cursor is a virtual base class.
326 327 328 |
# File 'lib/ffi/clang/cursor.rb', line 326 def virtual_base? Lib.is_virtual_base(@cursor) != 0 end |
#visibility ⇒ Object
Get the visibility of this cursor.
923 924 925 |
# File 'lib/ffi/clang/cursor.rb', line 923 def visibility Lib.get_cursor_visibility(@cursor) end |
#visit_children(&block) ⇒ Object
Visit only direct children without recursing.
530 531 532 |
# File 'lib/ffi/clang/cursor.rb', line 530 def visit_children(&block) each(false, &block) end |