1254721Semaste//===-- Declaration.h -------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_Declaration_h_ 11254721Semaste#define liblldb_Declaration_h_ 12254721Semaste 13254721Semaste#include "lldb/lldb-private.h" 14254721Semaste#include "lldb/Host/FileSpec.h" 15254721Semaste 16254721Semastenamespace lldb_private { 17254721Semaste 18254721Semaste//---------------------------------------------------------------------- 19254721Semaste/// @class Declaration Declaration.h "lldb/Symbol/Declaration.h" 20254721Semaste/// @brief A class that describes the declaration location of a 21254721Semaste/// lldb object. 22254721Semaste/// 23254721Semaste/// The declarations include the file specification, line number, and 24254721Semaste/// the column info and can help track where functions, blocks, inlined 25254721Semaste/// functions, types, variables, any many other debug core objects were 26254721Semaste/// declared. 27254721Semaste//---------------------------------------------------------------------- 28254721Semasteclass Declaration 29254721Semaste{ 30254721Semastepublic: 31254721Semaste //------------------------------------------------------------------ 32254721Semaste /// Default constructor. 33254721Semaste //------------------------------------------------------------------ 34254721Semaste Declaration () : 35254721Semaste m_file (), 36254721Semaste m_line (0) 37254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 38254721Semaste ,m_column (0) 39254721Semaste#endif 40254721Semaste { 41254721Semaste } 42254721Semaste 43254721Semaste 44254721Semaste //------------------------------------------------------------------ 45254721Semaste /// Construct with file specification, and optional line and column. 46254721Semaste /// 47254721Semaste /// @param[in] file_spec 48254721Semaste /// The file specification that describes where this was 49254721Semaste /// declared. 50254721Semaste /// 51254721Semaste /// @param[in] line 52254721Semaste /// The line number that describes where this was declared. Set 53254721Semaste /// to zero if there is no line number information. 54254721Semaste /// 55254721Semaste /// @param[in] column 56254721Semaste /// The column number that describes where this was declared. 57254721Semaste /// Set to zero if there is no column number information. 58254721Semaste //------------------------------------------------------------------ 59254721Semaste Declaration (const FileSpec& file_spec, uint32_t line = 0, uint32_t column = 0) : 60254721Semaste m_file (file_spec), 61254721Semaste m_line (line) 62254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 63254721Semaste ,m_column (column) 64254721Semaste#endif 65254721Semaste { 66254721Semaste } 67254721Semaste 68254721Semaste //------------------------------------------------------------------ 69254721Semaste /// Construct with a reference to another Declaration object. 70254721Semaste //------------------------------------------------------------------ 71254721Semaste Declaration (const Declaration& rhs) : 72254721Semaste m_file (rhs.m_file), 73254721Semaste m_line (rhs.m_line) 74254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 75254721Semaste ,m_column (rhs.m_column) 76254721Semaste#endif 77254721Semaste { 78254721Semaste 79254721Semaste } 80254721Semaste 81254721Semaste //------------------------------------------------------------------ 82254721Semaste /// Construct with a pointer to another Declaration object. 83254721Semaste //------------------------------------------------------------------ 84254721Semaste Declaration(const Declaration* decl_ptr) : 85254721Semaste m_file(), 86254721Semaste m_line(0) 87254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 88254721Semaste ,m_column(0) 89254721Semaste#endif 90254721Semaste { 91254721Semaste if (decl_ptr) 92254721Semaste *this = *decl_ptr; 93254721Semaste } 94254721Semaste 95254721Semaste //------------------------------------------------------------------ 96254721Semaste /// Clear the object's state. 97254721Semaste /// 98254721Semaste /// Sets the file specification to be empty, and the line and column 99254721Semaste /// to zero. 100254721Semaste //------------------------------------------------------------------ 101254721Semaste void 102254721Semaste Clear () 103254721Semaste { 104254721Semaste m_file.Clear(); 105254721Semaste m_line= 0; 106254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 107254721Semaste m_column = 0; 108254721Semaste#endif 109254721Semaste } 110254721Semaste 111254721Semaste //------------------------------------------------------------------ 112254721Semaste /// Compare two declaration objects. 113254721Semaste /// 114254721Semaste /// Compares the two file specifications from \a lhs and \a rhs. If 115254721Semaste /// the file specifications are equal, then continue to compare the 116254721Semaste /// line number and column numbers respectively. 117254721Semaste /// 118254721Semaste /// @param[in] lhs 119254721Semaste /// The Left Hand Side const Declaration object reference. 120254721Semaste /// 121254721Semaste /// @param[in] rhs 122254721Semaste /// The Right Hand Side const Declaration object reference. 123254721Semaste /// 124254721Semaste /// @return 125254721Semaste /// @li -1 if lhs < rhs 126254721Semaste /// @li 0 if lhs == rhs 127254721Semaste /// @li 1 if lhs > rhs 128254721Semaste //------------------------------------------------------------------ 129254721Semaste static int 130254721Semaste Compare (const Declaration& lhs, const Declaration& rhs); 131254721Semaste 132254721Semaste //------------------------------------------------------------------ 133254721Semaste /// Dump a description of this object to a Stream. 134254721Semaste /// 135254721Semaste /// Dump a description of the contents of this object to the 136254721Semaste /// supplied stream \a s. 137254721Semaste /// 138254721Semaste /// @param[in] s 139254721Semaste /// The stream to which to dump the object descripton. 140254721Semaste //------------------------------------------------------------------ 141254721Semaste void 142254721Semaste Dump (Stream *s, bool show_fullpaths) const; 143254721Semaste 144254721Semaste bool 145254721Semaste DumpStopContext (Stream *s, bool show_fullpaths) const; 146254721Semaste //------------------------------------------------------------------ 147254721Semaste /// Get accessor for the declaration column number. 148254721Semaste /// 149254721Semaste /// @return 150254721Semaste /// Non-zero indicates a valid column number, zero indicates no 151254721Semaste /// column information is available. 152254721Semaste //------------------------------------------------------------------ 153254721Semaste uint32_t 154254721Semaste GetColumn () const 155254721Semaste { 156254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 157254721Semaste return m_column; 158254721Semaste#else 159254721Semaste return 0; 160254721Semaste#endif 161254721Semaste } 162254721Semaste 163254721Semaste //------------------------------------------------------------------ 164254721Semaste /// Get accessor for file specification. 165254721Semaste /// 166254721Semaste /// @return 167254721Semaste /// A reference to the file specification object. 168254721Semaste //------------------------------------------------------------------ 169254721Semaste FileSpec& 170254721Semaste GetFile () 171254721Semaste { 172254721Semaste return m_file; 173254721Semaste } 174254721Semaste 175254721Semaste //------------------------------------------------------------------ 176254721Semaste /// Get const accessor for file specification. 177254721Semaste /// 178254721Semaste /// @return 179254721Semaste /// A const reference to the file specification object. 180254721Semaste //------------------------------------------------------------------ 181254721Semaste const FileSpec& 182254721Semaste GetFile () const 183254721Semaste { 184254721Semaste return m_file; 185254721Semaste } 186254721Semaste 187254721Semaste //------------------------------------------------------------------ 188254721Semaste /// Get accessor for the declaration line number. 189254721Semaste /// 190254721Semaste /// @return 191254721Semaste /// Non-zero indicates a valid line number, zero indicates no 192254721Semaste /// line information is available. 193254721Semaste //------------------------------------------------------------------ 194254721Semaste uint32_t 195254721Semaste GetLine () const 196254721Semaste { 197254721Semaste return m_line; 198254721Semaste } 199254721Semaste 200254721Semaste 201254721Semaste bool 202254721Semaste IsValid() const 203254721Semaste { 204254721Semaste return m_file && m_line != 0; 205254721Semaste } 206254721Semaste 207254721Semaste //------------------------------------------------------------------ 208254721Semaste /// Get the memory cost of this object. 209254721Semaste /// 210254721Semaste /// @return 211254721Semaste /// The number of bytes that this object occupies in memory. 212254721Semaste /// The returned value does not include the bytes for any 213254721Semaste /// shared string values. 214254721Semaste /// 215254721Semaste /// @see ConstString::StaticMemorySize () 216254721Semaste //------------------------------------------------------------------ 217254721Semaste size_t 218254721Semaste MemorySize () const; 219254721Semaste 220254721Semaste //------------------------------------------------------------------ 221254721Semaste /// Set accessor for the declaration column number. 222254721Semaste /// 223254721Semaste /// @param[in] column 224254721Semaste /// Non-zero indicates a valid column number, zero indicates no 225254721Semaste /// column information is available. 226254721Semaste //------------------------------------------------------------------ 227254721Semaste void 228254721Semaste SetColumn (uint32_t column) 229254721Semaste { 230254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 231254721Semaste m_column = col; 232254721Semaste#endif 233254721Semaste } 234254721Semaste 235254721Semaste //------------------------------------------------------------------ 236254721Semaste /// Set accessor for the declaration file specification. 237254721Semaste /// 238254721Semaste /// @param[in] file_spec 239254721Semaste /// The new declaration file specifciation. 240254721Semaste //------------------------------------------------------------------ 241254721Semaste void 242254721Semaste SetFile (const FileSpec& file_spec) 243254721Semaste { 244254721Semaste m_file = file_spec; 245254721Semaste } 246254721Semaste 247254721Semaste //------------------------------------------------------------------ 248254721Semaste /// Set accessor for the declaration line number. 249254721Semaste /// 250254721Semaste /// @param[in] line 251254721Semaste /// Non-zero indicates a valid line number, zero indicates no 252254721Semaste /// line information is available. 253254721Semaste //------------------------------------------------------------------ 254254721Semaste void 255254721Semaste SetLine (uint32_t line) 256254721Semaste { 257254721Semaste m_line = line; 258254721Semaste } 259254721Semasteprotected: 260254721Semaste //------------------------------------------------------------------ 261254721Semaste /// Member variables. 262254721Semaste //------------------------------------------------------------------ 263254721Semaste FileSpec m_file; ///< The file specification that points to the 264254721Semaste ///< source file where the declaration occurred. 265254721Semaste uint32_t m_line; ///< Non-zero values indicates a valid line number, 266254721Semaste ///< zero indicates no line number information is available. 267254721Semaste#ifdef LLDB_ENABLE_DECLARATION_COLUMNS 268254721Semaste uint32_t m_column; ///< Non-zero values indicates a valid column number, 269254721Semaste ///< zero indicates no column information is available. 270254721Semaste#endif 271254721Semaste}; 272254721Semaste 273254721Semastebool 274254721Semasteoperator == (const Declaration &lhs, const Declaration &rhs); 275254721Semaste 276254721Semaste} // namespace lldb_private 277254721Semaste 278254721Semaste#endif // liblldb_Declaration_h_ 279