1 //===- MsgHandler.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_MESSAGE_HANDLER_H 10 #define MCLD_MESSAGE_HANDLER_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 #include <string> 15 #include <llvm/ADT/StringRef.h> 16 #include <llvm/ADT/Twine.h> 17 #include <mcld/Support/Path.h> 18 #include <mcld/LD/DiagnosticEngine.h> 19 20 namespace mcld { 21 22 /** \class MsgHandler 23 * \brief MsgHandler controls the timing to output message. 24 */ 25 class MsgHandler 26 { 27 public: 28 MsgHandler(DiagnosticEngine& pEngine); 29 ~MsgHandler(); 30 31 bool emit(); 32 33 void addString(llvm::StringRef pStr) const; 34 35 void addString(const std::string& pStr) const; 36 37 void addTaggedVal(intptr_t pValue, DiagnosticEngine::ArgumentKind pKind) const; 38 39 private: 40 void flushCounts() 41 { m_Engine.state().numArgs = m_NumArgs; } 42 43 private: 44 DiagnosticEngine& m_Engine; 45 mutable unsigned int m_NumArgs; 46 }; 47 48 inline const MsgHandler & 49 operator<<(const MsgHandler& pHandler, llvm::StringRef pStr) 50 { 51 pHandler.addString(pStr); 52 return pHandler; 53 } 54 55 inline const MsgHandler & 56 operator<<(const MsgHandler& pHandler, const std::string& pStr) 57 { 58 pHandler.addString(pStr); 59 return pHandler; 60 } 61 62 inline const MsgHandler & 63 operator<<(const MsgHandler& pHandler, const sys::fs::Path& pPath) 64 { 65 pHandler.addString(pPath.native()); 66 return pHandler; 67 } 68 69 inline const MsgHandler & 70 operator<<(const MsgHandler& pHandler, const char* pStr) 71 { 72 pHandler.addTaggedVal(reinterpret_cast<intptr_t>(pStr), 73 DiagnosticEngine::ak_c_string); 74 return pHandler; 75 } 76 77 inline const MsgHandler & 78 operator<<(const MsgHandler& pHandler, int pValue) 79 { 80 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint); 81 return pHandler; 82 } 83 84 inline const MsgHandler & 85 operator<<(const MsgHandler& pHandler, unsigned int pValue) 86 { 87 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint); 88 return pHandler; 89 } 90 91 inline const MsgHandler & 92 operator<<(const MsgHandler& pHandler, long pValue) 93 { 94 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint); 95 return pHandler; 96 } 97 98 inline const MsgHandler & 99 operator<<(const MsgHandler& pHandler, unsigned long pValue) 100 { 101 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint); 102 return pHandler; 103 } 104 105 inline const MsgHandler & 106 operator<<(const MsgHandler& pHandler, bool pValue) 107 { 108 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_bool); 109 return pHandler; 110 } 111 112 } // namespace of mcld 113 114 #endif 115 116