PrettyPrinter.h revision 8987b2385d9ba63ada66e1344ace79b04d5cb5c3
142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek//===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===// 242a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// 342a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// The LLVM Compiler Infrastructure 442a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 742a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// 842a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek//===----------------------------------------------------------------------===// 942a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// 1042a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// This file defines the PrinterHelper interface. 1142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek// 1242a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek//===----------------------------------------------------------------------===// 1342a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 1442a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek#ifndef LLVM_CLANG_AST_PRETTY_PRINTER_H 1542a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek#define LLVM_CLANG_AST_PRETTY_PRINTER_H 1642a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 179313aac61d425f14fa0b82c3dfe1eb2c3626d38cArgyrios Kyrtzidis#include "clang/Basic/LangOptions.h" 18d47d3b0cfeb7e8564ff77f48130fe63282b6d127Chris Lattner#include "clang/Basic/LLVM.h" 197107d360db751aa974285ae2136aed76b6691b86Chandler Carruth 2042a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremeneknamespace clang { 2142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 2242a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekclass Stmt; 23d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregorclass TagDecl; 24e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattnerclass LangOptions; 25d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 2642a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekclass PrinterHelper { 2742a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekpublic: 2842a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek virtual ~PrinterHelper(); 29d47d3b0cfeb7e8564ff77f48130fe63282b6d127Chris Lattner virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0; 3042a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek}; 3142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 32d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor/// \brief Describes how types, statements, expressions, and 33d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor/// declarations should be printed. 34d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregorstruct PrintingPolicy { 35d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \brief Create a default printing policy for C. 361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PrintingPolicy(const LangOptions &LO) 37e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner : Indentation(2), LangOpts(LO), SuppressSpecifiers(false), 380daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), 39ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SuppressInitializers(false), 4084139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor Dump(false), ConstantArraySizeAsWritten(false), 4130c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor AnonymousTagLocations(true), SuppressStrongLifetime(false), 4230c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor Bool(LO.Bool) { } 43d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 44d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \brief The number of spaces to use to indent each line. 45d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor unsigned Indentation : 8; 46d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 47e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner /// \brief What language we're printing. 488987b2385d9ba63ada66e1344ace79b04d5cb5c3Douglas Gregor LangOptions LangOpts; 49d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 5042f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \brief Whether we should suppress printing of the actual specifiers for 5142f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// the given type or declaration. 52d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// 53d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// This flag is only used when we are printing declarators beyond 54d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// the first declarator within a declaration group. For example, given: 55d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// 56d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \code 57d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// const int *x, *y; 58d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \endcode 59d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// 6042f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// SuppressSpecifiers will be false when printing the 61d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// declaration for "x", so that we will print "int *x"; it will be 62d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \c true when we print "y", so that we suppress printing the 63d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// "const int" type specifier and instead only print the "*y". 6442f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman bool SuppressSpecifiers : 1; 6542f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman 660daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// \brief Whether type printing should skip printing the tag keyword. 670daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// 680daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// This is used when printing the inner type of elaborated types, 690daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// (as the tag keyword is part of the elaborated type): 700daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// 710daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// \code 720daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// struct Geometry::Point; 730daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// \endcode 740daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara bool SuppressTagKeyword : 1; 750daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara 7642f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \brief Whether type printing should skip printing the actual tag type. 7742f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// 7842f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// This is used when the caller needs to print a tag definition in front 7942f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// of the type, as in constructs like the following: 8042f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// 8142f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \code 8242f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// typedef struct { int x, y; } Point; 8342f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \endcode 8442f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman bool SuppressTag : 1; 85d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 862191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall /// \brief Suppresses printing of scope specifiers. 872191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall bool SuppressScope : 1; 882191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall 89ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Suppress printing of variable initializers. 90ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 91ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// This flag is used when printing the loop variable in a for-range 92ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// statement. For example, given: 93ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 94ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \code 95ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// for (auto x : coll) 96ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \endcode 97ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 98ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// SuppressInitializers will be true when printing "auto x", so that the 99ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// internal initializer constructed for x will not be printed. 100ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool SuppressInitializers : 1; 101ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1024fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor /// \brief True when we are "dumping" rather than "pretty-printing", 1034fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor /// where dumping involves printing the internal details of the AST 1044fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor /// and pretty-printing involves printing something similar to 1054fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor /// source code. 1064fe0c8e9c76b96e7aff21696a40dacc09d0237bcDouglas Gregor bool Dump : 1; 1077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1087e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \brief Whether we should print the sizes of constant array expressions 1097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// as written in the sources. 1107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// This flag is determines whether arrays types declared as 1127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \code 1147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// int a[4+10*10]; 1157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// char a[] = "A string"; 1167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \endcode 1177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// will be printed as written or as follows: 1197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \code 1217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// int a[104]; 1227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// char a[9] = "A string"; 1237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \endcode 1247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor bool ConstantArraySizeAsWritten : 1; 12584139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor 12684139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor /// \brief When printing an anonymous tag name, also print the location of 12784139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just 12884139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor /// prints "<anonymous>" for the name. 12984139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor bool AnonymousTagLocations : 1; 130f85e193739c953358c865005855253af4f68a497John McCall 131f85e193739c953358c865005855253af4f68a497John McCall /// \brief When true, suppress printing of the __strong lifetime qualifier in 132f85e193739c953358c865005855253af4f68a497John McCall /// ARC. 133f85e193739c953358c865005855253af4f68a497John McCall unsigned SuppressStrongLifetime : 1; 13430c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor 13530c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor /// \brief Whether we can use 'bool' rather than '_Bool', even if the language 13630c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor /// doesn't actually have 'bool' (because, e.g., it is defined as a macro). 13730c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor unsigned Bool : 1; 138d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor}; 139d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 14042a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek} // end namespace clang 14142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 1428467583c2704e7a9691ea56939a029015f0ade0aGabor Greif#endif 143