From: Dmitri Gribenko Date: Fri, 3 Aug 2012 00:01:01 +0000 (+0000) Subject: Comment AST: convert a huge if -- else if statement on Decl's type into a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5b32a08abe5530e9294b7b373cc70199b9e2fca4;p=clang Comment AST: convert a huge if -- else if statement on Decl's type into a switch. Thanks Sean Silva for suggestion! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161225 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Comment.cpp b/lib/AST/Comment.cpp index ba68cee734..645aea7ee9 100644 --- a/lib/AST/Comment.cpp +++ b/lib/AST/Comment.cpp @@ -151,8 +151,22 @@ void DeclInfo::fill() { TemplateParameters = NULL; if (!ThisDecl) { - // Defaults are OK. - } else if (const FunctionDecl *FD = dyn_cast(ThisDecl)) { + // If there is no declaration, the defaults is our only guess. + IsFilled = true; + return; + } + + Decl::Kind K = ThisDecl->getKind(); + switch (K) { + default: + // Defaults are should be good for declarations we don't handle explicitly. + break; + case Decl::Function: + case Decl::CXXMethod: + case Decl::CXXConstructor: + case Decl::CXXDestructor: + case Decl::CXXConversion: { + const FunctionDecl *FD = cast(ThisDecl); Kind = FunctionKind; ParamVars = ArrayRef(FD->param_begin(), FD->getNumParams()); @@ -164,53 +178,78 @@ void DeclInfo::fill() { FD->getTemplateParameterList(NumLists - 1); } - if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (K == Decl::CXXMethod) { + const CXXMethodDecl *MD = cast(ThisDecl); IsInstanceMethod = MD->isInstance(); IsClassMethod = !IsInstanceMethod; } - } else if (const ObjCMethodDecl *MD = dyn_cast(ThisDecl)) { + break; + } + case Decl::ObjCMethod: { + const ObjCMethodDecl *MD = cast(ThisDecl); Kind = FunctionKind; ParamVars = ArrayRef(MD->param_begin(), MD->param_size()); IsInstanceMethod = MD->isInstanceMethod(); IsClassMethod = !IsInstanceMethod; - } else if (const FunctionTemplateDecl *FTD = - dyn_cast(ThisDecl)) { + break; + } + case Decl::FunctionTemplate: { + const FunctionTemplateDecl *FTD = cast(ThisDecl); Kind = FunctionKind; IsTemplateDecl = true; const FunctionDecl *FD = FTD->getTemplatedDecl(); ParamVars = ArrayRef(FD->param_begin(), FD->getNumParams()); TemplateParameters = FTD->getTemplateParameters(); - } else if (const ClassTemplateDecl *CTD = - dyn_cast(ThisDecl)) { + break; + } + case Decl::ClassTemplate: { + const ClassTemplateDecl *CTD = cast(ThisDecl); Kind = ClassKind; IsTemplateDecl = true; TemplateParameters = CTD->getTemplateParameters(); - } else if (const ClassTemplatePartialSpecializationDecl *CTPSD = - dyn_cast(ThisDecl)) { + break; + } + case Decl::ClassTemplatePartialSpecialization: { + const ClassTemplatePartialSpecializationDecl *CTPSD = + cast(ThisDecl); Kind = ClassKind; IsTemplateDecl = true; IsTemplatePartialSpecialization = true; TemplateParameters = CTPSD->getTemplateParameters(); - } else if (isa(ThisDecl)) { + break; + } + case Decl::ClassTemplateSpecialization: Kind = ClassKind; IsTemplateDecl = true; IsTemplateSpecialization = true; - } else if (isa(ThisDecl)) { + break; + case Decl::Record: Kind = ClassKind; - } else if (isa(ThisDecl) || isa(ThisDecl)) { + break; + case Decl::Var: + case Decl::Field: + case Decl::ObjCIvar: + case Decl::ObjCAtDefsField: Kind = VariableKind; - } else if (isa(ThisDecl)) { + break; + case Decl::Namespace: Kind = NamespaceKind; - } else if (isa(ThisDecl)) { + break; + case Decl::Typedef: + case Decl::TypeAlias: Kind = TypedefKind; - } else if (const TypeAliasTemplateDecl *TAT = - dyn_cast(ThisDecl)) { + break; + case Decl::TypeAliasTemplate: { + const TypeAliasTemplateDecl *TAT = cast(ThisDecl); Kind = TypedefKind; IsTemplateDecl = true; TemplateParameters = TAT->getTemplateParameters(); + break; } + } + IsFilled = true; }