r197626 - Use getAsCXXRecordDecl to shorten some gets and casts

Jordan Rose jordan_rose at apple.com
Wed Dec 18 15:49:03 PST 2013


Should we add a castAsCXXRecordDecl that does this using cast<> instead of dyn_cast<>? Or is that just not worth the bother?

On Dec 18, 2013, at 15:17, Reid Kleckner <reid at kleckner.net> wrote:

> Author: rnk
> Date: Wed Dec 18 17:17:05 2013
> New Revision: 197626
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=197626&view=rev
> Log:
> Use getAsCXXRecordDecl to shorten some gets and casts
> 
> Modified:
>    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
> 
> Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=197626&r1=197625&r2=197626&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
> +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Dec 18 17:17:05 2013
> @@ -1040,8 +1040,7 @@ RecordLayoutBuilder::LayoutNonVirtualBas
>     if (I->isVirtual())
>       continue;
> 
> -    const CXXRecordDecl *BaseDecl =
> -      cast<CXXRecordDecl>(I->getType()->castAs<RecordType>()->getDecl());
> +    const CXXRecordDecl *BaseDecl = I->getType()->getAsCXXRecordDecl();
> 
>     // Skip the primary base, because we've already laid it out.  The
>     // !PrimaryBaseIsVirtual check is required because we might have a
> @@ -1123,8 +1122,7 @@ RecordLayoutBuilder::LayoutVirtualBases(
>     assert(!I->getType()->isDependentType() &&
>            "Cannot layout class with dependent bases.");
> 
> -    const CXXRecordDecl *BaseDecl =
> -      cast<CXXRecordDecl>(I->getType()->castAs<RecordType>()->getDecl());
> +    const CXXRecordDecl *BaseDecl = I->getType()->getAsCXXRecordDecl();
> 
>     if (I->isVirtual()) {
>       if (PrimaryBase != BaseDecl || !PrimaryBaseIsVirtual) {
> @@ -2345,8 +2343,7 @@ MicrosoftRecordLayoutBuilder::layoutNonV
>        i != e; ++i) {
>     if (i->isVirtual())
>       continue;
> -    const CXXRecordDecl *BaseDecl =
> -        cast<CXXRecordDecl>(i->getType()->castAs<RecordType>()->getDecl());
> +    const CXXRecordDecl *BaseDecl = i->getType()->getAsCXXRecordDecl();
>     if (BaseDecl == PrimaryBase)
>       continue;
>     const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
> @@ -2532,8 +2529,7 @@ void MicrosoftRecordLayoutBuilder::layou
>   for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
>                                                 e = RD->vbases_end();
>        i != e; ++i) {
> -    const CXXRecordDecl *BaseDecl =
> -        cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
> +    const CXXRecordDecl *BaseDecl = i->getType()->getAsCXXRecordDecl();
>     const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
>     updateAlignment(getBaseAlignment(Layout));
>   }
> @@ -2546,8 +2542,7 @@ void MicrosoftRecordLayoutBuilder::layou
>   for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
>                                                 e = RD->vbases_end();
>        i != e; ++i) {
> -    const CXXRecordDecl *BaseDecl =
> -        cast<CXXRecordDecl>(i->getType()->castAs<RecordType>()->getDecl());
> +    const CXXRecordDecl *BaseDecl = i->getType()->getAsCXXRecordDecl();
>     // If the last field we laid out was a non-zero length bitfield then add
>     // some extra padding for no obvious reason.
>     if (LastFieldIsNonZeroWidthBitfield)
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list