Remove clang::ast_type_traits namespace in favor of clang

DynTypedNode and ASTNodeKind are implemented as part of the clang AST
library, which uses the main clang namespace. There doesn't seem to be a
need for this extra level of namespacing.

I left behind aliases in the ast_type_traits namespace for out of tree
clients of these APIs. To provide aliases for the enumerators, I used
this pattern:
  namespace ast_type_traits {
  constexpr TraversalKind TK_AsIs = ::clang::TK_AsIs;
  }
I think the typedefs will be useful for migration, but we might be able
to drop these enumerator aliases.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D74499
diff --git a/clang/lib/AST/ParentMapContext.cpp b/clang/lib/AST/ParentMapContext.cpp
index e74e990..b73b327 100644
--- a/clang/lib/AST/ParentMapContext.cpp
+++ b/clang/lib/AST/ParentMapContext.cpp
@@ -34,54 +34,53 @@
     return nullptr;
 
   switch (Traversal) {
-  case ast_type_traits::TK_AsIs:
+  case TK_AsIs:
     return E;
-  case ast_type_traits::TK_IgnoreImplicitCastsAndParentheses:
+  case TK_IgnoreImplicitCastsAndParentheses:
     return E->IgnoreParenImpCasts();
-  case ast_type_traits::TK_IgnoreUnlessSpelledInSource:
+  case TK_IgnoreUnlessSpelledInSource:
     return E->IgnoreUnlessSpelledInSource();
   }
   llvm_unreachable("Invalid Traversal type!");
 }
 
