xref: /llvm-project/flang/tools/f18/dump.cpp (revision 352d347aa5f5f1ba9b17aedd90daa5c110b8a50e)
1 //===-- tools/f18/dump.cpp ------------------------------------------------===//
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 // This file defines Dump routines available for calling from the debugger.
10 // Each is based on operator<< for that type. There are overloadings for
11 // reference and pointer, and for dumping to a provided ostream or cerr.
12 
13 #ifdef DEBUGF18
14 
15 #include <iostream>
16 
17 #define DEFINE_DUMP(ns, name) \
18   namespace ns { \
19   class name; \
20   std::ostream &operator<<(std::ostream &, const name &); \
21   } \
22   void Dump(std::ostream &os, const ns::name &x) { os << x << '\n'; } \
23   void Dump(std::ostream &os, const ns::name *x) { \
24     if (x == nullptr) \
25       os << "null\n"; \
26     else \
27       Dump(os, *x); \
28   } \
29   void Dump(const ns::name &x) { Dump(std::cerr, x); } \
30   void Dump(const ns::name *x) { Dump(std::cerr, *x); }
31 
32 namespace Fortran {
33 DEFINE_DUMP(parser, Name)
34 DEFINE_DUMP(parser, CharBlock)
35 DEFINE_DUMP(semantics, Symbol)
36 DEFINE_DUMP(semantics, Scope)
37 DEFINE_DUMP(semantics, IntrinsicTypeSpec)
38 DEFINE_DUMP(semantics, DerivedTypeSpec)
39 DEFINE_DUMP(semantics, DeclTypeSpec)
40 }
41 
42 #endif
43