void VariableRefactorer::visitDeclRefExpr(const clang::DeclRefExpr *Expr) { if (!isVictim(Expr->getDecl())) return; addReplacement(Expr->getNameInfo().getLoc()); }
void VariableRefactorer::visitVarDecl(const clang::VarDecl *Decl) { if (!isVictim(Decl)) return; addReplacement(Decl->getLocation()); }
void VariableRefactorer::visitMemberExpr(const clang::MemberExpr *Expr) { auto Decl = Expr->getMemberDecl(); if (!clang::dyn_cast<clang::FieldDecl>(Decl) || !isVictim(Decl)) return; addReplacement(Expr->getMemberLoc()); }
void VariableRefactorer::visitCXXConstructorDecl( const clang::CXXConstructorDecl *Decl) { /* Handle field declarations initialized in an initializer list */ if (!Decl->hasBody()) return; for (const auto &Init : Decl->inits()) { if (!Init->isMemberInitializer() || !Init->isWritten()) continue; if (!isVictim(Init->getMember())) continue; addReplacement(Init->getSourceLocation()); } }
void VariableRefactorer::visitUsingDecl(const clang::UsingDecl *Decl) { /* * This function handles the following case: * namespace n { int x; } * * void f() { using n::x; x = 0; } * ^(1) * * The 'using n::x' creates a 'UsingShadowDecl' which references a * possible 'VarDecl'. */ for (const auto &SDecl : Decl->shadows()) { auto NamedDecl = SDecl->getUnderlyingDecl(); auto VarDecl = clang::dyn_cast<clang::VarDecl>(NamedDecl); if (VarDecl && isVictim(VarDecl)) { addReplacement(Decl->getLocation()); break; } } }
void HelpWriterContext::Impl::initDefaultReplacements() { const char *program = getProgramContext().programName(); addReplacement("[PROGRAM]", program); }