Style & indentation tweaks.
[oota-llvm.git] / lib / DebugInfo / DWARFDebugInfoEntry.h
1 //===-- DWARFDebugInfoEntry.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 LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
12
13 #include "DWARFAbbreviationDeclaration.h"
14 #include "llvm/Support/DataTypes.h"
15
16 namespace llvm {
17
18 class DWARFCompileUnit;
19 class DWARFContext;
20 class DWARFFormValue;
21
22 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
23 class DWARFDebugInfoEntryMinimal {
24   /// Offset within the .debug_info of the start of this entry.
25   uint64_t Offset;
26
27   /// How many to subtract from "this" to get the parent.
28   /// If zero this die has no parent.
29   uint32_t ParentIdx;
30
31   /// How many to add to "this" to get the sibling.
32   uint32_t SiblingIdx;
33
34   const DWARFAbbreviationDeclaration *AbbrevDecl;
35 public:
36   void dump(raw_ostream &OS, const DWARFCompileUnit *cu,
37             unsigned recurseDepth, unsigned indent = 0) const;
38   void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu,
39                      uint32_t *offset_ptr, uint16_t attr, uint16_t form,
40                      unsigned indent = 0) const;
41
42   bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
43                    uint32_t *offset_ptr);
44
45   /// Extract a debug info entry for a given compile unit from the
46   /// .debug_info and .debug_abbrev data starting at the given offset.
47   bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr);
48
49   uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
50   bool isNULL() const { return AbbrevDecl == 0; }
51   uint64_t getOffset() const { return Offset; }
52   uint32_t getNumAttributes() const {
53     return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
54   }
55   bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
56
57   // We know we are kept in a vector of contiguous entries, so we know
58   // our parent will be some index behind "this".
59   DWARFDebugInfoEntryMinimal *getParent() {
60     return ParentIdx > 0 ? this - ParentIdx : 0;
61   }
62   const DWARFDebugInfoEntryMinimal *getParent() const {
63     return ParentIdx > 0 ? this - ParentIdx : 0;
64   }
65   // We know we are kept in a vector of contiguous entries, so we know
66   // our sibling will be some index after "this".
67   DWARFDebugInfoEntryMinimal *getSibling() {
68     return SiblingIdx > 0 ? this + SiblingIdx : 0;
69   }
70   const DWARFDebugInfoEntryMinimal *getSibling() const {
71     return SiblingIdx > 0 ? this + SiblingIdx : 0;
72   }
73   // We know we are kept in a vector of contiguous entries, so we know
74   // we don't need to store our child pointer, if we have a child it will
75   // be the next entry in the list...
76   DWARFDebugInfoEntryMinimal *getFirstChild() {
77     return hasChildren() ? this + 1 : 0;
78   }
79   const DWARFDebugInfoEntryMinimal *getFirstChild() const {
80     return hasChildren() ? this + 1 : 0;
81   }
82
83   void setParent(DWARFDebugInfoEntryMinimal *parent) {
84     if (parent) {
85       // We know we are kept in a vector of contiguous entries, so we know
86       // our parent will be some index behind "this".
87       ParentIdx = this - parent;
88     } else
89       ParentIdx = 0;
90   }
91   void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
92     if (sibling) {
93       // We know we are kept in a vector of contiguous entries, so we know
94       // our sibling will be some index after "this".
95       SiblingIdx = sibling - this;
96       sibling->setParent(getParent());
97     } else
98       SiblingIdx = 0;
99   }
100
101   const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
102     return AbbrevDecl;
103   }
104
105   uint32_t getAttributeValue(const DWARFCompileUnit *cu,
106                              const uint16_t attr, DWARFFormValue &formValue,
107                              uint32_t *end_attr_offset_ptr = 0) const;
108
109   const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
110                                         const uint16_t attr,
111                                         const char *fail_value) const;
112
113   uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
114                                        const uint16_t attr,
115                                        uint64_t fail_value) const;
116
117   uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
118                                         const uint16_t attr,
119                                         uint64_t fail_value) const;
120
121   int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
122                                     const uint16_t attr,
123                                     int64_t fail_value) const;
124 };
125
126 }
127
128 #endif