Skip to content
Open
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
4 changes: 4 additions & 0 deletions lib/ffi_generator/clang/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def spelling
String.from_c(C.get_cursor_spelling(@c)).to_s
end

def attribute?
C.is_attribute(kind) == 1
end

def ==(other)
other.is_a?(self.class) && C.equal_cursors(@c, other.c) == 1
end
Expand Down
12 changes: 11 additions & 1 deletion lib/ffi_generator/generators/from_c_generator/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,17 @@ def read_struct_or_union_declaration(declaration_cursor, comment, name)
last_nested_declaration = nil
struct.fields << { name: field_name, type: field_type, comment: field_comment }
else
raise
if child.attribute?
attr_name = child.extent.tokens.find { |token| token.kind == :identifier }
attr_value = child.extent.tokens.find { |token| token.kind == :literal }
if attr_name
struct.attributes[attr_name.spelling.to_sym] = attr_value ? attr_value.spelling : true
else
raise "Unexpected attribute item #{child}"
end
else
raise "Unrecognized item #{child.kind}"
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Generator
class StructOrUnion < Type

attr_accessor :writer, :name, :description
attr_reader :fields, :oo_functions, :written
attr_reader :fields, :attributes, :oo_functions, :written

def initialize(generator, name, is_union)
@generator = generator
Expand All @@ -12,6 +12,7 @@ def initialize(generator, name, is_union)
@is_union = is_union
@description = []
@fields = []
@attributes = {}
@oo_functions = []
@written = false
end
Expand Down
Loading