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