1//===- DiagnosticEngine.cpp -----------------------------------------------===//
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#include <mcld/LD/DiagnosticEngine.h>
10#include <mcld/LD/DiagnosticPrinter.h>
11#include <mcld/LD/DiagnosticLineInfo.h>
12#include <mcld/MC/MCLDInfo.h>
13
14using namespace mcld;
15
16//===----------------------------------------------------------------------===//
17// DiagnosticEngine
18//===----------------------------------------------------------------------===//
19DiagnosticEngine::DiagnosticEngine()
20  : m_pLDInfo(NULL), m_pLineInfo(NULL), m_pPrinter(NULL),
21    m_pInfoMap(NULL), m_OwnPrinter(false) {
22}
23
24DiagnosticEngine::~DiagnosticEngine()
25{
26  if (m_OwnPrinter && m_pPrinter != NULL)
27    delete m_pPrinter;
28}
29
30void DiagnosticEngine::reset(const MCLDInfo& pLDInfo)
31{
32  m_pLDInfo = &pLDInfo;
33  m_pInfoMap = new DiagnosticInfos(*m_pLDInfo);
34  m_State.reset();
35}
36
37void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo)
38{
39  m_pLineInfo = &pLineInfo;
40}
41
42void DiagnosticEngine::setPrinter(DiagnosticPrinter& pPrinter,
43                                  bool pShouldOwnPrinter)
44{
45  if (m_OwnPrinter && NULL != m_pPrinter)
46    delete m_pPrinter;
47  m_pPrinter = &pPrinter;
48  m_OwnPrinter = pShouldOwnPrinter;
49}
50
51// emit - process current diagnostic.
52bool DiagnosticEngine::emit()
53{
54  bool emitted = m_pInfoMap->process(*this);
55  m_State.reset();
56  return emitted;
57}
58
59