6 void ApplyAnnotation(clang::NamedDecl *decl,
const std::string &key,
const T &values) {
7 const auto &ctx = decl->getASTContext();
9 std::vector<clang::Expr *> args;
10 args.reserve(values.size());
11 for (
size_t i = 0; i < values.size(); ++i) {
13 ctx.getConstantArrayType(
15 llvm::APInt(ctx.getTypeSize(ctx.getSizeType()), values[i].size() + 1),
17 clang::ArraySizeModifier::Normal,
22 clang::StringLiteral::Create(
23 decl->getASTContext(),
25 clang::StringLiteralKind::Ordinary,
30 args.push_back(clang::ConstantExpr::Create(decl->getASTContext(), literal));
34 decl->addAttr(clang::AnnotateAttr::CreateImplicit(
35 decl->getASTContext(),
41 auto GetPath(
const clang::NamedDecl *decl) -> std::deque<std::string> {
42 std::deque<std::string> namespaces;
43 for (; decl; decl = dyn_cast<clang::NamedDecl>(decl->getDeclContext())) {
44 if (
auto name = decl->getName(); !name.empty()) {
45 namespaces.push_front(name.str());
54 const auto isMethod = clang::dyn_cast<clang::CXXMethodDecl>(decl);
58 const auto dirs = GetPath(decl);
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