@@ -9,42 +9,39 @@ namespace architect
9
9
{
10
10
namespace
11
11
{
12
- CXChildVisitResult debugVisitor (CXCursor cursor, CXCursor parent, CXClientData clientData)
12
+ #ifdef ARCHITECT_CLANG_PRINT_CURSORS
13
+ CXChildVisitResult printCursorsVisitor (CXCursor cursor, CXCursor parent, CXClientData clientData)
13
14
{
14
15
std::string &prefix = *static_cast <std::string *>(clientData);
15
16
std::string subPrefix = prefix + " " ;
16
17
17
- CXCursorKind kind = clang_getCursorKind (cursor);
18
- std::string kindName (clang_getCString (clang_getCursorKindSpelling (kind ))); // debug
18
+ CXCursorKind cursorKind = clang_getCursorKind (cursor);
19
+ std::string cursorKindName (clang_getCString (clang_getCursorKindSpelling (cursorKind )));
19
20
20
21
CXType type = clang_getCursorType (cursor);
21
22
std::string typeName (clang_getCString (clang_getTypeSpelling (type)));
22
23
std::string typeKindName (clang_getCString (clang_getTypeKindSpelling (type.kind )));
24
+ int typeNumTemplateArguments = clang_Type_getNumTemplateArguments (type);
23
25
24
- std::string name (clang_getCString (clang_getCursorSpelling (cursor)));
25
- std::string displayName (clang_getCString (clang_getCursorDisplayName (cursor)));
26
-
27
- std::string usr (clang_getCString (clang_getCursorUSR (cursor)));
28
-
26
+ std::string cursorName (clang_getCString (clang_getCursorSpelling (cursor)));
27
+ std::string cursorDisplayName (clang_getCString (clang_getCursorDisplayName (cursor)));
28
+ std::string cursorUSR (clang_getCString (clang_getCursorUSR (cursor)));
29
29
int cursorNumTemplateArguments = clang_Cursor_getNumTemplateArguments (cursor);
30
- int typeNumTemplateArguments = clang_Type_getNumTemplateArguments (type);
31
30
32
31
std::cout
33
- << prefix << kindName << " \n "
32
+ << prefix << cursorKindName << " \n "
34
33
<< prefix << " type spelling: " << typeName << " \n "
35
34
<< prefix << " type kind spelling: " << typeKindName << " \n "
36
- << prefix << " cursor spelling: " << name << " \n "
37
- << prefix << " cursor display name: " << displayName << " \n "
38
- << prefix << " cursor usr: " << usr << " \n "
39
- // << prefix << " \ cursorNumTemplateArguments << ", " << typeNumTemplateArguments << ">"
35
+ << prefix << " type num template arguments: " << typeNumTemplateArguments << " \n "
36
+ << prefix << " cursor spelling: " << cursorName << " \n "
37
+ << prefix << " cursor display name: " << cursorDisplayName << " \n "
38
+ << prefix << " cursor usr: " << cursorUSR << " \n "
39
+ << prefix << " cursor num template arguments: " << cursorNumTemplateArguments << " \n "
40
40
<< std::endl;
41
41
42
- // if (kind == CXCursor_TranslationUnit)
43
- // return CXChildVisit_Break;
44
-
45
42
if (typeNumTemplateArguments > 0 )
46
43
{
47
- std::cout << prefix << " Template types:" << std::endl;
44
+ std::cout << prefix << " Type template types:" << std::endl;
48
45
for (int i = 0 ; i < typeNumTemplateArguments; ++i)
49
46
{
50
47
CXType argType = clang_Type_getTemplateArgumentAsType (type, i);
@@ -54,17 +51,14 @@ namespace architect
54
51
}
55
52
}
56
53
57
- if (clang_isReference (kind ))
54
+ if (clang_isReference (cursorKind ))
58
55
{
59
56
std::cout << prefix << " Reference" ;
60
57
CXCursor refCursor = clang_getCursorReferenced (cursor);
61
58
if (!clang_Cursor_isNull (refCursor))
62
59
{
63
60
std::string refName (clang_getCString (clang_getCursorSpelling (refCursor)));
64
61
std::cout << " : " << refName << std::endl;
65
-
66
- // clang_visitChildren(refCursor, debugVisitor, clientData);
67
- // debugVisitor(refCursor, cursor, &subPrefix);
68
62
}
69
63
std::cout << std::endl;
70
64
}
@@ -76,10 +70,11 @@ namespace architect
76
70
std::cout << prefix << " Parent: " << parentName << std::endl;
77
71
}
78
72
79
- clang_visitChildren (cursor, debugVisitor , &subPrefix);
73
+ clang_visitChildren (cursor, printCursorsVisitor , &subPrefix);
80
74
81
75
return CXChildVisit_Continue;
82
76
}
77
+ #endif
83
78
84
79
class VisitorContext
85
80
{
@@ -452,8 +447,10 @@ namespace architect
452
447
{
453
448
CXCursor rootCursor = clang_getTranslationUnitCursor (translationUnit);
454
449
455
- // std::string prefix;
456
- // clang_visitChildren(rootCursor, debugVisitor, &prefix);
450
+ #ifdef ARCHITECT_CLANG_PRINT_CURSORS
451
+ std::string prefix;
452
+ clang_visitChildren (rootCursor, printCursorsVisitor, &prefix);
453
+ #endif
457
454
458
455
VisitorContext context (®istry, ®istry.rootNameSpace );
459
456
clang_visitChildren (rootCursor, globalVisitor, &context);
0 commit comments