clang API Documentation

PrettyPrinter.h
Go to the documentation of this file.
00001 //===--- PrettyPrinter.h - Classes for aiding with AST printing -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines the PrinterHelper interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_PRETTYPRINTER_H
00015 #define LLVM_CLANG_AST_PRETTYPRINTER_H
00016 
00017 #include "clang/Basic/LLVM.h"
00018 #include "clang/Basic/LangOptions.h"
00019 
00020 namespace clang {
00021 
00022 class LangOptions;
00023 class SourceManager;
00024 class Stmt;
00025 class TagDecl;
00026 
00027 class PrinterHelper {
00028 public:
00029   virtual ~PrinterHelper();
00030   virtual bool handledStmt(Stmt* E, raw_ostream& OS) = 0;
00031 };
00032 
00033 /// \brief Describes how types, statements, expressions, and
00034 /// declarations should be printed.
00035 struct PrintingPolicy {
00036   /// \brief Create a default printing policy for C.
00037   PrintingPolicy(const LangOptions &LO)
00038     : LangOpts(LO), Indentation(2), SuppressSpecifiers(false),
00039       SuppressTagKeyword(false), SuppressTag(false), SuppressScope(false),
00040       SuppressUnwrittenScope(false), SuppressInitializers(false),
00041       ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
00042       SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
00043       Bool(LO.Bool), TerseOutput(false), PolishForDeclaration(false),
00044       Half(LO.Half), MSWChar(LO.MicrosoftExt && !LO.WChar),
00045       IncludeNewlines(true) { }
00046 
00047   /// \brief What language we're printing.
00048   LangOptions LangOpts;
00049 
00050   /// \brief The number of spaces to use to indent each line.
00051   unsigned Indentation : 8;
00052 
00053   /// \brief Whether we should suppress printing of the actual specifiers for
00054   /// the given type or declaration.
00055   ///
00056   /// This flag is only used when we are printing declarators beyond
00057   /// the first declarator within a declaration group. For example, given:
00058   ///
00059   /// \code
00060   /// const int *x, *y;
00061   /// \endcode
00062   ///
00063   /// SuppressSpecifiers will be false when printing the
00064   /// declaration for "x", so that we will print "int *x"; it will be
00065   /// \c true when we print "y", so that we suppress printing the
00066   /// "const int" type specifier and instead only print the "*y".
00067   bool SuppressSpecifiers : 1;
00068 
00069   /// \brief Whether type printing should skip printing the tag keyword.
00070   ///
00071   /// This is used when printing the inner type of elaborated types,
00072   /// (as the tag keyword is part of the elaborated type):
00073   ///
00074   /// \code
00075   /// struct Geometry::Point;
00076   /// \endcode
00077   bool SuppressTagKeyword : 1;
00078 
00079   /// \brief Whether type printing should skip printing the actual tag type.
00080   ///
00081   /// This is used when the caller needs to print a tag definition in front
00082   /// of the type, as in constructs like the following:
00083   ///
00084   /// \code
00085   /// typedef struct { int x, y; } Point;
00086   /// \endcode
00087   bool SuppressTag : 1;
00088 
00089   /// \brief Suppresses printing of scope specifiers.
00090   bool SuppressScope : 1;
00091 
00092   /// \brief Suppress printing parts of scope specifiers that don't need
00093   /// to be written, e.g., for inline or anonymous namespaces.
00094   bool SuppressUnwrittenScope : 1;
00095   
00096   /// \brief Suppress printing of variable initializers.
00097   ///
00098   /// This flag is used when printing the loop variable in a for-range
00099   /// statement. For example, given:
00100   ///
00101   /// \code
00102   /// for (auto x : coll)
00103   /// \endcode
00104   ///
00105   /// SuppressInitializers will be true when printing "auto x", so that the
00106   /// internal initializer constructed for x will not be printed.
00107   bool SuppressInitializers : 1;
00108 
00109   /// \brief Whether we should print the sizes of constant array expressions
00110   /// as written in the sources.
00111   ///
00112   /// This flag is determines whether arrays types declared as
00113   ///
00114   /// \code
00115   /// int a[4+10*10];
00116   /// char a[] = "A string";
00117   /// \endcode
00118   ///
00119   /// will be printed as written or as follows:
00120   ///
00121   /// \code
00122   /// int a[104];
00123   /// char a[9] = "A string";
00124   /// \endcode
00125   bool ConstantArraySizeAsWritten : 1;
00126   
00127   /// \brief When printing an anonymous tag name, also print the location of
00128   /// that entity (e.g., "enum <anonymous at t.h:10:5>"). Otherwise, just 
00129   /// prints "(anonymous)" for the name.
00130   bool AnonymousTagLocations : 1;
00131   
00132   /// \brief When true, suppress printing of the __strong lifetime qualifier in
00133   /// ARC.
00134   unsigned SuppressStrongLifetime : 1;
00135   
00136   /// \brief When true, suppress printing of lifetime qualifier in
00137   /// ARC.
00138   unsigned SuppressLifetimeQualifiers : 1;
00139   
00140   /// \brief Whether we can use 'bool' rather than '_Bool', even if the language
00141   /// doesn't actually have 'bool' (because, e.g., it is defined as a macro).
00142   unsigned Bool : 1;
00143 
00144   /// \brief Provide a 'terse' output.
00145   ///
00146   /// For example, in this mode we don't print function bodies, class members,
00147   /// declarations inside namespaces etc.  Effectively, this should print
00148   /// only the requested declaration.
00149   unsigned TerseOutput : 1;
00150   
00151   /// \brief When true, do certain refinement needed for producing proper
00152   /// declaration tag; such as, do not print attributes attached to the declaration.
00153   ///
00154   unsigned PolishForDeclaration : 1;
00155 
00156   /// \brief When true, print the half-precision floating-point type as 'half'
00157   /// instead of '__fp16'
00158   unsigned Half : 1;
00159 
00160   /// \brief When true, print the built-in wchar_t type as __wchar_t. For use in
00161   /// Microsoft mode when wchar_t is not available.
00162   unsigned MSWChar : 1;
00163 
00164   /// \brief When true, include newlines after statements like "break", etc.
00165   unsigned IncludeNewlines : 1;
00166 };
00167 
00168 } // end namespace clang
00169 
00170 #endif