1 //===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the PrinterHelper interface. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_AST_PRETTY_PRINTER_H 15 #define LLVM_CLANG_AST_PRETTY_PRINTER_H 16 17 #include "clang/Basic/LLVM.h" 18 #include "clang/Basic/LangOptions.h" 19 20 namespace clang { 21 22 class LangOptions; 23 class SourceManager; 24 class Stmt; 25 class TagDecl; 26 27 class PrinterHelper { 28 public: 29 virtual ~PrinterHelper(); 30 virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0; 31 }; 32 33 /// \brief Describes how types, statements, expressions, and 34 /// declarations should be printed. 35 struct PrintingPolicy { 36 /// \brief Create a default printing policy for C. PrintingPolicyPrintingPolicy37 PrintingPolicy(const LangOptions &LO) 38 : LangOpts(LO), Indentation(2), SuppressSpecifiers(false), 39 SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), 40 SuppressUnwrittenScope(false), SuppressInitializers(false), 41 ConstantArraySizeAsWritten(false), AnonymousTagLocations(true), 42 SuppressStrongLifetime(false), Bool(LO.Bool), 43 TerseOutput(false), PolishForDeclaration(false) { } 44 45 /// \brief What language we're printing. 46 LangOptions LangOpts; 47 48 /// \brief The number of spaces to use to indent each line. 49 unsigned Indentation : 8; 50 51 /// \brief Whether we should suppress printing of the actual specifiers for 52 /// the given type or declaration. 53 /// 54 /// This flag is only used when we are printing declarators beyond 55 /// the first declarator within a declaration group. For example, given: 56 /// 57 /// \code 58 /// const int *x, *y; 59 /// \endcode 60 /// 61 /// SuppressSpecifiers will be false when printing the 62 /// declaration for "x", so that we will print "int *x"; it will be 63 /// \c true when we print "y", so that we suppress printing the 64 /// "const int" type specifier and instead only print the "*y". 65 bool SuppressSpecifiers : 1; 66 67 /// \brief Whether type printing should skip printing the tag keyword. 68 /// 69 /// This is used when printing the inner type of elaborated types, 70 /// (as the tag keyword is part of the elaborated type): 71 /// 72 /// \code 73 /// struct Geometry::Point; 74 /// \endcode 75 bool SuppressTagKeyword : 1; 76 77 /// \brief Whether type printing should skip printing the actual tag type. 78 /// 79 /// This is used when the caller needs to print a tag definition in front 80 /// of the type, as in constructs like the following: 81 /// 82 /// \code 83 /// typedef struct { int x, y; } Point; 84 /// \endcode 85 bool SuppressTag : 1; 86 87 /// \brief Suppresses printing of scope specifiers. 88 bool SuppressScope : 1; 89 90 /// \brief Suppress printing parts of scope specifiers that don't need 91 /// to be written, e.g., for inline or anonymous namespaces. 92 bool SuppressUnwrittenScope : 1; 93 94 /// \brief Suppress printing of variable initializers. 95 /// 96 /// This flag is used when printing the loop variable in a for-range 97 /// statement. For example, given: 98 /// 99 /// \code 100 /// for (auto x : coll) 101 /// \endcode 102 /// 103 /// SuppressInitializers will be true when printing "auto x", so that the 104 /// internal initializer constructed for x will not be printed. 105 bool SuppressInitializers : 1; 106 107 /// \brief Whether we should print the sizes of constant array expressions 108 /// as written in the sources. 109 /// 110 /// This flag is determines whether arrays types declared as 111 /// 112 /// \code 113 /// int a[4+10*10]; 114 /// char a[] = "A string"; 115 /// \endcode 116 /// 117 /// will be printed as written or as follows: 118 /// 119 /// \code 120 /// int a[104]; 121 /// char a[9] = "A string"; 122 /// \endcode 123 bool ConstantArraySizeAsWritten : 1; 124 125 /// \brief When printing an anonymous tag name, also print the location of 126 /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just 127 /// prints "<anonymous>" for the name. 128 bool AnonymousTagLocations : 1; 129 130 /// \brief When true, suppress printing of the __strong lifetime qualifier in 131 /// ARC. 132 unsigned SuppressStrongLifetime : 1; 133 134 /// \brief Whether we can use 'bool' rather than '_Bool', even if the language 135 /// doesn't actually have 'bool' (because, e.g., it is defined as a macro). 136 unsigned Bool : 1; 137 138 /// \brief Provide a 'terse' output. 139 /// 140 /// For example, in this mode we don't print function bodies, class members, 141 /// declarations inside namespaces etc. Effectively, this should print 142 /// only the requested declaration. 143 unsigned TerseOutput : 1; 144 145 /// \brief When true, do certain refinement needed for producing proper 146 /// declaration tag; such as, do not print attributes attached to the declaration. 147 /// 148 unsigned PolishForDeclaration : 1; 149 }; 150 151 } // end namespace clang 152 153 #endif 154