diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
commit | 1928da94b55683957759d5c5ff4593a118773394 (patch) | |
tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /lib/Checker/LLVMConventionsChecker.cpp | |
parent | 53992adde3eda3ccf9da63bc7e45673f043de18f (diff) | |
download | FreeBSD-src-1928da94b55683957759d5c5ff4593a118773394.zip FreeBSD-src-1928da94b55683957759d5c5ff4593a118773394.tar.gz |
Update clang to r108243.
Diffstat (limited to 'lib/Checker/LLVMConventionsChecker.cpp')
-rw-r--r-- | lib/Checker/LLVMConventionsChecker.cpp | 50 |
1 files changed, 14 insertions, 36 deletions
diff --git a/lib/Checker/LLVMConventionsChecker.cpp b/lib/Checker/LLVMConventionsChecker.cpp index 39ded43..0576f08 100644 --- a/lib/Checker/LLVMConventionsChecker.cpp +++ b/lib/Checker/LLVMConventionsChecker.cpp @@ -34,13 +34,15 @@ static bool IsLLVMStringRef(QualType T) { "class llvm::StringRef"; } -static bool InStdNamespace(const Decl *D) { +/// Check whether the declaration is semantically inside the top-level +/// namespace named by ns. +static bool InNamespace(const Decl *D, const llvm::StringRef &NS) { const DeclContext *DC = D->getDeclContext(); const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D->getDeclContext()); if (!ND) return false; const IdentifierInfo *II = ND->getIdentifier(); - if (!II || II->getName() != "std") + if (!II || !II->getName().equals(NS)) return false; DC = ND->getDeclContext(); return isa<TranslationUnitDecl>(DC); @@ -56,50 +58,26 @@ static bool IsStdString(QualType T) { const TypedefDecl *TD = TT->getDecl(); - if (!InStdNamespace(TD)) + if (!InNamespace(TD, "std")) return false; return TD->getName() == "string"; } -static bool InClangNamespace(const Decl *D) { - const DeclContext *DC = D->getDeclContext(); - const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D->getDeclContext()); - if (!ND) - return false; - const IdentifierInfo *II = ND->getIdentifier(); - if (!II || II->getName() != "clang") - return false; - DC = ND->getDeclContext(); - return isa<TranslationUnitDecl>(DC); -} - -static bool InLLVMNamespace(const Decl *D) { - const DeclContext *DC = D->getDeclContext(); - const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D->getDeclContext()); - if (!ND) - return false; - const IdentifierInfo *II = ND->getIdentifier(); - if (!II || II->getName() != "llvm") - return false; - DC = ND->getDeclContext(); - return isa<TranslationUnitDecl>(DC); -} - static bool IsClangType(const RecordDecl *RD) { - return RD->getName() == "Type" && InClangNamespace(RD); + return RD->getName() == "Type" && InNamespace(RD, "clang"); } static bool IsClangDecl(const RecordDecl *RD) { - return RD->getName() == "Decl" && InClangNamespace(RD); + return RD->getName() == "Decl" && InNamespace(RD, "clang"); } static bool IsClangStmt(const RecordDecl *RD) { - return RD->getName() == "Stmt" && InClangNamespace(RD); + return RD->getName() == "Stmt" && InNamespace(RD, "clang"); } -static bool isClangAttr(const RecordDecl *RD) { - return RD->getName() == "Attr" && InClangNamespace(RD); +static bool IsClangAttr(const RecordDecl *RD) { + return RD->getName() == "Attr" && InNamespace(RD, "clang"); } static bool IsStdVector(QualType T) { @@ -110,7 +88,7 @@ static bool IsStdVector(QualType T) { TemplateName TM = TS->getTemplateName(); TemplateDecl *TD = TM.getAsTemplateDecl(); - if (!TD || !InStdNamespace(TD)) + if (!TD || !InNamespace(TD, "std")) return false; return TD->getName() == "vector"; @@ -124,7 +102,7 @@ static bool IsSmallVector(QualType T) { TemplateName TM = TS->getTemplateName(); TemplateDecl *TD = TM.getAsTemplateDecl(); - if (!TD || !InLLVMNamespace(TD)) + if (!TD || !InNamespace(TD, "llvm")) return false; return TD->getName() == "SmallVector"; @@ -214,7 +192,7 @@ static bool AllocatesMemory(QualType T) { // This type checking could be sped up via dynamic programming. static bool IsPartOfAST(const CXXRecordDecl *R) { - if (IsClangStmt(R) || IsClangType(R) || IsClangDecl(R) || isClangAttr(R)) + if (IsClangStmt(R) || IsClangType(R) || IsClangDecl(R) || IsClangAttr(R)) return true; for (CXXRecordDecl::base_class_const_iterator I = R->bases_begin(), @@ -316,7 +294,7 @@ static void ScanCodeDecls(DeclContext *DC, BugReporter &BR) { Decl *D = *I; - if (D->getBody()) + if (D->hasBody()) CheckStringRefAssignedTemporary(D, BR); if (CXXRecordDecl *R = dyn_cast<CXXRecordDecl>(D)) |