@@ -27,6 +27,8 @@ class MacroInfo;
27
27
class Module ;
28
28
class SourceLocation ;
29
29
30
+ // IMPORTANT: when you add a new interface to this class, please update the
31
+ // DelegatingDeserializationListener below.
30
32
class ASTDeserializationListener {
31
33
public:
32
34
virtual ~ASTDeserializationListener ();
@@ -44,6 +46,11 @@ class ASTDeserializationListener {
44
46
// / unqualified.
45
47
virtual void TypeRead (serialization::TypeIdx Idx, QualType T) { }
46
48
// / A decl was deserialized from the AST file.
49
+ //
50
+ // Note: Implementors should be cautious when introducing additional
51
+ // serialization (e.g., printing the qualified name of the declaration) within
52
+ // the callback. Doing so may lead to unintended and complex side effects, or
53
+ // even cause a crash.
47
54
virtual void DeclRead (GlobalDeclID ID, const Decl *D) {}
48
55
// / A predefined decl was built during the serialization.
49
56
virtual void PredefinedDeclBuilt (PredefinedDeclIDs ID, const Decl *D) {}
@@ -58,6 +65,70 @@ class ASTDeserializationListener {
58
65
virtual void ModuleImportRead (serialization::SubmoduleID ID,
59
66
SourceLocation ImportLoc) {}
60
67
};
61
- }
68
+
69
+ class DelegatingDeserializationListener : public ASTDeserializationListener {
70
+ ASTDeserializationListener *Previous;
71
+ bool DeletePrevious;
72
+
73
+ public:
74
+ explicit DelegatingDeserializationListener (
75
+ ASTDeserializationListener *Previous, bool DeletePrevious)
76
+ : Previous(Previous), DeletePrevious(DeletePrevious) {}
77
+ ~DelegatingDeserializationListener () override {
78
+ if (DeletePrevious)
79
+ delete Previous;
80
+ }
81
+
82
+ DelegatingDeserializationListener (const DelegatingDeserializationListener &) =
83
+ delete ;
84
+ DelegatingDeserializationListener &
85
+ operator =(const DelegatingDeserializationListener &) = delete ;
86
+
87
+ void ReaderInitialized (ASTReader *Reader) override {
88
+ if (Previous)
89
+ Previous->ReaderInitialized (Reader);
90
+ }
91
+ void IdentifierRead (serialization::IdentifierID ID,
92
+ IdentifierInfo *II) override {
93
+ if (Previous)
94
+ Previous->IdentifierRead (ID, II);
95
+ }
96
+ void MacroRead (serialization::MacroID ID, MacroInfo *MI) override {
97
+ if (Previous)
98
+ Previous->MacroRead (ID, MI);
99
+ }
100
+ void TypeRead (serialization::TypeIdx Idx, QualType T) override {
101
+ if (Previous)
102
+ Previous->TypeRead (Idx, T);
103
+ }
104
+ void DeclRead (GlobalDeclID ID, const Decl *D) override {
105
+ if (Previous)
106
+ Previous->DeclRead (ID, D);
107
+ }
108
+ void PredefinedDeclBuilt (PredefinedDeclIDs ID, const Decl *D) override {
109
+ if (Previous)
110
+ Previous->PredefinedDeclBuilt (ID, D);
111
+ }
112
+ void SelectorRead (serialization::SelectorID ID, Selector Sel) override {
113
+ if (Previous)
114
+ Previous->SelectorRead (ID, Sel);
115
+ }
116
+ void MacroDefinitionRead (serialization::PreprocessedEntityID PPID,
117
+ MacroDefinitionRecord *MD) override {
118
+ if (Previous)
119
+ Previous->MacroDefinitionRead (PPID, MD);
120
+ }
121
+ void ModuleRead (serialization::SubmoduleID ID, Module *Mod) override {
122
+ if (Previous)
123
+ Previous->ModuleRead (ID, Mod);
124
+ }
125
+ void ModuleImportRead (serialization::SubmoduleID ID,
126
+ SourceLocation ImportLoc) override {
127
+ if (Previous)
128
+ Previous->ModuleImportRead (ID, ImportLoc);
129
+ }
130
+ };
131
+
132
+ } // namespace clang
62
133
63
134
#endif
0 commit comments