Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:28

0001 //===--- ASTDumperUtils.h - Printing of AST nodes -------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements AST utilities for traversal down the tree.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_ASTDUMPERUTILS_H
0014 #define LLVM_CLANG_AST_ASTDUMPERUTILS_H
0015 
0016 #include "llvm/Support/raw_ostream.h"
0017 
0018 namespace clang {
0019 
0020 /// Used to specify the format for printing AST dump information.
0021 enum ASTDumpOutputFormat {
0022   ADOF_Default,
0023   ADOF_JSON
0024 };
0025 
0026 // Colors used for various parts of the AST dump
0027 // Do not use bold yellow for any text.  It is hard to read on white screens.
0028 
0029 struct TerminalColor {
0030   llvm::raw_ostream::Colors Color;
0031   bool Bold;
0032 };
0033 
0034 // Red           - CastColor
0035 // Green         - TypeColor
0036 // Bold Green    - DeclKindNameColor, UndeserializedColor
0037 // Yellow        - AddressColor, LocationColor
0038 // Blue          - CommentColor, NullColor, IndentColor
0039 // Bold Blue     - AttrColor
0040 // Bold Magenta  - StmtColor
0041 // Cyan          - ValueKindColor, ObjectKindColor
0042 // Bold Cyan     - ValueColor, DeclNameColor
0043 
0044 // Decl kind names (VarDecl, FunctionDecl, etc)
0045 static const TerminalColor DeclKindNameColor = {llvm::raw_ostream::GREEN, true};
0046 // Attr names (CleanupAttr, GuardedByAttr, etc)
0047 static const TerminalColor AttrColor = {llvm::raw_ostream::BLUE, true};
0048 // Statement names (DeclStmt, ImplicitCastExpr, etc)
0049 static const TerminalColor StmtColor = {llvm::raw_ostream::MAGENTA, true};
0050 // Comment names (FullComment, ParagraphComment, TextComment, etc)
0051 static const TerminalColor CommentColor = {llvm::raw_ostream::BLUE, false};
0052 
0053 // Type names (int, float, etc, plus user defined types)
0054 static const TerminalColor TypeColor = {llvm::raw_ostream::GREEN, false};
0055 
0056 // Pointer address
0057 static const TerminalColor AddressColor = {llvm::raw_ostream::YELLOW, false};
0058 // Source locations
0059 static const TerminalColor LocationColor = {llvm::raw_ostream::YELLOW, false};
0060 
0061 // lvalue/xvalue
0062 static const TerminalColor ValueKindColor = {llvm::raw_ostream::CYAN, false};
0063 // bitfield/objcproperty/objcsubscript/vectorcomponent
0064 static const TerminalColor ObjectKindColor = {llvm::raw_ostream::CYAN, false};
0065 // contains-errors
0066 static const TerminalColor ErrorsColor = {llvm::raw_ostream::RED, true};
0067 
0068 // Null statements
0069 static const TerminalColor NullColor = {llvm::raw_ostream::BLUE, false};
0070 
0071 // Undeserialized entities
0072 static const TerminalColor UndeserializedColor = {llvm::raw_ostream::GREEN,
0073                                                   true};
0074 
0075 // CastKind from CastExpr's
0076 static const TerminalColor CastColor = {llvm::raw_ostream::RED, false};
0077 
0078 // Value of the statement
0079 static const TerminalColor ValueColor = {llvm::raw_ostream::CYAN, true};
0080 // Decl names
0081 static const TerminalColor DeclNameColor = {llvm::raw_ostream::CYAN, true};
0082 
0083 // Indents ( `, -. | )
0084 static const TerminalColor IndentColor = {llvm::raw_ostream::BLUE, false};
0085 
0086 class ColorScope {
0087   llvm::raw_ostream &OS;
0088   const bool ShowColors;
0089 
0090 public:
0091   ColorScope(llvm::raw_ostream &OS, bool ShowColors, TerminalColor Color)
0092       : OS(OS), ShowColors(ShowColors) {
0093     if (ShowColors)
0094       OS.changeColor(Color.Color, Color.Bold);
0095   }
0096   ~ColorScope() {
0097     if (ShowColors)
0098       OS.resetColor();
0099   }
0100 };
0101 
0102 } // namespace clang
0103 
0104 #endif // LLVM_CLANG_AST_ASTDUMPERUTILS_H