[cfe-commits] r128878 - /cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Chandler Carruth chandlerc at gmail.com
Mon Apr 4 23:48:00 PDT 2011


Author: chandlerc
Date: Tue Apr  5 01:48:00 2011
New Revision: 128878

URL: http://llvm.org/viewvc/llvm-project?rev=128878&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=128878&r1=128877&r2=128878&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Apr  5 01:48:00 2011
@@ -379,40 +379,43 @@
 //===----------------------------------------------------------------------===//
 
 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;
 }





More information about the cfe-commits mailing list