DiagnosticEngine.h revision affc150dc44fab1911775a49636d0ce85333b634
1//===- DiagnosticEngine.h -------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#ifndef MCLD_DIAGNOSTIC_ENGINE_H 10#define MCLD_DIAGNOSTIC_ENGINE_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14#include <string> 15#include <llvm/Support/DataTypes.h> 16#include <mcld/LD/DiagnosticInfos.h> 17 18namespace mcld { 19 20class Input; 21class MCLDInfo; 22class MsgHandler; 23class DiagnosticPrinter; 24class DiagnosticLineInfo; 25 26/** \class DiagnosticEngine 27 * \brief DiagnosticEngine is used to report problems and issues. 28 * 29 * DiagnosticEngine is used to report problems and issues. It creates the 30 * Diagnostics and passes them to the DiagnosticPrinter for reporting to the 31 * user. 32 * 33 * DiagnosticEngine is a complex class, it is responsible for 34 * - remember the argument string for MsgHandler 35 * - choice the severity of a message by options 36 */ 37class DiagnosticEngine 38{ 39public: 40 enum Severity { 41 Unreachable, 42 Fatal, 43 Error, 44 Warning, 45 Debug, 46 Note, 47 Ignore, 48 None 49 }; 50 51 enum ArgumentKind { 52 ak_std_string, // std::string 53 ak_c_string, // const char * 54 ak_sint, // int 55 ak_uint, // unsigned int 56 ak_bool // bool 57 }; 58 59public: 60 DiagnosticEngine(const MCLDInfo& pLDInfo, 61 DiagnosticLineInfo* pLineInfo = NULL, 62 DiagnosticPrinter* pPrinter = NULL, 63 bool pShouldOwnPrinter = true); 64 65 ~DiagnosticEngine(); 66 67 // ----- printer functions ----- // 68 void setPrinter(DiagnosticPrinter& pPrinter, bool pShouldOwnPrinter = true); 69 70 DiagnosticPrinter* getPrinter() 71 { return m_pPrinter; } 72 73 const DiagnosticPrinter* getPrinter() const 74 { return m_pPrinter; } 75 76 DiagnosticPrinter* takePrinter() { 77 m_OwnPrinter = false; 78 return m_pPrinter; 79 } 80 81 bool ownPrinter() const 82 { return m_OwnPrinter; } 83 84 // ----- emission ----- // 85 // emit - process the message to printer 86 bool emit(); 87 88 // report - issue the message to the printer 89 MsgHandler report(uint16_t pID, Severity pSeverity); 90 91private: 92 friend class MsgHandler; 93 friend class Diagnostic; 94 95 enum { 96 /// MaxArguments - The maximum number of arguments we can hold. We currently 97 /// only support up to 10 arguments (%0-%9). 98 MaxArguments = 10, 99 }; 100 101 struct State 102 { 103 public: 104 State() : numArgs(0), ID(-1), severity(None), file(NULL) { } 105 ~State() { } 106 107 void reset() { 108 numArgs = 0; 109 ID = -1; 110 severity = None; 111 file = NULL; 112 } 113 114 public: 115 std::string ArgumentStrs[MaxArguments]; 116 intptr_t ArgumentVals[MaxArguments]; 117 uint8_t ArgumentKinds[MaxArguments]; 118 int8_t numArgs; 119 uint16_t ID; 120 Severity severity; 121 Input* file; 122 }; 123 124private: 125 State& state() 126 { return m_State; } 127 128 const State& state() const 129 { return m_State; } 130 131 DiagnosticInfos& infoMap() 132 { return m_InfoMap; } 133 134 const DiagnosticInfos& infoMap() const 135 { return m_InfoMap; } 136 137private: 138 const MCLDInfo& m_LDInfo; 139 DiagnosticLineInfo* m_pLineInfo; 140 DiagnosticPrinter* m_pPrinter; 141 DiagnosticInfos m_InfoMap; 142 bool m_OwnPrinter; 143 144 State m_State; 145}; 146 147} // namespace of mcld 148 149#endif 150 151