1 //===- TypeVisitorCallbackPipeline.h ----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_CODEVIEW_TYPEVISITORCALLBACKPIPELINE_H
10 #define LLVM_DEBUGINFO_CODEVIEW_TYPEVISITORCALLBACKPIPELINE_H
12 #include "llvm/DebugInfo/CodeView/CodeView.h"
13 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
14 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
15 #include "llvm/Support/Error.h"
21 class TypeVisitorCallbackPipeline : public TypeVisitorCallbacks {
23 TypeVisitorCallbackPipeline() = default;
25 Error visitUnknownType(CVRecord<TypeLeafKind> &Record) override {
26 for (auto Visitor : Pipeline) {
27 if (auto EC = Visitor->visitUnknownType(Record))
30 return Error::success();
33 Error visitUnknownMember(CVMemberRecord &Record) override {
34 for (auto Visitor : Pipeline) {
35 if (auto EC = Visitor->visitUnknownMember(Record))
38 return Error::success();
41 Error visitTypeBegin(CVType &Record) override {
42 for (auto Visitor : Pipeline) {
43 if (auto EC = Visitor->visitTypeBegin(Record))
46 return Error::success();
49 Error visitTypeBegin(CVType &Record, TypeIndex Index) override {
50 for (auto Visitor : Pipeline) {
51 if (auto EC = Visitor->visitTypeBegin(Record, Index))
54 return Error::success();
57 Error visitTypeEnd(CVType &Record) override {
58 for (auto Visitor : Pipeline) {
59 if (auto EC = Visitor->visitTypeEnd(Record))
62 return Error::success();
65 Error visitMemberBegin(CVMemberRecord &Record) override {
66 for (auto Visitor : Pipeline) {
67 if (auto EC = Visitor->visitMemberBegin(Record))
70 return Error::success();
73 Error visitMemberEnd(CVMemberRecord &Record) override {
74 for (auto Visitor : Pipeline) {
75 if (auto EC = Visitor->visitMemberEnd(Record))
78 return Error::success();
81 void addCallbackToPipeline(TypeVisitorCallbacks &Callbacks) {
82 Pipeline.push_back(&Callbacks);
85 void addCallbackToPipelineFront(TypeVisitorCallbacks &Callbacks) {
86 auto CallBackItr = Pipeline.begin();
87 Pipeline.insert(CallBackItr, &Callbacks);
90 #define TYPE_RECORD(EnumName, EnumVal, Name) \
91 Error visitKnownRecord(CVType &CVR, Name##Record &Record) override { \
92 return visitKnownRecordImpl(CVR, Record); \
94 #define MEMBER_RECORD(EnumName, EnumVal, Name) \
95 Error visitKnownMember(CVMemberRecord &CVMR, Name##Record &Record) \
97 return visitKnownMemberImpl(CVMR, Record); \
99 #define TYPE_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
100 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
101 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
104 template <typename T> Error visitKnownRecordImpl(CVType &CVR, T &Record) {
105 for (auto Visitor : Pipeline) {
106 if (auto EC = Visitor->visitKnownRecord(CVR, Record))
109 return Error::success();
112 template <typename T>
113 Error visitKnownMemberImpl(CVMemberRecord &CVMR, T &Record) {
114 for (auto Visitor : Pipeline) {
115 if (auto EC = Visitor->visitKnownMember(CVMR, Record))
118 return Error::success();
120 std::vector<TypeVisitorCallbacks *> Pipeline;
123 } // end namespace codeview
124 } // end namespace llvm
126 #endif // LLVM_DEBUGINFO_CODEVIEW_TYPEVISITORCALLBACKPIPELINE_H