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