status.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env ruby
  2. require "rtruckboris"
  3. require "term/ansicolor"
  4. def colorize(color, string)
  5. if color.is_a?(String)
  6. color = color.to_s
  7. elsif !color.is_a?(Symbol)
  8. raise "You should pass a string or a symbol"
  9. exit
  10. end
  11. "#{Term::ANSIColor.send(color.to_sym)}#{string}#{Term::ANSIColor.clear} "
  12. end
  13. def is_object_generator(f, object_name)
  14. if f.name.match(/.*2\z/)
  15. f.parameters.each do |p|
  16. if p.type.name.match(/#{object_name}/)
  17. return true
  18. end
  19. end
  20. false
  21. elsif f.return_type.name.match(/^#{object_name}$/)
  22. return true
  23. else
  24. false
  25. end
  26. end
  27. def is_object_method(f, object_name)
  28. f.parameters.each do |p|
  29. if p.type.name.match(/^#{object_name}$/)
  30. return true
  31. end
  32. end
  33. false
  34. end
  35. def display_infos(object_name, generators, methods, wrapped_methods = [])
  36. puts "#{colorize(:bold,object_name)} related functions"
  37. puts "\t#{colorize(:underscore,"Generators")}"
  38. generators.each do |g|
  39. gname = g.name
  40. if wrapped_methods.include?(gname)
  41. puts "\t\t#{colorize(:black,gname)}"
  42. else
  43. puts "\t\t#{gname}"
  44. end
  45. end
  46. # Sort on arguments number
  47. methods.sort! {|a,b| a.parameters_num <=> b.parameters_num}
  48. puts "\t#{colorize(:underscore,"Methods")} (order based on arguments number)"
  49. output_types = []
  50. input_types = []
  51. methods.each do |m|
  52. m.parameters.each do |p|
  53. input_types << p.type.name unless input_types.include?(p.type.name)
  54. end
  55. mname = m.name
  56. if wrapped_methods.include?(mname)
  57. puts "\t\t#{m.parameters_num} __ #{colorize(:black,mname)}"
  58. else
  59. puts "\t\t#{m.parameters_num} __ #{mname}"
  60. end
  61. output_types << m.return_type.name unless output_types.include?(m.return_type.name)
  62. end
  63. # puts "ouput_types:\n #{output_types.join(" ")}"
  64. # puts "input_types:\n #{input_types.join(" ")}"
  65. end
  66. def sumup_module_functions(functions, wrapped_methods = [])
  67. puts "#{colorize(:bold,"Module")} functions"
  68. functions.each do |f|
  69. if f.parameters.size == 0
  70. fname = f.name
  71. if wrapped_methods.include?(fname)
  72. puts "\t\t#{colorize(:black,fname)}"
  73. else
  74. puts "\t\t#{fname}"
  75. end
  76. end
  77. end
  78. end
  79. def sumup_objects(functions, objects, wrapped_methods = [])
  80. objects.each do |obj|
  81. obj_generators = []
  82. obj_methods = []
  83. functions.each do |f|
  84. obj_generators << f if is_object_generator(f, obj)
  85. obj_methods << f if is_object_method(f, obj)
  86. end
  87. display_infos(obj, obj_generators, obj_methods, wrapped_methods)
  88. end
  89. end
  90. # Get clang functions in the C code written
  91. CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
  92. SRC_FILES = Dir.glob("#{CURRENT_PATH}/../ext/clangc/*.[c|h]")
  93. MANAGED_FUNCTIONS = []
  94. SRC_FILES.each do |file|
  95. f = File.open(file, 'r')
  96. while !f.eof?
  97. line = f.readline
  98. if /(?<clang_function>clang_\w+)/ =~ line
  99. MANAGED_FUNCTIONS << clang_function
  100. end
  101. end
  102. end
  103. MANAGED_FUNCTIONS.uniq!
  104. # Get a list of all Clang functions
  105. clang_c = "/usr/include/clang-c/Index.h"
  106. header_paths = []
  107. gcc_lib_base='/usr/lib/gcc/' << `llvm-config --host-target`.chomp << "/*"
  108. gcc_lib = Dir.glob(gcc_lib_base ).sort.last + "/include"
  109. header_paths << gcc_lib
  110. header_paths << "/usr/include"
  111. header_paths << "/usr/include/clang-c"
  112. parser = Rtruckboris::HeaderParser.new(clang_c, header_paths)
  113. unless parser.parse(true)
  114. puts "Can't parse"
  115. exit
  116. end
  117. functions = parser.functions
  118. count = 0
  119. functions.each do |f|
  120. count += 1 if MANAGED_FUNCTIONS.include?(f.name)
  121. end
  122. # print global informations
  123. color = Term::ANSIColor
  124. print color.green, count.to_s, color.clear, "/", color.black, functions.size,
  125. color.clear, " functions wrapped => ", color.yellow,
  126. (count/(functions.size*1.00)) * 100, color.clear, "%\n\n"
  127. # print specific informations
  128. sumup_module_functions(functions, MANAGED_FUNCTIONS)
  129. sumup_objects(functions, ["CXIndex", "CXTranslationUnit", "CXDiagnostic", "CXFile","CXSourceRange", "CXSourceLocation", "CXCursor", "CXType"], MANAGED_FUNCTIONS)
  130. print "\n", color.green, count.to_s, color.clear, "/", color.black, functions.size,
  131. color.clear, " functions wrapped => ", color.yellow,
  132. (count/(functions.size*1.00)) * 100, color.clear, "%\n\n"