ffi-clang

FORK: Ruby FFI bindings for my custom patched clang 8.0.
git clone https://git.neptards.moe/neptards/ffi-clang.git
Log | Files | Refs | README

docs.rb (747B)


      1 #!/usr/bin/env ruby
      2 
      3 require 'rainbow'
      4 require 'ffi/clang'
      5 
      6 index = FFI::Clang::Index.new
      7 
      8 # clang -Xclang -ast-dump -fsyntax-only ./examples/docs.cpp
      9 
     10 def title(declaration)
     11 	puts ["Symbol:", Rainbow(declaration.spelling).blue.bright, "Type:", Rainbow(declaration.type.spelling).green, declaration.kind.to_s].join(' ')
     12 end
     13 
     14 ARGV.each do |path|
     15 	translation_unit = index.parse_translation_unit(path)
     16 	
     17 	declarations = translation_unit.cursor.select(&:declaration?)
     18 	
     19 	declarations.each do |declaration|
     20 		title declaration
     21 		
     22 		if location = declaration.location
     23 			puts "Defined at #{location.file}:#{location.line}"
     24 		end
     25 		
     26 		if comment = declaration.comment
     27 			# puts Rainbow(comment.inspect).gray
     28 			puts Rainbow(comment.text)
     29 		end
     30 	end
     31 end