blob: 36ba1cd26f28548a1cacbc2a8be94fe1830b885b [file] [log] [blame]
Zonr Changaffc1502012-07-16 14:28:23 +08001//===- 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//===----------------------------------------------------------------------===//
Stephen Hines87f34652014-02-14 18:00:16 -08009#ifndef MCLD_LD_MSGHANDLER_H
10#define MCLD_LD_MSGHANDLER_H
Zonr Changaffc1502012-07-16 14:28:23 +080011#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
Shih-wei Liao22add6f2012-12-15 17:21:00 -080017namespace mcld {
Zonr Changaffc1502012-07-16 14:28:23 +080018
19/** \class MsgHandler
20 * \brief MsgHandler controls the timing to output message.
21 */
22class MsgHandler
23{
24public:
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
36private:
37 void flushCounts()
38 { m_Engine.state().numArgs = m_NumArgs; }
39
40private:
41 DiagnosticEngine& m_Engine;
42 mutable unsigned int m_NumArgs;
43};
44
45inline const MsgHandler &
46operator<<(const MsgHandler& pHandler, llvm::StringRef pStr)
47{
48 pHandler.addString(pStr);
49 return pHandler;
50}
51
52inline const MsgHandler &
53operator<<(const MsgHandler& pHandler, const std::string& pStr)
54{
55 pHandler.addString(pStr);
56 return pHandler;
57}
58
59inline const MsgHandler &
60operator<<(const MsgHandler& pHandler, const sys::fs::Path& pPath)
61{
62 pHandler.addString(pPath.native());
63 return pHandler;
64}
65
66inline const MsgHandler &
67operator<<(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
74inline const MsgHandler &
75operator<<(const MsgHandler& pHandler, int pValue)
76{
77 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint);
78 return pHandler;
79}
80
81inline const MsgHandler &
82operator<<(const MsgHandler& pHandler, unsigned int pValue)
83{
84 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint);
85 return pHandler;
86}
87
88inline const MsgHandler &
89operator<<(const MsgHandler& pHandler, long pValue)
90{
91 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint);
92 return pHandler;
93}
94
95inline const MsgHandler &
96operator<<(const MsgHandler& pHandler, unsigned long pValue)
97{
98 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint);
99 return pHandler;
100}
101
102inline const MsgHandler &
Stephen Hinesf7ac0f12013-05-03 19:09:24 -0700103operator<<(const MsgHandler& pHandler, unsigned long long pValue)
104{
105 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_ulonglong);
106 return pHandler;
107}
108
109inline const MsgHandler &
Zonr Changaffc1502012-07-16 14:28:23 +0800110operator<<(const MsgHandler& pHandler, bool pValue)
111{
112 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_bool);
113 return pHandler;
114}
115
Zonr Changaffc1502012-07-16 14:28:23 +0800116} // namespace of mcld
117
118#endif
119