|
| | bash_command_sequence ()=default |
| |
| void | add_connective (bool is_and) |
| | Add a connective to the command sequence, finalizing the previously-received pipeline. Initially, ->add_code(some_pipeline) will store (for example) "echo hello, world" in the buffer for this entity. Subsequently calling ->add_connective() will turn that buffer into:
|
| |
| void | add_code (const std::string &code, bool add_newline=true) override |
| | Add code to the code entity.
|
| |
| std::string | get_code () const override |
| | Return the contents of the main code buffer as a string.
|
| |
| std::string | get_pre_code () const override |
| | Return the contents of the pre-code buffer as a string.
|
| |
| std::string | get_post_code () const override |
| | Return the contents of the post-code buffer as a string.
|
| |
| void | set_perfect_forwarding (bool enable) |
| |
| | bpp_string () |
| |
| void | add_code (const std::string &code, bool add_newline=true) override |
| | Add code to the primary buffer.
|
| |
| void | add_code_to_previous_line (const std::string &code) override |
| | Add code to the pre-code buffer.
|
| |
| void | add_code_to_next_line (const std::string &code) override |
| | Add code to the post-code buffer.
|
| |
| std::string | get_code () const override |
| | Return the contents of the main code buffer as a string.
|
| |
| std::string | get_pre_code () const override |
| | Return the contents of the pre-code buffer as a string.
|
| |
| std::string | get_post_code () const override |
| | Return the contents of the post-code buffer as a string.
|
| |
| | bpp_code_entity () |
| |
| 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 | set_requires_perfect_forwarding (bool require) |
| |
| bool | get_requires_perfect_forwarding () const |
| |
| virtual | ~bpp_entity ()=default |
| |
| virtual bool | add_class (std::shared_ptr< bpp_class > class_) |
| | Add a class to this entity's list of classes.
|
| |
| 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 |
| |
| std::unordered_map< std::string, std::shared_ptr< bpp_class > > | get_classes () const |
| |
| std::unordered_map< std::string, std::shared_ptr< bpp_object > > | get_objects () const |
| |
| std::shared_ptr< bpp_class > | get_class (const std::string &name) |
| |
| std::shared_ptr< bpp_object > | get_object (const std::string &name) |
| |
| std::shared_ptr< bpp_class > | get_parent () const |
| |
A sequence of bash commands connected by '&&' and '||'.
This entity type has two modes of operation:
- WITHOUT perfect_forwarding, the code buffer is consolidated into the single 'joined_code' buffer, which serves the purpose of pairing each command in the sequence with its respective pre- and post-code. This ensures that each command's pre- and post-code is only executed if that command is executed.
- WITH perfect_forwarding, the code buffer is split into the usual three distinct buffers of a bpp_string. These buffers are needed when we want to use bash_command_sequence as a bpp_string, i.e., in special cases where we do in fact need to separate the pre- and post-code from the main code. An example of such a case is in arithmetic substitution, e.g. $(( @object.method + 5 )). In that example case, it's important that the pre- and post-code for @object.method is not put inside the arithmetic expression, but rather before and after the entire expression.
| void bpp::bash_command_sequence::add_connective |
( |
bool |
is_and | ) |
|
Add a connective to the command sequence, finalizing the previously-received pipeline. Initially, ->add_code(some_pipeline) will store (for example) "echo hello, world" in the buffer for this entity. Subsequently calling ->add_connective() will turn that buffer into:
{
_pre-code_
echo hello, world
_post-code_
} _CONNECTIVE_
Preparing to receive the next pipeline
This splits each component of the command sequence across separate lines, which ensures that the relevant pre- and post-code for each component is executed IF AND ONLY IF that component is executed
Without doing this, a sequence such as false && @object.method would execute the pre- and post-code for @object.method, even though the method is guaranteed to never be called.
To give an extreme example, false && @(rm -rf /) would be catastrophic without this handling, as the pre-code necessary for the supershell involves executing the command inside of it and storing its output in a temporary variable to be substituted in place of the original expression. This would, in this case, execute rm -rf / regardless of the false && at the start of the command sequence.
By handling it in this way, however, the pre- and post-code for each component is only executed if that component is executed.
- Parameters
-
| is_and | True if the connective is '&&', false if it is '||' |