clang API Documentation
00001 //===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the PrinterHelper interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_AST_PRETTY_PRINTER_H 00015 #define LLVM_CLANG_AST_PRETTY_PRINTER_H 00016 00017 #include "clang/Basic/LangOptions.h" 00018 #include "clang/Basic/LLVM.h" 00019 00020 namespace clang { 00021 00022 class Stmt; 00023 class TagDecl; 00024 class LangOptions; 00025 00026 class PrinterHelper { 00027 public: 00028 virtual ~PrinterHelper(); 00029 virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0; 00030 }; 00031 00032 /// \brief Describes how types, statements, expressions, and 00033 /// declarations should be printed. 00034 struct PrintingPolicy { 00035 /// \brief Create a default printing policy for C. 00036 PrintingPolicy(const LangOptions &LO) 00037 : Indentation(2), LangOpts(LO), SuppressSpecifiers(false), 00038 SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), 00039 SuppressUnwrittenScope(false), SuppressInitializers(false), 00040 Dump(false), ConstantArraySizeAsWritten(false), 00041 AnonymousTagLocations(true), SuppressStrongLifetime(false), 00042 Bool(LO.Bool) { } 00043 00044 /// \brief The number of spaces to use to indent each line. 00045 unsigned Indentation : 8; 00046 00047 /// \brief What language we're printing. 00048 LangOptions LangOpts; 00049 00050 /// \brief Whether we should suppress printing of the actual specifiers for 00051 /// the given type or declaration. 00052 /// 00053 /// This flag is only used when we are printing declarators beyond 00054 /// the first declarator within a declaration group. For example, given: 00055 /// 00056 /// \code 00057 /// const int *x, *y; 00058 /// \endcode 00059 /// 00060 /// SuppressSpecifiers will be false when printing the 00061 /// declaration for "x", so that we will print "int *x"; it will be 00062 /// \c true when we print "y", so that we suppress printing the 00063 /// "const int" type specifier and instead only print the "*y". 00064 bool SuppressSpecifiers : 1; 00065 00066 /// \brief Whether type printing should skip printing the tag keyword. 00067 /// 00068 /// This is used when printing the inner type of elaborated types, 00069 /// (as the tag keyword is part of the elaborated type): 00070 /// 00071 /// \code 00072 /// struct Geometry::Point; 00073 /// \endcode 00074 bool SuppressTagKeyword : 1; 00075 00076 /// \brief Whether type printing should skip printing the actual tag type. 00077 /// 00078 /// This is used when the caller needs to print a tag definition in front 00079 /// of the type, as in constructs like the following: 00080 /// 00081 /// \code 00082 /// typedef struct { int x, y; } Point; 00083 /// \endcode 00084 bool SuppressTag : 1; 00085 00086 /// \brief Suppresses printing of scope specifiers. 00087 bool SuppressScope : 1; 00088 00089 /// \brief Suppress printing parts of scope specifiers that don't need 00090 /// to be written, e.g., for inline or anonymous namespaces. 00091 bool SuppressUnwrittenScope : 1; 00092 00093 /// \brief Suppress printing of variable initializers. 00094 /// 00095 /// This flag is used when printing the loop variable in a for-range 00096 /// statement. For example, given: 00097 /// 00098 /// \code 00099 /// for (auto x : coll) 00100 /// \endcode 00101 /// 00102 /// SuppressInitializers will be true when printing "auto x", so that the 00103 /// internal initializer constructed for x will not be printed. 00104 bool SuppressInitializers : 1; 00105 00106 /// \brief True when we are "dumping" rather than "pretty-printing", 00107 /// where dumping involves printing the internal details of the AST 00108 /// and pretty-printing involves printing something similar to 00109 /// source code. 00110 bool Dump : 1; 00111 00112 /// \brief Whether we should print the sizes of constant array expressions 00113 /// as written in the sources. 00114 /// 00115 /// This flag is determines whether arrays types declared as 00116 /// 00117 /// \code 00118 /// int a[4+10*10]; 00119 /// char a[] = "A string"; 00120 /// \endcode 00121 /// 00122 /// will be printed as written or as follows: 00123 /// 00124 /// \code 00125 /// int a[104]; 00126 /// char a[9] = "A string"; 00127 /// \endcode 00128 bool ConstantArraySizeAsWritten : 1; 00129 00130 /// \brief When printing an anonymous tag name, also print the location of 00131 /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just 00132 /// prints "<anonymous>" for the name. 00133 bool AnonymousTagLocations : 1; 00134 00135 /// \brief When true, suppress printing of the __strong lifetime qualifier in 00136 /// ARC. 00137 unsigned SuppressStrongLifetime : 1; 00138 00139 /// \brief Whether we can use 'bool' rather than '_Bool', even if the language 00140 /// doesn't actually have 'bool' (because, e.g., it is defined as a macro). 00141 unsigned Bool : 1; 00142 }; 00143 00144 } // end namespace clang 00145 00146 #endif