clang  6.0.0svn
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 /// Describes how types, statements, expressions, and declarations should be
34 /// printed.
35 ///
36 /// This type is intended to be small and suitable for passing by value.
37 /// It is very frequently copied.
39  /// \brief Create a default printing policy for the specified language.
41  : Indentation(2), SuppressSpecifiers(false),
42  SuppressTagKeyword(LO.CPlusPlus),
43  IncludeTagDefinition(false), SuppressScope(false),
44  SuppressUnwrittenScope(false), SuppressInitializers(false),
45  ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
46  SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
47  SuppressTemplateArgsInCXXConstructors(false),
48  Bool(LO.Bool), Restrict(LO.C99),
49  Alignof(LO.CPlusPlus11), UnderscoreAlignof(LO.C11),
50  UseVoidForZeroParams(!LO.CPlusPlus),
51  TerseOutput(false), PolishForDeclaration(false),
52  Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
53  IncludeNewlines(true), MSVCFormatting(false),
54  ConstantsAsWritten(false), SuppressImplicitBase(false),
55  FullyQualifiedName(false) { }
56 
57  /// Adjust this printing policy for cases where it's known that we're
58  /// printing C++ code (for instance, if AST dumping reaches a C++-only
59  /// construct). This should not be used if a real LangOptions object is
60  /// available.
62  SuppressTagKeyword = true;
63  Bool = true;
64  UseVoidForZeroParams = false;
65  }
66 
67  /// The number of spaces to use to indent each line.
68  unsigned Indentation : 8;
69 
70  /// Whether we should suppress printing of the actual specifiers for
71  /// the given type or declaration.
72  ///
73  /// This flag is only used when we are printing declarators beyond
74  /// the first declarator within a declaration group. For example, given:
75  ///
76  /// \code
77  /// const int *x, *y;
78  /// \endcode
79  ///
80  /// SuppressSpecifiers will be false when printing the
81  /// declaration for "x", so that we will print "int *x"; it will be
82  /// \c true when we print "y", so that we suppress printing the
83  /// "const int" type specifier and instead only print the "*y".
85 
86  /// Whether type printing should skip printing the tag keyword.
87  ///
88  /// This is used when printing the inner type of elaborated types,
89  /// (as the tag keyword is part of the elaborated type):
90  ///
91  /// \code
92  /// struct Geometry::Point;
93  /// \endcode
95 
96  /// When true, include the body of a tag definition.
97  ///
98  /// This is used to place the definition of a struct
99  /// in the middle of another declaration as with:
100  ///
101  /// \code
102  /// typedef struct { int x, y; } Point;
103  /// \endcode
105 
106  /// Suppresses printing of scope specifiers.
107  bool SuppressScope : 1;
108 
109  /// Suppress printing parts of scope specifiers that don't need
110  /// to be written, e.g., for inline or anonymous namespaces.
112 
113  /// Suppress printing of variable initializers.
114  ///
115  /// This flag is used when printing the loop variable in a for-range
116  /// statement. For example, given:
117  ///
118  /// \code
119  /// for (auto x : coll)
120  /// \endcode
121  ///
122  /// SuppressInitializers will be true when printing "auto x", so that the
123  /// internal initializer constructed for x will not be printed.
125 
126  /// Whether we should print the sizes of constant array expressions as written
127  /// in the sources.
128  ///
129  /// This flag determines whether array types declared as
130  ///
131  /// \code
132  /// int a[4+10*10];
133  /// char a[] = "A string";
134  /// \endcode
135  ///
136  /// will be printed as written or as follows:
137  ///
138  /// \code
139  /// int a[104];
140  /// char a[9] = "A string";
141  /// \endcode
143 
144  /// When printing an anonymous tag name, also print the location of that
145  /// entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just prints
146  /// "(anonymous)" for the name.
148 
149  /// When true, suppress printing of the __strong lifetime qualifier in ARC.
151 
152  /// When true, suppress printing of lifetime qualifier in ARC.
154 
155  /// When true, suppresses printing template arguments in names of C++
156  /// constructors.
158 
159  /// Whether we can use 'bool' rather than '_Bool' (even if the language
160  /// doesn't actually have 'bool', because, e.g., it is defined as a macro).
161  unsigned Bool : 1;
162 
163  /// Whether we can use 'restrict' rather than '__restrict'.
164  unsigned Restrict : 1;
165 
166  /// Whether we can use 'alignof' rather than '__alignof'.
167  unsigned Alignof : 1;
168 
169  /// Whether we can use '_Alignof' rather than '__alignof'.
170  unsigned UnderscoreAlignof : 1;
171 
172  /// Whether we should use '(void)' rather than '()' for a function prototype
173  /// with zero parameters.
174  unsigned UseVoidForZeroParams : 1;
175 
176  /// Provide a 'terse' output.
177  ///
178  /// For example, in this mode we don't print function bodies, class members,
179  /// declarations inside namespaces etc. Effectively, this should print
180  /// only the requested declaration.
181  unsigned TerseOutput : 1;
182 
183  /// When true, do certain refinement needed for producing proper declaration
184  /// tag; such as, do not print attributes attached to the declaration.
185  ///
186  unsigned PolishForDeclaration : 1;
187 
188  /// When true, print the half-precision floating-point type as 'half'
189  /// instead of '__fp16'
190  unsigned Half : 1;
191 
192  /// When true, print the built-in wchar_t type as __wchar_t. For use in
193  /// Microsoft mode when wchar_t is not available.
194  unsigned MSWChar : 1;
195 
196  /// When true, include newlines after statements like "break", etc.
197  unsigned IncludeNewlines : 1;
198 
199  /// Use whitespace and punctuation like MSVC does. In particular, this prints
200  /// anonymous namespaces as `anonymous namespace' and does not insert spaces
201  /// after template arguments.
202  bool MSVCFormatting : 1;
203 
204  /// Whether we should print the constant expressions as written in the
205  /// sources.
206  ///
207  /// This flag determines whether constants expressions like
208  ///
209  /// \code
210  /// 0x10
211  /// 2.5e3
212  /// \endcode
213  ///
214  /// will be printed as written or as follows:
215  ///
216  /// \code
217  /// 0x10
218  /// 2.5e3
219  /// \endcode
221 
222  /// When true, don't print the implicit 'self' or 'this' expressions.
224 
225  /// When true, print the fully qualified name of function declarations.
226  /// This is the opposite of SuppressScope and thus overrules it.
228 };
229 
230 } // end namespace clang
231 
232 #endif
PrintingPolicy(const LangOptions &LO)
Create a default printing policy for the specified language.
Definition: PrettyPrinter.h:40
Stmt - This represents one statement.
Definition: Stmt.h:66
unsigned MSWChar
When true, print the built-in wchar_t type as __wchar_t.
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
unsigned TerseOutput
Provide a &#39;terse&#39; 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.
unsigned UseVoidForZeroParams
Whether we should use &#39;(void)&#39; rather than &#39;()&#39; for a function prototype with zero parameters...
unsigned Half
When true, print the half-precision floating-point type as &#39;half&#39; instead of &#39;__fp16&#39;.
unsigned SuppressTemplateArgsInCXXConstructors
When true, suppresses printing template arguments in names of C++ constructors.
Defines the clang::LangOptions interface.
bool IncludeTagDefinition
When true, include the body of a tag definition.
virtual bool handledStmt(Stmt *E, raw_ostream &OS)=0
unsigned Restrict
Whether we can use &#39;restrict&#39; rather than &#39;__restrict&#39;.
unsigned Bool
Whether we can use &#39;bool&#39; rather than &#39;_Bool&#39; (even if the language doesn&#39;t actually have &#39;bool&#39;...
#define false
Definition: stdbool.h:33
unsigned Indentation
The number of spaces to use to indent each line.
Definition: PrettyPrinter.h:68
unsigned UnderscoreAlignof
Whether we can use &#39;_Alignof&#39; rather than &#39;__alignof&#39;.
bool SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Definition: PrettyPrinter.h:84
bool SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
Definition: PrettyPrinter.h:94
bool FullyQualifiedName
When true, print the fully qualified name of function declarations.
Dataflow Directional Tag Classes.
void adjustForCPlusPlus()
Adjust this printing policy for cases where it&#39;s known that we&#39;re printing C++ code (for instance...
Definition: PrettyPrinter.h:61
bool SuppressImplicitBase
When true, don&#39;t print the implicit &#39;self&#39; or &#39;this&#39; expressions.
bool SuppressUnwrittenScope
Suppress printing parts of scope specifiers that don&#39;t need to be written, e.g., for inline or anonym...
bool ConstantArraySizeAsWritten
Whether we should print the sizes of constant array expressions as written in the sources...
unsigned Alignof
Whether we can use &#39;alignof&#39; rather than &#39;__alignof&#39;.
bool ConstantsAsWritten
Whether we should print the constant 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>").
unsigned IncludeNewlines
When true, include newlines after statements like "break", etc.
bool MSVCFormatting
Use whitespace and punctuation like MSVC does.
#define true
Definition: stdbool.h:32
unsigned PolishForDeclaration
When true, do certain refinement needed for producing proper declaration tag; such as...