DiagnosticEngine.cpp revision 22add6ff3426df1a85089fe6a6e1597ee3b6f300
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/LD/MsgHandler.h> 13#include <mcld/LinkerConfig.h> 14 15#include <cassert> 16 17using namespace mcld; 18 19//===----------------------------------------------------------------------===// 20// DiagnosticEngine 21//===----------------------------------------------------------------------===// 22DiagnosticEngine::DiagnosticEngine() 23 : m_pConfig(NULL), m_pLineInfo(NULL), m_pPrinter(NULL), 24 m_pInfoMap(NULL), m_OwnPrinter(false) { 25} 26 27DiagnosticEngine::~DiagnosticEngine() 28{ 29 if (m_OwnPrinter && m_pPrinter != NULL) 30 delete m_pPrinter; 31 32 delete m_pInfoMap; 33} 34 35void DiagnosticEngine::reset(const LinkerConfig& pConfig) 36{ 37 m_pConfig = &pConfig; 38 delete m_pInfoMap; 39 m_pInfoMap = new DiagnosticInfos(*m_pConfig); 40 m_State.reset(); 41} 42 43void DiagnosticEngine::setLineInfo(DiagnosticLineInfo& pLineInfo) 44{ 45 m_pLineInfo = &pLineInfo; 46} 47 48void DiagnosticEngine::setPrinter(DiagnosticPrinter& pPrinter, 49 bool pShouldOwnPrinter) 50{ 51 if (m_OwnPrinter && NULL != m_pPrinter) 52 delete m_pPrinter; 53 m_pPrinter = &pPrinter; 54 m_OwnPrinter = pShouldOwnPrinter; 55} 56 57// emit - process current diagnostic. 58bool DiagnosticEngine::emit() 59{ 60 assert(NULL != m_pInfoMap); 61 bool emitted = m_pInfoMap->process(*this); 62 m_State.reset(); 63 return emitted; 64} 65 66MsgHandler 67DiagnosticEngine::report(uint16_t pID, DiagnosticEngine::Severity pSeverity) 68{ 69 m_State.ID = pID; 70 m_State.severity = pSeverity; 71 72 MsgHandler result(*this); 73 return result; 74} 75 76