diagnostics_display_examples.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env ruby
  2. require "clangc"
  3. # excludeDeclsFromPCH = 0, displayDiagnostics=0
  4. cindex = Clangc::Index.new(false, false)
  5. clang_headers_path = Dir.glob("/usr/lib/clang/*/include").collect {|x| "-I#{x}"}
  6. source = "#{File.expand_path(File.dirname(__FILE__))}/list.c"
  7. tu = cindex.parse_translation_unit(source: source,
  8. args: clang_headers_path,
  9. flags: :none)
  10. exit unless tu
  11. tu.diagnostics.each_with_index do |diagnostic, index|
  12. puts "################### Diagnostic N° #{index + 1 } #####################"
  13. puts "Default display options:"
  14. puts "\t #{diagnostic.format(Clangc::default_diagnostic_display_options)}"
  15. puts "None:"
  16. puts "\t #{diagnostic.format(0)}"
  17. puts "None + Source Location:"
  18. # Clangc::DiagnosticDisplayOptions::DISPLAY_SOURCE_LOCATION
  19. puts "\t #{diagnostic.format(:display_source_location)}"
  20. puts "None + Source Location + Column:"
  21. # Clangc::DiagnosticDisplayOptions::DISPLAY_SOURCE_LOCATION |
  22. # Clangc::DiagnosticDisplayOptions::DISPLAY_COLUMN
  23. puts "\t #{diagnostic.format([:display_source_location, :display_column])}"
  24. puts "None + Source Location + Column + Category Name:"
  25. # Clangc::DiagnosticDisplayOptions::DISPLAY_SOURCE_LOCATION |
  26. # Clangc::DiagnosticDisplayOptions::DISPLAY_COLUMN |
  27. # Clangc::DiagnosticDisplayOptions::DISPLAY_CATEGORY_NAME
  28. puts "\t #{diagnostic.format([:display_source_location,
  29. :display_column,
  30. :display_category_name])}"
  31. end