void created this revision.
void added reviewers: rsmith, rjmccall, aaron.ballman, dblaikie.
Herald added a subscriber: arphaman.
Herald added a project: All.
void requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147743

Files:
  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

Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2857,7 +2857,7 @@
   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;
     }
Index: clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===================================================================
--- clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -228,16 +228,17 @@
 
   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});
+          }
         }
       }
     }
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===================================================================
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1087,7 +1087,7 @@
   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 {
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===================================================================
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1218,7 +1218,7 @@
       SourceLocation FieldLoc = readSourceLocation();
       Designators.push_back(Designator::CreateFieldDesignator(
           Field->getIdentifier(), DotLoc, FieldLoc));
-      Designators.back().setField(Field);
+      Designators.back().setFieldDecl(Field);
       break;
     }
 
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -11663,10 +11663,10 @@
     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
           // different to the already assigned FieldDecl.
           ExprChanged = true;
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2370,7 +2370,7 @@
       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 @@
       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);
@@ -2760,7 +2760,7 @@
 
     // 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.
@@ -3249,7 +3249,7 @@
 
     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;
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -6423,7 +6423,7 @@
       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;
Index: clang/lib/Index/IndexBody.cpp
===================================================================
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -203,9 +203,12 @@
 
   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,12 @@
 
     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(), {}, E);
+          }
+        }
       }
       return true;
     };
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4407,7 +4407,7 @@
   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,
Index: clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
===================================================================
--- clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
+++ clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
@@ -124,10 +124,11 @@
 
   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;
Index: clang/include/clang/Sema/Designator.h
===================================================================
--- clang/include/clang/Sema/Designator.h
+++ clang/include/clang/Sema/Designator.h
@@ -21,7 +21,6 @@
 
 class Expr;
 class IdentifierInfo;
-class Sema;
 
 /// Designator - A designator in a C99 designated initializer.
 ///
@@ -40,17 +39,17 @@
   /// 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 @@
   //===--------------------------------------------------------------------===//
   // 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 @@
 
   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 @@
   //===--------------------------------------------------------------------===//
   // ArrayRangeDesignatorInfo:
 
+  /// Creates a GNU array-range designator.
   static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End,
                                                SourceLocation LBracketLoc,
                                                SourceLocation EllipsisLoc) {
Index: clang/include/clang/AST/Expr.h
===================================================================
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -5157,7 +5157,7 @@
     //===------------------------------------------------------------------===//
     // FieldDesignatorInfo
 
-    /// Initializes a field designator.
+    /// Creates a field designator.
     static Designator CreateFieldDesignator(const IdentifierInfo *FieldName,
                                             SourceLocation DotLoc,
                                             SourceLocation FieldLoc) {
@@ -5168,15 +5168,14 @@
 
     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);
     }
@@ -5194,7 +5193,7 @@
     //===------------------------------------------------------------------===//
     // ArrayOrRangeDesignator
 
-    /// Initializes an array designator.
+    /// Creates an array designator.
     static Designator CreateArrayDesignator(unsigned Index,
                                             SourceLocation LBracketLoc,
                                             SourceLocation RBracketLoc) {
@@ -5204,7 +5203,7 @@
       return D;
     }
 
-    /// Initializes a GNU array-range designator.
+    /// Creates a GNU array-range designator.
     static Designator CreateArrayRangeDesignator(unsigned Index,
                                                  SourceLocation LBracketLoc,
                                                  SourceLocation EllipsisLoc,
@@ -5240,12 +5239,6 @@
       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();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to