[NFC] cosmetic tweaks to ExprMutationAnalyzer to be more consistent
especially considering future changes. llvm-svn: 342340
This commit is contained in:
parent
37a72098ae
commit
cef621d094
|
@ -26,12 +26,14 @@ public:
|
||||||
ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
|
ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
|
||||||
: Stm(Stm), Context(Context) {}
|
: Stm(Stm), Context(Context) {}
|
||||||
|
|
||||||
bool isMutated(const Decl *Dec) { return findDeclMutation(Dec) != nullptr; }
|
|
||||||
bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
|
bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
|
||||||
|
bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; }
|
||||||
const Stmt *findMutation(const Expr *Exp);
|
const Stmt *findMutation(const Expr *Exp);
|
||||||
const Stmt *findDeclMutation(const Decl *Dec);
|
const Stmt *findMutation(const Decl *Dec);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
using ResultMap = llvm::DenseMap<const Expr *, const Stmt *>;
|
||||||
|
|
||||||
bool isUnevaluated(const Expr *Exp);
|
bool isUnevaluated(const Expr *Exp);
|
||||||
|
|
||||||
const Stmt *findExprMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
|
const Stmt *findExprMutation(ArrayRef<ast_matchers::BoundNodes> Matches);
|
||||||
|
@ -50,7 +52,7 @@ private:
|
||||||
llvm::DenseMap<const FunctionDecl *,
|
llvm::DenseMap<const FunctionDecl *,
|
||||||
std::unique_ptr<FunctionParmMutationAnalyzer>>
|
std::unique_ptr<FunctionParmMutationAnalyzer>>
|
||||||
FuncParmAnalyzer;
|
FuncParmAnalyzer;
|
||||||
llvm::DenseMap<const Expr *, const Stmt *> Results;
|
ResultMap Results;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A convenient wrapper around ExprMutationAnalyzer for analyzing function
|
// A convenient wrapper around ExprMutationAnalyzer for analyzing function
|
||||||
|
|
|
@ -131,13 +131,13 @@ ExprMutationAnalyzer::findExprMutation(ArrayRef<BoundNodes> Matches) {
|
||||||
const Stmt *
|
const Stmt *
|
||||||
ExprMutationAnalyzer::findDeclMutation(ArrayRef<BoundNodes> Matches) {
|
ExprMutationAnalyzer::findDeclMutation(ArrayRef<BoundNodes> Matches) {
|
||||||
for (const auto &DeclNodes : Matches) {
|
for (const auto &DeclNodes : Matches) {
|
||||||
if (const Stmt *S = findDeclMutation(DeclNodes.getNodeAs<Decl>("decl")))
|
if (const Stmt *S = findMutation(DeclNodes.getNodeAs<Decl>("decl")))
|
||||||
return S;
|
return S;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Stmt *ExprMutationAnalyzer::findDeclMutation(const Decl *Dec) {
|
const Stmt *ExprMutationAnalyzer::findMutation(const Decl *Dec) {
|
||||||
const auto Refs = match(
|
const auto Refs = match(
|
||||||
findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), Stm, Context);
|
findAll(declRefExpr(to(equalsNode(Dec))).bind("expr")), Stm, Context);
|
||||||
for (const auto &RefNodes : Refs) {
|
for (const auto &RefNodes : Refs) {
|
||||||
|
@ -280,15 +280,14 @@ const Stmt *ExprMutationAnalyzer::findReferenceMutation(const Expr *Exp) {
|
||||||
// Follow non-const reference returned by `operator*()` of move-only classes.
|
// Follow non-const reference returned by `operator*()` of move-only classes.
|
||||||
// These are typically smart pointers with unique ownership so we treat
|
// These are typically smart pointers with unique ownership so we treat
|
||||||
// mutation of pointee as mutation of the smart pointer itself.
|
// mutation of pointee as mutation of the smart pointer itself.
|
||||||
const auto Ref = match(
|
const auto Ref =
|
||||||
findAll(cxxOperatorCallExpr(
|
match(findAll(cxxOperatorCallExpr(
|
||||||
hasOverloadedOperatorName("*"),
|
hasOverloadedOperatorName("*"),
|
||||||
callee(cxxMethodDecl(ofClass(isMoveOnly()),
|
callee(cxxMethodDecl(ofClass(isMoveOnly()),
|
||||||
returns(hasUnqualifiedDesugaredType(
|
returns(nonConstReferenceType()))),
|
||||||
nonConstReferenceType())))),
|
argumentCountIs(1), hasArgument(0, equalsNode(Exp)))
|
||||||
argumentCountIs(1), hasArgument(0, equalsNode(Exp)))
|
.bind("expr")),
|
||||||
.bind("expr")),
|
Stm, Context);
|
||||||
Stm, Context);
|
|
||||||
if (const Stmt *S = findExprMutation(Ref))
|
if (const Stmt *S = findExprMutation(Ref))
|
||||||
return S;
|
return S;
|
||||||
|
|
||||||
|
@ -370,7 +369,7 @@ FunctionParmMutationAnalyzer::FunctionParmMutationAnalyzer(
|
||||||
for (const ParmVarDecl *Parm : Ctor->parameters()) {
|
for (const ParmVarDecl *Parm : Ctor->parameters()) {
|
||||||
if (Results.find(Parm) != Results.end())
|
if (Results.find(Parm) != Results.end())
|
||||||
continue;
|
continue;
|
||||||
if (const Stmt *S = InitAnalyzer.findDeclMutation(Parm))
|
if (const Stmt *S = InitAnalyzer.findMutation(Parm))
|
||||||
Results[Parm] = S;
|
Results[Parm] = S;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,7 +382,7 @@ FunctionParmMutationAnalyzer::findMutation(const ParmVarDecl *Parm) {
|
||||||
if (Memoized != Results.end())
|
if (Memoized != Results.end())
|
||||||
return Memoized->second;
|
return Memoized->second;
|
||||||
|
|
||||||
if (const Stmt *S = BodyAnalyzer.findDeclMutation(Parm))
|
if (const Stmt *S = BodyAnalyzer.findMutation(Parm))
|
||||||
return Results[Parm] = S;
|
return Results[Parm] = S;
|
||||||
|
|
||||||
return Results[Parm] = nullptr;
|
return Results[Parm] = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue