[clang] [WIP] Implement `print-deserialized-declarations` flag to dump source… (PR #133910)

Viktoriia Bakalova via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 3 02:46:41 PDT 2025


================
@@ -49,6 +51,135 @@ LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
 
 namespace {
 
+/// Dumps deserialized declarations.
+class DeserializedDeclsLineRangePrinter : public DelegatingDeserializationListener, public ASTConsumer {
+public:
+  explicit DeserializedDeclsLineRangePrinter(SourceManager &SM, std::unique_ptr<llvm::raw_fd_ostream> OS)
+      : DelegatingDeserializationListener(nullptr, false), SM(SM), OS(std::move(OS)) {}
----------------
VitaNuo wrote:

The chain of delegating listeners isn't available at the point where we create and register this listener ([this deserial listener](https://github.com/VitaNuo/llvm-project/blob/main/clang/lib/Frontend/FrontendAction.cpp#L977) is passed through a chain in `BeginSourceFile`, whereas our new listener is created and registered in `CreateWrappedASTConsumer`).

However, it seems to me that we can switch inheriting from `DelegatingDeserializationListener` to parent `ASTDeserializationListener`. We create our own `ASTConsumer`, for which `DeserializedDeclsLineRangePrinter` is the only deserialization listener, which IMU means we don't need any chaining. On the contrary, the chain of consumers in `BeginSourceFile` is attached to a single ASTConsumer, so chaining is inevitable.



https://github.com/llvm/llvm-project/pull/133910


More information about the cfe-commits mailing list