visit_children_cpp.rb 691 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env ruby
  2. require "clangc"
  3. source_file = "#{File.expand_path(File.dirname(__FILE__))}/source1.cpp"
  4. clang_headers_path = Dir.glob("/usr/lib/clang/*/include").collect {|x| "-I#{x}"}
  5. index = Clangc::Index.new(false, true)
  6. tu = index.create_translation_unit_from_source_file(source_file,
  7. ['-x'] +['c++'] +
  8. clang_headers_path)
  9. exit unless tu
  10. cursor = tu.cursor
  11. Clangc.visit_children(cursor: cursor) do |cursor, parent|
  12. puts cursor
  13. puts parent
  14. end
  15. myproc = proc do |cursor, parent|
  16. puts cursor
  17. puts parent
  18. end
  19. Clangc.visit_children(cursor: cursor, visitor: myproc)