6#ifndef SRC_BPP_INCLUDE_BPP_CODEGEN_H_
7#define SRC_BPP_INCLUDE_BPP_CODEGEN_H_
14#include <antlr4-runtime.h>
17#include "../antlr/BashppLexer.h"
18#include "../internal_error.h"
23class bash_while_condition;
56 const std::string& code_to_run,
57 bool in_while_condition,
58 std::shared_ptr<bash_while_condition> current_while_condition,
59 std::shared_ptr<bpp::bpp_program> program
63 std::shared_ptr<bpp_object>
object,
64 const std::string& object_ref,
65 std::shared_ptr<bpp::bpp_program> program
69 const std::string& reference_code,
70 const std::string& method_name,
71 std::shared_ptr<bpp_class> assumed_class,
72 bool force_static_reference,
73 std::shared_ptr<bpp::bpp_program> program
77 const std::string& reference_code,
78 const std::string& class_name,
79 std::shared_ptr<bpp::bpp_program> program
83 const std::string& reference_code,
84 std::shared_ptr<bpp::bpp_program> program
88 const std::string& new_address,
89 std::shared_ptr<bpp::bpp_class> new_class
97 std::shared_ptr<bpp::bpp_entity>
entity;
105 antlr4::tree::TerminalNode*
token =
nullptr;
108 std::optional<reference_error>
error;
112 const std::string& file,
113 std::shared_ptr<bpp::bpp_entity> context,
114 std::deque<antlr4::tree::TerminalNode*>* identifiers,
115 std::deque<std::string>* identifier_texts,
117 std::shared_ptr<bpp::bpp_program> program
121 const std::string& file,
122 std::shared_ptr<bpp::bpp_entity> context,
125 std::shared_ptr<bpp::bpp_program> program
131 using ident_t = std::remove_cvref_t<
decltype(identifiers)>;
132 using container_t = std::remove_pointer_t<ident_t>;
133 using value_t =
typename container_t::value_type;
135 std::deque<antlr4::tree::TerminalNode*> node_deque;
136 std::deque<std::string> text_deque;
138 if constexpr (std::is_convertible_v<value_t, std::string>) {
140 for (
const auto&
id : *identifiers) {
141 text_deque.push_back(
id);
144 }
else if constexpr (std::is_convertible_v<value_t, antlr4::tree::TerminalNode*>) {
146 for (
const auto& node : *identifiers) {
147 node_deque.push_back(node);
149 for (
const auto& node : node_deque) {
150 text_deque.push_back(node->getText());
154 static_assert(
sizeof(value_t) == 0,
155 "resolve_reference: Identifiers must be either strings or TerminalNode pointers.");
Definition bash_case.cpp:8
entity_reference resolve_reference_impl(const std::string &file, std::shared_ptr< bpp::bpp_entity > context, std::deque< antlr4::tree::TerminalNode * > *nodes, std::deque< std::string > *identifiers, bool declare_local, std::shared_ptr< bpp::bpp_program > program)
Resolves a reference to an entity in a particular context.
Definition bpp_codegen.cpp:306
entity_reference resolve_reference(const std::string &file, std::shared_ptr< bpp::bpp_entity > context, auto identifiers, bool declare_local, std::shared_ptr< bpp::bpp_program > program)
Definition bpp_codegen.h:120
code_segment generate_typeof_code(const std::string &reference_code, std::shared_ptr< bpp::bpp_program > program)
Definition bpp_codegen.cpp:201
code_segment generate_dynamic_cast_code(const std::string &reference_code, const std::string &class_name, std::shared_ptr< bpp::bpp_program > program)
Generates a code segment for performing a dynamic cast.
Definition bpp_codegen.cpp:185
code_segment generate_delete_code(std::shared_ptr< bpp::bpp_object > object, const std::string &object_ref, std::shared_ptr< bpp::bpp_program > program)
Generates a code segment for deleting an object.
Definition bpp_codegen.cpp:90
code_segment generate_method_call_code(const std::string &reference_code, const std::string &method_name, std::shared_ptr< bpp::bpp_class > assumed_class, bool force_static_reference, std::shared_ptr< bpp::bpp_program > program)
Generates a code segment for calling a method.
Definition bpp_codegen.cpp:128
code_segment inline_new(const std::string &new_address, std::shared_ptr< bpp::bpp_class > new_class)
Generates a code segment to INLINE class's "new" function within a method.
Definition bpp_codegen.cpp:241
A struct to hold (compiled) code segments.
Definition bpp_codegen.h:40
std::string full_code() const
Return the full code segment as a single string.
Definition bpp_codegen.h:50
std::string post_code
Definition bpp_codegen.h:43
std::string code
Definition bpp_codegen.h:42
std::string pre_code
Definition bpp_codegen.h:41
Definition bpp_codegen.h:103
std::string message
Definition bpp_codegen.h:104
antlr4::tree::TerminalNode * token
Definition bpp_codegen.h:105
Definition bpp_codegen.h:96
bool created_first_temporary_variable
Definition bpp_codegen.h:99
std::shared_ptr< bpp::bpp_class > class_containing_the_method
Definition bpp_codegen.h:101
std::shared_ptr< bpp::bpp_entity > entity
Definition bpp_codegen.h:97
bool created_second_temporary_variable
Definition bpp_codegen.h:100
code_segment reference_code
Definition bpp_codegen.h:98
std::optional< reference_error > error
Definition bpp_codegen.h:108