-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathdocs.rb
executable file
·35 lines (25 loc) · 856 Bytes
/
docs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2016-2022, by Samuel Williams.
require 'rainbow'
require 'ffi/clang'
index = FFI::Clang::Index.new
# clang -Xclang -ast-dump -fsyntax-only ./examples/docs.cpp
def title(declaration)
puts ["Symbol:", Rainbow(declaration.spelling).blue.bright, "Type:", Rainbow(declaration.type.spelling).green, declaration.kind.to_s].join(' ')
end
ARGV.each do |path|
translation_unit = index.parse_translation_unit(path)
declarations = translation_unit.cursor.select(&:declaration?)
declarations.each do |declaration|
title declaration
if location = declaration.location
puts "Defined at #{location.file}:#{location.line}"
end
if comment = declaration.comment
# puts Rainbow(comment.inspect).gray
puts Rainbow(comment.text)
end
end
end