]> git.proxmox.com Git - rustc.git/blame - src/llvm/tools/clang/include/clang/AST/PrettyPrinter.h
Imported Upstream version 0.6
[rustc.git] / src / llvm / tools / clang / include / clang / AST / PrettyPrinter.h
CommitLineData
223e47cc
LB
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_PRETTY_PRINTER_H
15#define LLVM_CLANG_AST_PRETTY_PRINTER_H
16
17#include "clang/Basic/LangOptions.h"
18#include "clang/Basic/LLVM.h"
19
20namespace clang {
21
22class Stmt;
23class TagDecl;
24class LangOptions;
25
26class PrinterHelper {
27public:
28 virtual ~PrinterHelper();
29 virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0;
30};
31
32/// \brief Describes how types, statements, expressions, and
33/// declarations should be printed.
34struct PrintingPolicy {
35 /// \brief Create a default printing policy for C.
36 PrintingPolicy(const LangOptions &LO)
37 : LangOpts(LO), Indentation(2), SuppressSpecifiers(false),
38 SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
39 SuppressUnwrittenScope(false), SuppressInitializers(false),
40 ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
41 SuppressStrongLifetime(false), Bool(LO.Bool),
42 TerseOutput(false), DumpSourceManager(0) { }
43
44 /// \brief What language we're printing.
45 LangOptions LangOpts;
46
47 /// \brief The number of spaces to use to indent each line.
48 unsigned Indentation : 8;
49
50 /// \brief Whether we should suppress printing of the actual specifiers for
51 /// the given type or declaration.
52 ///
53 /// This flag is only used when we are printing declarators beyond
54 /// the first declarator within a declaration group. For example, given:
55 ///
56 /// \code
57 /// const int *x, *y;
58 /// \endcode
59 ///
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;
65
66 /// \brief Whether type printing should skip printing the tag keyword.
67 ///
68 /// This is used when printing the inner type of elaborated types,
69 /// (as the tag keyword is part of the elaborated type):
70 ///
71 /// \code
72 /// struct Geometry::Point;
73 /// \endcode
74 bool SuppressTagKeyword : 1;
75
76 /// \brief Whether type printing should skip printing the actual tag type.
77 ///
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:
80 ///
81 /// \code
82 /// typedef struct { int x, y; } Point;
83 /// \endcode
84 bool SuppressTag : 1;
85
86 /// \brief Suppresses printing of scope specifiers.
87 bool SuppressScope : 1;
88
89 /// \brief Suppress printing parts of scope specifiers that don't need
90 /// to be written, e.g., for inline or anonymous namespaces.
91 bool SuppressUnwrittenScope : 1;
92
93 /// \brief Suppress printing of variable initializers.
94 ///
95 /// This flag is used when printing the loop variable in a for-range
96 /// statement. For example, given:
97 ///
98 /// \code
99 /// for (auto x : coll)
100 /// \endcode
101 ///
102 /// SuppressInitializers will be true when printing "auto x", so that the
103 /// internal initializer constructed for x will not be printed.
104 bool SuppressInitializers : 1;
105
106 /// \brief Whether we should print the sizes of constant array expressions
107 /// as written in the sources.
108 ///
109 /// This flag is determines whether arrays types declared as
110 ///
111 /// \code
112 /// int a[4+10*10];
113 /// char a[] = "A string";
114 /// \endcode
115 ///
116 /// will be printed as written or as follows:
117 ///
118 /// \code
119 /// int a[104];
120 /// char a[9] = "A string";
121 /// \endcode
122 bool ConstantArraySizeAsWritten : 1;
123
124 /// \brief When printing an anonymous tag name, also print the location of
125 /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just
126 /// prints "<anonymous>" for the name.
127 bool AnonymousTagLocations : 1;
128
129 /// \brief When true, suppress printing of the __strong lifetime qualifier in
130 /// ARC.
131 unsigned SuppressStrongLifetime : 1;
132
133 /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
134 /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
135 unsigned Bool : 1;
136
137 /// \brief Provide a 'terse' output.
138 ///
139 /// For example, in this mode we don't print function bodies, class members,
140 /// declarations inside namespaces etc. Effectively, this should print
141 /// only the requested declaration.
142 unsigned TerseOutput : 1;
143
144 /// \brief If we are "dumping" rather than "pretty-printing", this points to
145 /// a SourceManager which will be used to dump SourceLocations. Dumping
146 /// involves printing the internal details of the AST and pretty-printing
147 /// involves printing something similar to source code.
148 SourceManager *DumpSourceManager;
149};
150
151} // end namespace clang
152
153#endif