Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose libclang's anonymous methods. #79

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/ffi/clang/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def completion
CodeCompletion::String.new Lib.get_cursor_completion_string(@cursor)
end

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

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

def declaration?
Lib.is_declaration(kind) != 0
end
Expand Down
2 changes: 2 additions & 0 deletions lib/ffi/clang/lib/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ class CXCursorAndRangeVisitor < FFI::Struct
attach_function :find_references_in_file, :clang_findReferencesInFile, [CXCursor.by_value, :CXFile, CXCursorAndRangeVisitor.by_value], :result

attach_function :get_cursor_type, :clang_getCursorType, [CXCursor.by_value], CXType.by_value
attach_function :cursor_is_anonymous, :clang_Cursor_isAnonymous, [CXCursor.by_value], :uint
attach_function :cursor_is_anonymous_record_decl, :clang_Cursor_isAnonymousRecordDecl, [CXCursor.by_value], :uint
attach_function :get_cursor_result_type, :clang_getCursorResultType, [CXCursor.by_value], CXType.by_value
attach_function :get_typedef_decl_underlying_type, :clang_getTypedefDeclUnderlyingType, [CXCursor.by_value], CXType.by_value
attach_function :get_enum_decl_integer_type, :clang_getEnumDeclIntegerType, [CXCursor.by_value], CXType.by_value
Expand Down
10 changes: 10 additions & 0 deletions spec/ffi/clang/cursor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
let(:cursor_canon) { Index.new.parse_translation_unit(fixture_path("canonical.c")).cursor }
let(:cursor_pp) { Index.new.parse_translation_unit(fixture_path("docs.c"),[],[],[:detailed_preprocessing_record]).cursor }
let(:cursor_forward) { Index.new.parse_translation_unit(fixture_path("forward.h")).cursor }
let(:cursor_anonymous) { Index.new.parse_translation_unit(fixture_path("anonymous.h")).cursor }

it "can be obtained from a translation unit" do
expect(cursor).to be_kind_of(Cursor)
Expand Down Expand Up @@ -822,4 +823,13 @@
end
end
end

describe '#anonymous' do
let(:struct) { find_matching(cursor_anonymous) { |child, parent|
child.kind == :cursor_struct } }

it "is an an anonymous structure" do
expect(struct.anonymous?).to eq(true)
end
end
end
16 changes: 16 additions & 0 deletions spec/ffi/clang/fixtures/anonymous.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ANONYMOUS_H
#define ANONYMOUS_H

// This variable has an anonymous structure type
struct
{
int field1;
} someVariable;

struct A
{
struct
{
int field2;
} anonymousField;
}