-ast_type_traits::DynTypedNode
-ParentMapContext::traverseIgnored(const ast_type_traits::DynTypedNode &N) const {
+DynTypedNode ParentMapContext::traverseIgnored(const DynTypedNode &N) const {
   if (const auto *E = N.get<Expr>()) {
-    return ast_type_traits::DynTypedNode::create(*traverseIgnored(E));
+    return DynTypedNode::create(*traverseIgnored(E));
   }
   return N;
 }
 
 class ParentMapContext::ParentMap {
   /// Contains parents of a node.
-  using ParentVector = llvm::SmallVector<ast_type_traits::DynTypedNode, 2>;
+  using ParentVector = llvm::SmallVector<DynTypedNode, 2>;
 
   /// Maps from a node to its parents. This is used for nodes that have
   /// pointer identity only, which are more common and we can save space by
   /// only storing a unique pointer to them.
-  using ParentMapPointers = llvm::DenseMap<
-      const void *,
-      llvm::PointerUnion<const Decl *, const Stmt *,
-                         ast_type_traits::DynTypedNode *, ParentVector *>>;
+  using ParentMapPointers =
+      llvm::DenseMap<const void *,
+                     llvm::PointerUnion<const Decl *, const Stmt *,
+                                        DynTypedNode *, ParentVector *>>;
 
   /// Parent map for nodes without pointer identity. We store a full
   /// DynTypedNode for all keys.
-  using ParentMapOtherNodes = llvm::DenseMap<
-      ast_type_traits::DynTypedNode,
-      llvm::PointerUnion<const Decl *, const Stmt *,
-                         ast_type_traits::DynTypedNode *, ParentVector *>>;
+  using ParentMapOtherNodes =
+      llvm::DenseMap<DynTypedNode,
+                     llvm::PointerUnion<const Decl *, const Stmt *,
+                                        DynTypedNode *, ParentVector *>>;
 
   ParentMapPointers PointerParents;
   ParentMapOtherNodes OtherParents;
   class ASTVisitor;
 
-  static ast_type_traits::DynTypedNode
+  static DynTypedNode
   getSingleDynTypedNodeFromParentMap(ParentMapPointers::mapped_type U) {
     if (const auto *D = U.dyn_cast<const Decl *>())
-      return ast_type_traits::DynTypedNode::create(*D);
+      return DynTypedNode::create(*D);
     if (const auto *S = U.dyn_cast<const Stmt *>())
-      return ast_type_traits::DynTypedNode::create(*S);
-    return *U.get<ast_type_traits::DynTypedNode *>();
+      return DynTypedNode::create(*S);
+    return *U.get<DynTypedNode *>();
   }
 
   template <typename NodeTy, typename MapTy>
@@ -89,7 +88,7 @@
                                                         const MapTy &Map) {
     auto I = Map.find(Node);
     if (I == Map.end()) {
-      return llvm::ArrayRef<ast_type_traits::DynTypedNode>();
+      return llvm::ArrayRef<DynTypedNode>();
     }
     if (const auto *V = I->second.template dyn_cast<ParentVector *>()) {
       return llvm::makeArrayRef(*V);
@@ -101,28 +100,26 @@
   ParentMap(ASTContext &Ctx);
   ~ParentMap() {
     for (const auto &Entry : PointerParents) {
-      if (Entry.second.is<ast_type_traits::DynTypedNode *>()) {
-        delete Entry.second.get<ast_type_traits::DynTypedNode *>();
+      if (Entry.second.is<DynTypedNode *>()) {
+        delete Entry.second.get<DynTypedNode *>();
       } else if (Entry.second.is<ParentVector *>()) {
         delete Entry.second.get<ParentVector *>();
       }
     }
     for (const auto &Entry : OtherParents) {
-      if (Entry.second.is<ast_type_traits::DynTypedNode *>()) {
-        delete Entry.second.get<ast_type_traits::DynTypedNode *>();
+      if (Entry.second.is<DynTypedNode *>()) {
+        delete Entry.second.get<DynTypedNode *>();
       } else if (Entry.second.is<ParentVector *>()) {
         delete Entry.second.get<ParentVector *>();
       }
     }
   }
 
-  DynTypedNodeList getParents(ast_type_traits::TraversalKind TK,
-                              const ast_type_traits::DynTypedNode &Node) {
+  DynTypedNodeList getParents(TraversalKind TK, const DynTypedNode &Node) {
     if (Node.getNodeKind().hasPointerIdentity()) {
       auto ParentList =
           getDynNodeFromMap(Node.getMemoizationData(), PointerParents);
-      if (ParentList.size() == 1 &&
-          TK == ast_type_traits::TK_IgnoreUnlessSpelledInSource) {
+      if (ParentList.size() == 1 && TK == TK_IgnoreUnlessSpelledInSource) {
         const auto *E = ParentList[0].get<Expr>();
         const auto *Child = Node.get<Expr>();
         if (E && Child)
@@ -186,28 +183,25 @@
       }
       const auto *P = dyn_cast<Expr>(S);
       if (!P)
-        return ast_type_traits::DynTypedNode::create(*S);
+        return DynTypedNode::create(*S);
       Child = E;
       E = P;
     }
-    return ast_type_traits::DynTypedNode::create(*E);
+    return DynTypedNode::create(*E);
   }
 };
 
 /// Template specializations to abstract away from pointers and TypeLocs.
 /// @{
-template <typename T>
-static ast_type_traits::DynTypedNode createDynTypedNode(const T &Node) {
-  return ast_type_traits::DynTypedNode::create(*Node);
+template <typename T> static DynTypedNode createDynTypedNode(const T &Node) {
+  return DynTypedNode::create(*Node);
+}
+template <> DynTypedNode createDynTypedNode(const TypeLoc &Node) {
+  return DynTypedNode::create(Node);
 }
 template <>
-ast_type_traits::DynTypedNode createDynTypedNode(const TypeLoc &Node) {
-  return ast_type_traits::DynTypedNode::create(Node);
-}
-template <>
-ast_type_traits::DynTypedNode
-createDynTypedNode(const NestedNameSpecifierLoc &Node) {
-  return ast_type_traits::DynTypedNode::create(Node);
+DynTypedNode createDynTypedNode(const NestedNameSpecifierLoc &Node) {
+  return DynTypedNode::create(Node);
 }
 /// @}
 
@@ -257,13 +251,12 @@
         else if (const auto *S = ParentStack.back().get<Stmt>())
           NodeOrVector = S;
         else
-          NodeOrVector = new ast_type_traits::DynTypedNode(ParentStack.back());
+          NodeOrVector = new DynTypedNode(ParentStack.back());
       } else {
         if (!NodeOrVector.template is<ParentVector *>()) {
           auto *Vector = new ParentVector(
               1, getSingleDynTypedNodeFromParentMap(NodeOrVector));
-          delete NodeOrVector
-              .template dyn_cast<ast_type_traits::DynTypedNode *>();
+          delete NodeOrVector.template dyn_cast<DynTypedNode *>();
           NodeOrVector = Vector;
         }
 
@@ -299,28 +292,27 @@
 
   bool TraverseTypeLoc(TypeLoc TypeLocNode) {
     return TraverseNode(
-        TypeLocNode, ast_type_traits::DynTypedNode::create(TypeLocNode),
+        TypeLocNode, DynTypedNode::create(TypeLocNode),
         [&] { return VisitorBase::TraverseTypeLoc(TypeLocNode); },
         &Map.OtherParents);
   }
 
   bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNSLocNode) {
     return TraverseNode(
-        NNSLocNode, ast_type_traits::DynTypedNode::create(NNSLocNode),
+        NNSLocNode, DynTypedNode::create(NNSLocNode),
         [&] { return VisitorBase::TraverseNestedNameSpecifierLoc(NNSLocNode); },
         &Map.OtherParents);
   }
 
   ParentMap &Map;
-  llvm::SmallVector<ast_type_traits::DynTypedNode, 16> ParentStack;
+  llvm::SmallVector<DynTypedNode, 16> ParentStack;
 };
 
 ParentMapContext::ParentMap::ParentMap(ASTContext &Ctx) {
   ASTVisitor(*this).TraverseAST(Ctx);
 }
 
-DynTypedNodeList
-ParentMapContext::getParents(const ast_type_traits::DynTypedNode &Node) {
+DynTypedNodeList ParentMapContext::getParents(const DynTypedNode &Node) {
   if (!Parents)
     // We build the parent map for the traversal scope (usually whole TU), as
     // hasAncestor can escape any subtree.