sammccall created this revision.
sammccall added a reviewer: massberg.
Herald added a subscriber: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

The dump() is not actually included recursively in any other nodes' dump,
as this is too verbose (similar to NNS) but useful in its own right.

It's unfortunate to not have the actual tests yet, but the DynTypedNode
tests are matcher-based and adding matchers is a larger task than
DynTypedNode support (but can't be done first).

(I've got a clangd change stacked on this that uses DynTypedNode and
dump(), and both work. I'll send a change for matchers next).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159300

Files:
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/AST/ASTFwd.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/ASTDumper.cpp
  clang/lib/AST/ASTTypeTraits.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/unittests/AST/ASTTypeTraitsTest.cpp

Index: clang/unittests/AST/ASTTypeTraitsTest.cpp
===================================================================
--- clang/unittests/AST/ASTTypeTraitsTest.cpp
+++ clang/unittests/AST/ASTTypeTraitsTest.cpp
@@ -166,6 +166,7 @@
   VERIFY_NAME(QualType);
   VERIFY_NAME(TypeLoc);
   VERIFY_NAME(CXXCtorInitializer);
+  VERIFY_NAME(ConceptReference);
   VERIFY_NAME(NestedNameSpecifier);
   VERIFY_NAME(Decl);
   VERIFY_NAME(CXXRecordDecl);
@@ -209,6 +210,8 @@
                              ast_matchers::attr()));
 }
 
+// FIXME: add tests for ConceptReference once we add an ASTMatcher.
+
 TEST(DynTypedNode, DeclDump) {
   DumpVerifier Verifier;
   Verifier.expectSubstring("FunctionDecl");
Index: clang/lib/AST/TextNodeDumper.cpp
===================================================================
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -371,6 +371,20 @@
     OS << " selected";
 }
 
+void TextNodeDumper::Visit(const ConceptReference *R) {
+  if (!R) {
+    ColorScope Color(OS, ShowColors, NullColor);
+    OS << "<<<NULL>>> ConceptReference";
+    return;
+  }
+
+  OS << "ConceptReference";
+  dumpPointer(R);
+  dumpSourceRange(R->getSourceRange());
+  OS << ' ';
+  dumpBareDeclRef(R->getNamedConcept());
+}
+
 void TextNodeDumper::Visit(const concepts::Requirement *R) {
   if (!R) {
     ColorScope Color(OS, ShowColors, NullColor);
Index: clang/lib/AST/ASTTypeTraits.cpp
===================================================================
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
@@ -54,6 +55,7 @@
 #define ATTR(A) {NKI_Attr, #A "Attr"},
 #include "clang/Basic/AttrList.inc"
     {NKI_None, "ObjCProtocolLoc"},
+    {NKI_None, "ConceptReference"},
 };
 
 bool ASTNodeKind::isBaseOf(ASTNodeKind Other) const {
@@ -210,6 +212,8 @@
     A->printPretty(OS, PP);
   else if (const ObjCProtocolLoc *P = get<ObjCProtocolLoc>())
     P->getProtocol()->print(OS, PP);
+  else if (const ConceptReference *C = get<ConceptReference>())
+    C->print(OS, PP);
   else
     OS << "Unable to print values of type " << NodeKind.asStringRef() << "\n";
 }
@@ -222,6 +226,8 @@
     S->dump(OS, Context);
   else if (const Type *T = get<Type>())
     T->dump(OS, Context);
+  else if (const ConceptReference *C = get<ConceptReference>())
+    C->dump(OS);
   else
     OS << "Unable to dump values of type " << NodeKind.asStringRef() << "\n";
 }
@@ -247,5 +253,7 @@
     return A->getRange();
   if (const ObjCProtocolLoc *P = get<ObjCProtocolLoc>())
     return P->getSourceRange();
+  if (const ConceptReference *C = get<ConceptReference>())
+    return C->getSourceRange();
   return SourceRange();
 }
Index: clang/lib/AST/ASTDumper.cpp
===================================================================
--- clang/lib/AST/ASTDumper.cpp
+++ clang/lib/AST/ASTDumper.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/AST/ASTDumper.h"
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclLookups.h"
 #include "clang/AST/JSONNodeDumper.h"
@@ -333,3 +334,17 @@
                    Context.getDiagnostics().getShowColors());
   Dumper.Visit(*this, /*Ty=*/Context.getPointerType(Context.CharTy));
 }
