aboutsummaryrefslogtreecommitdiff
path: root/clang/include
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2019-01-12 16:35:37 +0000
committerStephen Kelly <steveire@gmail.com>2019-01-12 16:35:37 +0000
commit63a6f3acbd80c602647a2f37aabd2a5c2967094f (patch)
tree0bca1a191bf3436c49c9e654a4e5afe4a97f8d63 /clang/include
parent9bc90a28297adc95456893abd4eb2fa72139fced (diff)
Implement TemplateArgument dumping in terms of Visitor
Summary: Split the output streaming from the traversal to other AST nodes. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55491 llvm-svn: 351012
Diffstat (limited to 'clang/include')
-rw-r--r--clang/include/clang/AST/TemplateArgumentVisitor.h99
-rw-r--r--clang/include/clang/AST/TextNodeDumper.h17
2 files changed, 115 insertions, 1 deletions
diff --git a/clang/include/clang/AST/TemplateArgumentVisitor.h b/clang/include/clang/AST/TemplateArgumentVisitor.h
new file mode 100644
index 000000000000..e1cc392a1705
--- /dev/null
+++ b/clang/include/clang/AST/TemplateArgumentVisitor.h
@@ -0,0 +1,99 @@
+//===- TemplateArgumentVisitor.h - Visitor for TArg subclasses --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the TemplateArgumentVisitor interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
+#define LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
+
+#include "clang/AST/TemplateBase.h"
+
+namespace clang {
+
+namespace templateargumentvisitor {
+
+/// A simple visitor class that helps create template argument visitors.
+template <template <typename> class Ref, typename ImplClass,
+ typename RetTy = void, typename... ParamTys>
+class Base {
+public:
+#define REF(CLASS) typename Ref<CLASS>::type
+#define DISPATCH(NAME) \
+ case TemplateArgument::NAME: \
+ return static_cast<ImplClass *>(this)->Visit##NAME##TemplateArgument( \
+ TA, std::forward<ParamTys>(P)...)
+
+ RetTy Visit(REF(TemplateArgument) TA, ParamTys... P) {
+ switch (TA.getKind()) {
+ DISPATCH(Null);
+ DISPATCH(Type);
+ DISPATCH(Declaration);
+ DISPATCH(NullPtr);
+ DISPATCH(Integral);
+ DISPATCH(Template);
+ DISPATCH(TemplateExpansion);
+ DISPATCH(Expression);
+ DISPATCH(Pack);
+ }
+ llvm_unreachable("TemplateArgument is not covered in switch!");
+ }
+
+ // If the implementation chooses not to implement a certain visit
+ // method, fall back to the parent.
+
+#define VISIT_METHOD(CATEGORY) \
+ RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA, \
+ ParamTys... P) { \
+ return VisitTemplateArgument(TA, std::forward<ParamTys>(P)...); \
+ }
+
+ VISIT_METHOD(Null);
+ VISIT_METHOD(Type);
+ VISIT_METHOD(Declaration);
+ VISIT_METHOD(NullPtr);
+ VISIT_METHOD(Integral);
+ VISIT_METHOD(Template);
+ VISIT_METHOD(TemplateExpansion);
+ VISIT_METHOD(Expression);
+ VISIT_METHOD(Pack);
+
+ RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...) {
+ return RetTy();
+ }
+
+#undef REF
+#undef DISPATCH
+#undef VISIT_METHOD
+};
+
+} // namespace templateargumentvisitor
+
+/// A simple visitor class that helps create template argument visitors.
+///
+/// This class does not preserve constness of TemplateArgument references (see
+/// also ConstTemplateArgumentVisitor).
+template <typename ImplClass, typename RetTy = void, typename... ParamTys>
+class TemplateArgumentVisitor
+ : public templateargumentvisitor::Base<std::add_lvalue_reference, ImplClass,
+ RetTy, ParamTys...> {};
+
+/// A simple visitor class that helps create template argument visitors.
+///
+/// This class preserves constness of TemplateArgument references (see also
+/// TemplateArgumentVisitor).
+template <typename ImplClass, typename RetTy = void, typename... ParamTys>
+class ConstTemplateArgumentVisitor
+ : public templateargumentvisitor::Base<llvm::make_const_ref, ImplClass,
+ RetTy, ParamTys...> {};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h
index 2c3cc7294c1b..d5521199f9a5 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -20,6 +20,7 @@
#include "clang/AST/CommentCommandTraits.h"
#include "clang/AST/CommentVisitor.h"
#include "clang/AST/ExprCXX.h"
+#include "clang/AST/TemplateArgumentVisitor.h"
namespace clang {
@@ -123,7 +124,8 @@ class TextNodeDumper
: public TextTreeStructure,
public comments::ConstCommentVisitor<TextNodeDumper, void,
const comments::FullComment *>,
- public ConstAttrVisitor<TextNodeDumper> {
+ public ConstAttrVisitor<TextNodeDumper>,
+ public ConstTemplateArgumentVisitor<TextNodeDumper> {
raw_ostream &OS;
const bool ShowColors;
@@ -150,6 +152,9 @@ public:
void Visit(const Attr *A);
+ void Visit(const TemplateArgument &TA, SourceRange R,
+ const Decl *From = nullptr, StringRef Label = {});
+
void dumpPointer(const void *Ptr);
void dumpLocation(SourceLocation Loc);
void dumpSourceRange(SourceRange R);
@@ -186,6 +191,16 @@ public:
// Implements Visit methods for Attrs.
#include "clang/AST/AttrTextNodeDump.inc"
+
+ void VisitNullTemplateArgument(const TemplateArgument &TA);
+ void VisitTypeTemplateArgument(const TemplateArgument &TA);
+ void VisitDeclarationTemplateArgument(const TemplateArgument &TA);
+ void VisitNullPtrTemplateArgument(const TemplateArgument &TA);
+ void VisitIntegralTemplateArgument(const TemplateArgument &TA);
+ void VisitTemplateTemplateArgument(const TemplateArgument &TA);
+ void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA);
+ void VisitExpressionTemplateArgument(const TemplateArgument &TA);
+ void VisitPackTemplateArgument(const TemplateArgument &TA);
};
} // namespace clang