1 //===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the PrinterHelper interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_PRETTYPRINTER_H
15 #define LLVM_CLANG_AST_PRETTYPRINTER_H
17 #include "clang/Basic/LLVM.h"
18 #include "clang/Basic/LangOptions.h"
29 virtual ~PrinterHelper();
30 virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0;
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.
37 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), SuppressLifetimeQualifiers(false),
43 Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
44 Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
45 IncludeNewlines(true), MSVCFormatting(false) { }
47 /// \brief What language we're printing.
50 /// \brief The number of spaces to use to indent each line.
51 unsigned Indentation : 8;
53 /// \brief Whether we should suppress printing of the actual specifiers for
54 /// the given type or declaration.
56 /// This flag is only used when we are printing declarators beyond
57 /// the first declarator within a declaration group. For example, given:
63 /// SuppressSpecifiers will be false when printing the
64 /// declaration for "x", so that we will print "int *x"; it will be
65 /// \c true when we print "y", so that we suppress printing the
66 /// "const int" type specifier and instead only print the "*y".
67 bool SuppressSpecifiers : 1;
69 /// \brief Whether type printing should skip printing the tag keyword.
71 /// This is used when printing the inner type of elaborated types,
72 /// (as the tag keyword is part of the elaborated type):
75 /// struct Geometry::Point;
77 bool SuppressTagKeyword : 1;
79 /// \brief Whether type printing should skip printing the actual tag type.
81 /// This is used when the caller needs to print a tag definition in front
82 /// of the type, as in constructs like the following:
85 /// typedef struct { int x, y; } Point;
89 /// \brief Suppresses printing of scope specifiers.
90 bool SuppressScope : 1;
92 /// \brief Suppress printing parts of scope specifiers that don't need
93 /// to be written, e.g., for inline or anonymous namespaces.
94 bool SuppressUnwrittenScope : 1;
96 /// \brief Suppress printing of variable initializers.
98 /// This flag is used when printing the loop variable in a for-range
99 /// statement. For example, given:
102 /// for (auto x : coll)
105 /// SuppressInitializers will be true when printing "auto x", so that the
106 /// internal initializer constructed for x will not be printed.
107 bool SuppressInitializers : 1;
109 /// \brief Whether we should print the sizes of constant array expressions
110 /// as written in the sources.
112 /// This flag determines whether array types declared as
116 /// char a[] = "A string";
119 /// will be printed as written or as follows:
123 /// char a[9] = "A string";
125 bool ConstantArraySizeAsWritten : 1;
127 /// \brief When printing an anonymous tag name, also print the location of
128 /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just
129 /// prints "(anonymous)" for the name.
130 bool AnonymousTagLocations : 1;
132 /// \brief When true, suppress printing of the __strong lifetime qualifier in
134 unsigned SuppressStrongLifetime : 1;
136 /// \brief When true, suppress printing of lifetime qualifier in
138 unsigned SuppressLifetimeQualifiers : 1;
140 /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
141 /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
144 /// \brief Provide a 'terse' output.
146 /// For example, in this mode we don't print function bodies, class members,
147 /// declarations inside namespaces etc. Effectively, this should print
148 /// only the requested declaration.
149 unsigned TerseOutput : 1;
151 /// \brief When true, do certain refinement needed for producing proper
152 /// declaration tag; such as, do not print attributes attached to the declaration.
154 unsigned PolishForDeclaration : 1;
156 /// \brief When true, print the half-precision floating-point type as 'half'
157 /// instead of '__fp16'
160 /// \brief When true, print the built-in wchar_t type as __wchar_t. For use in
161 /// Microsoft mode when wchar_t is not available.
162 unsigned MSWChar : 1;
164 /// \brief When true, include newlines after statements like "break", etc.
165 unsigned IncludeNewlines : 1;
167 /// \brief Use whitespace and punctuation like MSVC does. In particular, this
168 /// prints anonymous namespaces as `anonymous namespace' and does not insert
169 /// spaces after template arguments.
170 bool MSVCFormatting : 1;
173 } // end namespace clang