diff options
author | Kelvin Li <kkwli0@gmail.com> | 2018-09-15 13:54:15 +0000 |
---|---|---|
committer | Kelvin Li <kkwli0@gmail.com> | 2018-09-15 13:54:15 +0000 |
commit | 3a0edf1ccbe2869fb92e8cda66da6207c80f3c36 (patch) | |
tree | 9a33c5b14c408eaa789d7e9d40f003048fe4f50e /include/clang | |
parent | 9bc2172b74282966fdc9c29ac26bb9ad1e9dd3f5 (diff) |
[OPENMP] Move OMPClauseReader/Writer classes to ASTReader/Writer (NFC)
Move declarations for OMPClauseReader, OMPClauseWriter to ASTReader.h
and ASTWriter.h and move implementation to ASTReader.cpp and
ASTWriter.cpp. This change helps generalize the serialization of
OpenMP clauses and will be used in the future implementation of new
OpenMP directives (e.g. requires).
Patch by Patrick Lyster
Differential Revision: https://reviews.llvm.org/D52097
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342322 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/AST/OpenMPClause.h | 37 | ||||
-rw-r--r-- | include/clang/AST/StmtVisitor.h | 35 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 16 | ||||
-rw-r--r-- | include/clang/Serialization/ASTWriter.h | 13 |
4 files changed, 66 insertions, 35 deletions
diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index 99fa7a3592..f6e0c85267 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -5041,6 +5041,43 @@ public: } }; +/// This class implements a simple visitor for OMPClause +/// subclasses. +template<class ImplClass, template <typename> class Ptr, typename RetTy> +class OMPClauseVisitorBase { +public: +#define PTR(CLASS) typename Ptr<CLASS>::type +#define DISPATCH(CLASS) \ + return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S)) + +#define OPENMP_CLAUSE(Name, Class) \ + RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); } +#include "clang/Basic/OpenMPKinds.def" + + RetTy Visit(PTR(OMPClause) S) { + // Top switch clause: visit each OMPClause. + switch (S->getClauseKind()) { + default: llvm_unreachable("Unknown clause kind!"); +#define OPENMP_CLAUSE(Name, Class) \ + case OMPC_ ## Name : return Visit ## Class(static_cast<PTR(Class)>(S)); +#include "clang/Basic/OpenMPKinds.def" + } + } + // Base case, ignore it. :) + RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); } +#undef PTR +#undef DISPATCH +}; + +template <typename T> +using const_ptr = typename std::add_pointer<typename std::add_const<T>::type>; + +template<class ImplClass, typename RetTy = void> +class OMPClauseVisitor : + public OMPClauseVisitorBase <ImplClass, std::add_pointer, RetTy> {}; +template<class ImplClass, typename RetTy = void> +class ConstOMPClauseVisitor : + public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {}; } // namespace clang #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H diff --git a/include/clang/AST/StmtVisitor.h b/include/clang/AST/StmtVisitor.h index 30bc257c7e..bbfffe8186 100644 --- a/include/clang/AST/StmtVisitor.h +++ b/include/clang/AST/StmtVisitor.h @@ -195,41 +195,6 @@ template<typename ImplClass, typename RetTy=void, typename... ParamTys> class ConstStmtVisitor : public StmtVisitorBase<make_const_ptr, ImplClass, RetTy, ParamTys...> {}; -/// This class implements a simple visitor for OMPClause -/// subclasses. -template<class ImplClass, template <typename> class Ptr, typename RetTy> -class OMPClauseVisitorBase { -public: -#define PTR(CLASS) typename Ptr<CLASS>::type -#define DISPATCH(CLASS) \ - return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S)) - -#define OPENMP_CLAUSE(Name, Class) \ - RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); } -#include "clang/Basic/OpenMPKinds.def" - - RetTy Visit(PTR(OMPClause) S) { - // Top switch clause: visit each OMPClause. - switch (S->getClauseKind()) { - default: llvm_unreachable("Unknown clause kind!"); -#define OPENMP_CLAUSE(Name, Class) \ - case OMPC_ ## Name : return Visit ## Class(static_cast<PTR(Class)>(S)); -#include "clang/Basic/OpenMPKinds.def" - } - } - // Base case, ignore it. :) - RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); } -#undef PTR -#undef DISPATCH -}; - -template<class ImplClass, typename RetTy = void> -class OMPClauseVisitor : - public OMPClauseVisitorBase <ImplClass, make_ptr, RetTy> {}; -template<class ImplClass, typename RetTy = void> -class ConstOMPClauseVisitor : - public OMPClauseVisitorBase <ImplClass, make_const_ptr, RetTy> {}; - } // namespace clang #endif // LLVM_CLANG_AST_STMTVISITOR_H diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 98f8f5af48..f97f545852 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -18,6 +18,7 @@ #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" @@ -2677,6 +2678,21 @@ inline void PCHValidator::Error(const char *Msg) { Reader.Error(Msg); } +class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> { + ASTRecordReader &Record; + ASTContext &Context; + +public: + OMPClauseReader(ASTRecordReader &Record) + : Record(Record), Context(Record.getContext()) {} + +#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C); +#include "clang/Basic/OpenMPKinds.def" + OMPClause *readClause(); + void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); + void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); +}; + } // namespace clang #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 1a89a9e14a..da8b10a3f4 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -19,6 +19,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" @@ -993,6 +994,18 @@ public: bool hasEmittedPCH() const { return Buffer->IsComplete; } }; +class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> { + ASTRecordWriter &Record; + +public: + OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {} +#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *S); +#include "clang/Basic/OpenMPKinds.def" + void writeClause(OMPClause *C); + void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); + void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); +}; + } // namespace clang #endif // LLVM_CLANG_SERIALIZATION_ASTWRITER_H |