You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB
Ruby

# frozen_string_literal: true
class Dumper
class <<self
alias dump new
end
def initialize parser
@parser = parser
dump_cursor parser.tu.cursor, ''
end
def dump_cursor c, indent
print "#{indent}\e[1m#{c.kind} #{c.spelling}\e[0m"
return puts ' (filtered)' unless @parser.filter[c, nil]
funs = %i(
display_name deleted? declaration? expression? statement? attribute?
access_specifier invalid? location extent type result_type underlying_type
enum_decl_integer_type typedef_type virtual_base? dynamic_call? variadic?
definition? static? virtual? override? defaulted? pure_virtual? const?
enum_value enum_unsigned_value enum_type specialized_template canonical
definition referenced semantic_parent lexical_parent template_kind
num_args linkage bitfield? bitwidth num_overloaded_decls num_arguments
num_template_arguments
)
# public? private? protected? => access_specifier
# translation_unit? preprocessing? unexposed? language usr
puts ':'
funs.each do |x|
str =
case res = c.send(x)
when FFI::Clang::Cursor
"Cursor(#{res.kind}, #{res.spelling})"
when FFI::Clang::Type
"Type(#{res.spelling})"
when FFI::Clang::SourceLocation
"#{res.file}:#{res.line}:#{res.column}"
when FFI::Clang::SourceRange
"#{res.start.file}:#{res.start.line}:#{res.start.column}.."\
"#{res.end.file}:#{res.end.line}:#{res.end.column}"
else
res.inspect
end
puts "#{indent} #{x} = #{str}"
end
c.visit_children do |c2|
dump_cursor c2, indent + ' '
:continue
end
end
end