diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-08-03 00:01:01 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-08-03 00:01:01 +0000 |
commit | 5b32a08abe5530e9294b7b373cc70199b9e2fca4 (patch) | |
tree | 0a94051f1d55711e83fc1341db467ced6581037c /lib/AST/Comment.cpp | |
parent | d015f4febe85d3e3340172d70042840c51bbd836 (diff) |
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
Diffstat (limited to 'lib/AST/Comment.cpp')
-rw-r--r-- | lib/AST/Comment.cpp | 73 |
1 files changed, 56 insertions, 17 deletions
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<FunctionDecl>(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<FunctionDecl>(ThisDecl); Kind = FunctionKind; ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), FD->getNumParams()); @@ -164,53 +178,78 @@ void DeclInfo::fill() { FD->getTemplateParameterList(NumLists - 1); } - if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { + if (K == Decl::CXXMethod) { + const CXXMethodDecl *MD = cast<CXXMethodDecl>(ThisDecl); IsInstanceMethod = MD->isInstance(); IsClassMethod = !IsInstanceMethod; } - } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(ThisDecl)) { + break; + } + case Decl::ObjCMethod: { + const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(ThisDecl); Kind = FunctionKind; ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(), MD->param_size()); IsInstanceMethod = MD->isInstanceMethod(); IsClassMethod = !IsInstanceMethod; - } else if (const FunctionTemplateDecl *FTD = - dyn_cast<FunctionTemplateDecl>(ThisDecl)) { + break; + } + case Decl::FunctionTemplate: { + const FunctionTemplateDecl *FTD = cast<FunctionTemplateDecl>(ThisDecl); Kind = FunctionKind; IsTemplateDecl = true; const FunctionDecl *FD = FTD->getTemplatedDecl(); ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), FD->getNumParams()); TemplateParameters = FTD->getTemplateParameters(); - } else if (const ClassTemplateDecl *CTD = - dyn_cast<ClassTemplateDecl>(ThisDecl)) { + break; + } + case Decl::ClassTemplate: { + const ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(ThisDecl); Kind = ClassKind; IsTemplateDecl = true; TemplateParameters = CTD->getTemplateParameters(); - } else if (const ClassTemplatePartialSpecializationDecl *CTPSD = - dyn_cast<ClassTemplatePartialSpecializationDecl>(ThisDecl)) { + break; + } + case Decl::ClassTemplatePartialSpecialization: { + const ClassTemplatePartialSpecializationDecl *CTPSD = + cast<ClassTemplatePartialSpecializationDecl>(ThisDecl); Kind = ClassKind; IsTemplateDecl = true; IsTemplatePartialSpecialization = true; TemplateParameters = CTPSD->getTemplateParameters(); - } else if (isa<ClassTemplateSpecializationDecl>(ThisDecl)) { + break; + } + case Decl::ClassTemplateSpecialization: Kind = ClassKind; IsTemplateDecl = true; IsTemplateSpecialization = true; - } else if (isa<RecordDecl>(ThisDecl)) { + break; + case Decl::Record: Kind = ClassKind; - } else if (isa<VarDecl>(ThisDecl) || isa<FieldDecl>(ThisDecl)) { + break; + case Decl::Var: + case Decl::Field: + case Decl::ObjCIvar: + case Decl::ObjCAtDefsField: Kind = VariableKind; - } else if (isa<NamespaceDecl>(ThisDecl)) { + break; + case Decl::Namespace: Kind = NamespaceKind; - } else if (isa<TypedefNameDecl>(ThisDecl)) { + break; + case Decl::Typedef: + case Decl::TypeAlias: Kind = TypedefKind; - } else if (const TypeAliasTemplateDecl *TAT = - dyn_cast<TypeAliasTemplateDecl>(ThisDecl)) { + break; + case Decl::TypeAliasTemplate: { + const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(ThisDecl); Kind = TypedefKind; IsTemplateDecl = true; TemplateParameters = TAT->getTemplateParameters(); + break; } + } + IsFilled = true; } |