20#include <llvm/Support/CommandLine.h>
24 constexpr char Delimiter =
'\\';
49 void ApplyAnnotation(clang::NamedDecl *decl,
const std::string &key,
const std::string* values,
const size_t valuesSize) {
50 auto &ctx = decl->getASTContext();
65 for (
auto i = 0; i < valuesSize; ++i) {
66 ss << Delimiter << values[i];
69 const auto attr = clang::AnnotateAttr::CreateImplicit(ctx, ss.str(),
nullptr, 0);
74 auto GetPath(
const clang::NamedDecl *decl) -> std::vector<std::string> {
75 std::vector<std::string> namespaces;
76 for (; decl; decl = dyn_cast<clang::NamedDecl>(decl->getDeclContext())) {
77 if (
auto name = decl->getDeclName().getAsString(); !name.empty()) {
78 namespaces.insert(namespaces.begin(), name);
88 std::stringstream ss{ annotation };
89 for (std::string term; std::getline(ss, term, Delimiter); key =
false) {
99 const auto isMethod = clang::dyn_cast<clang::CXXMethodDecl>(decl);
103 const auto dirs = GetPath(decl);
104 ApplyAnnotation(decl,
prefix::Path, dirs.data(), dirs.size());
constexpr std::string Path
constexpr std::string Type
constexpr std::string Method
constexpr std::string Function
void CreateAnnotation(clang::FunctionDecl *decl)
Annotate a declaration with its information that may be lost.
constexpr std::string Namespace
std::vector< std::string > Values
Annotation(const std::string &annotation)