Bash++
Bash++ compiler internal documentation
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
bpp::bash_command_sequence Class Reference

A sequence of bash commands connected by '&&' and '||'. More...

#include <bpp.h>

Inheritance diagram for bpp::bash_command_sequence:
Inheritance graph
[legend]
Collaboration diagram for bpp::bash_command_sequence:
Collaboration graph
[legend]

Public Member Functions

 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)
 
- Public Member Functions inherited from bpp::bpp_string
 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.
 
- Public Member Functions inherited from bpp::bpp_code_entity
 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
 
- Public Member Functions inherited from bpp::bpp_entity
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_classget_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_classget_containing_class ()
 Get the class which contains this entity.
 
virtual std::weak_ptr< bpp_programget_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::SymbolPositionget_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_classget_class (const std::string &name)
 
std::shared_ptr< bpp_objectget_object (const std::string &name)
 
std::shared_ptr< bpp_classget_parent () const
 

Protected Member Functions

void join ()
 

Protected Attributes

std::string joined_code = ""
 
bool contains_multiple_commands = false
 
bool perfect_forwarding = false
 
- Protected Attributes inherited from bpp::bpp_code_entity
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 = ""
 
std::unordered_map< std::string, std::weak_ptr< bpp_class > > classes
 A map of class names to class objects within this entity.
 
std::unordered_map< std::string, std::weak_ptr< bpp_object > > objects
 A map of object names to bpp_objects within this entity.
 
std::unordered_map< std::string, std::shared_ptr< bpp_object > > local_objects
 Like objects, but only for objects whose scope is local to this entity.
 
std::shared_ptr< bpp_classtype = nullptr
 
std::weak_ptr< bpp_classcontaining_class
 
std::weak_ptr< bpp_programcontaining_program
 
std::vector< std::weak_ptr< bpp_class > > parents
 
std::weak_ptr< bpp_methodoverridden_method
 
bpp::SymbolPosition initial_definition
 
std::list< bpp::SymbolPositionreferences
 

Detailed Description

A sequence of bash commands connected by '&&' and '||'.

This entity type has two modes of operation:

Constructor & Destructor Documentation

◆ bash_command_sequence()

bpp::bash_command_sequence::bash_command_sequence ( )
default

Member Function Documentation

◆ add_code()

void bpp::bash_command_sequence::add_code ( const std::string &  code,
bool  add_newline = true 
)
overridevirtual

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.

Parameters
codeThe code to add
add_newlineWhether to add a newline character after the code (default: true)

Reimplemented from bpp::bpp_code_entity.

◆ add_connective()

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_andTrue if the connective is '&&', false if it is '||'

◆ get_code()

std::string bpp::bash_command_sequence::get_code ( ) const
overridevirtual

Return the contents of the main code buffer as a string.

Reimplemented from bpp::bpp_code_entity.

◆ get_post_code()

std::string bpp::bash_command_sequence::get_post_code ( ) const
overridevirtual

Return the contents of the post-code buffer as a string.

Reimplemented from bpp::bpp_code_entity.

◆ get_pre_code()

std::string bpp::bash_command_sequence::get_pre_code ( ) const
overridevirtual

Return the contents of the pre-code buffer as a string.

Reimplemented from bpp::bpp_code_entity.

◆ join()

void bpp::bash_command_sequence::join ( )
protected

◆ set_perfect_forwarding()

void bpp::bash_command_sequence::set_perfect_forwarding ( bool  enable)

Member Data Documentation

◆ contains_multiple_commands

bool bpp::bash_command_sequence::contains_multiple_commands = false
protected

◆ joined_code

std::string bpp::bash_command_sequence::joined_code = ""
protected

◆ perfect_forwarding

bool bpp::bash_command_sequence::perfect_forwarding = false
protected

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