Remove dead code.
[oota-llvm.git] / include / llvm / DebugInfo.h
1 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- 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 // This file defines a bunch of datatypes that are useful for creating and
11 // walking debug info in LLVM IR form. They essentially provide wrappers around
12 // the information in the global variables that's needed when constructing the
13 // DWARF information.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_DEBUGINFO_H
18 #define LLVM_DEBUGINFO_H
19
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
24
25 namespace llvm {
26   class BasicBlock;
27   class Constant;
28   class Function;
29   class GlobalVariable;
30   class Module;
31   class Type;
32   class Value;
33   class DbgDeclareInst;
34   class DbgValueInst;
35   class Instruction;
36   class MDNode;
37   class NamedMDNode;
38   class LLVMContext;
39   class raw_ostream;
40
41   class DIFile;
42   class DISubprogram;
43   class DILexicalBlock;
44   class DILexicalBlockFile;
45   class DIVariable;
46   class DIType;
47   class DIObjCProperty;
48
49   /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
50   /// This should not be stored in a container, because the underlying MDNode
51   /// may change in certain situations.
52   class DIDescriptor {
53   public:
54     enum {
55       FlagPrivate            = 1 << 0,
56       FlagProtected          = 1 << 1,
57       FlagFwdDecl            = 1 << 2,
58       FlagAppleBlock         = 1 << 3,
59       FlagBlockByrefStruct   = 1 << 4,
60       FlagVirtual            = 1 << 5,
61       FlagArtificial         = 1 << 6,
62       FlagExplicit           = 1 << 7,
63       FlagPrototyped         = 1 << 8,
64       FlagObjcClassComplete  = 1 << 9,
65       FlagObjectPointer      = 1 << 10,
66       FlagVector             = 1 << 11,
67       FlagStaticMember       = 1 << 12,
68       FlagIndirectVariable   = 1 << 13
69     };
70   protected:
71     const MDNode *DbgNode;
72
73     StringRef getStringField(unsigned Elt) const;
74     unsigned getUnsignedField(unsigned Elt) const {
75       return (unsigned)getUInt64Field(Elt);
76     }
77     uint64_t getUInt64Field(unsigned Elt) const;
78     int64_t getInt64Field(unsigned Elt) const;
79     DIDescriptor getDescriptorField(unsigned Elt) const;
80
81     template <typename DescTy>
82     DescTy getFieldAs(unsigned Elt) const {
83       return DescTy(getDescriptorField(Elt));
84     }
85
86     GlobalVariable *getGlobalVariableField(unsigned Elt) const;
87     Constant *getConstantField(unsigned Elt) const;
88     Function *getFunctionField(unsigned Elt) const;
89     void replaceFunctionField(unsigned Elt, Function *F);
90
91   public:
92     explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
93
94     bool Verify() const;
95
96     operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
97     MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
98
99     // An explicit operator bool so that we can do testing of DI values
100     // easily.
101     // FIXME: This operator bool isn't actually protecting anything at the
102     // moment due to the conversion operator above making DIDescriptor nodes
103     // implicitly convertable to bool.
104     LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
105
106     bool operator==(DIDescriptor Other) const {
107       return DbgNode == Other.DbgNode;
108     }
109     bool operator!=(DIDescriptor Other) const {
110       return !operator==(Other);
111     }
112
113     unsigned getTag() const {
114       return getUnsignedField(0) & ~LLVMDebugVersionMask;
115     }
116
117     bool isDerivedType() const;
118     bool isCompositeType() const;
119     bool isBasicType() const;
120     bool isVariable() const;
121     bool isSubprogram() const;
122     bool isGlobalVariable() const;
123     bool isScope() const;
124     bool isFile() const;
125     bool isCompileUnit() const;
126     bool isNameSpace() const;
127     bool isLexicalBlockFile() const;
128     bool isLexicalBlock() const;
129     bool isSubrange() const;
130     bool isEnumerator() const;
131     bool isType() const;
132     bool isUnspecifiedParameter() const;
133     bool isTemplateTypeParameter() const;
134     bool isTemplateValueParameter() const;
135     bool isObjCProperty() const;
136     bool isImportedEntity() const;
137
138     /// print - print descriptor.
139     void print(raw_ostream &OS) const;
140
141     /// dump - print descriptor to dbgs() with a newline.
142     void dump() const;
143   };
144
145   /// DISubrange - This is used to represent ranges, for array bounds.
146   class DISubrange : public DIDescriptor {
147     friend class DIDescriptor;
148     void printInternal(raw_ostream &OS) const;
149   public:
150     explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
151
152     int64_t getLo() const { return getInt64Field(1); }
153     int64_t  getCount() const { return getInt64Field(2); }
154     bool Verify() const;
155   };
156
157   /// DIArray - This descriptor holds an array of descriptors.
158   class DIArray : public DIDescriptor {
159   public:
160     explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
161
162     unsigned getNumElements() const;
163     DIDescriptor getElement(unsigned Idx) const {
164       return getDescriptorField(Idx);
165     }
166   };
167
168   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
169   /// FIXME: it seems strange that this doesn't have either a reference to the
170   /// type/precision or a file/line pair for location info.
171   class DIEnumerator : public DIDescriptor {
172     friend class DIDescriptor;
173     void printInternal(raw_ostream &OS) const;
174   public:
175     explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
176
177     StringRef getName() const        { return getStringField(1); }
178     int64_t getEnumValue() const      { return getInt64Field(2); }
179     bool Verify() const;
180   };
181
182   /// DIScope - A base class for various scopes.
183   class DIScope : public DIDescriptor {
184   protected:
185     friend class DIDescriptor;
186     void printInternal(raw_ostream &OS) const;
187   public:
188     explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
189
190     StringRef getFilename() const;
191     StringRef getDirectory() const;
192   };
193
194   /// DIType - This is a wrapper for a type.
195   /// FIXME: Types should be factored much better so that CV qualifiers and
196   /// others do not require a huge and empty descriptor full of zeros.
197   class DIType : public DIScope {
198   protected:
199     friend class DIDescriptor;
200     void printInternal(raw_ostream &OS) const;
201
202   public:
203     DIType(const MDNode *N = 0) : DIScope(N) {}
204
205     /// Verify - Verify that a type descriptor is well formed.
206     bool Verify() const;
207
208     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
209     StringRef getName() const           { return getStringField(3);     }
210     unsigned getLineNumber() const      { return getUnsignedField(4); }
211     uint64_t getSizeInBits() const      { return getUInt64Field(5); }
212     uint64_t getAlignInBits() const     { return getUInt64Field(6); }
213     // FIXME: Offset is only used for DW_TAG_member nodes.  Making every type
214     // carry this is just plain insane.
215     uint64_t getOffsetInBits() const    { return getUInt64Field(7); }
216     unsigned getFlags() const           { return getUnsignedField(8); }
217     bool isPrivate() const {
218       return (getFlags() & FlagPrivate) != 0;
219     }
220     bool isProtected() const {
221       return (getFlags() & FlagProtected) != 0;
222     }
223     bool isForwardDecl() const {
224       return (getFlags() & FlagFwdDecl) != 0;
225     }
226     // isAppleBlock - Return true if this is the Apple Blocks extension.
227     bool isAppleBlockExtension() const {
228       return (getFlags() & FlagAppleBlock) != 0;
229     }
230     bool isBlockByrefStruct() const {
231       return (getFlags() & FlagBlockByrefStruct) != 0;
232     }
233     bool isVirtual() const {
234       return (getFlags() & FlagVirtual) != 0;
235     }
236     bool isArtificial() const {
237       return (getFlags() & FlagArtificial) != 0;
238     }
239     bool isObjectPointer() const {
240       return (getFlags() & FlagObjectPointer) != 0;
241     }
242     bool isObjcClassComplete() const {
243       return (getFlags() & FlagObjcClassComplete) != 0;
244     }
245     bool isVector() const {
246       return (getFlags() & FlagVector) != 0;
247     }
248     bool isStaticMember() const {
249       return (getFlags() & FlagStaticMember) != 0;
250     }
251     bool isValid() const {
252       return DbgNode && isType();
253     }
254
255     /// isUnsignedDIType - Return true if type encoding is unsigned.
256     bool isUnsignedDIType();
257
258     /// replaceAllUsesWith - Replace all uses of debug info referenced by
259     /// this descriptor.
260     void replaceAllUsesWith(DIDescriptor &D);
261     void replaceAllUsesWith(MDNode *D);
262   };
263
264   /// DIBasicType - A basic type, like 'int' or 'float'.
265   class DIBasicType : public DIType {
266   public:
267     explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
268
269     unsigned getEncoding() const { return getUnsignedField(9); }
270
271     /// Verify - Verify that a basic type descriptor is well formed.
272     bool Verify() const;
273   };
274
275   /// DIDerivedType - A simple derived type, like a const qualified type,
276   /// a typedef, a pointer or reference, et cetera.  Or, a data member of
277   /// a class/struct/union.
278   class DIDerivedType : public DIType {
279     friend class DIDescriptor;
280     void printInternal(raw_ostream &OS) const;
281
282   public:
283     explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
284
285     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
286
287     /// getOriginalTypeSize - If this type is derived from a base type then
288     /// return base type size.
289     uint64_t getOriginalTypeSize() const;
290
291     /// getObjCProperty - Return property node, if this ivar is
292     /// associated with one.
293     MDNode *getObjCProperty() const;
294
295     DIType getClassType() const {
296       assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
297       return getFieldAs<DIType>(10);
298     }
299
300     Constant *getConstant() const {
301       assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
302       return getConstantField(10);
303     }
304
305     /// Verify - Verify that a derived type descriptor is well formed.
306     bool Verify() const;
307   };
308
309   /// DICompositeType - This descriptor holds a type that can refer to multiple
310   /// other types, like a function or struct.
311   /// DICompositeType is derived from DIDerivedType because some
312   /// composite types (such as enums) can be derived from basic types
313   // FIXME: Make this derive from DIType directly & just store the
314   // base type in a single DIType field.
315   class DICompositeType : public DIDerivedType {
316     friend class DIDescriptor;
317     void printInternal(raw_ostream &OS) const;
318   public:
319     explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
320
321     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
322     void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
323     unsigned getRunTimeLang() const { return getUnsignedField(11); }
324     DICompositeType getContainingType() const {
325       return getFieldAs<DICompositeType>(12);
326     }
327     void setContainingType(DICompositeType ContainingType);
328     DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
329
330     /// Verify - Verify that a composite type descriptor is well formed.
331     bool Verify() const;
332   };
333
334   /// DIFile - This is a wrapper for a file.
335   class DIFile : public DIScope {
336     friend class DIDescriptor;
337   public:
338     explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
339     MDNode *getFileNode() const;
340     bool Verify() const;
341   };
342
343   /// DICompileUnit - A wrapper for a compile unit.
344   class DICompileUnit : public DIScope {
345     friend class DIDescriptor;
346     void printInternal(raw_ostream &OS) const;
347   public:
348     explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
349
350     unsigned getLanguage() const { return getUnsignedField(2); }
351     StringRef getProducer() const { return getStringField(3); }
352
353     bool isOptimized() const { return getUnsignedField(4) != 0; }
354     StringRef getFlags() const { return getStringField(5); }
355     unsigned getRunTimeVersion() const { return getUnsignedField(6); }
356
357     DIArray getEnumTypes() const;
358     DIArray getRetainedTypes() const;
359     DIArray getSubprograms() const;
360     DIArray getGlobalVariables() const;
361     DIArray getImportedEntities() const;
362
363     StringRef getSplitDebugFilename() const { return getStringField(12); }
364
365     /// Verify - Verify that a compile unit is well formed.
366     bool Verify() const;
367   };
368
369   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
370   class DISubprogram : public DIScope {
371     friend class DIDescriptor;
372     void printInternal(raw_ostream &OS) const;
373   public:
374     explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
375
376     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
377     StringRef getName() const         { return getStringField(3); }
378     StringRef getDisplayName() const  { return getStringField(4); }
379     StringRef getLinkageName() const  { return getStringField(5); }
380     unsigned getLineNumber() const      { return getUnsignedField(6); }
381     DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
382
383     /// isLocalToUnit - Return true if this subprogram is local to the current
384     /// compile unit, like 'static' in C.
385     unsigned isLocalToUnit() const     { return getUnsignedField(8); }
386     unsigned isDefinition() const      { return getUnsignedField(9); }
387
388     unsigned getVirtuality() const { return getUnsignedField(10); }
389     unsigned getVirtualIndex() const { return getUnsignedField(11); }
390
391     DICompositeType getContainingType() const {
392       return getFieldAs<DICompositeType>(12);
393     }
394
395     unsigned getFlags() const {
396       return getUnsignedField(13);
397     }
398
399     unsigned isArtificial() const    {
400       return (getUnsignedField(13) & FlagArtificial) != 0;
401     }
402     /// isPrivate - Return true if this subprogram has "private"
403     /// access specifier.
404     bool isPrivate() const    {
405       return (getUnsignedField(13) & FlagPrivate) != 0;
406     }
407     /// isProtected - Return true if this subprogram has "protected"
408     /// access specifier.
409     bool isProtected() const    {
410       return (getUnsignedField(13) & FlagProtected) != 0;
411     }
412     /// isExplicit - Return true if this subprogram is marked as explicit.
413     bool isExplicit() const    {
414       return (getUnsignedField(13) & FlagExplicit) != 0;
415     }
416     /// isPrototyped - Return true if this subprogram is prototyped.
417     bool isPrototyped() const    {
418       return (getUnsignedField(13) & FlagPrototyped) != 0;
419     }
420
421     unsigned isOptimized() const;
422
423     /// Verify - Verify that a subprogram descriptor is well formed.
424     bool Verify() const;
425
426     /// describes - Return true if this subprogram provides debugging
427     /// information for the function F.
428     bool describes(const Function *F);
429
430     Function *getFunction() const { return getFunctionField(15); }
431     void replaceFunction(Function *F) { replaceFunctionField(15, F); }
432     DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
433     DISubprogram getFunctionDeclaration() const {
434       return getFieldAs<DISubprogram>(17);
435     }
436     MDNode *getVariablesNodes() const;
437     DIArray getVariables() const;
438
439     /// getScopeLineNumber - Get the beginning of the scope of the
440     /// function, not necessarily where the name of the program
441     /// starts.
442     unsigned getScopeLineNumber() const { return getUnsignedField(19); }
443   };
444
445   /// DILexicalBlock - This is a wrapper for a lexical block.
446   class DILexicalBlock : public DIScope {
447   public:
448     explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
449     DIScope getContext() const       { return getFieldAs<DIScope>(2);      }
450     unsigned getLineNumber() const   { return getUnsignedField(3);         }
451     unsigned getColumnNumber() const { return getUnsignedField(4);         }
452     bool Verify() const;
453   };
454
455   /// DILexicalBlockFile - This is a wrapper for a lexical block with
456   /// a filename change.
457   class DILexicalBlockFile : public DIScope {
458   public:
459     explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
460     DIScope getContext() const {
461       if (getScope().isSubprogram())
462         return getScope();
463       return getScope().getContext();
464     }
465     unsigned getLineNumber() const { return getScope().getLineNumber(); }
466     unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
467     DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
468     bool Verify() const;
469   };
470
471   /// DINameSpace - A wrapper for a C++ style name space.
472   class DINameSpace : public DIScope {
473     friend class DIDescriptor;
474     void printInternal(raw_ostream &OS) const;
475   public:
476     explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
477     DIScope getContext() const     { return getFieldAs<DIScope>(2);      }
478     StringRef getName() const      { return getStringField(3);           }
479     unsigned getLineNumber() const { return getUnsignedField(4);         }
480     bool Verify() const;
481   };
482
483   /// DITemplateTypeParameter - This is a wrapper for template type parameter.
484   class DITemplateTypeParameter : public DIDescriptor {
485   public:
486     explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
487
488     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
489     StringRef getName() const        { return getStringField(2); }
490     DIType getType() const           { return getFieldAs<DIType>(3); }
491     StringRef getFilename() const    {
492       return getFieldAs<DIFile>(4).getFilename();
493     }
494     StringRef getDirectory() const   {
495       return getFieldAs<DIFile>(4).getDirectory();
496     }
497     unsigned getLineNumber() const   { return getUnsignedField(5); }
498     unsigned getColumnNumber() const { return getUnsignedField(6); }
499     bool Verify() const;
500   };
501
502   /// DITemplateValueParameter - This is a wrapper for template value parameter.
503   class DITemplateValueParameter : public DIDescriptor {
504   public:
505     explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
506
507     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
508     StringRef getName() const        { return getStringField(2); }
509     DIType getType() const           { return getFieldAs<DIType>(3); }
510     Value *getValue() const;
511     StringRef getFilename() const    {
512       return getFieldAs<DIFile>(5).getFilename();
513     }
514     StringRef getDirectory() const   {
515       return getFieldAs<DIFile>(5).getDirectory();
516     }
517     unsigned getLineNumber() const   { return getUnsignedField(6); }
518     unsigned getColumnNumber() const { return getUnsignedField(7); }
519     bool Verify() const;
520   };
521
522   /// DIGlobalVariable - This is a wrapper for a global variable.
523   class DIGlobalVariable : public DIDescriptor {
524     friend class DIDescriptor;
525     void printInternal(raw_ostream &OS) const;
526   public:
527     explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
528
529     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
530     StringRef getName() const         { return getStringField(3); }
531     StringRef getDisplayName() const  { return getStringField(4); }
532     StringRef getLinkageName() const  { return getStringField(5); }
533     StringRef getFilename() const {
534       return getFieldAs<DIFile>(6).getFilename();
535     }
536     StringRef getDirectory() const {
537       return getFieldAs<DIFile>(6).getDirectory();
538
539     }
540
541     unsigned getLineNumber() const      { return getUnsignedField(7); }
542     DIType getType() const              { return getFieldAs<DIType>(8); }
543     unsigned isLocalToUnit() const      { return getUnsignedField(9); }
544     unsigned isDefinition() const       { return getUnsignedField(10); }
545
546     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
547     Constant *getConstant() const   { return getConstantField(11); }
548     DIDerivedType getStaticDataMemberDeclaration() const {
549       return getFieldAs<DIDerivedType>(12);
550     }
551
552     /// Verify - Verify that a global variable descriptor is well formed.
553     bool Verify() const;
554   };
555
556   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
557   /// global etc).
558   class DIVariable : public DIDescriptor {
559     friend class DIDescriptor;
560     void printInternal(raw_ostream &OS) const;
561   public:
562     explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
563
564     DIScope getContext() const          { return getFieldAs<DIScope>(1); }
565     StringRef getName() const           { return getStringField(2);     }
566     DIFile getFile() const              { return getFieldAs<DIFile>(3); }
567     unsigned getLineNumber() const      {
568       return (getUnsignedField(4) << 8) >> 8;
569     }
570     unsigned getArgNumber() const       {
571       unsigned L = getUnsignedField(4);
572       return L >> 24;
573     }
574     DIType getType() const              { return getFieldAs<DIType>(5); }
575
576     /// isArtificial - Return true if this variable is marked as "artificial".
577     bool isArtificial() const    {
578       return (getUnsignedField(6) & FlagArtificial) != 0;
579     }
580
581     bool isObjectPointer() const {
582       return (getUnsignedField(6) & FlagObjectPointer) != 0;
583     }
584
585     /// \brief Return true if this variable is represented as a pointer.
586     bool isIndirect() const {
587       return (getUnsignedField(6) & FlagIndirectVariable) != 0;
588     }
589
590     /// getInlinedAt - If this variable is inlined then return inline location.
591     MDNode *getInlinedAt() const;
592
593     /// Verify - Verify that a variable descriptor is well formed.
594     bool Verify() const;
595
596     /// HasComplexAddr - Return true if the variable has a complex address.
597     bool hasComplexAddress() const {
598       return getNumAddrElements() > 0;
599     }
600
601     unsigned getNumAddrElements() const;
602
603     uint64_t getAddrElement(unsigned Idx) const {
604       return getUInt64Field(Idx+8);
605     }
606
607     /// isBlockByrefVariable - Return true if the variable was declared as
608     /// a "__block" variable (Apple Blocks).
609     bool isBlockByrefVariable() const {
610       return getType().isBlockByrefStruct();
611     }
612
613     /// isInlinedFnArgument - Return true if this variable provides debugging
614     /// information for an inlined function arguments.
615     bool isInlinedFnArgument(const Function *CurFn);
616
617     void printExtendedName(raw_ostream &OS) const;
618   };
619
620   /// DILocation - This object holds location information. This object
621   /// is not associated with any DWARF tag.
622   class DILocation : public DIDescriptor {
623   public:
624     explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
625
626     unsigned getLineNumber() const     { return getUnsignedField(0); }
627     unsigned getColumnNumber() const   { return getUnsignedField(1); }
628     DIScope  getScope() const          { return getFieldAs<DIScope>(2); }
629     DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
630     StringRef getFilename() const    { return getScope().getFilename(); }
631     StringRef getDirectory() const   { return getScope().getDirectory(); }
632     bool Verify() const;
633   };
634
635   class DIObjCProperty : public DIDescriptor {
636     friend class DIDescriptor;
637     void printInternal(raw_ostream &OS) const;
638   public:
639     explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
640
641     StringRef getObjCPropertyName() const { return getStringField(1); }
642     DIFile getFile() const { return getFieldAs<DIFile>(2); }
643     unsigned getLineNumber() const { return getUnsignedField(3); }
644
645     StringRef getObjCPropertyGetterName() const {
646       return getStringField(4);
647     }
648     StringRef getObjCPropertySetterName() const {
649       return getStringField(5);
650     }
651     bool isReadOnlyObjCProperty() const {
652       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
653     }
654     bool isReadWriteObjCProperty() const {
655       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
656     }
657     bool isAssignObjCProperty() const {
658       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
659     }
660     bool isRetainObjCProperty() const {
661       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
662     }
663     bool isCopyObjCProperty() const {
664       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
665     }
666     bool isNonAtomicObjCProperty() const {
667       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
668     }
669
670     DIType getType() const { return getFieldAs<DIType>(7); }
671
672     /// Verify - Verify that a derived type descriptor is well formed.
673     bool Verify() const;
674   };
675
676   /// \brief An imported module (C++ using directive or similar).
677   class DIImportedEntity : public DIDescriptor {
678     friend class DIDescriptor;
679     void printInternal(raw_ostream &OS) const;
680   public:
681     explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
682     DIScope getContext() const { return getFieldAs<DIScope>(1); }
683     DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
684     unsigned getLineNumber() const { return getUnsignedField(3); }
685     StringRef getName() const { return getStringField(4); }
686     bool Verify() const;
687   };
688
689   /// getDISubprogram - Find subprogram that is enclosing this scope.
690   DISubprogram getDISubprogram(const MDNode *Scope);
691
692   /// getDICompositeType - Find underlying composite type.
693   DICompositeType getDICompositeType(DIType T);
694
695   /// isSubprogramContext - Return true if Context is either a subprogram
696   /// or another context nested inside a subprogram.
697   bool isSubprogramContext(const MDNode *Context);
698
699   /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
700   /// to hold function specific information.
701   NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
702
703   /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
704   /// suitable to hold function specific information.
705   NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
706
707   /// createInlinedVariable - Create a new inlined variable based on current
708   /// variable.
709   /// @param DV            Current Variable.
710   /// @param InlinedScope  Location at current variable is inlined.
711   DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
712                                    LLVMContext &VMContext);
713
714   /// cleanseInlinedVariable - Remove inlined scope from the variable.
715   DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
716
717   /// DebugInfoFinder tries to list all debug info MDNodes in a module. To
718   /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
719   /// processDeclare and processValue. processModule will go through
720   /// all DICompileUnits and list debug info MDNodes used by the CUs.
721   class DebugInfoFinder {
722   public:
723     /// processModule - Process entire module and collect debug info
724     /// anchors.
725     void processModule(const Module &M);
726
727     /// processDeclare - Process DbgDeclareInst.
728     void processDeclare(const DbgDeclareInst *DDI);
729     /// Process DbgValueInst.
730     void processValue(const DbgValueInst *DVI);
731
732     /// Clear all lists.
733     void reset();
734   private:
735     /// processType - Process DIType.
736     void processType(DIType DT);
737
738     /// processLexicalBlock - Process DILexicalBlock.
739     void processLexicalBlock(DILexicalBlock LB);
740
741     /// processSubprogram - Process DISubprogram.
742     void processSubprogram(DISubprogram SP);
743
744     /// processLocation - Process DILocation.
745     void processLocation(DILocation Loc);
746
747     void processScope(DIScope Scope);
748
749     /// addCompileUnit - Add compile unit into CUs.
750     bool addCompileUnit(DICompileUnit CU);
751
752     /// addGlobalVariable - Add global variable into GVs.
753     bool addGlobalVariable(DIGlobalVariable DIG);
754
755     // addSubprogram - Add subprogram into SPs.
756     bool addSubprogram(DISubprogram SP);
757
758     /// addType - Add type into Tys.
759     bool addType(DIType DT);
760
761     bool addScope(DIScope Scope);
762
763   public:
764     typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
765     iterator compile_unit_begin()    const { return CUs.begin(); }
766     iterator compile_unit_end()      const { return CUs.end(); }
767     iterator subprogram_begin()      const { return SPs.begin(); }
768     iterator subprogram_end()        const { return SPs.end(); }
769     iterator global_variable_begin() const { return GVs.begin(); }
770     iterator global_variable_end()   const { return GVs.end(); }
771     iterator type_begin()            const { return TYs.begin(); }
772     iterator type_end()              const { return TYs.end(); }
773     iterator scope_begin()           const { return Scopes.begin(); }
774     iterator scope_end()             const { return Scopes.end(); }
775
776     unsigned compile_unit_count()    const { return CUs.size(); }
777     unsigned global_variable_count() const { return GVs.size(); }
778     unsigned subprogram_count()      const { return SPs.size(); }
779     unsigned type_count()            const { return TYs.size(); }
780     unsigned scope_count()           const { return Scopes.size(); }
781
782   private:
783     SmallVector<MDNode *, 8> CUs;  // Compile Units
784     SmallVector<MDNode *, 8> SPs;  // Subprograms
785     SmallVector<MDNode *, 8> GVs;  // Global Variables;
786     SmallVector<MDNode *, 8> TYs;  // Types
787     SmallVector<MDNode *, 8> Scopes; // Scopes
788     SmallPtrSet<MDNode *, 64> NodesSeen;
789   };
790 } // end namespace llvm
791
792 #endif