Skip to content

Commit f6e0eaa

Browse files
committed
Add ARCHITECT_CLANG_PRINT_CURSORS
1 parent e69cb00 commit f6e0eaa

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

code/library/clang.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,39 @@ namespace architect
99
{
1010
namespace
1111
{
12-
CXChildVisitResult debugVisitor(CXCursor cursor, CXCursor parent, CXClientData clientData)
12+
#ifdef ARCHITECT_CLANG_PRINT_CURSORS
13+
CXChildVisitResult printCursorsVisitor(CXCursor cursor, CXCursor parent, CXClientData clientData)
1314
{
1415
std::string &prefix = *static_cast<std::string *>(clientData);
1516
std::string subPrefix = prefix + " ";
1617

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)));
1920

2021
CXType type = clang_getCursorType(cursor);
2122
std::string typeName(clang_getCString(clang_getTypeSpelling(type)));
2223
std::string typeKindName(clang_getCString(clang_getTypeKindSpelling(type.kind)));
24+
int typeNumTemplateArguments = clang_Type_getNumTemplateArguments(type);
2325

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)));
2929
int cursorNumTemplateArguments = clang_Cursor_getNumTemplateArguments(cursor);
30-
int typeNumTemplateArguments = clang_Type_getNumTemplateArguments(type);
3130

3231
std::cout
33-
<< prefix << kindName << "\n"
32+
<< prefix << cursorKindName << "\n"
3433
<< prefix << " type spelling: " << typeName << "\n"
3534
<< 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"
4040
<< std::endl;
4141

42-
//if (kind == CXCursor_TranslationUnit)
43-
// return CXChildVisit_Break;
44-
4542
if (typeNumTemplateArguments > 0)
4643
{
47-
std::cout << prefix << " Template types:" << std::endl;
44+
std::cout << prefix << " Type template types:" << std::endl;
4845
for (int i = 0; i < typeNumTemplateArguments; ++i)
4946
{
5047
CXType argType = clang_Type_getTemplateArgumentAsType(type, i);
@@ -54,17 +51,14 @@ namespace architect
5451
}
5552
}
5653

57-
if (clang_isReference(kind))
54+
if (clang_isReference(cursorKind))
5855
{
5956
std::cout << prefix << " Reference";
6057
CXCursor refCursor = clang_getCursorReferenced(cursor);
6158
if (!clang_Cursor_isNull(refCursor))
6259
{
6360
std::string refName(clang_getCString(clang_getCursorSpelling(refCursor)));
6461
std::cout << ": " << refName << std::endl;
65-
66-
//clang_visitChildren(refCursor, debugVisitor, clientData);
67-
//debugVisitor(refCursor, cursor, &subPrefix);
6862
}
6963
std::cout << std::endl;
7064
}
@@ -76,10 +70,11 @@ namespace architect
7670
std::cout << prefix << " Parent: " << parentName << std::endl;
7771
}
7872

79-
clang_visitChildren(cursor, debugVisitor, &subPrefix);
73+
clang_visitChildren(cursor, printCursorsVisitor, &subPrefix);
8074

8175
return CXChildVisit_Continue;
8276
}
77+
#endif
8378

8479
class VisitorContext
8580
{
@@ -452,8 +447,10 @@ namespace architect
452447
{
453448
CXCursor rootCursor = clang_getTranslationUnitCursor(translationUnit);
454449

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
457454

458455
VisitorContext context(&registry, &registry.rootNameSpace);
459456
clang_visitChildren(rootCursor, globalVisitor, &context);

premake5.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ flags {
2222
"Unicode",
2323
}
2424

25+
defines {
26+
-- "ARCHITECT_CLANG_PRINT_CURSORS", -- for debugging cursor traversal
27+
}
28+
2529
if formats.clang then defines { "ARCHITECT_CLANG_SUPPORT" } end
2630
if formats.console then defines { "ARCHITECT_CONSOLE_SUPPORT" } end
2731
if formats.dot then defines { "ARCHITECT_DOT_SUPPORT" } end

0 commit comments

Comments
 (0)