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
29 virtual ~PrinterHelper();
30 virtual bool handledStmt(Stmt* E, llvm::raw_ostream& OS) = 0;
33 /// \brief Describes how types, statements, expressions, and
34 /// declarations should be printed.
35 struct PrintingPolicy {
36 /// \brief Create a default printing policy for C.
37 PrintingPolicy(const LangOptions &LO)
38 : Indentation(2), LangOpts(LO), SuppressSpecifiers(false),
39 SuppressTag(false), SuppressScope(false),
40 Dump(false), ConstantArraySizeAsWritten(false),
41 AnonymousTagLocations(true) { }
43 /// \brief The number of spaces to use to indent each line.
44 unsigned Indentation : 8;
46 /// \brief What language we're printing.
47 const LangOptions &LangOpts;
49 /// \brief Whether we should suppress printing of the actual specifiers for
50 /// the given type or declaration.
52 /// This flag is only used when we are printing declarators beyond
53 /// the first declarator within a declaration group. For example, given:
59 /// SuppressSpecifiers will be false when printing the
60 /// declaration for "x", so that we will print "int *x"; it will be
61 /// \c true when we print "y", so that we suppress printing the
62 /// "const int" type specifier and instead only print the "*y".
63 bool SuppressSpecifiers : 1;
65 /// \brief Whether type printing should skip printing the actual tag type.
67 /// This is used when the caller needs to print a tag definition in front
68 /// of the type, as in constructs like the following:
71 /// typedef struct { int x, y; } Point;
75 /// \brief Suppresses printing of scope specifiers.
76 bool SuppressScope : 1;
78 /// \brief True when we are "dumping" rather than "pretty-printing",
79 /// where dumping involves printing the internal details of the AST
80 /// and pretty-printing involves printing something similar to
84 /// \brief Whether we should print the sizes of constant array expressions
85 /// as written in the sources.
87 /// This flag is determines whether arrays types declared as
91 /// char a[] = "A string";
94 /// will be printed as written or as follows:
98 /// char a[9] = "A string";
100 bool ConstantArraySizeAsWritten : 1;
102 /// \brief When printing an anonymous tag name, also print the location of
103 /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just
104 /// prints "<anonymous>" for the name.
105 bool AnonymousTagLocations : 1;
108 } // end namespace clang