DiagnosticEngine.cpp revision 67e37f1be98c926645219cfb47fab9e90d8c725c
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 if (NULL != m_pLineInfo) 30 delete m_pLineInfo; 31} 32 33void DiagnosticEngine::reset(const MCLDInfo& pLDInfo) 34{ 35 m_pLDInfo = &pLDInfo; 36 m_pInfoMap = new DiagnosticInfos(*m_pLDInfo); 37 m_State.reset(); 38} 39 40void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo) 41{ 42 m_pLineInfo = &pLineInfo; 43} 44 45void DiagnosticEngine::setPrinter(DiagnosticPrinter& pPrinter, 46 bool pShouldOwnPrinter) 47{ 48 if (m_OwnPrinter && NULL != m_pPrinter) 49 delete m_pPrinter; 50 m_pPrinter = &pPrinter; 51 m_OwnPrinter = pShouldOwnPrinter; 52} 53 54// emit - process current diagnostic. 55bool DiagnosticEngine::emit() 56{ 57 bool emitted = m_pInfoMap->process(*this); 58 m_State.reset(); 59 return emitted; 60} 61 62