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 <antlr4-runtime.h>
12 
13 #include "../internal_error.cpp"
14 
15 namespace bpp {
16 // Minimal forward declarations
17 class bpp_program;
18 class bash_while_condition;
19 class bpp_class;
20 class bpp_object;
21 
35 struct code_segment {
36  std::string pre_code;
37  std::string code;
38  std::string post_code;
39 
45  std::string full_code() const {
46  return pre_code + (pre_code.empty() ? "" : "\n") + code + (post_code.empty() ? "" : "\n") + post_code;
47  }
48 };
49 
51  const std::string& code_to_run,
52  bool in_while_condition,
53  std::shared_ptr<bash_while_condition> current_while_condition,
54  std::shared_ptr<bpp::bpp_program> program
55  );
56 
58  std::shared_ptr<bpp_object> object,
59  const std::string& object_ref,
60  std::shared_ptr<bpp::bpp_program> program
61  );
62 
64  const std::string& reference_code,
65  const std::string& method_name,
66  std::shared_ptr<bpp_class> assumed_class,
67  std::shared_ptr<bpp::bpp_program> program
68  );
69 
71  const std::string& reference_code,
72  const std::string& class_name,
73  std::shared_ptr<bpp::bpp_program> program
74  );
75 
77  const std::string& new_address,
78  std::shared_ptr<bpp::bpp_class> new_class
79  );
80 
81 } // namespace bpp
82 
83 #endif // SRC_BPP_INCLUDE_BPP_CODEGEN_H_
Definition: bash_case.cpp:11
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:30
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:162
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:78
code_segment generate_method_call_code(const std::string &reference_code, const std::string &method_name, std::shared_ptr< bpp::bpp_class > assumed_class, std::shared_ptr< bpp::bpp_program > program)
Generates a code segment for calling a method.
Definition: bpp_codegen.cpp:116
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:203
A struct to hold (compiled) code segments.
Definition: bpp_codegen.h:35
std::string full_code() const
Return the full code segment as a single string.
Definition: bpp_codegen.h:45
std::string post_code
Definition: bpp_codegen.h:38
std::string code
Definition: bpp_codegen.h:37
std::string pre_code
Definition: bpp_codegen.h:36