1193326Sed//===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10193326Sed//  This file defines the PrinterHelper interface.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed
14193326Sed#ifndef LLVM_CLANG_AST_PRETTY_PRINTER_H
15193326Sed#define LLVM_CLANG_AST_PRETTY_PRINTER_H
16193326Sed
17249423Sdim#include "clang/Basic/LLVM.h"
18218893Sdim#include "clang/Basic/LangOptions.h"
19218893Sdim
20193326Sednamespace clang {
21193326Sed
22249423Sdimclass LangOptions;
23249423Sdimclass SourceManager;
24193326Sedclass Stmt;
25193326Sedclass TagDecl;
26193326Sed
27193326Sedclass PrinterHelper {
28193326Sedpublic:
29193326Sed  virtual ~PrinterHelper();
30226633Sdim  virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0;
31193326Sed};
32193326Sed
33193326Sed/// \brief Describes how types, statements, expressions, and
34193326Sed/// declarations should be printed.
35193326Sedstruct PrintingPolicy {
36193326Sed  /// \brief Create a default printing policy for C.
37198092Srdivacky  PrintingPolicy(const LangOptions &LO)
38239462Sdim    : LangOpts(LO), Indentation(2), SuppressSpecifiers(false),
39221345Sdim      SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
40234353Sdim      SuppressUnwrittenScope(false), SuppressInitializers(false),
41239462Sdim      ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
42263508Sdim      SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
43263508Sdim      Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
44263508Sdim      MSWChar(LO.MicrosoftExt && !LO.WChar) { }
45193326Sed
46239462Sdim  /// \brief What language we're printing.
47239462Sdim  LangOptions LangOpts;
48239462Sdim
49193326Sed  /// \brief The number of spaces to use to indent each line.
50193326Sed  unsigned Indentation : 8;
51193326Sed
52193326Sed  /// \brief Whether we should suppress printing of the actual specifiers for
53193326Sed  /// the given type or declaration.
54193326Sed  ///
55193326Sed  /// This flag is only used when we are printing declarators beyond
56193326Sed  /// the first declarator within a declaration group. For example, given:
57193326Sed  ///
58193326Sed  /// \code
59193326Sed  /// const int *x, *y;
60193326Sed  /// \endcode
61193326Sed  ///
62193326Sed  /// SuppressSpecifiers will be false when printing the
63193326Sed  /// declaration for "x", so that we will print "int *x"; it will be
64193326Sed  /// \c true when we print "y", so that we suppress printing the
65193326Sed  /// "const int" type specifier and instead only print the "*y".
66193326Sed  bool SuppressSpecifiers : 1;
67193326Sed
68221345Sdim  /// \brief Whether type printing should skip printing the tag keyword.
69221345Sdim  ///
70221345Sdim  /// This is used when printing the inner type of elaborated types,
71221345Sdim  /// (as the tag keyword is part of the elaborated type):
72221345Sdim  ///
73221345Sdim  /// \code
74221345Sdim  /// struct Geometry::Point;
75221345Sdim  /// \endcode
76221345Sdim  bool SuppressTagKeyword : 1;
77221345Sdim
78193326Sed  /// \brief Whether type printing should skip printing the actual tag type.
79193326Sed  ///
80193326Sed  /// This is used when the caller needs to print a tag definition in front
81193326Sed  /// of the type, as in constructs like the following:
82193326Sed  ///
83193326Sed  /// \code
84193326Sed  /// typedef struct { int x, y; } Point;
85193326Sed  /// \endcode
86193326Sed  bool SuppressTag : 1;
87193326Sed
88198092Srdivacky  /// \brief Suppresses printing of scope specifiers.
89198092Srdivacky  bool SuppressScope : 1;
90198092Srdivacky
91234353Sdim  /// \brief Suppress printing parts of scope specifiers that don't need
92234353Sdim  /// to be written, e.g., for inline or anonymous namespaces.
93234353Sdim  bool SuppressUnwrittenScope : 1;
94234353Sdim
95221345Sdim  /// \brief Suppress printing of variable initializers.
96221345Sdim  ///
97221345Sdim  /// This flag is used when printing the loop variable in a for-range
98221345Sdim  /// statement. For example, given:
99221345Sdim  ///
100221345Sdim  /// \code
101221345Sdim  /// for (auto x : coll)
102221345Sdim  /// \endcode
103221345Sdim  ///
104221345Sdim  /// SuppressInitializers will be true when printing "auto x", so that the
105221345Sdim  /// internal initializer constructed for x will not be printed.
106221345Sdim  bool SuppressInitializers : 1;
107221345Sdim
108198092Srdivacky  /// \brief Whether we should print the sizes of constant array expressions
109198092Srdivacky  /// as written in the sources.
110198092Srdivacky  ///
111198092Srdivacky  /// This flag is determines whether arrays types declared as
112198092Srdivacky  ///
113198092Srdivacky  /// \code
114198092Srdivacky  /// int a[4+10*10];
115198092Srdivacky  /// char a[] = "A string";
116198092Srdivacky  /// \endcode
117198092Srdivacky  ///
118198092Srdivacky  /// will be printed as written or as follows:
119198092Srdivacky  ///
120198092Srdivacky  /// \code
121198092Srdivacky  /// int a[104];
122198092Srdivacky  /// char a[9] = "A string";
123198092Srdivacky  /// \endcode
124198092Srdivacky  bool ConstantArraySizeAsWritten : 1;
125206275Srdivacky
126206275Srdivacky  /// \brief When printing an anonymous tag name, also print the location of
127206275Srdivacky  /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just
128206275Srdivacky  /// prints "<anonymous>" for the name.
129206275Srdivacky  bool AnonymousTagLocations : 1;
130224145Sdim
131224145Sdim  /// \brief When true, suppress printing of the __strong lifetime qualifier in
132224145Sdim  /// ARC.
133224145Sdim  unsigned SuppressStrongLifetime : 1;
134226633Sdim
135263508Sdim  /// \brief When true, suppress printing of lifetime qualifier in
136263508Sdim  /// ARC.
137263508Sdim  unsigned SuppressLifetimeQualifiers : 1;
138263508Sdim
139226633Sdim  /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
140226633Sdim  /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
141226633Sdim  unsigned Bool : 1;
142239462Sdim
143243830Sdim  /// \brief Provide a 'terse' output.
144243830Sdim  ///
145243830Sdim  /// For example, in this mode we don't print function bodies, class members,
146243830Sdim  /// declarations inside namespaces etc.  Effectively, this should print
147243830Sdim  /// only the requested declaration.
148243830Sdim  unsigned TerseOutput : 1;
149243830Sdim
150249423Sdim  /// \brief When true, do certain refinement needed for producing proper
151249423Sdim  /// declaration tag; such as, do not print attributes attached to the declaration.
152243830Sdim  ///
153249423Sdim  unsigned PolishForDeclaration : 1;
154263508Sdim
155263508Sdim  /// \brief When true, print the built-in wchar_t type as __wchar_t. For use in
156263508Sdim  /// Microsoft mode when wchar_t is not available.
157263508Sdim  unsigned MSWChar : 1;
158193326Sed};
159193326Sed
160193326Sed} // end namespace clang
161193326Sed
162193326Sed#endif
163