libshit

Just some random shit
git clone https://git.neptards.moe/neptards/libshit.git
Log | Files | Refs | Submodules | README | LICENSE

dump.rb (1700B)


      1 # frozen_string_literal: true
      2 
      3 class Dumper
      4   class <<self
      5     alias dump new
      6   end
      7 
      8   def initialize parser
      9     @parser = parser
     10     dump_cursor parser.tu.cursor, ''
     11   end
     12 
     13   def dump_cursor c, indent
     14     print "#{indent}\e[1m#{c.kind} #{c.spelling}\e[0m"
     15     return puts ' (filtered)' unless @parser.filter[c, nil]
     16 
     17     funs = %i(
     18       display_name deleted? declaration? expression? statement? attribute?
     19       access_specifier invalid? location extent type result_type underlying_type
     20       enum_decl_integer_type typedef_type virtual_base? dynamic_call? variadic?
     21       definition? static? virtual? override? defaulted? pure_virtual? const?
     22       enum_value enum_unsigned_value enum_type specialized_template canonical
     23       definition referenced semantic_parent lexical_parent template_kind
     24       num_args linkage bitfield? bitwidth num_overloaded_decls num_arguments
     25       num_template_arguments
     26     )
     27     # public? private? protected? => access_specifier
     28     # translation_unit? preprocessing? unexposed? language usr
     29 
     30     puts ':'
     31     funs.each do |x|
     32       str =
     33         case res = c.send(x)
     34         when FFI::Clang::Cursor
     35           "Cursor(#{res.kind}, #{res.spelling})"
     36         when FFI::Clang::Type
     37           "Type(#{res.spelling})"
     38         when FFI::Clang::SourceLocation
     39           "#{res.file}:#{res.line}:#{res.column}"
     40         when FFI::Clang::SourceRange
     41           "#{res.start.file}:#{res.start.line}:#{res.start.column}.."\
     42           "#{res.end.file}:#{res.end.line}:#{res.end.column}"
     43         else
     44           res.inspect
     45         end
     46       puts "#{indent}  #{x} = #{str}"
     47     end
     48 
     49     c.visit_children do |c2|
     50       dump_cursor c2, indent + '  '
     51       :continue
     52     end
     53   end
     54 end