Home | History | Annotate | Download | only in DWARF
      1 //===-- DWARFDeclContext.h --------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef SymbolFileDWARF_DWARFDeclContext_h_
     11 #define SymbolFileDWARF_DWARFDeclContext_h_
     12 
     13 // C Includes
     14 // C++ Includes
     15 #include <string>
     16 #include <vector>
     17 // Other libraries and framework includes
     18 #include "lldb/Core/ConstString.h"
     19 // Project includes
     20 #include "DWARFDefines.h"
     21 
     22 //----------------------------------------------------------------------
     23 // DWARFDeclContext
     24 //
     25 // A class that represents a declaration context all the way down to a
     26 // DIE. This is useful when trying to find a DIE in one DWARF to a DIE
     27 // in another DWARF file.
     28 //----------------------------------------------------------------------
     29 
     30 class DWARFDeclContext
     31 {
     32 public:
     33     struct Entry
     34     {
     35         Entry () :
     36             tag(0),
     37             name(NULL)
     38         {
     39         }
     40         Entry (dw_tag_t t, const char *n) :
     41             tag(t),
     42             name(n)
     43         {
     44         }
     45 
     46         bool
     47         NameMatches (const Entry& rhs) const
     48         {
     49             if (name == rhs.name)
     50                 return true;
     51             else if (name && rhs.name)
     52                 return strcmp(name, rhs.name) == 0;
     53             return false;
     54         }
     55 
     56         // Test operator
     57         operator bool() const
     58         {
     59             return tag != 0;
     60         }
     61 
     62         dw_tag_t tag;
     63         const char *name;
     64     };
     65 
     66     DWARFDeclContext () :
     67         m_entries()
     68     {
     69     }
     70 
     71     void
     72     AppendDeclContext (dw_tag_t tag, const char *name)
     73     {
     74         m_entries.push_back(Entry(tag, name));
     75     }
     76 
     77     bool
     78     operator ==(const DWARFDeclContext& rhs) const;
     79 
     80     uint32_t
     81     GetSize() const
     82     {
     83         return m_entries.size();
     84     }
     85 
     86     Entry &
     87     operator[] (uint32_t idx)
     88     {
     89         // "idx" must be valid
     90         return m_entries[idx];
     91     }
     92 
     93     const Entry &
     94     operator[] (uint32_t idx) const
     95     {
     96         // "idx" must be valid
     97         return m_entries[idx];
     98     }
     99 
    100     const char *
    101     GetQualifiedName () const;
    102 
    103 protected:
    104     typedef std::vector<Entry> collection;
    105     collection m_entries;
    106     mutable std::string m_qualified_name;
    107 };
    108 
    109 #endif  // SymbolFileDWARF_DWARFDeclContext_h_
    110