[clang] 3506e42 - Comment AST: Factor out function type extraction in DeclInfo::fill (NFC)

Aaron Puchert via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 9 13:30:37 PST 2021


Author: Aaron Puchert
Date: 2021-11-09T22:30:08+01:00
New Revision: 3506e42ab67eef41a1f27e180e7c552a2ffff7bb

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

LOG: Comment AST: Factor out function type extraction in DeclInfo::fill (NFC)

Reviewed By: gribozavr2

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

Added: 
    

Modified: 
    clang/lib/AST/Comment.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp
index a02cc9d119fe..94f65466ad10 100644
--- a/clang/lib/AST/Comment.cpp
+++ b/clang/lib/AST/Comment.cpp
@@ -221,6 +221,7 @@ void DeclInfo::fill() {
   CurrentDecl = CommentDecl;
 
   Decl::Kind K = CommentDecl->getKind();
+  const TypeSourceInfo *TSI = nullptr;
   switch (K) {
   default:
     // Defaults are should be good for declarations we don't handle explicitly.
@@ -297,72 +298,46 @@ void DeclInfo::fill() {
   case Decl::EnumConstant:
   case Decl::ObjCIvar:
   case Decl::ObjCAtDefsField:
-  case Decl::ObjCProperty: {
-    const TypeSourceInfo *TSI;
+  case Decl::ObjCProperty:
     if (const auto *VD = dyn_cast<DeclaratorDecl>(CommentDecl))
       TSI = VD->getTypeSourceInfo();
     else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(CommentDecl))
       TSI = PD->getTypeSourceInfo();
-    else
-      TSI = nullptr;
-    if (TSI) {
-      TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
-      FunctionTypeLoc FTL;
-      if (getFunctionTypeLoc(TL, FTL)) {
-        ParamVars = FTL.getParams();
-        ReturnType = FTL.getReturnLoc().getType();
-      }
-    }
     Kind = VariableKind;
     break;
-  }
   case Decl::Namespace:
     Kind = NamespaceKind;
     break;
   case Decl::TypeAlias:
-  case Decl::Typedef: {
+  case Decl::Typedef:
     Kind = TypedefKind;
-    // If this is a typedef / using to something we consider a function, extract
-    // arguments and return type.
-    const TypeSourceInfo *TSI =
-        K == Decl::Typedef
-            ? cast<TypedefDecl>(CommentDecl)->getTypeSourceInfo()
-            : cast<TypeAliasDecl>(CommentDecl)->getTypeSourceInfo();
-    if (!TSI)
-      break;
-    TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
-    FunctionTypeLoc FTL;
-    if (getFunctionTypeLoc(TL, FTL)) {
-      Kind = FunctionKind;
-      ParamVars = FTL.getParams();
-      ReturnType = FTL.getReturnLoc().getType();
-    }
+    TSI = cast<TypedefNameDecl>(CommentDecl)->getTypeSourceInfo();
     break;
-  }
   case Decl::TypeAliasTemplate: {
     const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(CommentDecl);
     Kind = TypedefKind;
     TemplateKind = Template;
     TemplateParameters = TAT->getTemplateParameters();
-    TypeAliasDecl *TAD = TAT->getTemplatedDecl();
-    if (!TAD)
-      break;
+    if (TypeAliasDecl *TAD = TAT->getTemplatedDecl())
+      TSI = TAD->getTypeSourceInfo();
+    break;
+  }
+  case Decl::Enum:
+    Kind = EnumKind;
+    break;
+  }
 
-    const TypeSourceInfo *TSI = TAD->getTypeSourceInfo();
-    if (!TSI)
-      break;
+  // If the type is a typedef / using to something we consider a function,
+  // extract arguments and return type.
+  if (TSI) {
     TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
     FunctionTypeLoc FTL;
     if (getFunctionTypeLoc(TL, FTL)) {
-      Kind = FunctionKind;
+      if (Kind == TypedefKind)
+        Kind = FunctionKind;
       ParamVars = FTL.getParams();
       ReturnType = FTL.getReturnLoc().getType();
     }
-    break;
-  }
-  case Decl::Enum:
-    Kind = EnumKind;
-    break;
   }
 
   IsFilled = true;


        


More information about the cfe-commits mailing list