From 48b0863f52616cff30b652da6f25503d82afd89b Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 14 Jul 2014 23:12:54 +0000 Subject: [PATCH] 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. llvm-svn: 213009 --- clang/include/clang/AST/ExprCXX.h | 4 ++-- clang/lib/AST/ExprCXX.cpp | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index 4403b0858fc8..517840679949 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/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/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index 1c906789ab7a..31bf432cf9f9 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/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;