ast_visting_danger_zone.rb 624 B

12345678910111213141516171819202122
  1. #!/usr/bin/env ruby
  2. require "clangc"
  3. source_file = "#{File.expand_path(File.dirname(__FILE__))}/source1.c"
  4. clang_headers_path = Dir.glob("/usr/lib/clang/*/include").collect {|x| "-I#{x}"}
  5. index = Clangc::Index.new(false, false)
  6. tu = index.create_translation_unit_from_source_file(source_file,
  7. clang_headers_path)
  8. exit unless tu
  9. Clangc.visit_children(cursor: tu.cursor) do |cursor, parent|
  10. if cursor.location.spelling[0].name == source_file
  11. puts "#{cursor.spelling} #{cursor.kind}"
  12. end
  13. 1/0
  14. #puts parent.spelling
  15. Clangc::ChildVisitResult::RECURSE
  16. end