Joos1W Compiler Framework
All Classes Functions Typedefs Pages
SourceManager Class Reference

Public Member Functions

 SourceManager (SourceManager const &)=delete
 
SourceManageroperator= (SourceManager const &)=delete
 
void addFile (std::string_view path)
 Add a file and its contents to the SourceManager. More...
 
void emplaceBuffer ()
 Push a new buffer onto the buffer stack.
 
std::string & currentBuffer ()
 Grab a reference to the current buffer.
 
auto files () const
 Get iterator for files.
 

Static Public Member Functions

static std::string getFileName (SourceFile file)
 Get the name of a file.
 
static void print (std::ostream &os, SourceFile const &file)
 Print the name of the file to the output stream. More...
 
static std::string const & getBuffer (SourceFile file)
 Get the buffer for a file. More...
 

Detailed Description

Definition at line 44 of file SourceManager.h.

Member Function Documentation

◆ addFile()

void SourceManager::addFile ( std::string_view  path)
inline

Add a file and its contents to the SourceManager.

Parameters
pathThe path to the file

Definition at line 52 of file SourceManager.h.

52  {
53  // Check the path ends in ".java"
54  if(path.size() < 5 || path.substr(path.size() - 5) != ".java") {
55  throw utils::FatalError{"File " + std::string{path} + " is not a .java file"};
56  }
57  std::ifstream file{std::string{path}};
58  if(!file) {
59  throw utils::FatalError{"File " + std::string{path} + " does not exist"};
60  }
61  files_.emplace_back(path, std::istreambuf_iterator<char>{file}, this);
62  }

◆ getBuffer()

static std::string const& SourceManager::getBuffer ( SourceFile  file)
inlinestatic

Get the buffer for a file.

Parameters
fileThe file to get the buffer for
Returns
A string_view of the buffer

Definition at line 103 of file SourceManager.h.

103  {
104  return static_cast<File const*>(file.id_)->buffer;
105  }

◆ print()

static void SourceManager::print ( std::ostream &  os,
SourceFile const &  file 
)
inlinestatic

Print the name of the file to the output stream.

Parameters
osThe output stream to print to
fileThe SourceFile to print

Definition at line 92 of file SourceManager.h.

92  {
93  if(file.id_ == nullptr) {
94  os << "??";
95  } else {
96  os << static_cast<File const*>(file.id_)->name;
97  }
98  }

The documentation for this class was generated from the following file: