]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/AST/PrettyPrinter.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / AST / PrettyPrinter.h
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
19 namespace llvm {
20   class raw_ostream;
21 }
22
23 namespace clang {
24
25 class Stmt;
26 class TagDecl;
27 class LangOptions;
28
29 class PrinterHelper {
30 public:
31   virtual ~PrinterHelper();
32   virtual bool handledStmt(Stmt* E, llvm::raw_ostream& OS) = 0;
33 };
34
35 /// \brief Describes how types, statements, expressions, and
36 /// declarations should be printed.
37 struct PrintingPolicy {
38   /// \brief Create a default printing policy for C.
39   PrintingPolicy(const LangOptions &LO)
40     : Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
41       SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
42       SuppressInitializers(false),
43       Dump(false), ConstantArraySizeAsWritten(false),
44       AnonymousTagLocations(true), SuppressStrongLifetime(false) { }
45
46   /// \brief The number of spaces to use to indent each line.
47   unsigned Indentation : 8;
48
49   /// \brief What language we're printing.
50   const LangOptions LangOpts;
51
52   /// \brief Whether we should suppress printing of the actual specifiers for
53   /// the given type or declaration.
54   ///
55   /// This flag is only used when we are printing declarators beyond
56   /// the first declarator within a declaration group. For example, given:
57   ///
58   /// \code
59   /// const int *x, *y;
60   /// \endcode
61   ///
62   /// SuppressSpecifiers will be false when printing the
63   /// declaration for "x", so that we will print "int *x"; it will be
64   /// \c true when we print "y", so that we suppress printing the
65   /// "const int" type specifier and instead only print the "*y".
66   bool SuppressSpecifiers : 1;
67
68   /// \brief Whether type printing should skip printing the tag keyword.
69   ///
70   /// This is used when printing the inner type of elaborated types,
71   /// (as the tag keyword is part of the elaborated type):
72   ///
73   /// \code
74   /// struct Geometry::Point;
75   /// \endcode
76   bool SuppressTagKeyword : 1;
77
78   /// \brief Whether type printing should skip printing the actual tag type.
79   ///
80   /// This is used when the caller needs to print a tag definition in front
81   /// of the type, as in constructs like the following:
82   ///
83   /// \code
84   /// typedef struct { int x, y; } Point;
85   /// \endcode
86   bool SuppressTag : 1;
87
88   /// \brief Suppresses printing of scope specifiers.
89   bool SuppressScope : 1;
90
91   /// \brief Suppress printing of variable initializers.
92   ///
93   /// This flag is used when printing the loop variable in a for-range
94   /// statement. For example, given:
95   ///
96   /// \code
97   /// for (auto x : coll)
98   /// \endcode
99   ///
100   /// SuppressInitializers will be true when printing "auto x", so that the
101   /// internal initializer constructed for x will not be printed.
102   bool SuppressInitializers : 1;
103
104   /// \brief True when we are "dumping" rather than "pretty-printing",
105   /// where dumping involves printing the internal details of the AST
106   /// and pretty-printing involves printing something similar to
107   /// source code.
108   bool Dump : 1;
109
110   /// \brief Whether we should print the sizes of constant array expressions
111   /// as written in the sources.
112   ///
113   /// This flag is determines whether arrays types declared as
114   ///
115   /// \code
116   /// int a[4+10*10];
117   /// char a[] = "A string";
118   /// \endcode
119   ///
120   /// will be printed as written or as follows:
121   ///
122   /// \code
123   /// int a[104];
124   /// char a[9] = "A string";
125   /// \endcode
126   bool ConstantArraySizeAsWritten : 1;
127   
128   /// \brief When printing an anonymous tag name, also print the location of
129   /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just 
130   /// prints "<anonymous>" for the name.
131   bool AnonymousTagLocations : 1;
132   
133   /// \brief When true, suppress printing of the __strong lifetime qualifier in
134   /// ARC.
135   unsigned SuppressStrongLifetime : 1;
136 };
137
138 } // end namespace clang
139
140 #endif