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