+
+//===----------------------------------------------------------------------===//
+// ConceptReference method implementations
+//===----------------------------------------------------------------------===//
+
+LLVM_DUMP_METHOD void ConceptReference::dump() const {
+  dump(llvm::errs());
+}
+
+LLVM_DUMP_METHOD void ConceptReference::dump(raw_ostream &OS) const {
+  auto &Ctx = getNamedConcept()->getASTContext();
+  ASTDumper P(OS, Ctx, Ctx.getDiagnostics().getShowColors());
+  P.Visit(this);
+}
Index: clang/include/clang/AST/TextNodeDumper.h
===================================================================
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -189,6 +189,8 @@
 
   void Visit(const GenericSelectionExpr::ConstAssociation &A);
 
+  void Visit(const ConceptReference *);
+
   void Visit(const concepts::Requirement *R);
 
   void Visit(const APValue &Value, QualType Ty);
@@ -204,6 +206,7 @@
   void dumpCleanupObject(const ExprWithCleanups::CleanupObject &C);
   void dumpTemplateSpecializationKind(TemplateSpecializationKind TSK);
   void dumpNestedNameSpecifier(const NestedNameSpecifier *NNS);
+  void dumpConceptReference(const ConceptReference *R);
 
   void dumpDeclRef(const Decl *D, StringRef Label = {});
 
Index: clang/include/clang/AST/ASTTypeTraits.h
===================================================================
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -163,6 +163,7 @@
 #define ATTR(A) NKI_##A##Attr,
 #include "clang/Basic/AttrList.inc"
     NKI_ObjCProtocolLoc,
+    NKI_ConceptReference,
     NKI_NumberOfKinds
   };
 
@@ -222,6 +223,7 @@
 KIND_TO_KIND_ID(Attr)
 KIND_TO_KIND_ID(ObjCProtocolLoc)
 KIND_TO_KIND_ID(CXXBaseSpecifier)
+KIND_TO_KIND_ID(ConceptReference)
 #define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
 #include "clang/AST/DeclNodes.inc"
 #define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
@@ -582,6 +584,10 @@
 struct DynTypedNode::BaseConverter<ObjCProtocolLoc, void>
     : public ValueConverter<ObjCProtocolLoc> {};
 
+template <>
+struct DynTypedNode::BaseConverter<ConceptReference, void>
+    : public PtrConverter<ConceptReference> {};
+
 // The only operation we allow on unsupported types is \c get.
 // This allows to conveniently use \c DynTypedNode when having an arbitrary
 // AST node that is not supported, but prevents misuse - a user cannot create
Index: clang/include/clang/AST/ASTNodeTraverser.h
===================================================================
--- clang/include/clang/AST/ASTNodeTraverser.h
+++ clang/include/clang/AST/ASTNodeTraverser.h
@@ -252,6 +252,10 @@
     });
   }
 
+  void Visit(const ConceptReference *R) {
+    getNodeDelegate().AddChild([=] { getNodeDelegate().Visit(R); });
+  }
+
   void Visit(const APValue &Value, QualType Ty) {
     getNodeDelegate().AddChild([=] { getNodeDelegate().Visit(Value, Ty); });
   }
@@ -288,6 +292,8 @@
       Visit(C);
     else if (const auto *T = N.get<TemplateArgument>())
       Visit(*T);
+    else if (const auto *CR = N.get<ConceptReference>())
+      Visit(CR);
   }
 
   void dumpDeclContext(const DeclContext *DC) {
Index: clang/include/clang/AST/ASTFwd.h
===================================================================
--- clang/include/clang/AST/ASTFwd.h
+++ clang/include/clang/AST/ASTFwd.h
@@ -34,6 +34,7 @@
 #define ATTR(A) class A##Attr;
 #include "clang/Basic/AttrList.inc"
 class ObjCProtocolLoc;
+class ConceptReference;
 
 } // end namespace clang
 
Index: clang/include/clang/AST/ASTConcept.h
===================================================================
--- clang/include/clang/AST/ASTConcept.h
+++ clang/include/clang/AST/ASTConcept.h
@@ -213,6 +213,8 @@
   }
 
   void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
+  void dump() const;
+  void dump(llvm::raw_ostream &) const;
 };
 
 /// Models the abbreviated syntax to constrain a template type parameter:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to