32 ASTContext &Context,
const Stmt &Statement, StringRef QualifiedName) {
38 if (AddedUsing.count(std::make_pair(Function, QualifiedName.str())) != 0)
41 SourceLocation InsertLoc = Lexer::getLocForEndOfToken(
42 Function->getBody()->getBeginLoc(), 0, SourceMgr, Context.getLangOpts());
45 if (SourceMgr.getFileID(InsertLoc) != SourceMgr.getMainFileID())
50 bool AlreadyHasUsingDecl =
51 !match(stmt(hasAncestor(decl(has(usingDecl(hasAnyUsingShadowDecl(
52 hasTargetDecl(hasName(QualifiedName.str())))))))),
55 if (AlreadyHasUsingDecl) {
56 AddedUsing.emplace(Function, QualifiedName.str());
60 auto ConflictingDecl = namedDecl(hasName(UnqualifiedName));
61 bool HasConflictingDeclaration =
62 !match(findAll(ConflictingDecl), *Function, Context).empty();
63 bool HasConflictingDeclRef =
64 !match(findAll(declRefExpr(to(ConflictingDecl))), *Function, Context)
66 if (HasConflictingDeclaration || HasConflictingDeclRef)
69 std::string Declaration =
70 (llvm::Twine(
"\nusing ") + QualifiedName +
";").str();
72 AddedUsing.emplace(Function, QualifiedName.str());
73 return FixItHint::CreateInsertion(InsertLoc, Declaration);