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 18 namespace mcld { 19 20 class Input; 21 class MCLDInfo; 22 class MsgHandler; 23 class DiagnosticPrinter; 24 class 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 */ 37 class DiagnosticEngine 38 { 39 public: 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 59 public: 60 DiagnosticEngine(); 61 62 ~DiagnosticEngine(); 63 64 void reset(const MCLDInfo& pLDInfo); 65 66 void setLineInfo(DiagnosticLineInfo& pLineInfo); 67 68 void setPrinter(DiagnosticPrinter& pPrinter, bool pShouldOwnPrinter = true); 69 getPrinter()70 DiagnosticPrinter* getPrinter() 71 { return m_pPrinter; } 72 getPrinter()73 const DiagnosticPrinter* getPrinter() const 74 { return m_pPrinter; } 75 takePrinter()76 DiagnosticPrinter* takePrinter() { 77 m_OwnPrinter = false; 78 return m_pPrinter; 79 } 80 ownPrinter()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 91 private: 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: StateState104 State() : numArgs(0), ID(-1), severity(None), file(NULL) { } ~StateState105 ~State() { } 106 resetState107 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 124 private: state()125 State& state() 126 { return m_State; } 127 state()128 const State& state() const 129 { return m_State; } 130 infoMap()131 DiagnosticInfos& infoMap() { 132 assert(NULL != m_pInfoMap && "DiagnosticEngine was not initialized!"); 133 return *m_pInfoMap; 134 } 135 infoMap()136 const DiagnosticInfos& infoMap() const { 137 assert(NULL != m_pInfoMap && "DiagnosticEngine was not initialized!"); 138 return *m_pInfoMap; 139 } 140 141 private: 142 const MCLDInfo* m_pLDInfo; 143 DiagnosticLineInfo* m_pLineInfo; 144 DiagnosticPrinter* m_pPrinter; 145 DiagnosticInfos* m_pInfoMap; 146 bool m_OwnPrinter; 147 148 State m_State; 149 }; 150 151 } // namespace of mcld 152 153 #endif 154 155