aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/AnalysisBasedWarnings.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-04-05 06:48:00 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-04-05 06:48:00 +0000
commit9f6494687c05fe1d334af76408ee056b5f80e027 (patch)
tree463f0a86fc2c2bcd2565554634c1b8735396ed10 /lib/Sema/AnalysisBasedWarnings.cpp
parente1b02e00d851389415a5b7a1398de26c382887c6 (diff)
Cleanup the style of some of this code prior to functional changes.
I think this moves the code in the desired direction of the new style recommendations (and style conventional in Clang), but if anyone prefers the previous style, or has other suggestions just chime in and I'll follow up. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128878 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r--lib/Sema/AnalysisBasedWarnings.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index ecfa821358..efb71baddb 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -379,40 +379,43 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
//===----------------------------------------------------------------------===//
namespace {
+/// ContainsReference - A visitor class to search for references to
+/// a particular declaration (the needle) within any evaluated component of an
+/// expression (recursively).
class ContainsReference : public EvaluatedExprVisitor<ContainsReference> {
- bool containsReference;
- const DeclRefExpr *dr;
+ bool FoundReference;
+ const DeclRefExpr *Needle;
+
public:
- ContainsReference(ASTContext &context,
- const DeclRefExpr *dr) :
- EvaluatedExprVisitor<ContainsReference>(context),
- containsReference(false), dr(dr) {}
-
- void VisitExpr(Expr *e) {
+ ContainsReference(ASTContext &Context, const DeclRefExpr *Needle)
+ : EvaluatedExprVisitor<ContainsReference>(Context),
+ FoundReference(false), Needle(Needle) {}
+
+ void VisitExpr(Expr *E) {
// Stop evaluating if we already have a reference.
- if (containsReference)
+ if (FoundReference)
return;
-
- EvaluatedExprVisitor<ContainsReference>::VisitExpr(e);
+
+ EvaluatedExprVisitor<ContainsReference>::VisitExpr(E);
}
-
- void VisitDeclRefExpr(DeclRefExpr *e) {
- if (e == dr)
- containsReference = true;
- else
- EvaluatedExprVisitor<ContainsReference>::VisitDeclRefExpr(e);
+
+ void VisitDeclRefExpr(DeclRefExpr *E) {
+ if (E == Needle)
+ FoundReference = true;
+ else
+ EvaluatedExprVisitor<ContainsReference>::VisitDeclRefExpr(E);
}
-
- bool doesContainReference() const { return containsReference; }
+
+ bool doesContainReference() const { return FoundReference; }
};
}
-static bool isSelfInit(ASTContext &context,
- const VarDecl *vd, const DeclRefExpr *dr) {
- if (const Expr *exp = vd->getInit()) {
- ContainsReference contains(context, dr);
- contains.Visit(const_cast<Expr*>(exp));
- return contains.doesContainReference();
+static bool isSelfInit(ASTContext &Context,
+ const VarDecl *VD, const DeclRefExpr *DR) {
+ if (const Expr *E = VD->getInit()) {
+ ContainsReference CR(Context, DR);
+ CR.Visit(const_cast<Expr*>(E));
+ return CR.doesContainReference();
}
return false;
}