예제 #1
0
void VariableRefactorer::visitDeclRefExpr(const clang::DeclRefExpr *Expr)
{
    if (!isVictim(Expr->getDecl()))
        return;

    addReplacement(Expr->getNameInfo().getLoc());
}
예제 #2
0
void VariableRefactorer::visitVarDecl(const clang::VarDecl *Decl)
{
    if (!isVictim(Decl))
        return;

    addReplacement(Decl->getLocation());
}
예제 #3
0
void VariableRefactorer::visitMemberExpr(const clang::MemberExpr *Expr)
{
    auto Decl = Expr->getMemberDecl();
    if (!clang::dyn_cast<clang::FieldDecl>(Decl) || !isVictim(Decl))
        return;

    addReplacement(Expr->getMemberLoc());
}
예제 #4
0
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());
    }
}
예제 #5
0
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;
        }
    }
}
예제 #6
0
void HelpWriterContext::Impl::initDefaultReplacements()
{
    const char *program = getProgramContext().programName();
    addReplacement("[PROGRAM]", program);
}