DiagnosticEngine.cpp revision affc150dc44fab1911775a49636d0ce85333b634
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 18DiagnosticEngine::DiagnosticEngine(const MCLDInfo& pLDInfo, 19 DiagnosticLineInfo* pLineInfo, 20 DiagnosticPrinter* pPrinter, 21 bool pShouldOwnPrinter) 22 : m_LDInfo(pLDInfo), 23 m_pLineInfo(pLineInfo), 24 m_pPrinter(pPrinter), 25 m_InfoMap(pLDInfo), 26 m_OwnPrinter(pShouldOwnPrinter) { 27 if (NULL == m_pPrinter) { 28 m_pPrinter = new DiagnosticPrinter(); // Dumb printer 29 m_OwnPrinter = true; 30 } 31} 32 33DiagnosticEngine::~DiagnosticEngine() 34{ 35 if (m_OwnPrinter && m_pPrinter != NULL) 36 delete m_pPrinter; 37 38 if (NULL != m_pLineInfo) 39 delete m_pLineInfo; 40} 41 42void DiagnosticEngine::setPrinter(DiagnosticPrinter& pPrinter, 43 bool pShouldOwnPrinter) 44{ 45 if (m_OwnPrinter && m_pPrinter != NULL) 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_InfoMap.process(*this); 55 m_State.reset(); 56 return emitted; 57} 58 59