[clang-tools-extra] b51a03e - [Clang][NFC] Rename methods/vars to reflect their real usage

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 18 13:48:18 PDT 2023


Author: Bill Wendling
Date: 2023-04-18T13:48:08-07:00
New Revision: b51a03e1bbe7ea8868ffb24472fc532d0c00943c

URL: https://github.com/llvm/llvm-project/commit/b51a03e1bbe7ea8868ffb24472fc532d0c00943c
DIFF: https://github.com/llvm/llvm-project/commit/b51a03e1bbe7ea8868ffb24472fc532d0c00943c.diff

LOG: [Clang][NFC] Rename methods/vars to reflect their real usage

The "getField" method is a bit confusing considering we also have a
"getFieldName" method. Instead, use "getFieldDecl" rather than
"getField".

Differential Revision: https://reviews.llvm.org/D147743

Added: 
    

Modified: 
    clang-tools-extra/clangd/FindTarget.cpp
    clang-tools-extra/clangd/XRefs.cpp
    clang/include/clang/AST/Expr.h
    clang/include/clang/Sema/Designator.h
    clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
    clang/lib/AST/Expr.cpp
    clang/lib/Index/IndexBody.cpp
    clang/lib/Sema/SemaCodeComplete.cpp
    clang/lib/Sema/SemaInit.cpp
    clang/lib/Sema/TreeTransform.h
    clang/lib/Serialization/ASTReaderStmt.cpp
    clang/lib/Serialization/ASTWriterStmt.cpp
    clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
    clang/tools/libclang/CIndex.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 1caf70183fdb6..efbd05e2b74d3 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -288,7 +288,7 @@ struct TargetFinder {
         for (const DesignatedInitExpr::Designator &D :
              llvm::reverse(DIE->designators()))
           if (D.isFieldDesignator()) {
-            Outer.add(D.getField(), Flags);
+            Outer.add(D.getFieldDecl(), Flags);
             // We don't know which designator was intended, we assume the outer.
             break;
           }
@@ -808,7 +808,7 @@ llvm::SmallVector<ReferenceLoc> refInStmt(const Stmt *S,
         Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
                                     D.getFieldLoc(),
                                     /*IsDecl=*/false,
-                                    {D.getField()}});
+                                    {D.getFieldDecl()}});
       }
     }
 

diff  --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 9a1bd7dbd2564..23dd72d43d3bb 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1907,7 +1907,7 @@ static QualType typeForNode(const SelectionTree::Node *N) {
         // In .foo.bar we want to jump to bar's type, so find *last* field.
         for (auto &D : llvm::reverse(S->designators()))
           if (D.isFieldDesignator())
-            if (const auto *FD = D.getField())
+            if (const auto *FD = D.getFieldDecl())
               return FD->getType();
         return QualType();
       }

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a9941d9e8af49..a7e28c852d6ec 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -5163,7 +5163,7 @@ class DesignatedInitExpr final
     //===------------------------------------------------------------------===//
     // FieldDesignatorInfo
 
