SourceManager.h revision 5f54ac373b119a4c6693e4875c48aa761fba0c86
1//===-- SourceManager.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_SourceManager_h_ 11#define liblldb_SourceManager_h_ 12 13// C Includes 14// C++ Includes 15#include <map> 16#include <vector> 17 18// Other libraries and framework includes 19// Project includes 20#include "lldb/lldb-private.h" 21#include "lldb/Host/FileSpec.h" 22 23namespace lldb_private { 24 25class SourceManager 26{ 27public: 28#ifndef SWIG 29 class File 30 { 31 public: 32 File (const FileSpec &file_spec); 33 ~File(); 34 35 size_t 36 DisplaySourceLines (uint32_t line, 37 uint32_t context_before, 38 uint32_t context_after, 39 Stream *s); 40 41 uint32_t 42 GetLineOffset (uint32_t line); 43 44 bool 45 LineIsValid (uint32_t line); 46 47 bool 48 FileSpecMatches (const FileSpec &file_spec); 49 50 protected: 51 52 bool 53 CalculateLineOffsets (uint32_t line = UINT32_MAX); 54 55 FileSpec m_file_spec; 56 TimeValue m_mod_time; // Keep the modification time that this file data is valid for 57 lldb::DataBufferSP m_data_sp; 58 typedef std::vector<uint32_t> LineOffsets; 59 LineOffsets m_offsets; 60 }; 61#endif 62 63 64 //------------------------------------------------------------------ 65 // Constructors and Destructors 66 //------------------------------------------------------------------ 67 SourceManager(); 68 69 ~SourceManager(); 70 71 typedef lldb::SharedPtr<File>::Type FileSP; 72 73 FileSP 74 GetFile (const FileSpec &file_spec); 75 76 size_t 77 DisplaySourceLines (const FileSpec &file, 78 uint32_t line, 79 uint32_t context_before, 80 uint32_t context_after, 81 Stream *s); 82 83 size_t 84 DisplaySourceLinesWithLineNumbers (const FileSpec &file, 85 uint32_t line, 86 uint32_t context_before, 87 uint32_t context_after, 88 const char* current_line_cstr, 89 Stream *s); 90 91 // This variant uses the last file we visited. 92 size_t 93 DisplaySourceLinesWithLineNumbersUsingLastFile (uint32_t line, 94 uint32_t context_before, 95 uint32_t context_after, 96 const char* current_line_cstr, 97 Stream *s); 98 99 size_t 100 DisplayMoreWithLineNumbers (Stream *s); 101 102protected: 103 //------------------------------------------------------------------ 104 // Classes that inherit from SourceManager can see and modify these 105 //------------------------------------------------------------------ 106 typedef std::map <FileSpec, FileSP> FileCache; 107 FileCache m_file_cache; 108 FileSP m_last_file_sp; 109 uint32_t m_last_file_line; 110 uint32_t m_last_file_context_before; 111 uint32_t m_last_file_context_after; 112private: 113 //------------------------------------------------------------------ 114 // For SourceManager only 115 //------------------------------------------------------------------ 116 DISALLOW_COPY_AND_ASSIGN (SourceManager); 117}; 118 119} // namespace lldb_private 120 121#endif // liblldb_SourceManager_h_ 122