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 17d47d3b0cfeb7e8564ff77f48130fe63282b6d127Chris Lattner#include "clang/Basic/LLVM.h" 1830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Basic/LangOptions.h" 197107d360db751aa974285ae2136aed76b6691b86Chandler Carruth 2042a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremeneknamespace clang { 2142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 222fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramerclass LangOptions; 232fa67efeaf66a9332c30a026dc1c21bef6c33a6cBenjamin Kramerclass SourceManager; 2442a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekclass Stmt; 25d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregorclass TagDecl; 26d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 2742a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekclass PrinterHelper { 2842a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekpublic: 2942a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek virtual ~PrinterHelper(); 30d47d3b0cfeb7e8564ff77f48130fe63282b6d127Chris Lattner virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0; 3142a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek}; 3242a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 33d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor/// \brief Describes how types, statements, expressions, and 34d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor/// declarations should be printed. 35d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregorstruct PrintingPolicy { 36d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \brief Create a default printing policy for C. 371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump PrintingPolicy(const LangOptions &LO) 38d1420c6fa788669e49f21e184927c7833881e399Richard Smith : LangOpts(LO), Indentation(2), SuppressSpecifiers(false), 390daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false), 4025270b6e6a8416b7532cfe552b41794418ea19b1Douglas Gregor SuppressUnwrittenScope(false), SuppressInitializers(false), 41d1420c6fa788669e49f21e184927c7833881e399Richard Smith ConstantArraySizeAsWritten(false), AnonymousTagLocations(true), 429fe529f15723018a2fecdcc35611210f92ed2b82Fariborz Jahanian SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false), 439fe529f15723018a2fecdcc35611210f92ed2b82Fariborz Jahanian Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false), 44651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar), 45651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines IncludeNewlines(true) { } 46d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 47e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner /// \brief What language we're printing. 488987b2385d9ba63ada66e1344ace79b04d5cb5c3Douglas Gregor LangOptions LangOpts; 49d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 50d1420c6fa788669e49f21e184927c7833881e399Richard Smith /// \brief The number of spaces to use to indent each line. 51d1420c6fa788669e49f21e184927c7833881e399Richard Smith unsigned Indentation : 8; 52d1420c6fa788669e49f21e184927c7833881e399Richard Smith 5342f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \brief Whether we should suppress printing of the actual specifiers for 5442f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// the given type or declaration. 55d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// 56d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// This flag is only used when we are printing declarators beyond 57d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// the first declarator within a declaration group. For example, given: 58d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// 59d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \code 60d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// const int *x, *y; 61d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \endcode 62d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// 6342f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// SuppressSpecifiers will be false when printing the 64d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// declaration for "x", so that we will print "int *x"; it will be 65d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// \c true when we print "y", so that we suppress printing the 66d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor /// "const int" type specifier and instead only print the "*y". 6742f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman bool SuppressSpecifiers : 1; 6842f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman 690daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// \brief Whether type printing should skip printing the tag keyword. 700daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// 710daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// This is used when printing the inner type of elaborated types, 720daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// (as the tag keyword is part of the elaborated type): 730daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// 740daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// \code 750daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// struct Geometry::Point; 760daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara /// \endcode 770daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara bool SuppressTagKeyword : 1; 780daaf32723ac78549c507c2a68a5300502703673Abramo Bagnara 7942f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \brief Whether type printing should skip printing the actual tag type. 8042f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// 8142f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// This is used when the caller needs to print a tag definition in front 8242f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// of the type, as in constructs like the following: 8342f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// 8442f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \code 8542f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// typedef struct { int x, y; } Point; 8642f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman /// \endcode 8742f42c0dd5cf71fbfc6fa282d03079a902f6e342Eli Friedman bool SuppressTag : 1; 88d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 892191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall /// \brief Suppresses printing of scope specifiers. 902191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall bool SuppressScope : 1; 912191b20bfb31fc0e22a158f6b4204cd0b7dbd0fdJohn McCall 9225270b6e6a8416b7532cfe552b41794418ea19b1Douglas Gregor /// \brief Suppress printing parts of scope specifiers that don't need 9325270b6e6a8416b7532cfe552b41794418ea19b1Douglas Gregor /// to be written, e.g., for inline or anonymous namespaces. 9425270b6e6a8416b7532cfe552b41794418ea19b1Douglas Gregor bool SuppressUnwrittenScope : 1; 9525270b6e6a8416b7532cfe552b41794418ea19b1Douglas Gregor 96ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Suppress printing of variable initializers. 97ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 98ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// This flag is used when printing the loop variable in a for-range 99ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// statement. For example, given: 100ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 101ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \code 102ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// for (auto x : coll) 103ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \endcode 104ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 105ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// SuppressInitializers will be true when printing "auto x", so that the 106ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// internal initializer constructed for x will not be printed. 107ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith bool SuppressInitializers : 1; 108ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 1097e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \brief Whether we should print the sizes of constant array expressions 1107e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// as written in the sources. 1117e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// This flag is determines whether arrays types declared as 1137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1147e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \code 1157e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// int a[4+10*10]; 1167e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// char a[] = "A string"; 1177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \endcode 1187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1197e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// will be printed as written or as follows: 1207e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// 1217e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \code 1227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// int a[104]; 1237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// char a[9] = "A string"; 1247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor /// \endcode 1257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor bool ConstantArraySizeAsWritten : 1; 12684139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor 12784139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor /// \brief When printing an anonymous tag name, also print the location of 12884139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just 129651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// prints "(anonymous)" for the name. 13084139d6ef8967cfdb70d37378a7a65cc4827d44dDouglas Gregor bool AnonymousTagLocations : 1; 131f85e193739c953358c865005855253af4f68a497John McCall 132f85e193739c953358c865005855253af4f68a497John McCall /// \brief When true, suppress printing of the __strong lifetime qualifier in 133f85e193739c953358c865005855253af4f68a497John McCall /// ARC. 134f85e193739c953358c865005855253af4f68a497John McCall unsigned SuppressStrongLifetime : 1; 13530c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor 1369fe529f15723018a2fecdcc35611210f92ed2b82Fariborz Jahanian /// \brief When true, suppress printing of lifetime qualifier in 1379fe529f15723018a2fecdcc35611210f92ed2b82Fariborz Jahanian /// ARC. 1389fe529f15723018a2fecdcc35611210f92ed2b82Fariborz Jahanian unsigned SuppressLifetimeQualifiers : 1; 1399fe529f15723018a2fecdcc35611210f92ed2b82Fariborz Jahanian 14030c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor /// \brief Whether we can use 'bool' rather than '_Bool', even if the language 14130c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor /// doesn't actually have 'bool' (because, e.g., it is defined as a macro). 14230c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor unsigned Bool : 1; 143d1420c6fa788669e49f21e184927c7833881e399Richard Smith 144d1fc82efd53ffda30f4f16041399d78f3bf0705fDmitri Gribenko /// \brief Provide a 'terse' output. 145eb8f2efb17c74620510a38cb437e792ea9c76021Dmitri Gribenko /// 146eb8f2efb17c74620510a38cb437e792ea9c76021Dmitri Gribenko /// For example, in this mode we don't print function bodies, class members, 147eb8f2efb17c74620510a38cb437e792ea9c76021Dmitri Gribenko /// declarations inside namespaces etc. Effectively, this should print 148eb8f2efb17c74620510a38cb437e792ea9c76021Dmitri Gribenko /// only the requested declaration. 149d1fc82efd53ffda30f4f16041399d78f3bf0705fDmitri Gribenko unsigned TerseOutput : 1; 1501bfb00dabf83d8c8b95b7276b4c0ae3fd64832c8Fariborz Jahanian 15140902d817e5a73850045d8a0c9795bc5047ee000Fariborz Jahanian /// \brief When true, do certain refinement needed for producing proper 15240902d817e5a73850045d8a0c9795bc5047ee000Fariborz Jahanian /// declaration tag; such as, do not print attributes attached to the declaration. 1531bfb00dabf83d8c8b95b7276b4c0ae3fd64832c8Fariborz Jahanian /// 15440902d817e5a73850045d8a0c9795bc5047ee000Fariborz Jahanian unsigned PolishForDeclaration : 1; 15515f92bad58c8650b1306729744b1a1230197497aHans Wennborg 156651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief When true, print the half-precision floating-point type as 'half' 157651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// instead of '__fp16' 158651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned Half : 1; 159651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 16015f92bad58c8650b1306729744b1a1230197497aHans Wennborg /// \brief When true, print the built-in wchar_t type as __wchar_t. For use in 16115f92bad58c8650b1306729744b1a1230197497aHans Wennborg /// Microsoft mode when wchar_t is not available. 16215f92bad58c8650b1306729744b1a1230197497aHans Wennborg unsigned MSWChar : 1; 163651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 164651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief When true, include newlines after statements like "break", etc. 165651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned IncludeNewlines : 1; 166d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor}; 167d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor 16842a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek} // end namespace clang 16942a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek 1708467583c2704e7a9691ea56939a029015f0ade0aGabor Greif#endif 171