-    /// Initializes a field designator.
+    /// Creates a field designator.
     static Designator CreateFieldDesignator(const IdentifierInfo *FieldName,
                                             SourceLocation DotLoc,
                                             SourceLocation FieldLoc) {
@@ -5174,15 +5174,14 @@ class DesignatedInitExpr final
 
     const IdentifierInfo *getFieldName() const;
 
-    FieldDecl *getField() const {
+    FieldDecl *getFieldDecl() const {
       assert(isFieldDesignator() && "Only valid on a field designator");
       if (FieldInfo.NameOrField & 0x01)
         return nullptr;
-      else
-        return reinterpret_cast<FieldDecl *>(FieldInfo.NameOrField);
+      return reinterpret_cast<FieldDecl *>(FieldInfo.NameOrField);
     }
 
-    void setField(FieldDecl *FD) {
+    void setFieldDecl(FieldDecl *FD) {
       assert(isFieldDesignator() && "Only valid on a field designator");
       FieldInfo.NameOrField = reinterpret_cast<uintptr_t>(FD);
     }
@@ -5200,7 +5199,7 @@ class DesignatedInitExpr final
     //===------------------------------------------------------------------===//
     // ArrayOrRangeDesignator
 
-    /// Initializes an array designator.
+    /// Creates an array designator.
     static Designator CreateArrayDesignator(unsigned Index,
                                             SourceLocation LBracketLoc,
                                             SourceLocation RBracketLoc) {
@@ -5210,7 +5209,7 @@ class DesignatedInitExpr final
       return D;
     }
 
-    /// Initializes a GNU array-range designator.
+    /// Creates a GNU array-range designator.
     static Designator CreateArrayRangeDesignator(unsigned Index,
                                                  SourceLocation LBracketLoc,
                                                  SourceLocation EllipsisLoc,
@@ -5246,12 +5245,6 @@ class DesignatedInitExpr final
       return ArrayOrRangeInfo.RBracketLoc;
     }
 
-    unsigned xgetFirstExprIndex() const {
-      assert((isArrayDesignator() || isArrayRangeDesignator()) &&
-             "Only valid on an array or array-range designator");
-      return ArrayOrRangeInfo.Index;
-    }
-
     SourceLocation getBeginLoc() const LLVM_READONLY {
       if (isFieldDesignator())
         return getDotLoc().isInvalid() ? getFieldLoc() : getDotLoc();

diff  --git a/clang/include/clang/Sema/Designator.h b/clang/include/clang/Sema/Designator.h
index 06045d7ca82e1..244535978d4bf 100644
--- a/clang/include/clang/Sema/Designator.h
+++ b/clang/include/clang/Sema/Designator.h
@@ -21,7 +21,6 @@ namespace clang {
 
 class Expr;
 class IdentifierInfo;
-class Sema;
 
 /// Designator - A designator in a C99 designated initializer.
 ///
@@ -40,17 +39,17 @@ class Designator {
   /// A field designator, e.g., ".x = 42".
   struct FieldDesignatorInfo {
     /// Refers to the field being initialized.
-    const IdentifierInfo *II;
+    const IdentifierInfo *FieldName;
 
     /// The location of the '.' in the designated initializer.
     SourceLocation DotLoc;
 
     /// The location of the field name in the designated initializer.
-    SourceLocation NameLoc;
+    SourceLocation FieldLoc;
 
-    FieldDesignatorInfo(const IdentifierInfo *II, SourceLocation DotLoc,
-                        SourceLocation NameLoc)
-        : II(II), DotLoc(DotLoc), NameLoc(NameLoc) {}
+    FieldDesignatorInfo(const IdentifierInfo *FieldName, SourceLocation DotLoc,
+                        SourceLocation FieldLoc)
+        : FieldName(FieldName), DotLoc(DotLoc), FieldLoc(FieldLoc) {}
   };
 
   /// An array designator, e.g., "[42] = 0".
@@ -112,17 +111,18 @@ class Designator {
   //===--------------------------------------------------------------------===//
   // FieldDesignatorInfo
 
-  static Designator CreateFieldDesignator(const IdentifierInfo *II,
+  /// Creates a field designator.
+  static Designator CreateFieldDesignator(const IdentifierInfo *FieldName,
                                           SourceLocation DotLoc,
-                                          SourceLocation NameLoc) {
+                                          SourceLocation FieldLoc) {
     Designator D(FieldDesignator);
-    new (&D.FieldInfo) FieldDesignatorInfo(II, DotLoc, NameLoc);
+    new (&D.FieldInfo) FieldDesignatorInfo(FieldName, DotLoc, FieldLoc);
     return D;
   }
 
-  const IdentifierInfo *getField() const {
+  const IdentifierInfo *getFieldDecl() const {
     assert(isFieldDesignator() && "Invalid accessor");
-    return FieldInfo.II;
+    return FieldInfo.FieldName;
   }
 
   SourceLocation getDotLoc() const {
@@ -132,12 +132,13 @@ class Designator {
 
   SourceLocation getFieldLoc() const {
     assert(isFieldDesignator() && "Invalid accessor");
-    return FieldInfo.NameLoc;
+    return FieldInfo.FieldLoc;
   }
 
   //===--------------------------------------------------------------------===//
   // ArrayDesignatorInfo:
 
+  /// Creates an array designator.
   static Designator CreateArrayDesignator(Expr *Index,
                                           SourceLocation LBracketLoc) {
     Designator D(ArrayDesignator);
@@ -167,6 +168,7 @@ class Designator {
   //===--------------------------------------------------------------------===//
   // ArrayRangeDesignatorInfo:
 
+  /// Creates a GNU array-range designator.
   static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End,
                                                SourceLocation LBracketLoc,
                                                SourceLocation EllipsisLoc) {

diff  --git a/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h b/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
index 6fb2decf8614a..015dbba26f688 100644
--- a/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ b/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -124,10 +124,11 @@ class RecursiveSymbolVisitor
 
   bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
     for (const DesignatedInitExpr::Designator &D : E->designators()) {
-      if (D.isFieldDesignator() && D.getField()) {
-        const FieldDecl *Decl = D.getField();
-        if (!visit(Decl, D.getFieldLoc(), D.getFieldLoc()))
-          return false;
+      if (D.isFieldDesignator()) {
+        if (const FieldDecl *Decl = D.getFieldDecl()) {
+          if (!visit(Decl, D.getFieldLoc(), D.getFieldLoc()))
+            return false;
+        }
       }
     }
     return true;

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 5050abf1b5b5a..eca78060b7e7b 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4407,7 +4407,7 @@ const IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const {
   assert(isFieldDesignator() && "Only valid on a field designator");
   if (FieldInfo.NameOrField & 0x01)
     return reinterpret_cast<IdentifierInfo *>(FieldInfo.NameOrField & ~0x01);
-  return getField()->getIdentifier();
+  return getFieldDecl()->getIdentifier();
 }
 
 DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty,

diff  --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 8b8235c133023..e5f1764550ffa 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -203,9 +203,12 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
 
   bool VisitDesignatedInitExpr(DesignatedInitExpr *E) {
     for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
-      if (D.isFieldDesignator() && D.getField())
-        return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), Parent,
-                                        ParentDC, SymbolRoleSet(), {}, E);
+      if (D.isFieldDesignator()) {
+        if (const FieldDecl *FD = D.getFieldDecl()) {
+          return IndexCtx.handleReference(FD, D.getFieldLoc(), Parent,
+                                          ParentDC, SymbolRoleSet(), {}, E);
+        }
+      }
     }
     return true;
   }
@@ -417,10 +420,13 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
 
     auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool {
       for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) {
-        if (D.isFieldDesignator() && D.getField())
-          return IndexCtx.handleReference(D.getField(), D.getFieldLoc(),
-                                          Parent, ParentDC, SymbolRoleSet(),
-                                          {}, E);
+        if (D.isFieldDesignator()) {
+          if (const FieldDecl *FD = D.getFieldDecl()) {
+            return IndexCtx.handleReference(FD, D.getFieldLoc(), Parent,
+                                            ParentDC, SymbolRoleSet(),
+                                            /*Relations=*/{}, E);
+          }
+        }
       }
       return true;
     };

diff  --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index 7dc645b94aa61..2073df0305166 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6423,7 +6423,7 @@ static QualType getDesignatedType(QualType BaseType, const Designation &Desig) {
       assert(D.isFieldDesignator());
       auto *RD = getAsRecordDecl(BaseType);
       if (RD && RD->isCompleteDefinition()) {
-        for (const auto *Member : RD->lookup(D.getField()))
+        for (const auto *Member : RD->lookup(D.getFieldDecl()))
           if (const FieldDecl *FD = llvm::dyn_cast<FieldDecl>(Member)) {
             NextType = FD->getType();
             break;

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index be46191a19b93..018ba5ed1bce4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2370,7 +2370,7 @@ static void ExpandAnonymousFieldDesignator(Sema &SemaRef,
       Replacements.push_back(Designator::CreateFieldDesignator(
           (IdentifierInfo *)nullptr, SourceLocation(), SourceLocation()));
     assert(isa<FieldDecl>(*PI));
-    Replacements.back().setField(cast<FieldDecl>(*PI));
+    Replacements.back().setFieldDecl(cast<FieldDecl>(*PI));
   }
 
   // Expand the current designator into the set of replacement
@@ -2591,7 +2591,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
       return true;
     }
 
-    FieldDecl *KnownField = D->getField();
+    FieldDecl *KnownField = D->getFieldDecl();
     if (!KnownField) {
       const IdentifierInfo *FieldName = D->getFieldName();
       DeclContext::lookup_result Lookup = RT->getDecl()->lookup(FieldName);
@@ -2762,7 +2762,7 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
 
     // Update the designator with the field declaration.
     if (!VerifyOnly)
-      D->setField(*Field);
+      D->setFieldDecl(*Field);
 
     // Make sure that our non-designated initializer list has space
     // for a subobject corresponding to this field.
@@ -3251,7 +3251,7 @@ ExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
 
     if (D.isFieldDesignator()) {
       Designators.push_back(ASTDesignator::CreateFieldDesignator(
-          D.getField(), D.getDotLoc(), D.getFieldLoc()));
+          D.getFieldDecl(), D.getDotLoc(), D.getFieldLoc()));
     } else if (D.isArrayDesignator()) {
       Expr *Index = static_cast<Expr *>(D.getArrayIndex());
       llvm::APSInt IndexValue;

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index e788f196e7780..1d09450454262 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -11663,10 +11663,10 @@ TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
     if (D.isFieldDesignator()) {
       Desig.AddDesignator(Designator::CreateFieldDesignator(
           D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
-      if (D.getField()) {
+      if (D.getFieldDecl()) {
         FieldDecl *Field = cast_or_null<FieldDecl>(
-            getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
-        if (Field != D.getField())
+            getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
+        if (Field != D.getFieldDecl())
           // Rebuild the expression when the transformed FieldDecl is
           // 
diff erent to the already assigned FieldDecl.
           ExprChanged = true;

diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index 032f685a872e8..cfe0dd121f5f7 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1218,7 +1218,7 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
       SourceLocation FieldLoc = readSourceLocation();
       Designators.push_back(Designator::CreateFieldDesignator(
           Field->getIdentifier(), DotLoc, FieldLoc));
-      Designators.back().setField(Field);
+      Designators.back().setFieldDecl(Field);
       break;
     }
 

diff  --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 021765b69edea..b3fa1cb3d5dec 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1087,7 +1087,7 @@ void ASTStmtWriter::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
   Record.push_back(E->usesGNUSyntax());
   for (const DesignatedInitExpr::Designator &D : E->designators()) {
     if (D.isFieldDesignator()) {
-      if (FieldDecl *Field = D.getField()) {
+      if (FieldDecl *Field = D.getFieldDecl()) {
         Record.push_back(serialization::DESIG_FIELD_DECL);
         Record.AddDeclRef(Field);
       } else {

diff  --git a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
index aecfffcbef1fa..9cdeeec0574b4 100644
--- a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -228,16 +228,17 @@ class RenameLocFinder : public RecursiveASTVisitor<RenameLocFinder> {
 
   bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
     for (const DesignatedInitExpr::Designator &D : E->designators()) {
-      if (D.isFieldDesignator() && D.getField()) {
-        const FieldDecl *Decl = D.getField();
-        if (isInUSRSet(Decl)) {
-          auto StartLoc = D.getFieldLoc();
-          auto EndLoc = D.getFieldLoc();
-          RenameInfos.push_back({StartLoc, EndLoc,
-                                 /*FromDecl=*/nullptr,
-                                 /*Context=*/nullptr,
-                                 /*Specifier=*/nullptr,
-                                 /*IgnorePrefixQualifiers=*/true});
+      if (D.isFieldDesignator()) {
+        if (const FieldDecl *Decl = D.getFieldDecl()) {
+          if (isInUSRSet(Decl)) {
+            auto StartLoc = D.getFieldLoc();
+            auto EndLoc = D.getFieldLoc();
+            RenameInfos.push_back({StartLoc, EndLoc,
+                                   /*FromDecl=*/nullptr,
+                                   /*Context=*/nullptr,
+                                   /*Specifier=*/nullptr,
+                                   /*IgnorePrefixQualifiers=*/true});
+          }
         }
       }
     }

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 30416e46ce173..bb536112e2094 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2857,7 +2857,7 @@ void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
   for (const DesignatedInitExpr::Designator &D :
        llvm::reverse(E->designators())) {
     if (D.isFieldDesignator()) {
-      if (FieldDecl *Field = D.getField())
+      if (const FieldDecl *Field = D.getFieldDecl())
         AddMemberRef(Field, D.getFieldLoc());
       continue;
     }


        


More information about the cfe-commits mailing list