|
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 |
| void | set_target_bash_version (const BashVersion &version) |
| void | set_unsaved_file_contents (const std::string &file_path, const std::string &contents) |
| Set the unsaved contents for a file to reflect in-editor changes. | |
| void | remove_unsaved_file_contents (const std::string &file_path) |
| std::string | get_file_contents (const std::string &file_path) |
| Get the contents of a file, considering unsaved changes if present. | |
| 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. | |
| 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) |
| 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::unordered_map< std::string, std::string > | unsaved_changes |
| BashVersion | target_bash_version = {5, 2} |
| std::recursive_mutex | pool_mutex |
| std::unique_ptr< Snapshot > | snapshot = std::make_unique<Snapshot>() |
| std::recursive_mutex | snapshot_mutex |
| 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::string ProgramPool::get_file_contents | ( | const std::string & | file_path | ) |
Get the contents of a file, considering unsaved changes if present.
If there are unsaved changes for the given file path, those contents are returned. Otherwise, the contents are read from the file on disk.
| file_path | The file path to get the contents of. |
| 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. |
| void ProgramPool::remove_unsaved_file_contents | ( | const std::string & | file_path | ) |
| void ProgramPool::set_suppress_warnings | ( | bool | suppress | ) |
| void ProgramPool::set_target_bash_version | ( | const BashVersion & | version | ) |
| void ProgramPool::set_unsaved_file_contents | ( | const std::string & | file_path, |
| const std::string & | contents | ||
| ) |
Set the unsaved contents for a file to reflect in-editor changes.
Future re-parses of the relevant program will use these contents
| file_path | The file path to set unsaved contents for. |
| contents | The unsaved contents of the file. |
| void ProgramPool::set_utf16_mode | ( | bool | mode | ) |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |