On Thu, Aug 30, 2012 at 4:11 AM, Richard Trieu <[email protected]> wrote:
> For too long, -ast-dump would produce drab, monochromatic, textual AST's. > Large walls of text to slough through to find the interesting bits. > Worse, if a statement filled more than one line, the structural > information of the tree would be easily lost amid the type names, source > locations, pointer address, and statement names. Fear not, a solution > presents itself! > > 1) The addition of ASCII characters into the unused indents at the > beginning of lines. Pipes "|", dashes "-", and backslashes "\" quickly > show relationships between the different statements. Find siblings, > parents, and children fast and easy, never lose your place again. > > 2) For each statement, different parts are highlighted with different > colors. This visually separates the components and allows faster > differentiating. Looking for a specific type? All types are the same > color. Same for the statement names. And source locations. > > 3) But wait, there's more! Since -ast-dump and dump() use the same > ASTVisitor, you can also get colors in your debugger! Just use dumpColor() > instead of dump() and get colors while you debug. > > To use, either use "clang -Xclang -ast-dump" or "clang -cc1 -ast-dump > -fcolor-diagnostics" from a color-enabled terminal. > > Implementation detail: > Color changes were handled by changeColor() and resetColor() from the > raw_ostream. The different colors are stored in constants at the top of > the class before being used in the relevant visit method. > > Tree structure printing was handled by a vector of statuses. The status > indicates if there's future children at the level of the index. This is > enough information to generate the tree structure. This replaces the > integer indent counter. > > To determine if color printing is required, the dumper queries the > DiagnosticEngine in the SourceManager. This is enough for -ast-dump. > However, when debugging and call Stmt.dump(), the Stmt doesn't have a > SourceManager. It is possible to call dump() with a SourceManager, but to > simplify things, a dumpColor() was created to force color printing. > > I've attached a patch and an image showing the difference between color > and no color. Work in progress, comments welcome. > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > It is amazing how such a little thing as sprinkling colors makes it so much more accessible. -- Matthieu
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
