clang-ast: argument is source file. show CXXMethod also.
This commit is contained in:
parent
68cd43d3f9
commit
f44f726e10
|
@ -16,10 +16,15 @@ std::ostream& operator<<(std::ostream& stream, const CXString& str)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
if (argc == 1) {
|
||||||
|
std::cerr << "No source file\n";
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
CXIndex index = clang_createIndex(0, 0);
|
CXIndex index = clang_createIndex(0, 0);
|
||||||
CXTranslationUnit unit = clang_parseTranslationUnit(
|
CXTranslationUnit unit = clang_parseTranslationUnit(
|
||||||
index,
|
index,
|
||||||
"file1.cpp", argv, argc,
|
argv[1], nullptr, 0,
|
||||||
nullptr, 0,
|
nullptr, 0,
|
||||||
CXTranslationUnit_None);
|
CXTranslationUnit_None);
|
||||||
if (unit == nullptr) {
|
if (unit == nullptr) {
|
||||||
|
@ -35,13 +40,14 @@ int main(int argc, char **argv)
|
||||||
cursor,
|
cursor,
|
||||||
[](CXCursor c, CXCursor parent, CXClientData client_data) {
|
[](CXCursor c, CXCursor parent, CXClientData client_data) {
|
||||||
switch (clang_getCursorKind(c)) {
|
switch (clang_getCursorKind(c)) {
|
||||||
case CXCursor_FunctionDecl: {
|
case CXCursor_FunctionDecl:
|
||||||
|
case CXCursor_CXXMethod: {
|
||||||
CXSourceLocation location = clang_getCursorLocation(c);
|
CXSourceLocation location = clang_getCursorLocation(c);
|
||||||
CXString filename;
|
CXString filename;
|
||||||
unsigned int line, column;
|
unsigned int line, column;
|
||||||
clang_getPresumedLocation(location, &filename, &line, &column);
|
clang_getPresumedLocation(location, &filename, &line, &column);
|
||||||
|
|
||||||
std::cout << "<FunctionDecl"
|
std::cout << "<" << clang_getCursorKindSpelling(clang_getCursorKind(c))
|
||||||
<< " name=\"" << clang_getCursorSpelling(c) << '\"'
|
<< " name=\"" << clang_getCursorSpelling(c) << '\"'
|
||||||
<< " filename=\"" << filename << '\"'
|
<< " filename=\"" << filename << '\"'
|
||||||
<< " line=\"" << line << '\"'
|
<< " line=\"" << line << '\"'
|
||||||
|
|
Loading…
Reference in New Issue