Skip to content

Commit 57d3266

Browse files
[WIP] extract comments
1 parent 0e2e57d commit 57d3266

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ CPPINTEROP_API bool IsVariable(TCppScope_t scope);
375375
/// namespace, variable, or a function).
376376
CPPINTEROP_API std::string GetName(TCppScope_t klass);
377377

378+
CPPINTEROP_API std::string GetDocString(TCppScope_t scope);
379+
378380
/// This is similar to GetName() function, but besides
379381
/// the name, it also gets the template arguments.
380382
CPPINTEROP_API std::string GetCompleteName(TCppScope_t klass);

lib/CppInterOp/CppInterOp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Compatibility.h"
1313

1414
#include "clang/AST/Attrs.inc"
15+
#include "clang/AST/Comment.h"
1516
#include "clang/AST/CXXInheritance.h"
1617
#include "clang/AST/Decl.h"
1718
#include "clang/AST/DeclAccessPair.h"
@@ -613,6 +614,15 @@ bool IsVariable(TCppScope_t scope) {
613614
return llvm::isa_and_nonnull<clang::VarDecl>(D);
614615
}
615616

617+
std::string GetDocString(TCppScope_t scope) {
618+
auto *D = static_cast<Decl*>(scope);
619+
auto &AST = getASTContext(D);
620+
const clang::RawComment *Comment = AST.getRawCommentForAnyRedecl(D);
621+
if (!Comment)
622+
return "";
623+
return Comment->getFormattedText(AST.getSourceManager(), AST.getDiagnostics());
624+
}
625+
616626
std::string GetName(TCppType_t klass) {
617627
auto* D = (clang::NamedDecl*)klass;
618628

0 commit comments

Comments
 (0)