DebugInfo: Remove dead code from old DebugLoc API
[oota-llvm.git] / include / llvm / IR / DebugLoc.h
1 //===- DebugLoc.h - Debug Location Information ------------------*- 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 number of light weight data structures used
11 // to describe and track debug location information.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_DEBUGLOC_H
16 #define LLVM_IR_DEBUGLOC_H
17
18 #include "llvm/IR/TrackingMDRef.h"
19 #include "llvm/Support/DataTypes.h"
20
21 namespace llvm {
22
23   class LLVMContext;
24   class raw_ostream;
25   class MDLocation;
26
27   /// \brief A debug info location.
28   ///
29   /// This class is a wrapper around a tracking reference to an \a MDLocation
30   /// pointer.
31   ///
32   /// To avoid extra includes, \a DebugLoc doubles the \a MDLocation API with a
33   /// one based on relatively opaque \a MDNode pointers.
34   class DebugLoc {
35     TrackingMDNodeRef Loc;
36
37   public:
38     DebugLoc() {}
39     DebugLoc(DebugLoc &&X) : Loc(std::move(X.Loc)) {}
40     DebugLoc(const DebugLoc &X) : Loc(X.Loc) {}
41     DebugLoc &operator=(DebugLoc &&X) {
42       Loc = std::move(X.Loc);
43       return *this;
44     }
45     DebugLoc &operator=(const DebugLoc &X) {
46       Loc = X.Loc;
47       return *this;
48     }
49
50     /// \brief Construct from an \a MDLocation.
51     DebugLoc(MDLocation *L);
52
53     /// \brief Construct from an \a MDNode.
54     ///
55     /// Note: if \c N is not an \a MDLocation, a verifier check will fail, and
56     /// accessors will crash.  However, construction from other nodes is
57     /// supported in order to handle forward references when reading textual
58     /// IR.
59     explicit DebugLoc(MDNode *N);
60
61     /// \brief Get the underlying \a MDLocation.
62     ///
63     /// \pre !*this or \c isa<MDLocation>(getAsMDNode()).
64     /// @{
65     MDLocation *get() const;
66     operator MDLocation *() const { return get(); }
67     MDLocation *operator->() const { return get(); }
68     MDLocation &operator*() const { return *get(); }
69     /// @}
70
71     /// \brief Check for null.
72     ///
73     /// Check for null in a way that is safe with broken debug info.  Unlike
74     /// the conversion to \c MDLocation, this doesn't require that \c Loc is of
75     /// the right type.  Important for cases like \a llvm::StripDebugInfo() and
76     /// \a Instruction::hasMetadata().
77     explicit operator bool() const { return Loc; }
78
79     /// \brief Check whether this has a trivial destructor.
80     bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
81
82     /// \brief Create a new DebugLoc.
83     ///
84     /// Create a new DebugLoc at the specified line/col and scope/inline.  This
85     /// forwards to \a MDLocation::get().
86     ///
87     /// If \c !Scope, returns a default-constructed \a DebugLoc.
88     ///
89     /// FIXME: Remove this.  Users should use MDLocation::get().
90     static DebugLoc get(unsigned Line, unsigned Col, MDNode *Scope,
91                         MDNode *InlinedAt = nullptr);
92
93     /// \brief Translate the DILexicalBlock into a DebugLoc.
94     ///
95     /// FIXME: Remove this.  It has only one user, and the user just wants to
96     /// pass an \a MDScope around.
97     static DebugLoc getFromDILexicalBlock(MDNode *N);
98
99     unsigned getLine() const;
100     unsigned getCol() const;
101     MDNode *getScope() const;
102     MDLocation *getInlinedAt() const;
103
104     /// \brief Get the fully inlined-at scope for a DebugLoc.
105     ///
106     /// Gets the inlined-at scope for a DebugLoc.
107     MDNode *getInlinedAtScope() const;
108
109     /// \brief Find the debug info location for the start of the function.
110     ///
111     /// Walk up the scope chain of given debug loc and find line number info
112     /// for the function.
113     ///
114     /// FIXME: Remove this.  Users should use MDLocation/MDLocalScope API to
115     /// find the subprogram, and then MDLocation::get().
116     DebugLoc getFnDebugLoc() const;
117
118     /// \brief Return \c this as a bar \a MDNode.
119     MDNode *getAsMDNode() const { return Loc; }
120
121     bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
122     bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
123
124     void dump() const;
125
126     /// \brief prints source location /path/to/file.exe:line:col @[inlined at]
127     void print(raw_ostream &OS) const;
128   };
129
130 } // end namespace llvm
131
132 #endif /* LLVM_SUPPORT_DEBUGLOC_H */