1 //===-- Declaration.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 liblldb_Declaration_h_ 11 #define liblldb_Declaration_h_ 12 13 #include "lldb/lldb-private.h" 14 #include "lldb/Host/FileSpec.h" 15 16 namespace lldb_private { 17 18 //---------------------------------------------------------------------- 19 /// @class Declaration Declaration.h "lldb/Symbol/Declaration.h" 20 /// @brief A class that describes the declaration location of a 21 /// lldb object. 22 /// 23 /// The declarations include the file specification, line number, and 24 /// the column info and can help track where functions, blocks, inlined 25 /// functions, types, variables, any many other debug core objects were 26 /// declared. 27 //---------------------------------------------------------------------- 28 class Declaration 29 { 30 public: 31 //------------------------------------------------------------------ 32 /// Default constructor. 33 //------------------------------------------------------------------ Declaration()34 Declaration () : 35 m_file (), 36 m_line (0) 37 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 38 ,m_column (0) 39 #endif 40 { 41 } 42 43 44 //------------------------------------------------------------------ 45 /// Construct with file specification, and optional line and column. 46 /// 47 /// @param[in] file_spec 48 /// The file specification that describes where this was 49 /// declared. 50 /// 51 /// @param[in] line 52 /// The line number that describes where this was declared. Set 53 /// to zero if there is no line number information. 54 /// 55 /// @param[in] column 56 /// The column number that describes where this was declared. 57 /// Set to zero if there is no column number information. 58 //------------------------------------------------------------------ 59 Declaration (const FileSpec& file_spec, uint32_t line = 0, uint32_t column = 0) : m_file(file_spec)60 m_file (file_spec), 61 m_line (line) 62 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 63 ,m_column (column) 64 #endif 65 { 66 } 67 68 //------------------------------------------------------------------ 69 /// Construct with a reference to another Declaration object. 70 //------------------------------------------------------------------ Declaration(const Declaration & rhs)71 Declaration (const Declaration& rhs) : 72 m_file (rhs.m_file), 73 m_line (rhs.m_line) 74 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 75 ,m_column (rhs.m_column) 76 #endif 77 { 78 79 } 80 81 //------------------------------------------------------------------ 82 /// Construct with a pointer to another Declaration object. 83 //------------------------------------------------------------------ Declaration(const Declaration * decl_ptr)84 Declaration(const Declaration* decl_ptr) : 85 m_file(), 86 m_line(0) 87 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 88 ,m_column(0) 89 #endif 90 { 91 if (decl_ptr) 92 *this = *decl_ptr; 93 } 94 95 //------------------------------------------------------------------ 96 /// Clear the object's state. 97 /// 98 /// Sets the file specification to be empty, and the line and column 99 /// to zero. 100 //------------------------------------------------------------------ 101 void Clear()102 Clear () 103 { 104 m_file.Clear(); 105 m_line= 0; 106 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 107 m_column = 0; 108 #endif 109 } 110 111 //------------------------------------------------------------------ 112 /// Compare two declaration objects. 113 /// 114 /// Compares the two file specifications from \a lhs and \a rhs. If 115 /// the file specifications are equal, then continue to compare the 116 /// line number and column numbers respectively. 117 /// 118 /// @param[in] lhs 119 /// The Left Hand Side const Declaration object reference. 120 /// 121 /// @param[in] rhs 122 /// The Right Hand Side const Declaration object reference. 123 /// 124 /// @return 125 /// @li -1 if lhs < rhs 126 /// @li 0 if lhs == rhs 127 /// @li 1 if lhs > rhs 128 //------------------------------------------------------------------ 129 static int 130 Compare (const Declaration& lhs, const Declaration& rhs); 131 132 //------------------------------------------------------------------ 133 /// Dump a description of this object to a Stream. 134 /// 135 /// Dump a description of the contents of this object to the 136 /// supplied stream \a s. 137 /// 138 /// @param[in] s 139 /// The stream to which to dump the object descripton. 140 //------------------------------------------------------------------ 141 void 142 Dump (Stream *s, bool show_fullpaths) const; 143 144 bool 145 DumpStopContext (Stream *s, bool show_fullpaths) const; 146 //------------------------------------------------------------------ 147 /// Get accessor for the declaration column number. 148 /// 149 /// @return 150 /// Non-zero indicates a valid column number, zero indicates no 151 /// column information is available. 152 //------------------------------------------------------------------ 153 uint32_t GetColumn()154 GetColumn () const 155 { 156 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 157 return m_column; 158 #else 159 return 0; 160 #endif 161 } 162 163 //------------------------------------------------------------------ 164 /// Get accessor for file specification. 165 /// 166 /// @return 167 /// A reference to the file specification object. 168 //------------------------------------------------------------------ 169 FileSpec& GetFile()170 GetFile () 171 { 172 return m_file; 173 } 174 175 //------------------------------------------------------------------ 176 /// Get const accessor for file specification. 177 /// 178 /// @return 179 /// A const reference to the file specification object. 180 //------------------------------------------------------------------ 181 const FileSpec& GetFile()182 GetFile () const 183 { 184 return m_file; 185 } 186 187 //------------------------------------------------------------------ 188 /// Get accessor for the declaration line number. 189 /// 190 /// @return 191 /// Non-zero indicates a valid line number, zero indicates no 192 /// line information is available. 193 //------------------------------------------------------------------ 194 uint32_t GetLine()195 GetLine () const 196 { 197 return m_line; 198 } 199 200 201 bool IsValid()202 IsValid() const 203 { 204 return m_file && m_line != 0; 205 } 206 207 //------------------------------------------------------------------ 208 /// Get the memory cost of this object. 209 /// 210 /// @return 211 /// The number of bytes that this object occupies in memory. 212 /// The returned value does not include the bytes for any 213 /// shared string values. 214 /// 215 /// @see ConstString::StaticMemorySize () 216 //------------------------------------------------------------------ 217 size_t 218 MemorySize () const; 219 220 //------------------------------------------------------------------ 221 /// Set accessor for the declaration column number. 222 /// 223 /// @param[in] column 224 /// Non-zero indicates a valid column number, zero indicates no 225 /// column information is available. 226 //------------------------------------------------------------------ 227 void SetColumn(uint32_t column)228 SetColumn (uint32_t column) 229 { 230 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 231 m_column = col; 232 #endif 233 } 234 235 //------------------------------------------------------------------ 236 /// Set accessor for the declaration file specification. 237 /// 238 /// @param[in] file_spec 239 /// The new declaration file specifciation. 240 //------------------------------------------------------------------ 241 void SetFile(const FileSpec & file_spec)242 SetFile (const FileSpec& file_spec) 243 { 244 m_file = file_spec; 245 } 246 247 //------------------------------------------------------------------ 248 /// Set accessor for the declaration line number. 249 /// 250 /// @param[in] line 251 /// Non-zero indicates a valid line number, zero indicates no 252 /// line information is available. 253 //------------------------------------------------------------------ 254 void SetLine(uint32_t line)255 SetLine (uint32_t line) 256 { 257 m_line = line; 258 } 259 protected: 260 //------------------------------------------------------------------ 261 /// Member variables. 262 //------------------------------------------------------------------ 263 FileSpec m_file; ///< The file specification that points to the 264 ///< source file where the declaration occurred. 265 uint32_t m_line; ///< Non-zero values indicates a valid line number, 266 ///< zero indicates no line number information is available. 267 #ifdef LLDB_ENABLE_DECLARATION_COLUMNS 268 uint32_t m_column; ///< Non-zero values indicates a valid column number, 269 ///< zero indicates no column information is available. 270 #endif 271 }; 272 273 bool 274 operator == (const Declaration &lhs, const Declaration &rhs); 275 276 } // namespace lldb_private 277 278 #endif // liblldb_Declaration_h_ 279