[Patch] DeclContext printer

Hi,

Attached patch implements an initial framework of a DeclContextPrinter. It can print DeclContext and its Decls in indented format. An Example:

$ cat 3.cpp
class A {
int a;
void f();
};
void A::f() {
a = 3;
}

$ clang -print-decl-contexts 3.cpp
[translation unit] 0x9754d7c
__builtin_va_list
[class] A 0x9753310
A 0x975ce20
a
<c++ method> f
<c++ ctor> A
<c++ ctor> A
<c++ method> operator=
<c++ dtor> ~A
[c++ method] f [[0x9753310]]

Some comments: ‘<>’ indicates a declaration, ‘’ indicates a definition, ‘[]’ displays the semantic DeclContext which is different from the lexical DeclContext.

This visualization should be helpful for DeclContext debugging.

dcprinter.patch (8.35 KB)

Hello Zhongxing,