32 const std::vector<std::string> &Abbreviations) {
34 if (!Function || !Function->hasBody())
37 if (AddedAliases[Function].contains(Namespace.str()))
45 const auto *ExistingAlias = selectFirst<NamedDecl>(
46 "alias", match(functionDecl(hasBody(compoundStmt(has(declStmt(
47 has(namespaceAliasDecl(hasTargetNamespace(hasName(
48 std::string(Namespace))))
52 if (ExistingAlias !=
nullptr) {
53 AddedAliases[Function][Namespace.str()] = ExistingAlias->getName().str();
57 for (
const auto &Abbreviation : Abbreviations) {
58 DeclarationMatcher ConflictMatcher = namedDecl(hasName(Abbreviation));
59 const auto HasConflictingChildren =
60 !match(findAll(ConflictMatcher), *Function, Context).empty();
61 const auto HasConflictingAncestors =
62 !match(functionDecl(hasAncestor(decl(has(ConflictMatcher)))), *Function,
65 if (HasConflictingAncestors || HasConflictingChildren)
68 std::string Declaration =
69 (llvm::Twine(
"\nnamespace ") + Abbreviation +
" = " + Namespace +
";")
72 Lexer::getLocForEndOfToken(Function->getBody()->getBeginLoc(), 0,
73 SourceMgr, Context.getLangOpts());
74 AddedAliases[Function][Namespace.str()] = Abbreviation;
75 return FixItHint::CreateInsertion(Loc, Declaration);