PrettyPrinter.h revision 25cf760b54d3b88633827501013bc51a29b28aba
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 17namespace llvm { 18 class raw_ostream; 19} 20 21namespace clang { 22 23class Stmt; 24class TagDecl; 25class LangOptions; 26 27class PrinterHelper { 28public: 29 virtual ~PrinterHelper(); 30 virtual bool handledStmt(Stmt* E, llvm::raw_ostream& OS) = 0; 31}; 32 33/// \brief Describes how types, statements, expressions, and 34/// declarations should be printed. 35struct PrintingPolicy { 36 /// \brief Create a default printing policy for C. 37 PrintingPolicy(const LangOptions &LO) 38 : Indentation(2), LangOpts(LO), SuppressSpecifiers(false), 39 SuppressTag(false), SuppressTagKind(false), SuppressScope(false), 40 Dump(false), ConstantArraySizeAsWritten(false) { } 41 42 /// \brief The number of spaces to use to indent each line. 43 unsigned Indentation : 8; 44 45 /// \brief What language we're printing. 46 const LangOptions &LangOpts; 47 48 /// \brief Whether we should suppress printing of the actual specifiers for 49 /// the given type or declaration. 50 /// 51 /// This flag is only used when we are printing declarators beyond 52 /// the first declarator within a declaration group. For example, given: 53 /// 54 /// \code 55 /// const int *x, *y; 56 /// \endcode 57 /// 58 /// SuppressSpecifiers will be false when printing the 59 /// declaration for "x", so that we will print "int *x"; it will be 60 /// \c true when we print "y", so that we suppress printing the 61 /// "const int" type specifier and instead only print the "*y". 62 bool SuppressSpecifiers : 1; 63 64 /// \brief Whether type printing should skip printing the actual tag type. 65 /// 66 /// This is used when the caller needs to print a tag definition in front 67 /// of the type, as in constructs like the following: 68 /// 69 /// \code 70 /// typedef struct { int x, y; } Point; 71 /// \endcode 72 bool SuppressTag : 1; 73 74 /// \brief If we are printing a tag type, suppresses printing of the 75 /// kind of tag, e.g., "struct", "union", "enum". 76 bool SuppressTagKind : 1; 77 78 /// \brief Suppresses printing of scope specifiers. 79 bool SuppressScope : 1; 80 81 /// \brief True when we are "dumping" rather than "pretty-printing", 82 /// where dumping involves printing the internal details of the AST 83 /// and pretty-printing involves printing something similar to 84 /// source code. 85 bool Dump : 1; 86 87 /// \brief Whether we should print the sizes of constant array expressions 88 /// as written in the sources. 89 /// 90 /// This flag is determines whether arrays types declared as 91 /// 92 /// \code 93 /// int a[4+10*10]; 94 /// char a[] = "A string"; 95 /// \endcode 96 /// 97 /// will be printed as written or as follows: 98 /// 99 /// \code 100 /// int a[104]; 101 /// char a[9] = "A string"; 102 /// \endcode 103 bool ConstantArraySizeAsWritten : 1; 104}; 105 106} // end namespace clang 107 108#endif 109