|
Bash++
Bash++ compiler internal documentation
|
An entity which can contain code. More...
#include <bpp.h>


Public Member Functions | |
| virtual void | add_code (const std::string &code, bool add_newline=true) |
| Add code to the code entity. | |
| virtual void | add_code_to_previous_line (const std::string &code) |
| Add code to the code entity's pre-code buffer. | |
| virtual void | add_code_to_next_line (const std::string &code) |
| Add code to the code entity's post-code buffer. | |
| bool | add_object (std::shared_ptr< bpp_object > object, bool make_local=false) override |
| Add an object to the code entity. | |
| virtual void | flush_nextline_buffer () |
| virtual void | flush_postline_buffer () |
| virtual void | flush_code_buffers () |
| virtual void | clear_all_buffers () |
| void | destruct_local_objects (std::shared_ptr< bpp_program > program) |
| Destruct all local objects in the code entity. | |
| virtual std::string | get_code () const |
| Return the contents of the main code buffer as a string. | |
| virtual std::string | get_pre_code () const |
| Return the contents of the pre-code buffer as a string. | |
| virtual std::string | get_post_code () const |
| Return the contents of the post-code buffer as a string. | |
| void | set_requires_perfect_forwarding (bool require) |
| bool | get_requires_perfect_forwarding () const |
| void | adopt (std::shared_ptr< bpp_entity > entity) |
| Take ownership of all local objects in another entity, by moving them into this entity's local object map. | |
Public Member Functions inherited from bpp::bpp_entity | |
| bpp_entity ()=default | |
| virtual | ~bpp_entity ()=default |
| bpp_entity (const bpp_entity &other)=default | |
| bpp_entity & | operator= (const bpp_entity &other)=default |
| bpp_entity (bpp_entity &&other) noexcept=default | |
| bpp_entity & | operator= (bpp_entity &&other) noexcept=default |
| virtual std::shared_ptr< bpp_class > | get_class () |
| virtual std::string | get_address () const |
| virtual void | set_name (const std::string &name) |
| virtual std::string | get_name () const |
| virtual std::weak_ptr< bpp::bpp_class > | get_containing_class () |
| Get the class which contains this entity. | |
| virtual std::weak_ptr< bpp_program > | get_containing_program () |
| virtual bool | set_containing_class (std::weak_ptr< bpp::bpp_class > containing_class) |
| void | inherit (std::shared_ptr< bpp_entity > parent) |
| Inherit from a parent entity. | |
| void | inherit (std::shared_ptr< bpp_program > program) |
| virtual void | inherit (std::shared_ptr< bpp_class > parent) |
| void | set_definition_position (const std::string &file, uint64_t line, uint64_t column) |
| void | add_reference (const std::string &file, uint64_t line, uint64_t column) |
| bpp::SymbolPosition | get_initial_definition () const |
| std::list< bpp::SymbolPosition > | get_references () const |
| virtual std::shared_ptr< bpp_class > | get_class (const std::string &name, size_t max_visible_index=SIZE_MAX) |
| std::shared_ptr< bpp_object > | get_object (const std::string &name, size_t max_visible_index=SIZE_MAX) |
| virtual const OwnedEntityList< bpp_class > & | get_classes () const |
| virtual std::vector< std::shared_ptr< bpp_object > > | get_all_known_objects () const |
| const OwnedEntityList< bpp_object > & | get_local_objects () const |
| std::shared_ptr< bpp_class > | get_parent () const |
| size_t | number_of_known_objects () const |
| virtual size_t | number_of_known_classes () const |
Protected Attributes | |
| std::shared_ptr< std::ostream > | code = std::make_shared<std::ostringstream>() |
| std::string | nextline_buffer |
| std::string | postline_buffer |
| bool | buffers_flushed = false |
| bool | requires_perfect_forwarding = false |
| Signals to bash_command_sequence entities whether they should operate in perfect forwarding mode I.e., whether this entity has special need to separate its pre- and post-code from its main code. | |
Protected Attributes inherited from bpp::bpp_entity | |
| std::string | name |
| OwnedEntityList< bpp_object > | local_objects |
| size_t | parent_visible_object_count_at_creation = 0 |
| size_t | program_visible_class_count_at_creation = 0 |
| std::weak_ptr< bpp_class > | type |
| std::weak_ptr< bpp_class > | containing_class |
| std::weak_ptr< bpp_program > | containing_program |
| std::vector< std::weak_ptr< bpp_class > > | parents |
| For classes: the list of parent classes, in order. | |
| std::weak_ptr< bpp_entity > | parent_entity |
| For all entities (except program), the parent entity from which this entity inherits. | |
| std::weak_ptr< bpp_method > | overridden_method |
| bpp::SymbolPosition | initial_definition |
| std::list< bpp::SymbolPosition > | references |
An entity which can contain code.
Such as a method, a supershell, or the program itself
This class provides the basic functionality for entities which can contain code Including 3 distinct code buffers:
Generally, the pre_code and post_code are used to set up and clean up the environment
This class also provides the ability to add code to the pre_code, code, and post_code buffers And to flush those buffers when necessary
|
virtual |
Add code to the code entity.
This function adds code to the code entity's primary buffer. If the code contains a newline character, all code buffers are flushed. This ensures that the pre- and post- code relevant to each particular line of code is placed before and after the relevant line of code.
| code | The code to add |
| add_newline | Whether to add a newline character after the code (default: true) |
Reimplemented in bpp::bpp_string, and bpp::bash_command_sequence.
|
virtual |
Add code to the code entity's post-code buffer.
Reimplemented in bpp::bpp_string.
|
virtual |
Add code to the code entity's pre-code buffer.
Reimplemented in bpp::bpp_string.
|
overridevirtual |
Add an object to the code entity.
Adding an object to a code entity involves adding the necessary code to create the object. Unlike in the case where we add an object to a non-code entity, where we only need to update the object map.
This function generates the code necessary to create the object, including calling its constructor if it exists.
| object | The object to add |
Reimplemented from bpp::bpp_entity.
Reimplemented in bpp::bpp_method.
| void bpp::bpp_code_entity::adopt | ( | std::shared_ptr< bpp_entity > | entity | ) |
Take ownership of all local objects in another entity, by moving them into this entity's local object map.
This is used when exiting a supershell, since the parent code entity of the supershell should be responsible for managing the lifetime of objects created within the supershell, as per the spec.
| entity | The entity to adopt the local objects of |
|
virtual |
| void bpp::bpp_code_entity::destruct_local_objects | ( | std::shared_ptr< bpp_program > | program | ) |
Destruct all local objects in the code entity.
This function generates the code necessary to destruct all local objects in the code entity, and adds it to the code buffer. That code calls the destructor for each local object, if it exists, and then deletes the object.
It does not destruct local pointers, whose memory management is the responsibility of the programmer.
This function is called by the compiler at the end of the scope of code entities which hold "block-local" scope Class methods, bash functions, subshells, or simple blocks ("{ ... }") have block-local scope (i.e., their local objects are only accessible within the block of code they are defined in, and not in any nested blocks) Supershells, by contrast, do not have block-local scope, and objects instantiated within them are expected to persist until the end of the containing method or function
| program | Pointer to the bpp_program |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
Return the contents of the main code buffer as a string.
Reimplemented in bpp::bpp_string, bpp::bash_command_sequence, bpp::bash_while_or_until_loop, and bpp::bash_if_branch.
|
virtual |
Return the contents of the post-code buffer as a string.
Reimplemented in bpp::bpp_string, bpp::bash_command_sequence, bpp::bash_while_or_until_loop, and bpp::bash_if_branch.
|
virtual |
Return the contents of the pre-code buffer as a string.
Reimplemented in bpp::bpp_string, bpp::bash_command_sequence, bpp::bash_while_or_until_loop, and bpp::bash_if_branch.
| bool bpp::bpp_code_entity::get_requires_perfect_forwarding | ( | ) | const |
| void bpp::bpp_code_entity::set_requires_perfect_forwarding | ( | bool | require | ) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Signals to bash_command_sequence entities whether they should operate in perfect forwarding mode I.e., whether this entity has special need to separate its pre- and post-code from its main code.