Skip to content

Commit

Permalink
Comment AST: convert a huge if -- else if statement on Decl's type in…
Browse files Browse the repository at this point in the history
…to a

switch.  Thanks Sean Silva for suggestion!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161225 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
gribozavr committed Aug 3, 2012
1 parent d015f4f commit 5b32a08
Showing 1 changed file with 56 additions and 17 deletions.
73 changes: 56 additions & 17 deletions lib/AST/Comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}

Expand Down

0 comments on commit 5b32a08

Please sign in to comment.