blob: 9b1ed809b113d5112ea5df360cbda80ce34fedcf [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//===----------------------------------------------------------------------===//
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
Shih-wei Liao22add6f2012-12-15 17:21:00 -080020namespace mcld {
Zonr Changaffc1502012-07-16 14:28:23 +080021
22/** \class MsgHandler
23 * \brief MsgHandler controls the timing to output message.
24 */
25class MsgHandler
26{
27public:
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
39private:
40 void flushCounts()
41 { m_Engine.state().numArgs = m_NumArgs; }
42
43private:
44 DiagnosticEngine& m_Engine;
45 mutable unsigned int m_NumArgs;
46};
47
48inline const MsgHandler &
49operator<<(const MsgHandler& pHandler, llvm::StringRef pStr)
50{
51 pHandler.addString(pStr);
52 return pHandler;
53}
54
55inline const MsgHandler &
56operator<<(const MsgHandler& pHandler, const std::string& pStr)
57{
58 pHandler.addString(pStr);
59 return pHandler;
60}
61
62inline const MsgHandler &
63operator<<(const MsgHandler& pHandler, const sys::fs::Path& pPath)
64{
65 pHandler.addString(pPath.native());
66 return pHandler;
67}
68
69inline const MsgHandler &
70operator<<(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
77inline const MsgHandler &
78operator<<(const MsgHandler& pHandler, int pValue)
79{
80 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint);
81 return pHandler;
82}
83
84inline const MsgHandler &
85operator<<(const MsgHandler& pHandler, unsigned int pValue)
86{
87 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint);
88 return pHandler;
89}
90
91inline const MsgHandler &
92operator<<(const MsgHandler& pHandler, long pValue)
93{
94 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_sint);
95 return pHandler;
96}
97
98inline const MsgHandler &
99operator<<(const MsgHandler& pHandler, unsigned long pValue)
100{
101 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_uint);
102 return pHandler;
103}
104
105inline const MsgHandler &
Stephen Hinesf7ac0f12013-05-03 19:09:24 -0700106operator<<(const MsgHandler& pHandler, unsigned long long pValue)
107{
108 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_ulonglong);
109 return pHandler;
110}
111
112inline const MsgHandler &
Zonr Changaffc1502012-07-16 14:28:23 +0800113operator<<(const MsgHandler& pHandler, bool pValue)
114{
115 pHandler.addTaggedVal(pValue, DiagnosticEngine::ak_bool);
116 return pHandler;
117}
118
Zonr Changaffc1502012-07-16 14:28:23 +0800119} // namespace of mcld
120
121#endif
122