1 //===- ExtractAPI/Serialization/SerializerBase.h ----------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines the ExtractAPI APISetVisitor interface.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SERIALIZERBASE_H
15 #define LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SERIALIZERBASE_H
16 
17 #include "clang/ExtractAPI/API.h"
18 
19 namespace clang {
20 namespace extractapi {
21 
22 /// The base interface of visitors for API information.
23 template <typename Derived> class APISetVisitor {
24 public:
25   void traverseAPISet() {
26     getDerived()->traverseGlobalVariableRecords();
27 
28     getDerived()->traverseGlobalFunctionRecords();
29 
30     getDerived()->traverseEnumRecords();
31 
32     getDerived()->traverseStructRecords();
33 
34     getDerived()->traverseObjCInterfaces();
35 
36     getDerived()->traverseObjCProtocols();
37 
38     getDerived()->traverseMacroDefinitionRecords();
39 
40     getDerived()->traverseTypedefRecords();
41   }
42 
43   void traverseGlobalFunctionRecords() {
44     for (const auto &GlobalFunction : API.getGlobalFunctions())
45       getDerived()->visitGlobalFunctionRecord(*GlobalFunction.second);
46   }
47 
48   void traverseGlobalVariableRecords() {
49     for (const auto &GlobalVariable : API.getGlobalVariables())
50       getDerived()->visitGlobalVariableRecord(*GlobalVariable.second);
51   }
52 
53   void traverseEnumRecords() {
54     for (const auto &Enum : API.getEnums())
55       getDerived()->visitEnumRecord(*Enum.second);
56   }
57 
58   void traverseStructRecords() {
59     for (const auto &Struct : API.getStructs())
60       getDerived()->visitStructRecord(*Struct.second);
61   }
62 
63   void traverseObjCInterfaces() {
64     for (const auto &Interface : API.getObjCInterfaces())
65       getDerived()->visitObjCContainerRecord(*Interface.second);
66   }
67 
68   void traverseObjCProtocols() {
69     for (const auto &Protocol : API.getObjCProtocols())
70       getDerived()->visitObjCContainerRecord(*Protocol.second);
71   }
72 
73   void traverseMacroDefinitionRecords() {
74     for (const auto &Macro : API.getMacros())
75       getDerived()->visitMacroDefinitionRecord(*Macro.second);
76   }
77 
78   void traverseTypedefRecords() {
79     for (const auto &Typedef : API.getTypedefs())
80       getDerived()->visitTypedefRecord(*Typedef.second);
81   }
82 
83   /// Visit a global function record.
84   void visitGlobalFunctionRecord(const GlobalFunctionRecord &Record){};
85 
86   /// Visit a global variable record.
87   void visitGlobalVariableRecord(const GlobalVariableRecord &Record){};
88 
89   /// Visit an enum record.
90   void visitEnumRecord(const EnumRecord &Record){};
91 
92   /// Visit a struct record.
93   void visitStructRecord(const StructRecord &Record){};
94 
95   /// Visit an Objective-C container record.
96   void visitObjCContainerRecord(const ObjCContainerRecord &Record){};
97 
98   /// Visit a macro definition record.
99   void visitMacroDefinitionRecord(const MacroDefinitionRecord &Record){};
100 
101   /// Visit a typedef record.
102   void visitTypedefRecord(const TypedefRecord &Record){};
103 
104 protected:
105   const APISet &API;
106 
107 public:
108   APISetVisitor() = delete;
109   APISetVisitor(const APISetVisitor &) = delete;
110   APISetVisitor(APISetVisitor &&) = delete;
111   APISetVisitor &operator=(const APISetVisitor &) = delete;
112   APISetVisitor &operator=(APISetVisitor &&) = delete;
113 
114 protected:
115   APISetVisitor(const APISet &API) : API(API) {}
116   ~APISetVisitor() = default;
117 
118   Derived *getDerived() { return static_cast<Derived *>(this); };
119 };
120 
121 } // namespace extractapi
122 } // namespace clang
123 
124 #endif // LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SERIALIZERBASE_H
125