Bash++
Bash++ compiler internal documentation
bpp_codegen.h
Go to the documentation of this file.
1 
6 #ifndef SRC_BPP_INCLUDE_BPP_CODEGEN_H_
7 #define SRC_BPP_INCLUDE_BPP_CODEGEN_H_
8 
9 #include <string>
10 #include <memory>
11 #include <optional>
12 #include <deque>
13 #include <antlr4-runtime.h>
14 
15 #include "bpp.h"
16 #include "../antlr/BashppLexer.h"
17 #include "../internal_error.h"
18 
19 namespace bpp {
20 // Minimal forward declarations
21 class bpp_program;
22 class bash_while_condition;
23 class bpp_class;
24 class bpp_object;
25 
39 struct code_segment {
40  std::string pre_code;
41  std::string code;
42  std::string post_code;
43 
49  std::string full_code() const {
50  return pre_code + (pre_code.empty() ? "" : "\n") + code + (post_code.empty() ? "" : "\n") + post_code;
51  }
52 };
53 
55  const std::string& code_to_run,
56  bool in_while_condition,
57  std::shared_ptr<bash_while_condition> current_while_condition,
58  std::shared_ptr<bpp::bpp_program> program
59  );
60 
62  std::shared_ptr<bpp_object> object,
63  const std::string& object_ref,
64  std::shared_ptr<bpp::bpp_program> program
65  );
66 
68  const std::string& reference_code,
69  const std::string& method_name,
70  std::shared_ptr<bpp_class> assumed_class,
71  bool force_static_reference,
72  std::shared_ptr<bpp::bpp_program> program
73  );
74 
76  const std::string& reference_code,
77  const std::string& class_name,
78  std::shared_ptr<bpp::bpp_program> program
79  );
80 
82  const std::string& new_address,
83  std::shared_ptr<bpp::bpp_class> new_class
84  );
85 
86 
88  std::shared_ptr<bpp::bpp_entity> entity;
92  std::shared_ptr<bpp::bpp_class> class_containing_the_method;
93 
94  struct reference_error {
95  std::string message;
96  antlr4::tree::TerminalNode* token = nullptr;
97  };
98 
99  std::optional<reference_error> error;
100 };
101 
103  std::shared_ptr<bpp::bpp_code_entity> context,
104  std::deque<antlr4::tree::TerminalNode*> identifiers,
105  std::shared_ptr<bpp::bpp_class> current_class,
106  std::shared_ptr<bpp::bpp_program> program
107 );
108 
109 } // namespace bpp
110 
111 #endif // SRC_BPP_INCLUDE_BPP_CODEGEN_H_
Definition: bash_case.cpp:8
code_segment generate_supershell_code(const std::string &code_to_run, bool in_while_condition, std::shared_ptr< bash_while_condition > current_while_condition, std::shared_ptr< bpp::bpp_program > program)
Generates a supershell code segment for executing a bash command.
Definition: bpp_codegen.cpp:27
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:170
entity_reference resolve_reference(std::shared_ptr< bpp::bpp_code_entity > context, std::deque< antlr4::tree::TerminalNode * > identifiers, std::shared_ptr< bpp::bpp_class > current_class, std::shared_ptr< bpp::bpp_program > program)
Resolves a reference to an entity in a particular context.
Definition: bpp_codegen.cpp:275
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:75
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:113
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:211
A struct to hold (compiled) code segments.
Definition: bpp_codegen.h:39
std::string full_code() const
Return the full code segment as a single string.
Definition: bpp_codegen.h:49
std::string post_code
Definition: bpp_codegen.h:42
std::string code
Definition: bpp_codegen.h:41
std::string pre_code
Definition: bpp_codegen.h:40
Definition: bpp_codegen.h:94
std::string message
Definition: bpp_codegen.h:95
antlr4::tree::TerminalNode * token
Definition: bpp_codegen.h:96
Definition: bpp_codegen.h:87
bool created_first_temporary_variable
Definition: bpp_codegen.h:90
std::shared_ptr< bpp::bpp_class > class_containing_the_method
Definition: bpp_codegen.h:92
std::shared_ptr< bpp::bpp_entity > entity
Definition: bpp_codegen.h:88
bool created_second_temporary_variable
Definition: bpp_codegen.h:91
code_segment reference_code
Definition: bpp_codegen.h:89
std::optional< reference_error > error
Definition: bpp_codegen.h:99