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_PRETTY_PRINTER_H
15 #define LLVM_CLANG_AST_PRETTY_PRINTER_H
17 #include "clang/Basic/LangOptions.h"
18 #include "clang/Basic/LLVM.h"
28 virtual ~PrinterHelper();
29 virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0;
32 /// \brief Describes how types, statements, expressions, and
33 /// declarations should be printed.
34 struct PrintingPolicy {
35 /// \brief Create a default printing policy for C.
36 PrintingPolicy(const LangOptions &LO)
37 : Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
38 SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
39 SuppressInitializers(false),
40 Dump(false), ConstantArraySizeAsWritten(false),
41 AnonymousTagLocations(true), SuppressStrongLifetime(false),
44 /// \brief The number of spaces to use to indent each line.
45 unsigned Indentation : 8;
47 /// \brief What language we're printing.
50 /// \brief Whether we should suppress printing of the actual specifiers for
51 /// the given type or declaration.
53 /// This flag is only used when we are printing declarators beyond
54 /// the first declarator within a declaration group. For example, given:
60 /// SuppressSpecifiers will be false when printing the
61 /// declaration for "x", so that we will print "int *x"; it will be
62 /// \c true when we print "y", so that we suppress printing the
63 /// "const int" type specifier and instead only print the "*y".
64 bool SuppressSpecifiers : 1;
66 /// \brief Whether type printing should skip printing the tag keyword.
68 /// This is used when printing the inner type of elaborated types,
69 /// (as the tag keyword is part of the elaborated type):
72 /// struct Geometry::Point;
74 bool SuppressTagKeyword : 1;
76 /// \brief Whether type printing should skip printing the actual tag type.
78 /// This is used when the caller needs to print a tag definition in front
79 /// of the type, as in constructs like the following:
82 /// typedef struct { int x, y; } Point;
86 /// \brief Suppresses printing of scope specifiers.
87 bool SuppressScope : 1;
89 /// \brief Suppress printing of variable initializers.
91 /// This flag is used when printing the loop variable in a for-range
92 /// statement. For example, given:
95 /// for (auto x : coll)
98 /// SuppressInitializers will be true when printing "auto x", so that the
99 /// internal initializer constructed for x will not be printed.
100 bool SuppressInitializers : 1;
102 /// \brief True when we are "dumping" rather than "pretty-printing",
103 /// where dumping involves printing the internal details of the AST
104 /// and pretty-printing involves printing something similar to
108 /// \brief Whether we should print the sizes of constant array expressions
109 /// as written in the sources.
111 /// This flag is determines whether arrays types declared as
115 /// char a[] = "A string";
118 /// will be printed as written or as follows:
122 /// char a[9] = "A string";
124 bool ConstantArraySizeAsWritten : 1;
126 /// \brief When printing an anonymous tag name, also print the location of
127 /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just
128 /// prints "<anonymous>" for the name.
129 bool AnonymousTagLocations : 1;
131 /// \brief When true, suppress printing of the __strong lifetime qualifier in
133 unsigned SuppressStrongLifetime : 1;
135 /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
136 /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
140 } // end namespace clang