1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===--- DiagnosticRenderer.h - Diagnostic Pretty-Printing ------*- C++ -*-===// 2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// The LLVM Compiler Infrastructure 4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source 6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details. 7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This is a utility class that provides support for pretty-printing of 11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// diagnostics. It is used to implement the different code paths which require 12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// such functionality in a consistent way. 13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_CLANG_FRONTEND_DIAGNOSTICRENDERER_H 17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_CLANG_FRONTEND_DIAGNOSTICRENDERER_H 18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/Diagnostic.h" 20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/LLVM.h" 21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "clang/Basic/SourceLocation.h" 22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/PointerUnion.h" 23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace clang { 25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DiagnosticOptions; 27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass LangOptions; 28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass SourceManager; 29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robottypedef llvm::PointerUnion<const Diagnostic *, 31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const StoredDiagnostic *> DiagOrStoredDiag; 32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Class to encapsulate the logic for formatting a diagnostic message. 34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Actual "printing" logic is implemented by subclasses. 36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// This class provides an interface for building and emitting 38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// diagnostic, including all of the macro backtraces, caret diagnostics, FixIt 39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Hints, and code snippets. In the presence of macros this involves 40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// a recursive process, synthesizing notes for each macro expansion. 41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// A brief worklist: 43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// FIXME: Sink the recursive printing of template instantiations into this 44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// class. 45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DiagnosticRenderer { 46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprotected: 47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const LangOptions &LangOpts; 48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; 49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The location of the previous diagnostic if known. 51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This will be invalid in cases where there is no (known) previous 53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// diagnostic location, or that location itself is invalid or comes from 54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// a different source manager than SM. 55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation LastLoc; 56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The location of the last include whose stack was printed if known. 58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Same restriction as LastLoc essentially, but tracking include stack 60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// root locations rather than diagnostic locations. 61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SourceLocation LastIncludeLoc; 62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief The level of the last diagnostic emitted. 64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// The level of the last diagnostic emitted. Used to detect level changes 66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// which change the amount of information displayed. 67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level LastLevel; 68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticRenderer(const LangOptions &LangOpts, 70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticOptions *DiagOpts); 71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual ~DiagnosticRenderer(); 73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, 75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level, 76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef Message, 77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<CharSourceRange> Ranges, 78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagOrStoredDiag Info) = 0; 79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, 81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level, 82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<CharSourceRange> Ranges) = 0; 83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitCodeContext(FullSourceLoc Loc, 85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level, 86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallVectorImpl<CharSourceRange> &Ranges, 87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<FixItHint> Hints) = 0; 88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) = 0; 90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, 91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef ModuleName) = 0; 92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, 93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef ModuleName) = 0; 94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void beginDiagnostic(DiagOrStoredDiag D, 96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level) {} 97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void endDiagnostic(DiagOrStoredDiag D, 98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level) {} 99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate: 102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitBasicNote(StringRef Message); 103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc, 104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level); 105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitIncludeStackRecursively(FullSourceLoc Loc); 106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitImportStack(FullSourceLoc Loc); 107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitImportStackRecursively(FullSourceLoc Loc, StringRef ModuleName); 108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitModuleBuildStack(const SourceManager &SM); 109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, 110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints); 111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitSingleMacroExpansion(FullSourceLoc Loc, 112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticsEngine::Level Level, 113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<CharSourceRange> Ranges); 114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level, 115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<CharSourceRange> Ranges, 116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<FixItHint> Hints); 117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Emit a diagnostic. 120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This is the primary entry point for emitting diagnostic messages. 122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// It handles formatting and rendering the message as well as any ancillary 123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// information needed based on macros whose expansions impact the 124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// diagnostic. 125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Loc The location for this caret. 127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Level The level of the diagnostic to be emitted. 128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Message The diagnostic message to emit. 129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param Ranges The underlined ranges for this code snippet. 130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \param FixItHints The FixIt hints active for this diagnostic. 131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level, 132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef Message, ArrayRef<CharSourceRange> Ranges, 133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ArrayRef<FixItHint> FixItHints, 134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagOrStoredDiag D = (Diagnostic *)nullptr); 135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitStoredDiagnostic(StoredDiagnostic &Diag); 137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// Subclass of DiagnosticRender that turns all subdiagostics into explicit 140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// notes. It is up to subclasses to further define the behavior. 141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass DiagnosticNoteRenderer : public DiagnosticRenderer { 142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticNoteRenderer(const LangOptions &LangOpts, 144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DiagnosticOptions *DiagOpts) 145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : DiagnosticRenderer(LangOpts, DiagOpts) {} 146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot ~DiagnosticNoteRenderer() override; 148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override; 150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, 152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef ModuleName) override; 153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, 155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot StringRef ModuleName) override; 156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot virtual void emitNote(FullSourceLoc Loc, StringRef Message) = 0; 158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} // end clang namespace 160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif 161