Bash++
Bash++ compiler internal documentation
bpp_code_entity.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Andrew S. Rightenburg
3 * Bash++: Bash with classes
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#pragma once
8
9#include <memory>
10#include <string>
11#include <sstream>
12
13#include "bpp.h"
14#include "bpp_entity.h"
15
16namespace bpp {
17
36 protected:
37 std::shared_ptr<std::ostream> code = std::make_shared<std::ostringstream>();
38 std::string nextline_buffer;
39 std::string postline_buffer;
40 bool buffers_flushed = false;
41
48 public:
49 virtual void add_code(const std::string& code, bool add_newline = true);
50 virtual void add_code_to_previous_line(const std::string& code);
51 virtual void add_code_to_next_line(const std::string& code);
52
53 bool add_object(std::shared_ptr<bpp_object> object, bool make_local = false) override;
54
55 virtual void flush_nextline_buffer();
56 virtual void flush_postline_buffer();
57 virtual void flush_code_buffers();
58
59 virtual void clear_all_buffers();
60
61 void destruct_local_objects(std::shared_ptr<bpp_program> program);
62
63 virtual std::string get_code() const;
64 virtual std::string get_pre_code() const;
65 virtual std::string get_post_code() const;
66
67 void set_requires_perfect_forwarding(bool require);
69
70 void adopt(std::shared_ptr<bpp_entity> entity);
71};
72
73} // namespace bpp
An entity which can contain code.
Definition bpp_code_entity.h:35
void set_requires_perfect_forwarding(bool require)
Definition bpp_code_entity.cpp:205
virtual void add_code_to_next_line(const std::string &code)
Add code to the code entity's post-code buffer.
Definition bpp_code_entity.cpp:59
std::shared_ptr< std::ostream > code
Definition bpp_code_entity.h:37
std::string postline_buffer
Definition bpp_code_entity.h:39
virtual void flush_code_buffers()
Definition bpp_code_entity.cpp:84
virtual void add_code_to_previous_line(const std::string &code)
Add code to the code entity's pre-code buffer.
Definition bpp_code_entity.cpp:51
virtual void flush_postline_buffer()
Definition bpp_code_entity.cpp:74
virtual std::string get_post_code() const
Return the contents of the post-code buffer as a string.
Definition bpp_code_entity.cpp:201
virtual std::string get_pre_code() const
Return the contents of the pre-code buffer as a string.
Definition bpp_code_entity.cpp:194
virtual void flush_nextline_buffer()
Definition bpp_code_entity.cpp:64
virtual void clear_all_buffers()
Definition bpp_code_entity.cpp:90
bool requires_perfect_forwarding
Signals to bash_command_sequence entities whether they should operate in perfect forwarding mode I....
Definition bpp_code_entity.h:47
bool add_object(std::shared_ptr< bpp_object > object, bool make_local=false) override
Add an object to the code entity.
Definition bpp_code_entity.cpp:110
bool get_requires_perfect_forwarding() const
Definition bpp_code_entity.cpp:209
virtual void add_code(const std::string &code, bool add_newline=true)
Add code to the code entity.
Definition bpp_code_entity.cpp:24
virtual std::string get_code() const
Return the contents of the main code buffer as a string.
Definition bpp_code_entity.cpp:183
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...
Definition bpp_code_entity.cpp:221
std::string nextline_buffer
Definition bpp_code_entity.h:38
bool buffers_flushed
Definition bpp_code_entity.h:40
void destruct_local_objects(std::shared_ptr< bpp_program > program)
Destruct all local objects in the code entity.
Definition bpp_code_entity.cpp:172
The base class for all entities in the Bash++ compiler.
Definition bpp_entity.h:25
Definition bash_case.cpp:9