ROSE  0.11.51.0
SourceLister.h
1 #ifndef ROSE_BinaryAnalysis_ModelChecker_SourceLister_H
2 #define ROSE_BinaryAnalysis_ModelChecker_SourceLister_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/ModelChecker/Types.h>
7 
8 #include <boost/filesystem.hpp>
9 #include <boost/format.hpp>
10 #include <Rose/SourceLocation.h>
11 
12 namespace Rose {
13 namespace BinaryAnalysis {
14 namespace ModelChecker {
15 
19 class SourceLister {
20 public:
21  using Ptr = SourceListerPtr;
22 
23  struct Settings {
24  std::vector<boost::filesystem::path> directories;
25  boost::format currentLineFormat{"| ==> %06d %s"};
26  boost::format contextLineFormat{"| %06d %s"};
27  size_t leadingContext = 3;
28  size_t trailingContext = 3;
29  };
30 
31 private:
32  mutable SAWYER_THREAD_TRAITS::Mutex mutex_; // protects the following data members
34  Settings settings_;
35 
36 protected:
37  SourceLister();
38  explicit SourceLister(const Settings&);
39 
40 public:
49  static Ptr instance();
50  static Ptr instance(const Settings&);
61  boost::format currentLineFormat() const;
62  void currentLineFormat(const boost::format&);
73  boost::format contextLineFormat() const;
74  void contextLineFormat(const boost::format&);
85  size_t leadingContext() const;
86  void leadingContext(size_t);
97  size_t trailingContext() const;
98  void trailingContext(size_t);
109  std::vector<boost::filesystem::path> directories() const;
110  void directories(const std::vector<boost::filesystem::path>&);
119  void appendDirectory(const boost::filesystem::path&);
120 
128  bool list(std::ostream&, const SourceLocation&, const std::string &prefix);
129 
130 private:
131  // Decompose a path into search components. For instance, the path "/foo/bar/baz.c" will return
132  // /foo/bar/baz.c
133  // foo/bar/baz.c
134  // bar/baz.c
135  // baz.c
136  static std::vector<boost::filesystem::path> decompose(const boost::filesystem::path&);
137 
138  // Find a readable file by searching in the specified directory for each of the file names. Returns
139  // the path found, or empty.
140  static boost::filesystem::path findFile(const boost::filesystem::path &dir, const std::vector<boost::filesystem::path> &names);
141 };
142 
143 } // namespace
144 } // namespace
145 } // namespace
146 
147 #endif
148 #endif
Information about a source location.
boost::format contextLineFormat() const
Property: Format context lines.
void appendDirectory(const boost::filesystem::path &)
Add a search directory.
bool list(std::ostream &, const SourceLocation &, const std::string &prefix)
List some lines of source code.
Main namespace for the ROSE library.
size_t trailingContext() const
Property: Number of trailing context lines.
size_t leadingContext() const
Property: Number of leading context lines.
boost::format currentLineFormat() const
Property: Format string for current line.
static Ptr instance()
Allocating constructor.
Container associating values with keys.
Definition: Sawyer/Map.h:66
std::vector< boost::filesystem::path > directories() const
Property: Search directories.