Bash++
Bash++ compiler internal documentation
|
Manages a pool of bpp_program objects for efficient reuse and access. More...
#include <ProgramPool.h>
Classes | |
struct | Snapshot |
Public Member Functions | |
ProgramPool (size_t max_programs=10) | |
void | add_include_path (const std::string &path) |
Add an include path for use by all future programs to be added to the pool. | |
void | set_suppress_warnings (bool suppress) |
void | set_utf16_mode (bool mode) |
bool | get_utf16_mode () const |
std::shared_ptr< bpp::bpp_program > | get_program (const std::string &file_path, bool jump_queue=false) |
Get or create a program for the given file path. | |
bool | has_program (const std::string &file_path) |
Check if a program for the given file path exists in the pool. | |
std::shared_ptr< bpp::bpp_program > | re_parse_program (const std::string &file_path) |
Re-parse a program for the given file path. | |
std::shared_ptr< bpp::bpp_program > | re_parse_program (const std::string &file_path, std::pair< std::string, std::string > replacement_file_contents) |
Re-parse a program for the given file path, with unsaved changes parsed instead of the file on disk. | |
void | open_file (const std::string &file_path) |
Mark a file as open in the program pool. | |
void | close_file (const std::string &file_path) |
Mark a file as closed in the program pool. | |
void | clean () |
Private Member Functions | |
void | _remove_oldest_program () |
void | _remove_program (size_t index) |
std::shared_ptr< bpp::bpp_program > | _parse_program (const std::string &file_path, std::optional< std::pair< std::string, std::string > > replacement_file_contents=std::nullopt) |
void | update_snapshot () |
Snapshot | load_snapshot () const |
Private Attributes | |
size_t | max_programs = 10 |
std::vector< std::shared_ptr< bpp::bpp_program > > | programs |
std::unordered_map< std::string, size_t > | program_indices |
std::unordered_map< std::string, bool > | open_files |
std::recursive_mutex | pool_mutex |
std::atomic< std::shared_ptr< Snapshot > > | snapshot |
bool | utf16_mode = false |
std::shared_ptr< std::vector< std::string > > | include_paths = std::make_shared<std::vector<std::string>>() |
bool | suppress_warnings = false |
Manages a pool of bpp_program objects for efficient reuse and access.
Copyright (C) 2025 Andrew S. Rightenburg Bash++: Bash with classes
Each parsed program has its data stored in a bpp_program object. The ProgramPool class allows for efficient management of these objects, including adding, retrieving, and removing programs based on file paths.
By default, it keeps a maximum of 10 programs in the pool. When an 11th program is added, the oldest program is removed to make space.
Having a program in the pool means that it has been parsed and is ready for use. I.e., we do not have to re-parse the program every time we want to request information from it, Such as "where was this entity defined?" or "what's the class of this object?"
The pool is designed to be thread-safe, allowing multiple threads to access and modify the pool concurrently.
|
explicit |
Copyright (C) 2025 Andrew S. Rightenburg Bash++: Bash with classes
|
private |
|
private |
|
private |
void ProgramPool::add_include_path | ( | const std::string & | path | ) |
Add an include path for use by all future programs to be added to the pool.
This mirrors the -I
option in bpp
path | The include path to add. |
void ProgramPool::clean | ( | ) |
void ProgramPool::close_file | ( | const std::string & | file_path | ) |
Mark a file as closed in the program pool.
If the program pool discovers that all files for a particular program have been closed, it will remove the program from the pool.
file_path | The file which has been closed |
std::shared_ptr< bpp::bpp_program > ProgramPool::get_program | ( | const std::string & | file_path, |
bool | jump_queue = false |
||
) |
Get or create a program for the given file path.
If a program in the pool reports that it controls the file at the given path, that program is returned. If no program exists for that file, we create a new program, add it to the pool, and return the new program.
file_path | The source file path to get or create a program for. |
jump_queue | Whether to jump the request queue. If true, the request is processed immediately. However, we will also refuse to create a new program – if none exists, and you've asked to jump the queue, we will simply return nullptr. |
bool ProgramPool::get_utf16_mode | ( | ) | const |
bool ProgramPool::has_program | ( | const std::string & | file_path | ) |
Check if a program for the given file path exists in the pool.
file_path | The source file path to check for a program. |
|
private |
void ProgramPool::open_file | ( | const std::string & | file_path | ) |
Mark a file as open in the program pool.
file_path | The file which has been opened |
std::shared_ptr< bpp::bpp_program > ProgramPool::re_parse_program | ( | const std::string & | file_path | ) |
Re-parse a program for the given file path.
file_path | The source file which has been modified, triggering the re-parse. |
std::shared_ptr< bpp::bpp_program > ProgramPool::re_parse_program | ( | const std::string & | file_path, |
std::pair< std::string, std::string > | replacement_file_contents | ||
) |
Re-parse a program for the given file path, with unsaved changes parsed instead of the file on disk.
file_path | The source file which has been modified, triggering the re-parse. |
replacement_file_contents | A pair: the first element is the path to the file with unsaved changes, the second element is the new contents of the file to use instead of the file on disk. |
void ProgramPool::set_suppress_warnings | ( | bool | suppress | ) |
void ProgramPool::set_utf16_mode | ( | bool | mode | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |