/
test-libclang.p6
39 lines (30 loc) · 1020 Bytes
/
test-libclang.p6
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
36
37
38
39
use v6;
use NativeCall;
use lib 'lib';
use Libclang::Raw;
sub visitChildren(Pointer[CXCursor] $cursor, Pointer[CXCursor] $parent) {
my $spelling = clang_getCursorSpelling($cursor);
my $kind = clang_getCursorKind($cursor);
my $kind-spelling = clang_getCursorKindSpelling($kind);
printf("Cursor '%s' of kind '%s'\n", $spelling, $kind-spelling);
return CXChildVisit_Recurse;
}
printf("libclang version '%s'\n", clang_getClangVersion);
my $index = clang_createIndex(0, 0);
LEAVE clang_disposeIndex($index);
my $null-ptr = Pointer.new;
my $unit = clang_parseTranslationUnit(
$index,
$*SPEC.catfile($*PROGRAM.IO.parent, "header.hpp"),
$null-ptr,
0,
$null-ptr,
0,
CXTranslationUnit_None
);
die "Unable to parse translation unit. Quitting."
unless $unit.defined;
LEAVE clang_disposeTranslationUnit($unit) if $unit.defined;
my $cursor-ptr = clang_getTranslationUnitCursor($unit);
LEAVE free($cursor-ptr) if $cursor-ptr.defined;
clang_visitChildren($cursor-ptr, &visitChildren);