clang  3.7.0
PrettyPrinter.h
Go to the documentation of this file.
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_PRETTYPRINTER_H
15 #define LLVM_CLANG_AST_PRETTYPRINTER_H
16 
17 #include "clang/Basic/LLVM.h"
19 
20 namespace clang {
21 
22 class LangOptions;
23 class SourceManager;
24 class Stmt;
25 class TagDecl;
26 
28 public:
29  virtual ~PrinterHelper();
30  virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0;
31 };
32 
33 /// \brief Describes how types, statements, expressions, and
34 /// declarations should be printed.
36  /// \brief Create a default printing policy for C.
44  Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
46 
47  /// \brief What language we're printing.
49 
50  /// \brief The number of spaces to use to indent each line.
51  unsigned Indentation : 8;
52 
53  /// \brief Whether we should suppress printing of the actual specifiers for
54  /// the given type or declaration.
55  ///
56  /// This flag is only used when we are printing declarators beyond
57  /// the first declarator within a declaration group. For example, given:
58  ///
59  /// \code
60  /// const int *x, *y;
61  /// \endcode
62  ///
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".
68 
69  /// \brief Whether type printing should skip printing the tag keyword.
70  ///
71  /// This is used when printing the inner type of elaborated types,
72  /// (as the tag keyword is part of the elaborated type):
73  ///
74  /// \code
75  /// struct Geometry::Point;
76  /// \endcode
78 
79  /// \brief Whether type printing should skip printing the actual tag type.
80  ///
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:
83  ///
84  /// \code
85  /// typedef struct { int x, y; } Point;
86  /// \endcode
87  bool SuppressTag : 1;
88 
89  /// \brief Suppresses printing of scope specifiers.
90  bool SuppressScope : 1;
91 
92  /// \brief Suppress printing parts of scope specifiers that don't need
93  /// to be written, e.g., for inline or anonymous namespaces.
95 
96  /// \brief Suppress printing of variable initializers.
97  ///
98  /// This flag is used when printing the loop variable in a for-range
99  /// statement. For example, given:
100  ///
101  /// \code
102  /// for (auto x : coll)
103  /// \endcode
104  ///
105  /// SuppressInitializers will be true when printing "auto x", so that the
106  /// internal initializer constructed for x will not be printed.
108 
109  /// \brief Whether we should print the sizes of constant array expressions
110  /// as written in the sources.
111  ///
112  /// This flag is determines whether arrays types declared as
113  ///
114  /// \code
115  /// int a[4+10*10];
116  /// char a[] = "A string";
117  /// \endcode
118  ///
119  /// will be printed as written or as follows:
120  ///
121  /// \code
122  /// int a[104];
123  /// char a[9] = "A string";
124  /// \endcode
126 
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.
131 
132  /// \brief When true, suppress printing of the __strong lifetime qualifier in
133  /// ARC.
135 
136  /// \brief When true, suppress printing of lifetime qualifier in
137  /// ARC.
139 
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).
142  unsigned Bool : 1;
143 
144  /// \brief Provide a 'terse' output.
145  ///
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;
150 
151  /// \brief When true, do certain refinement needed for producing proper
152  /// declaration tag; such as, do not print attributes attached to the declaration.
153  ///
154  unsigned PolishForDeclaration : 1;
155 
156  /// \brief When true, print the half-precision floating-point type as 'half'
157  /// instead of '__fp16'
158  unsigned Half : 1;
159 
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;
163 
164  /// \brief When true, include newlines after statements like "break", etc.
165  unsigned IncludeNewlines : 1;
166 };
167 
168 } // end namespace clang
169 
170 #endif
PrintingPolicy(const LangOptions &LO)
Create a default printing policy for C.
Definition: PrettyPrinter.h:37
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t. For use in Microsoft mode when wchar_t is no...
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:35
unsigned TerseOutput
Provide a 'terse' output.
unsigned SuppressLifetimeQualifiers
When true, suppress printing of lifetime qualifier in ARC.
bool SuppressInitializers
Suppress printing of variable initializers.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
unsigned SuppressStrongLifetime
When true, suppress printing of the __strong lifetime qualifier in ARC.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
bool SuppressScope
Suppresses printing of scope specifiers.
Definition: PrettyPrinter.h:90
unsigned Half
When true, print the half-precision floating-point type as 'half' instead of '__fp16'.
LangOptions LangOpts
What language we're printing.
Definition: PrettyPrinter.h:48
Defines the clang::LangOptions interface.
virtual bool handledStmt(Stmt *E, raw_ostream &OS)=0
unsigned Bool
Whether we can use 'bool' rather than '_Bool', even if the language doesn't actually have 'bool' (bec...
#define false
Definition: stdbool.h:33
unsigned Indentation
The number of spaces to use to indent each line.
Definition: PrettyPrinter.h:51
bool SuppressTag
Whether type printing should skip printing the actual tag type.
Definition: PrettyPrinter.h:87
bool SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Definition: PrettyPrinter.h:67
bool SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
Definition: PrettyPrinter.h:77
bool SuppressUnwrittenScope
Suppress printing parts of scope specifiers that don't need to be written, e.g., for inline or anonym...
Definition: PrettyPrinter.h:94
bool ConstantArraySizeAsWritten
Whether we should print the sizes of constant array expressions as written in the sources...
bool AnonymousTagLocations
When printing an anonymous tag name, also print the location of that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just prints "(anonymous)" for the name.
unsigned IncludeNewlines
When true, include newlines after statements like "break", etc.
#define true
Definition: stdbool.h:32
unsigned PolishForDeclaration
When true, do certain refinement needed for producing proper declaration tag; such as...