From: David Majnemer Date: Mon, 14 Jul 2014 23:12:54 +0000 (+0000) Subject: AST: Cleanup __uuidof related code X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f1cd79083f02d5fc0115f17910c4e2fc1e5393a;p=clang AST: Cleanup __uuidof related code Switch some things to use range-based for loops. Change CXXUuidofExpr::GetUuidAttrOfType's return type to be const. No functionality changed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213009 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 4403b0858f..5178406799 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -737,8 +737,8 @@ public: /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to /// a single GUID. - static UuidAttr *GetUuidAttrOfType(QualType QT, - bool *HasMultipleGUIDsPtr = nullptr); + static const UuidAttr *GetUuidAttrOfType(QualType QT, + bool *HasMultipleGUIDsPtr = nullptr); // Iterators child_range children() { diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 1c906789ab..31bf432cf9 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -55,8 +55,8 @@ QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { } // static -UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, - bool *RDHasMultipleGUIDsPtr) { +const UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, + bool *RDHasMultipleGUIDsPtr) { // Optionally remove one level of pointer, reference or array indirection. const Type *Ty = QT.getTypePtr(); if (QT->isPointerType() || QT->isReferenceType()) @@ -64,7 +64,6 @@ UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, else if (QT->isArrayType()) Ty = Ty->getBaseElementTypeUnsafe(); - // Loop all record redeclaration looking for an uuid attribute. CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); if (!RD) return nullptr; @@ -73,13 +72,12 @@ UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, if (ClassTemplateSpecializationDecl *CTSD = dyn_cast(RD)) { const TemplateArgumentList &TAL = CTSD->getTemplateArgs(); - UuidAttr *UuidForRD = nullptr; + const UuidAttr *UuidForRD = nullptr; - for (unsigned I = 0, N = TAL.size(); I != N; ++I) { - const TemplateArgument &TA = TAL[I]; + for (const TemplateArgument &TA : TAL.asArray()) { bool SeenMultipleGUIDs = false; - UuidAttr *UuidForTA = nullptr; + const UuidAttr *UuidForTA = nullptr; if (TA.getKind() == TemplateArgument::Type) UuidForTA = GetUuidAttrOfType(TA.getAsType(), &SeenMultipleGUIDs); else if (TA.getKind() == TemplateArgument::Declaration) @@ -108,8 +106,9 @@ UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, return UuidForRD; } - for (auto I : RD->redecls()) - if (auto Uuid = I->getAttr()) + // Loop over all record redeclarations looking for a uuid attribute. + for (const TagDecl *I : RD->redecls()) + if (const UuidAttr *Uuid = I->getAttr()) return Uuid; return nullptr;