[cfe-commits] r105170 - /cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp

Nick Lewycky nicholas at mxc.ca
Sun May 30 11:05:23 PDT 2010


Author: nicholas
Date: Sun May 30 13:05:23 2010
New Revision: 105170

URL: http://llvm.org/viewvc/llvm-project?rev=105170&view=rev
Log:
Refactor the Is{Std,Clang,LLVM}Namespace methods and rename 'isClangAttr' to
'IsClangAttr' to match prevailing style in this file. Patch by Jon Mulder!

Modified:
    cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp

Modified: cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp?rev=105170&r1=105169&r2=105170&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp (original)
+++ cfe/trunk/lib/Checker/LLVMConventionsChecker.cpp Sun May 30 13:05:23 2010
@@ -34,13 +34,15 @@
           "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 @@
 
   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 @@
   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 @@
   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 @@
 
 // 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(),





More information about the cfe-commits mailing list