Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / DebugInfo / DWARF / DWARFAttribute.h
blobfc6f0a4436051d37ee02f638f40453aa98ef6d8f
1 //===- DWARFAttribute.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_DWARFATTRIBUTE_H
10 #define LLVM_DEBUGINFO_DWARFATTRIBUTE_H
12 #include "llvm/BinaryFormat/Dwarf.h"
13 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
14 #include <cstdint>
16 namespace llvm {
18 //===----------------------------------------------------------------------===//
19 /// Encapsulates a DWARF attribute value and all of the data required to
20 /// describe the attribute value.
21 ///
22 /// This class is designed to be used by clients that want to iterate across all
23 /// attributes in a DWARFDie.
24 struct DWARFAttribute {
25 /// The debug info/types offset for this attribute.
26 uint32_t Offset = 0;
27 /// The debug info/types section byte size of the data for this attribute.
28 uint32_t ByteSize = 0;
29 /// The attribute enumeration of this attribute.
30 dwarf::Attribute Attr;
31 /// The form and value for this attribute.
32 DWARFFormValue Value;
34 DWARFAttribute(uint32_t O, dwarf::Attribute A = dwarf::Attribute(0),
35 dwarf::Form F = dwarf::Form(0)) : Attr(A), Value(F) {}
37 bool isValid() const {
38 return Offset != 0 && Attr != dwarf::Attribute(0);
41 explicit operator bool() const {
42 return isValid();
45 void clear() {
46 Offset = 0;
47 ByteSize = 0;
48 Attr = dwarf::Attribute(0);
49 Value = DWARFFormValue();
53 } // end namespace llvm
55 #endif // LLVM_DEBUGINFO_DWARFATTRIBUTE_H