diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-03-27 04:46:07 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-03-27 04:46:07 +0000 |
commit | 1dbc7a7a5a4836f84d7304762ba93da34a339c52 (patch) | |
tree | 788cff8495e6c05b6510c4ff5d487e7191284006 /clang/lib/AST | |
parent | ff379b69b2f82c9ca9b955b0458bb1aba85b9b85 (diff) | |
download | bcm5719-llvm-1dbc7a7a5a4836f84d7304762ba93da34a339c52.tar.gz bcm5719-llvm-1dbc7a7a5a4836f84d7304762ba93da34a339c52.zip |
Improve the representation of CXXUuidofExpr
Keep a pointer to the UuidAttr that the CXXUuidofExpr corresponds to.
This makes translating from __uuidof to the underlying constant a lot
more straightforward.
llvm-svn: 264529
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ExprCXX.cpp | 73 | ||||
-rw-r--r-- | clang/lib/AST/MicrosoftMangle.cpp | 2 |
2 files changed, 3 insertions, 72 deletions
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index b1b91f78d7a..438a376aed4 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -54,77 +54,8 @@ QualType CXXUuidofExpr::getTypeOperand(ASTContext &Context) const { Operand.get<TypeSourceInfo *>()->getType().getNonReferenceType(), Quals); } -// static -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()) - Ty = QT->getPointeeType().getTypePtr(); - else if (QT->isArrayType()) - Ty = Ty->getBaseElementTypeUnsafe(); - - const CXXRecordDecl *RD = Ty->getAsCXXRecordDecl(); - if (!RD) - return nullptr; - - if (const UuidAttr *Uuid = RD->getMostRecentDecl()->getAttr<UuidAttr>()) - return Uuid; - - // __uuidof can grab UUIDs from template arguments. - if (const ClassTemplateSpecializationDecl *CTSD = - dyn_cast<ClassTemplateSpecializationDecl>(RD)) { - const TemplateArgumentList &TAL = CTSD->getTemplateArgs(); - const UuidAttr *UuidForRD = nullptr; - - for (const TemplateArgument &TA : TAL.asArray()) { - bool SeenMultipleGUIDs = false; - - const UuidAttr *UuidForTA = nullptr; - if (TA.getKind() == TemplateArgument::Type) - UuidForTA = GetUuidAttrOfType(TA.getAsType(), &SeenMultipleGUIDs); - else if (TA.getKind() == TemplateArgument::Declaration) - UuidForTA = - GetUuidAttrOfType(TA.getAsDecl()->getType(), &SeenMultipleGUIDs); - - // If the template argument has a UUID, there are three cases: - // - This is the first UUID seen for this RecordDecl. - // - This is a different UUID than previously seen for this RecordDecl. - // - This is the same UUID than previously seen for this RecordDecl. - if (UuidForTA) { - if (!UuidForRD) - UuidForRD = UuidForTA; - else if (UuidForRD != UuidForTA) - SeenMultipleGUIDs = true; - } - - // Seeing multiple UUIDs means that we couldn't find a UUID - if (SeenMultipleGUIDs) { - if (RDHasMultipleGUIDsPtr) - *RDHasMultipleGUIDsPtr = true; - return nullptr; - } - } - - return UuidForRD; - } - - return nullptr; -} - -StringRef CXXUuidofExpr::getUuidAsStringRef(ASTContext &Context) const { - StringRef Uuid; - if (isTypeOperand()) - Uuid = CXXUuidofExpr::GetUuidAttrOfType(getTypeOperand(Context))->getGuid(); - else { - // Special case: __uuidof(0) means an all-zero GUID. - Expr *Op = getExprOperand(); - if (!Op->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) - Uuid = CXXUuidofExpr::GetUuidAttrOfType(Op->getType())->getGuid(); - else - Uuid = "00000000-0000-0000-0000-000000000000"; - } - return Uuid; +StringRef CXXUuidofExpr::getUuidAsStringRef() const { + return UA ? UA->getGuid() : "00000000-0000-0000-0000-000000000000"; } // CXXScalarValueInitExpr diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 2be8cec696d..002c2205314 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -1186,7 +1186,7 @@ void MicrosoftCXXNameMangler::mangleExpression(const Expr *E) { // This CXXUuidofExpr is mangled as-if it were actually a VarDecl from // const __s_GUID _GUID_{lower case UUID with underscores} - StringRef Uuid = UE->getUuidAsStringRef(Context.getASTContext()); + StringRef Uuid = UE->getUuidAsStringRef(); std::string Name = "_GUID_" + Uuid.lower(); std::replace(Name.begin(), Name.end(), '-', '_'); |