Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
39645 views
//===-- DWARFDeclContext.h --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H1011#include "DWARFDefines.h"12#include "lldb/Utility/ConstString.h"13#include "llvm/ADT/StringExtras.h"1415#include <cassert>16#include <string>17#include <vector>1819namespace lldb_private::plugin {20namespace dwarf {21// DWARFDeclContext22//23// A class that represents a declaration context all the way down to a24// DIE. This is useful when trying to find a DIE in one DWARF to a DIE25// in another DWARF file.2627class DWARFDeclContext {28public:29struct Entry {30Entry() = default;31Entry(dw_tag_t t, const char *n) : tag(t), name(n) {}3233bool NameMatches(const Entry &rhs) const {34if (name == rhs.name)35return true;36else if (name && rhs.name)37return strcmp(name, rhs.name) == 0;38return false;39}4041/// Returns the name of this entry if it has one, or the appropriate42/// "anonymous {namespace, class, struct, union}".43const char *GetName() const;4445// Test operator46explicit operator bool() const { return tag != 0; }4748dw_tag_t tag = llvm::dwarf::DW_TAG_null;49const char *name = nullptr;50};5152DWARFDeclContext() : m_entries() {}5354DWARFDeclContext(llvm::ArrayRef<Entry> entries) {55llvm::append_range(m_entries, entries);56}5758void AppendDeclContext(dw_tag_t tag, const char *name) {59m_entries.push_back(Entry(tag, name));60}6162bool operator==(const DWARFDeclContext &rhs) const;63bool operator!=(const DWARFDeclContext &rhs) const { return !(*this == rhs); }6465uint32_t GetSize() const { return m_entries.size(); }6667Entry &operator[](uint32_t idx) {68assert(idx < m_entries.size() && "invalid index");69return m_entries[idx];70}7172const Entry &operator[](uint32_t idx) const {73assert(idx < m_entries.size() && "invalid index");74return m_entries[idx];75}7677const char *GetQualifiedName() const;7879// Same as GetQualifiedName, but the life time of the returned string will80// be that of the LLDB session.81ConstString GetQualifiedNameAsConstString() const {82return ConstString(GetQualifiedName());83}8485void Clear() {86m_entries.clear();87m_qualified_name.clear();88}8990friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,91const DWARFDeclContext &ctx) {92OS << "DWARFDeclContext{";93llvm::ListSeparator LS;94for (const Entry &e : ctx.m_entries) {95OS << LS << "{" << DW_TAG_value_to_name(e.tag) << ", " << e.GetName()96<< "}";97}98return OS << "}";99}100101protected:102typedef std::vector<Entry> collection;103collection m_entries;104mutable std::string m_qualified_name;105};106} // namespace dwarf107} // namespace lldb_private::plugin108109#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDECLCONTEXT_H110111112