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