Bash++
Bash++ compiler internal documentation
bpp.h
Go to the documentation of this file.
1 
6 #ifndef SRC_BPP_INCLUDE_BPP_H_
7 #define SRC_BPP_INCLUDE_BPP_H_
8 
9 #include <string>
10 #include <sstream>
11 #include <vector>
12 #include <unordered_map>
13 #include <memory>
14 
15 #include "replace_all.cpp"
16 
17 namespace bpp {
18 
19 enum bpp_scope {
24 };
25 
30 };
31 
32 // Forward declarations
33 
34 class bpp_entity;
35 class bpp_code_entity;
36 class bpp_string;
37 class bpp_method;
38 class bpp_constructor;
39 class bpp_destructor;
40 class bpp_method_parameter;
41 class bpp_class;
42 class bpp_object;
43 class bpp_datamember;
44 class bpp_program;
45 
46 // Statement types
47 class bash_while_loop;
48 class bash_while_condition;
49 class bash_if;
50 class bash_if_branch;
51 class bash_case;
52 class bash_case_pattern;
53 class bpp_delete_statement;
54 class bpp_dynamic_cast_statement;
55 class bpp_pointer_dereference;
56 class bpp_value_assignment;
57 class bpp_object_assignment;
58 class bpp_object_reference;
59 class bpp_object_address;
60 
65 static const std::shared_ptr<bpp_entity> inaccessible_entity = std::make_shared<bpp_entity>();
66 
71 static const std::shared_ptr<bpp_datamember> inaccessible_datamember = std::make_shared<bpp_datamember>();
72 
77 static const std::shared_ptr<bpp_method> inaccessible_method = std::make_shared<bpp_method>();
78 
83 static const char bpp_nullptr[] = "0";
84 
92 class bpp_entity {
93  protected:
98  std::unordered_map<std::string, std::shared_ptr<bpp_class>> classes;
99 
104  std::unordered_map<std::string, std::shared_ptr<bpp_object>> objects;
105 
110  std::unordered_map<std::string, std::shared_ptr<bpp_object>> local_objects;
111  std::shared_ptr<bpp_class> type = nullptr;
112  std::weak_ptr<bpp_class> containing_class;
113  std::vector<std::shared_ptr<bpp_class>> parents;
114  public:
115  virtual ~bpp_entity() = default;
116  virtual bool add_class(std::shared_ptr<bpp_class> class_);
117  virtual bool add_object(std::shared_ptr<bpp_object> object);
118 
119  virtual std::shared_ptr<bpp_class> get_class() const;
120  virtual std::string get_address() const;
121  virtual std::string get_name() const;
122  virtual std::weak_ptr<bpp::bpp_class> get_containing_class() const;
123  virtual bool set_containing_class(std::weak_ptr<bpp::bpp_class> containing_class);
124 
125  virtual void inherit(std::shared_ptr<bpp_entity> parent);
126  virtual void inherit(std::shared_ptr<bpp_class> parent);
127 
128  virtual std::unordered_map<std::string, std::shared_ptr<bpp_class>> get_classes() const;
129  virtual std::unordered_map<std::string, std::shared_ptr<bpp_object>> get_objects() const;
130  virtual std::shared_ptr<bpp_class> get_class(const std::string& name);
131  virtual std::shared_ptr<bpp_object> get_object(const std::string& name);
132 };
133 
151 class bpp_code_entity : public bpp_entity {
152  protected:
153  std::shared_ptr<std::ostream> code = std::make_shared<std::ostringstream>();
154  std::string nextline_buffer = "";
155  std::string postline_buffer = "";
156  bool buffers_flushed = false;
157  public:
158  bpp_code_entity();
159  virtual ~bpp_code_entity() = default;
160 
161  virtual void add_code(const std::string& code, bool add_newline = true);
162  virtual void add_code_to_previous_line(const std::string& code);
163  virtual void add_code_to_next_line(const std::string& code);
164 
165  bool add_object(std::shared_ptr<bpp_object> object) override;
166 
167  virtual void flush_nextline_buffer();
168  virtual void flush_postline_buffer();
169  virtual void flush_code_buffers();
170 
171  virtual void clear_all_buffers();
172 
173  virtual std::string get_code() const;
174  virtual std::string get_pre_code() const;
175  virtual std::string get_post_code() const;
176 };
177 
239 class bpp_string : public bpp_code_entity {
240  public:
241  bpp_string();
242 
243  void add_code(const std::string& code, bool add_newline = true) override;
244  void add_code_to_previous_line(const std::string& code) override;
245  void add_code_to_next_line(const std::string& code) override;
246 
247  std::string get_code() const override;
248  std::string get_pre_code() const override;
249  std::string get_post_code() const override;
250 };
251 
257 class bpp_method : public bpp_code_entity {
258  private:
259  std::string name;
260  std::vector<std::shared_ptr<bpp_method_parameter>> parameters;
262  bool m_is_virtual = false;
263  bool inherited = false;
264  public:
265  bpp_method();
266  explicit bpp_method(const std::string& name);
267 
268  bool add_object_as_parameter(std::shared_ptr<bpp_object> object);
269 
270  virtual bool add_parameter(std::shared_ptr<bpp_method_parameter> parameter);
271  void set_name(const std::string& name);
272  void set_scope(bpp_scope scope);
273  void set_virtual(bool is_virtual);
274  void set_inherited(bool is_inherited);
275 
276  std::string get_name() const;
277  std::vector<std::shared_ptr<bpp_method_parameter>> get_parameters() const;
278  bpp_scope get_scope() const;
279  bool is_virtual() const;
280  bool is_inherited() const;
281 
282  void destruct_local_objects();
283 };
284 
289 class bpp_constructor : public bpp_method {
290  public:
291  bpp_constructor();
292 
293  bool add_parameter(std::shared_ptr<bpp_method_parameter> parameter) override;
294 };
295 
300 class bpp_destructor : public bpp_method {
301  public:
302  bpp_destructor();
303 
304  bool add_parameter(std::shared_ptr<bpp_method_parameter> parameter) override;
305 };
306 
313  private:
314  std::shared_ptr<bpp_class> type;
315  std::string name;
316  public:
317  explicit bpp_method_parameter(const std::string& name);
318 
319  void set_type(std::shared_ptr<bpp_class>);
320 
321  std::string get_name() const;
322  std::shared_ptr<bpp_class> get_type() const;
323 };
324 
330 class bpp_class : public bpp_entity, public std::enable_shared_from_this<bpp_class> {
331  private:
332  std::string name;
333  std::vector<std::shared_ptr<bpp_method>> methods;
334  std::vector<std::shared_ptr<bpp_datamember>> datamembers;
335  std::shared_ptr<bpp_constructor> constructor;
336  std::shared_ptr<bpp_destructor> destructor;
337  bool constructor_set = false;
338  bool destructor_set = false;
340 
343  public:
344  bpp_class();
345 
346  std::weak_ptr<bpp_class> get_containing_class() const override;
347  bool set_containing_class(std::weak_ptr<bpp::bpp_class> containing_class) override;
348 
349  std::shared_ptr<bpp_class> get_class() const override;
350 
351  void set_name(const std::string& name);
352  bool add_method(std::shared_ptr<bpp_method> method);
353  bool add_datamember(std::shared_ptr<bpp_datamember> datamember);
354  bool set_constructor(std::shared_ptr<bpp_constructor> constructor);
355  bool set_destructor(std::shared_ptr<bpp_destructor> destructor);
356 
357  std::string get_name() const;
358  std::vector<std::shared_ptr<bpp_method>> get_methods() const;
359  std::vector<std::shared_ptr<bpp_datamember>> get_datamembers() const;
360  std::shared_ptr<bpp_constructor> get_constructor() const;
361  std::shared_ptr<bpp_destructor> get_destructor() const;
362  bool has_constructor() const;
363  bool has_destructor() const;
364 
365  std::shared_ptr<bpp_method> get_method(const std::string& name, std::shared_ptr<bpp_entity> context);
366  std::shared_ptr<bpp_method> get_method_UNSAFE(const std::string& name);
367  std::shared_ptr<bpp_datamember> get_datamember(const std::string& name, std::shared_ptr<bpp_entity> context);
368 
369  void inherit(std::shared_ptr<bpp_class> parent) override;
370  std::shared_ptr<bpp::bpp_class> get_parent();
371 };
372 
378 class bpp_object : public bpp_entity {
379  protected:
380  std::string name = "";
381  std::string address = "";
382  std::string assignment_value = "";
383  std::string pre_access_code = "";
384  std::string post_access_code = "";
385  std::shared_ptr<bpp_class> type;
386  bool m_is_pointer = false;
387  std::shared_ptr<bpp::bpp_object> copy_from = nullptr;
388  public:
389  bpp_object();
390  explicit bpp_object(const std::string& name);
391  bpp_object(const std::string& name, bool is_pointer);
392 
393  void set_class(std::shared_ptr<bpp_class> object_class);
394  void set_pointer(bool is_pointer);
395  void set_name(const std::string& name);
396  void set_address(const std::string& address);
397  void set_assignment_value(const std::string& assignment_value);
398  void set_pre_access_code(const std::string& pre_access_code);
399  void set_post_access_code(const std::string& post_access_code);
400  void set_nullptr();
401 
402  std::string get_name() const;
403  virtual std::string get_address() const;
404  std::string get_assignment_value() const;
405  std::shared_ptr<bpp_class> get_class() const;
406  std::string get_pre_access_code() const;
407  std::string get_post_access_code() const;
408  std::shared_ptr<bpp::bpp_object> get_copy_from() const;
409 
410  bool is_pointer() const;
411 };
412 
418 class bpp_datamember : public bpp_object {
419  private:
420  std::string default_value = "";
422  bool array = false;
423  public:
424  bpp_datamember();
425 
426  void set_default_value(const std::string& default_value);
427  void set_scope(bpp_scope scope);
428  void set_array(bool is_array);
429 
430  std::string get_address() const override;
431  std::string get_default_value() const;
432  bpp_scope get_scope() const;
433  bool is_array() const;
434 };
435 
441 class bpp_program : public bpp_code_entity {
442  private:
443  std::shared_ptr<bpp_class> primitive_class;
444  uint64_t supershell_counter = 0;
445  uint64_t assignment_counter = 0;
446  uint64_t function_counter = 0;
447  uint64_t dynamic_cast_counter = 0;
448  uint64_t object_counter = 0;
449  public:
450  bpp_program();
451 
452  bool set_containing_class(std::weak_ptr<bpp_class> containing_class) override;
453  void set_output_stream(std::shared_ptr<std::ostream> output_stream);
454 
455  bool add_class(std::shared_ptr<bpp_class> class_) override;
456 
457  std::shared_ptr<bpp_class> get_primitive_class() const;
458 
460  uint64_t get_supershell_counter() const;
461 
463  uint64_t get_assignment_counter() const;
464 
466  uint64_t get_function_counter() const;
467 
469  uint64_t get_dynamic_cast_counter() const;
470 
472  uint64_t get_object_counter() const;
473 };
474 
490  private:
491  std::shared_ptr<bpp::bash_while_condition> while_condition;
492  public:
493  bash_while_loop();
494 
495  void set_while_condition(std::shared_ptr<bpp::bash_while_condition> while_condition);
496  std::shared_ptr<bpp::bash_while_condition> get_while_condition() const;
497 
498  std::string get_code() const override;
499  std::string get_pre_code() const override;
500  std::string get_post_code() const override;
501 };
502 
511  private:
513  std::vector<std::string> supershell_function_calls = {};
514  public:
516 
518  void add_supershell_function_call(const std::string& function_call);
519  std::vector<std::string> get_supershell_function_calls() const;
520 };
521 
540 class bash_if : public bpp_string {
541  private:
542  std::string conditional_branch_pre_code = "";
544  std::vector<std::pair<std::string, std::string>> conditional_branches = {};
545  public:
546  bash_if();
547 
548  void add_conditional_branch_pre_code(const std::string& pre_code);
549  void add_conditional_branch_post_code(const std::string& post_code);
550  void new_branch();
551  void add_condition_code(const std::string& condition_code);
552  void add_branch_code(const std::string& branch_code);
553  std::string get_conditional_branch_pre_code() const;
554  std::string get_conditional_branch_post_code() const;
555  const std::vector<std::pair<std::string, std::string>>& get_conditional_branches() const;
556 };
557 
569  private:
570  std::shared_ptr<bpp::bash_if> if_statement;
571  public:
572  bash_if_branch();
573 
574  void set_if_statement(std::shared_ptr<bpp::bash_if> if_statement);
575  std::shared_ptr<bpp::bash_if> get_if_statement() const;
576 
577  std::string get_code() const override;
578  std::string get_pre_code() const override;
579  std::string get_post_code() const override;
580 };
581 
591 class bash_case : public bpp_string {
592  private:
593  std::string cases = "";
594  public:
595  bash_case();
596 
597  void add_case(const std::string& case_);
598 
599  const std::string& get_cases() const;
600 };
601 
612  private:
613  std::string pattern = "";
614  std::shared_ptr<bpp::bash_case> containing_case;
615  public:
617 
618  void set_pattern(const std::string& pattern);
619  void set_containing_case(std::shared_ptr<bpp::bash_case> containing_case);
620 
621  const std::string& get_pattern() const;
622  std::shared_ptr<bpp::bash_case> get_containing_case() const;
623 };
624 
634 class bash_for : public bpp_code_entity {
635  private:
636  std::string header_pre_code = "";
637  std::string header_post_code = "";
638  std::string header_code = "";
639  public:
640  bash_for();
641 
642  void set_header_pre_code(const std::string& pre_code);
643  void set_header_post_code(const std::string& post_code);
644  void set_header_code(const std::string& code);
645 
646  const std::string& get_header_pre_code() const;
647  const std::string& get_header_post_code() const;
648  const std::string& get_header_code() const;
649 };
650 
663  private:
664  std::shared_ptr<bpp::bpp_object> object_to_delete;
665  bool force_ptr = false;
666  public:
667  bpp_delete_statement() = default;
668 
669  void set_object_to_delete(std::shared_ptr<bpp::bpp_object> object);
670  void set_force_pointer(bool force_pointer);
671  std::shared_ptr<bpp::bpp_object> get_object_to_delete() const;
672  bool force_pointer() const;
673 };
674 
687  private:
688  std::shared_ptr<bpp::bpp_class> cast_to;
689  std::string cast_address = "";
690  public:
692 
693  void set_cast_to(std::shared_ptr<bpp::bpp_class> cast_to);
694  void set_cast_address(const std::string& cast_address);
695  std::shared_ptr<bpp::bpp_class> get_cast_to() const;
696  std::string get_cast_address() const;
697 };
698 
707  private:
708  std::shared_ptr<bpp::bpp_value_assignment> value_assignment;
709  public:
711 
712  void set_value_assignment(std::shared_ptr<bpp::bpp_value_assignment> value_assignment);
713  std::shared_ptr<bpp::bpp_value_assignment> get_value_assignment() const;
714 };
715 
724  private:
726  std::shared_ptr<bpp_entity> nonprimitive_object;
727  bool lvalue_nonprimitive = false;
728  bool array_assignment = false;
729  bool adding = false;
730  public:
732 
733  void set_nonprimitive_assignment(bool is_nonprimitive);
734  void set_nonprimitive_object(std::shared_ptr<bpp_entity> object);
735  void set_lvalue_nonprimitive(bool is_nonprimitive);
736  void set_array_assignment(bool is_array);
737  void set_adding(bool is_adding);
738 
739  bool is_nonprimitive_assignment() const;
740  std::shared_ptr<bpp_entity> get_nonprimitive_object() const;
741  bool lvalue_is_nonprimitive() const;
742  bool is_array_assignment() const;
743  bool is_adding() const;
744 };
745 
754  private:
755  std::string lvalue = "";
756  std::string rvalue = "";
757  bool lvalue_nonprimitive = false;
758  bool rvalue_nonprimitive = false;
759  std::shared_ptr<bpp_entity> lvalue_object;
760  std::shared_ptr<bpp_entity> rvalue_object;
761  bool adding = false;
762  bool rvalue_array = false;
763  public:
765 
766  void set_lvalue(const std::string& lvalue);
767  void set_rvalue(const std::string& rvalue);
768  void set_lvalue_nonprimitive(bool is_nonprimitive);
769  void set_rvalue_nonprimitive(bool is_nonprimitive);
770  void set_lvalue_object(std::shared_ptr<bpp_entity> object);
771  void set_rvalue_object(std::shared_ptr<bpp_entity> object);
772  void set_adding(bool is_adding);
773  void set_rvalue_array(bool is_array);
774 
775  std::string get_lvalue() const;
776  std::string get_rvalue() const;
777  bool lvalue_is_nonprimitive() const;
778  bool rvalue_is_nonprimitive() const;
779  std::shared_ptr<bpp_entity> get_lvalue_object() const;
780  std::shared_ptr<bpp_entity> get_rvalue_object() const;
781  bool is_adding() const;
782  bool rvalue_is_array() const;
783 };
784 
793  private:
795  std::string array_index = "";
796  public:
798 
800  void set_array_index(const std::string& array_index);
802  std::string get_array_index() const;
803 };
804 
813  public:
814  bpp_object_address() = default;
815 };
816 
817 } // namespace bpp
818 
819 #endif // SRC_BPP_INCLUDE_BPP_H_
A pattern for a case statement in Bash++.
Definition: bpp.h:611
std::string pattern
Definition: bpp.h:613
void set_containing_case(std::shared_ptr< bpp::bash_case > containing_case)
Definition: bash_case_pattern.cpp:19
const std::string & get_pattern() const
Definition: bash_case_pattern.cpp:23
void set_pattern(const std::string &pattern)
Definition: bash_case_pattern.cpp:15
bash_case_pattern()
Definition: bash_case_pattern.cpp:13
std::shared_ptr< bpp::bash_case > containing_case
Definition: bpp.h:614
std::shared_ptr< bpp::bash_case > get_containing_case() const
Definition: bash_case_pattern.cpp:27
A case statement in Bash++.
Definition: bpp.h:591
std::string cases
Definition: bpp.h:593
bash_case()
Definition: bash_case.cpp:13
const std::string & get_cases() const
Definition: bash_case.cpp:19
void add_case(const std::string &case_)
Definition: bash_case.cpp:15
A for loop in Bash++.
Definition: bpp.h:634
const std::string & get_header_post_code() const
Definition: bash_for.cpp:31
bash_for()
Definition: bash_for.cpp:13
void set_header_post_code(const std::string &post_code)
Definition: bash_for.cpp:19
const std::string & get_header_pre_code() const
Definition: bash_for.cpp:27
void set_header_code(const std::string &code)
Definition: bash_for.cpp:23
std::string header_code
Definition: bpp.h:638
std::string header_pre_code
Definition: bpp.h:636
void set_header_pre_code(const std::string &pre_code)
Definition: bash_for.cpp:15
std::string header_post_code
Definition: bpp.h:637
const std::string & get_header_code() const
Definition: bash_for.cpp:35
A branch of an if statement in Bash++.
Definition: bpp.h:568
void set_if_statement(std::shared_ptr< bpp::bash_if > if_statement)
Definition: bash_if_branch.cpp:15
std::shared_ptr< bpp::bash_if > get_if_statement() const
Definition: bash_if_branch.cpp:19
bash_if_branch()
Definition: bash_if_branch.cpp:13
std::string get_pre_code() const override
Return the contents of the pre-code buffer as a string.
Definition: bash_if_branch.cpp:27
std::string get_post_code() const override
Return the contents of the post-code buffer as a string.
Definition: bash_if_branch.cpp:35
std::string get_code() const override
Return the contents of the main code buffer as a string.
Definition: bash_if_branch.cpp:23
std::shared_ptr< bpp::bash_if > if_statement
Definition: bpp.h:570
An if statement in Bash++.
Definition: bpp.h:540
std::vector< std::pair< std::string, std::string > > conditional_branches
Definition: bpp.h:544
void add_conditional_branch_post_code(const std::string &post_code)
Definition: bash_if.cpp:19
void new_branch()
Definition: bash_if.cpp:23
std::string conditional_branch_pre_code
Definition: bpp.h:542
void add_branch_code(const std::string &branch_code)
Definition: bash_if.cpp:31
void add_condition_code(const std::string &condition_code)
Definition: bash_if.cpp:27
std::string get_conditional_branch_post_code() const
Definition: bash_if.cpp:39
bash_if()
Definition: bash_if.cpp:13
const std::vector< std::pair< std::string, std::string > > & get_conditional_branches() const
Definition: bash_if.cpp:43
std::string conditional_branch_post_code
Definition: bpp.h:543
void add_conditional_branch_pre_code(const std::string &pre_code)
Definition: bash_if.cpp:15
std::string get_conditional_branch_pre_code() const
Definition: bash_if.cpp:35
The condition for a while loop in Bash++.
Definition: bpp.h:510
bash_while_condition()
Definition: bash_while_condition.cpp:13
std::vector< std::string > supershell_function_calls
Definition: bpp.h:513
int supershell_count
Definition: bpp.h:512
void increment_supershell_count()
Definition: bash_while_condition.cpp:15
std::vector< std::string > get_supershell_function_calls() const
Definition: bash_while_condition.cpp:23
void add_supershell_function_call(const std::string &function_call)
Definition: bash_while_condition.cpp:19
A while loop in Bash++.
Definition: bpp.h:489
std::string get_post_code() const override
Return the contents of the post-code buffer as a string.
Definition: bash_while_loop.cpp:35
void set_while_condition(std::shared_ptr< bpp::bash_while_condition > while_condition)
Definition: bash_while_loop.cpp:15
std::shared_ptr< bpp::bash_while_condition > while_condition
Definition: bpp.h:491
std::string get_code() const override
Return the contents of the main code buffer as a string.
Definition: bash_while_loop.cpp:23
bash_while_loop()
Definition: bash_while_loop.cpp:13
std::string get_pre_code() const override
Return the contents of the pre-code buffer as a string.
Definition: bash_while_loop.cpp:27
std::shared_ptr< bpp::bash_while_condition > get_while_condition() const
Definition: bash_while_loop.cpp:19
A class in Bash++.
Definition: bpp.h:330
void set_name(const std::string &name)
Definition: bpp_class.cpp:64
bool set_constructor(std::shared_ptr< bpp_constructor > constructor)
Definition: bpp_class.cpp:132
bool set_containing_class(std::weak_ptr< bpp::bpp_class > containing_class) override
Definition: bpp_class.cpp:60
std::string get_name() const
Definition: bpp_class.cpp:150
std::shared_ptr< bpp_destructor > get_destructor() const
Definition: bpp_class.cpp:166
bool destructor_set
Definition: bpp.h:338
bpp_class()
Definition: bpp_class.cpp:13
bool set_destructor(std::shared_ptr< bpp_destructor > destructor)
Definition: bpp_class.cpp:141
std::string name
Definition: bpp.h:332
void inherit(std::shared_ptr< bpp_class > parent) override
Inherit from a parent class.
Definition: bpp_class.cpp:276
bool add_method(std::shared_ptr< bpp_method > method)
Add a method to the class.
Definition: bpp_class.cpp:73
std::weak_ptr< bpp_class > get_containing_class() const override
Get the class which contains this entity.
Definition: bpp_class.cpp:52
std::shared_ptr< bpp_destructor > destructor
Definition: bpp.h:336
std::vector< std::shared_ptr< bpp_datamember > > get_datamembers() const
Definition: bpp_class.cpp:158
void add_default_toPrimitive()
Add the default toPrimitive method.
Definition: bpp_class.cpp:39
bool has_destructor() const
Definition: bpp_class.cpp:174
std::vector< std::shared_ptr< bpp_datamember > > datamembers
Definition: bpp.h:334
std::shared_ptr< bpp_class > get_class() const override
Definition: bpp_class.cpp:56
std::shared_ptr< bpp_datamember > get_datamember(const std::string &name, std::shared_ptr< bpp_entity > context)
Get a datamember by name.
Definition: bpp_class.cpp:246
std::shared_ptr< bpp_constructor > get_constructor() const
Definition: bpp_class.cpp:162
bool has_custom_toPrimitive
Definition: bpp.h:339
bool has_constructor() const
Definition: bpp_class.cpp:170
void remove_default_toPrimitive()
Remove the default toPrimitive method.
Definition: bpp_class.cpp:21
std::shared_ptr< bpp::bpp_class > get_parent()
Definition: bpp_class.cpp:332
std::shared_ptr< bpp_method > get_method(const std::string &name, std::shared_ptr< bpp_entity > context)
Get a method by name.
Definition: bpp_class.cpp:191
std::shared_ptr< bpp_constructor > constructor
Definition: bpp.h:335
std::shared_ptr< bpp_method > get_method_UNSAFE(const std::string &name)
Get a method by name without checking the context.
Definition: bpp_class.cpp:224
bool constructor_set
Definition: bpp.h:337
std::vector< std::shared_ptr< bpp_method > > get_methods() const
Definition: bpp_class.cpp:154
bool add_datamember(std::shared_ptr< bpp_datamember > datamember)
Add a datamember to the class.
Definition: bpp_class.cpp:113
std::vector< std::shared_ptr< bpp_method > > methods
Definition: bpp.h:333
An entity which can contain code.
Definition: bpp.h:151
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:60
bpp_code_entity()
Definition: bpp_code_entity.cpp:13
std::shared_ptr< std::ostream > code
Definition: bpp.h:153
std::string postline_buffer
Definition: bpp.h:155
virtual void flush_code_buffers()
Definition: bpp_code_entity.cpp:85
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:52
virtual void flush_postline_buffer()
Definition: bpp_code_entity.cpp:75
virtual std::string get_post_code() const
Return the contents of the post-code buffer as a string.
Definition: bpp_code_entity.cpp:168
bool add_object(std::shared_ptr< bpp_object > object) override
Add an object to the code entity.
Definition: bpp_code_entity.cpp:111
virtual std::string get_pre_code() const
Return the contents of the pre-code buffer as a string.
Definition: bpp_code_entity.cpp:161
virtual void flush_nextline_buffer()
Definition: bpp_code_entity.cpp:65
virtual ~bpp_code_entity()=default
virtual void clear_all_buffers()
Definition: bpp_code_entity.cpp:91
virtual void add_code(const std::string &code, bool add_newline=true)
Add code to the code entity.
Definition: bpp_code_entity.cpp:25
virtual std::string get_code() const
Return the contents of the main code buffer as a string.
Definition: bpp_code_entity.cpp:150
std::string nextline_buffer
Definition: bpp.h:154
bool buffers_flushed
Definition: bpp.h:156
A constructor in a class.
Definition: bpp.h:289
bpp_constructor()
Definition: bpp_constructor.cpp:13
bool add_parameter(std::shared_ptr< bpp_method_parameter > parameter) override
Add a parameter to the method.
Definition: bpp_constructor.cpp:15
A data member in a class.
Definition: bpp.h:418
bool is_array() const
Definition: bpp_datamember.cpp:39
bool array
Definition: bpp.h:422
void set_scope(bpp_scope scope)
Definition: bpp_datamember.cpp:19
std::string get_default_value() const
Definition: bpp_datamember.cpp:31
void set_default_value(const std::string &default_value)
Definition: bpp_datamember.cpp:15
std::string get_address() const override
Definition: bpp_datamember.cpp:27
bpp_scope scope
Definition: bpp.h:421
std::string default_value
Definition: bpp.h:420
bpp_scope get_scope() const
Definition: bpp_datamember.cpp:35
bpp_datamember()
Definition: bpp_datamember.cpp:13
void set_array(bool is_array)
Definition: bpp_datamember.cpp:23
A delete statement in Bash++.
Definition: bpp.h:662
std::shared_ptr< bpp::bpp_object > get_object_to_delete() const
Definition: bpp_delete_statement.cpp:21
void set_force_pointer(bool force_pointer)
Definition: bpp_delete_statement.cpp:17
void set_object_to_delete(std::shared_ptr< bpp::bpp_object > object)
Definition: bpp_delete_statement.cpp:13
bool force_pointer() const
Definition: bpp_delete_statement.cpp:25
bool force_ptr
Definition: bpp.h:665
std::shared_ptr< bpp::bpp_object > object_to_delete
Definition: bpp.h:664
A destructor in a class.
Definition: bpp.h:300
bool add_parameter(std::shared_ptr< bpp_method_parameter > parameter) override
Add a parameter to the method.
Definition: bpp_destructor.cpp:15
bpp_destructor()
Definition: bpp_destructor.cpp:13
A dynamic_cast statement in Bash++.
Definition: bpp.h:686
std::string cast_address
Definition: bpp.h:689
std::shared_ptr< bpp::bpp_class > get_cast_to() const
Definition: bpp_dynamic_cast_statement.cpp:23
void set_cast_address(const std::string &cast_address)
Definition: bpp_dynamic_cast_statement.cpp:19
bpp_dynamic_cast_statement()
Definition: bpp_dynamic_cast_statement.cpp:13
std::shared_ptr< bpp::bpp_class > cast_to
Definition: bpp.h:688
void set_cast_to(std::shared_ptr< bpp::bpp_class > cast_to)
Definition: bpp_dynamic_cast_statement.cpp:15
std::string get_cast_address() const
Definition: bpp_dynamic_cast_statement.cpp:27
The base class for all entities in the Bash++ compiler.
Definition: bpp.h:92
virtual std::unordered_map< std::string, std::shared_ptr< bpp_object > > get_objects() const
Definition: bpp_entity.cpp:103
virtual std::shared_ptr< bpp_class > get_class() const
Definition: bpp_entity.cpp:48
std::unordered_map< std::string, std::shared_ptr< bpp_class > > classes
A map of class names to class objects within this entity.
Definition: bpp.h:98
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.
Definition: bpp.h:110
virtual bool add_object(std::shared_ptr< bpp_object > object)
Add an object to this entity's list of objects.
Definition: bpp_entity.cpp:32
virtual ~bpp_entity()=default
virtual std::unordered_map< std::string, std::shared_ptr< bpp_class > > get_classes() const
Definition: bpp_entity.cpp:99
std::vector< std::shared_ptr< bpp_class > > parents
Definition: bpp.h:113
virtual std::shared_ptr< bpp_object > get_object(const std::string &name)
Definition: bpp_entity.cpp:118
std::shared_ptr< bpp_class > type
Definition: bpp.h:111
virtual std::string get_address() const
Definition: bpp_entity.cpp:52
virtual std::weak_ptr< bpp::bpp_class > get_containing_class() const
Get the class which contains this entity.
Definition: bpp_entity.cpp:65
std::unordered_map< std::string, std::shared_ptr< bpp_object > > objects
A map of object names to bpp_objects within this entity.
Definition: bpp.h:104
std::weak_ptr< bpp_class > containing_class
Definition: bpp.h:112
virtual bool set_containing_class(std::weak_ptr< bpp::bpp_class > containing_class)
Definition: bpp_entity.cpp:69
virtual std::string get_name() const
Definition: bpp_entity.cpp:56
virtual void inherit(std::shared_ptr< bpp_entity > parent)
Inherit from a parent entity.
Definition: bpp_entity.cpp:81
virtual bool add_class(std::shared_ptr< bpp_class > class_)
Add a class to this entity's list of classes.
Definition: bpp_entity.cpp:18
A parameter in a method.
Definition: bpp.h:312
std::shared_ptr< bpp_class > get_type() const
Definition: bpp_method_parameter.cpp:23
bpp_method_parameter(const std::string &name)
Definition: bpp_method_parameter.cpp:13
std::shared_ptr< bpp_class > type
Definition: bpp.h:314
void set_type(std::shared_ptr< bpp_class >)
Definition: bpp_method_parameter.cpp:15
std::string name
Definition: bpp.h:315
std::string get_name() const
Definition: bpp_method_parameter.cpp:19
A method in a class.
Definition: bpp.h:257
bool inherited
Definition: bpp.h:263
bool add_object_as_parameter(std::shared_ptr< bpp_object > object)
Add a non-primitive object as a parameter to the method.
Definition: bpp_method.cpp:23
virtual bool add_parameter(std::shared_ptr< bpp_method_parameter > parameter)
Add a parameter to the method.
Definition: bpp_method.cpp:45
bool is_virtual() const
Definition: bpp_method.cpp:96
std::string name
Definition: bpp.h:259
void set_scope(bpp_scope scope)
Definition: bpp_method.cpp:72
bpp_scope scope
Definition: bpp.h:261
std::vector< std::shared_ptr< bpp_method_parameter > > get_parameters() const
Definition: bpp_method.cpp:88
bpp_method()
Definition: bpp_method.cpp:13
void set_virtual(bool is_virtual)
Definition: bpp_method.cpp:76
bpp_scope get_scope() const
Definition: bpp_method.cpp:92
std::string get_name() const
Definition: bpp_method.cpp:84
void set_inherited(bool is_inherited)
Definition: bpp_method.cpp:80
void set_name(const std::string &name)
Definition: bpp_method.cpp:68
std::vector< std::shared_ptr< bpp_method_parameter > > parameters
Definition: bpp.h:260
bool is_inherited() const
Definition: bpp_method.cpp:100
bool m_is_virtual
Definition: bpp.h:262
void destruct_local_objects()
Destruct all local objects.
Definition: bpp_method.cpp:111
A statement which takes the address of an object in Bash++.
Definition: bpp.h:812
An object assignment statement in Bash++.
Definition: bpp.h:753
void set_rvalue_array(bool is_array)
Definition: bpp_object_assignment.cpp:43
bool rvalue_array
Definition: bpp.h:762
bool rvalue_is_array() const
Definition: bpp_object_assignment.cpp:75
void set_adding(bool is_adding)
Definition: bpp_object_assignment.cpp:39
bool adding
Definition: bpp.h:761
std::shared_ptr< bpp_entity > lvalue_object
Definition: bpp.h:759
void set_rvalue_nonprimitive(bool is_nonprimitive)
Definition: bpp_object_assignment.cpp:27
bool rvalue_nonprimitive
Definition: bpp.h:758
bpp_object_assignment()
Definition: bpp_object_assignment.cpp:13
std::shared_ptr< bpp_entity > get_lvalue_object() const
Definition: bpp_object_assignment.cpp:63
void set_lvalue(const std::string &lvalue)
Definition: bpp_object_assignment.cpp:15
bool rvalue_is_nonprimitive() const
Definition: bpp_object_assignment.cpp:59
void set_lvalue_object(std::shared_ptr< bpp_entity > object)
Definition: bpp_object_assignment.cpp:31
std::string get_rvalue() const
Definition: bpp_object_assignment.cpp:51
std::string get_lvalue() const
Definition: bpp_object_assignment.cpp:47
void set_lvalue_nonprimitive(bool is_nonprimitive)
Definition: bpp_object_assignment.cpp:23
void set_rvalue(const std::string &rvalue)
Definition: bpp_object_assignment.cpp:19
std::shared_ptr< bpp_entity > rvalue_object
Definition: bpp.h:760
std::string lvalue
Definition: bpp.h:755
bool lvalue_is_nonprimitive() const
Definition: bpp_object_assignment.cpp:55
std::string rvalue
Definition: bpp.h:756
bool lvalue_nonprimitive
Definition: bpp.h:757
bool is_adding() const
Definition: bpp_object_assignment.cpp:71
std::shared_ptr< bpp_entity > get_rvalue_object() const
Definition: bpp_object_assignment.cpp:67
void set_rvalue_object(std::shared_ptr< bpp_entity > object)
Definition: bpp_object_assignment.cpp:35
An object reference in Bash++.
Definition: bpp.h:792
void set_array_index(const std::string &array_index)
Definition: bpp_object_reference.cpp:19
bpp::reference_type get_reference_type() const
Definition: bpp_object_reference.cpp:23
bpp::reference_type reference_type
Definition: bpp.h:794
bpp_object_reference()
Definition: bpp_object_reference.cpp:13
std::string array_index
Definition: bpp.h:795
std::string get_array_index() const
Definition: bpp_object_reference.cpp:27
void set_reference_type(bpp::reference_type reference_type)
Definition: bpp_object_reference.cpp:15
An object in Bash++.
Definition: bpp.h:378
std::string get_pre_access_code() const
Definition: bpp_object.cpp:69
bool is_pointer() const
Definition: bpp_object.cpp:77
void set_pre_access_code(const std::string &pre_access_code)
Definition: bpp_object.cpp:39
void set_pointer(bool is_pointer)
Definition: bpp_object.cpp:23
void set_address(const std::string &address)
Definition: bpp_object.cpp:31
virtual std::string get_address() const
Definition: bpp_object.cpp:57
std::string address
Definition: bpp.h:381
void set_post_access_code(const std::string &post_access_code)
Definition: bpp_object.cpp:43
std::string get_post_access_code() const
Definition: bpp_object.cpp:73
std::string get_assignment_value() const
Definition: bpp_object.cpp:61
std::shared_ptr< bpp_class > get_class() const
Definition: bpp_object.cpp:65
void set_assignment_value(const std::string &assignment_value)
Definition: bpp_object.cpp:35
std::string pre_access_code
Definition: bpp.h:383
void set_nullptr()
Definition: bpp_object.cpp:47
std::shared_ptr< bpp_class > type
Definition: bpp.h:385
std::string post_access_code
Definition: bpp.h:384
bpp_object()
Definition: bpp_object.cpp:13
bool m_is_pointer
Definition: bpp.h:386
std::string assignment_value
Definition: bpp.h:382
std::shared_ptr< bpp::bpp_object > get_copy_from() const
Definition: bpp_object.cpp:81
void set_name(const std::string &name)
Definition: bpp_object.cpp:27
std::string name
Definition: bpp.h:380
void set_class(std::shared_ptr< bpp_class > object_class)
Definition: bpp_object.cpp:19
std::shared_ptr< bpp::bpp_object > copy_from
Definition: bpp.h:387
std::string get_name() const
Definition: bpp_object.cpp:53
A pointer dereference in Bash++.
Definition: bpp.h:706
bpp_pointer_dereference()
Definition: bpp_pointer_dereference.cpp:13
std::shared_ptr< bpp::bpp_value_assignment > value_assignment
Definition: bpp.h:708
std::shared_ptr< bpp::bpp_value_assignment > get_value_assignment() const
Definition: bpp_pointer_dereference.cpp:19
void set_value_assignment(std::shared_ptr< bpp::bpp_value_assignment > value_assignment)
Definition: bpp_pointer_dereference.cpp:15
The main program.
Definition: bpp.h:441
uint64_t get_dynamic_cast_counter() const
Definition: bpp_program.cpp:225
uint64_t assignment_counter
Definition: bpp.h:445
std::shared_ptr< bpp_class > primitive_class
Definition: bpp.h:443
uint64_t dynamic_cast_counter
Definition: bpp.h:447
bool set_containing_class(std::weak_ptr< bpp_class > containing_class) override
Definition: bpp_program.cpp:26
uint64_t get_supershell_counter() const
Definition: bpp_program.cpp:189
void increment_function_counter()
Definition: bpp_program.cpp:201
uint64_t get_assignment_counter() const
Definition: bpp_program.cpp:197
uint64_t object_counter
Definition: bpp.h:448
std::shared_ptr< bpp_class > get_primitive_class() const
Definition: bpp_program.cpp:34
uint64_t supershell_counter
Definition: bpp.h:444
uint64_t get_function_counter() const
Definition: bpp_program.cpp:211
uint64_t function_counter
Definition: bpp.h:446
bool add_class(std::shared_ptr< bpp_class > class_) override
Add a class to the program.
Definition: bpp_program.cpp:43
uint64_t get_object_counter() const
Definition: bpp_program.cpp:233
void increment_dynamic_cast_counter()
Definition: bpp_program.cpp:215
bpp_program()
Definition: bpp_program.cpp:14
void increment_supershell_counter()
Definition: bpp_program.cpp:180
void increment_assignment_counter()
Definition: bpp_program.cpp:193
void set_output_stream(std::shared_ptr< std::ostream > output_stream)
Definition: bpp_program.cpp:30
void increment_object_counter()
Definition: bpp_program.cpp:229
The practical difference between bpp_code_entity and bpp_string is how we handle the code buffers.
Definition: bpp.h:239
std::string get_pre_code() const override
Return the contents of the pre-code buffer as a string.
Definition: bpp_string.cpp:43
void add_code(const std::string &code, bool add_newline=true) override
Add code to the primary buffer.
Definition: bpp_string.cpp:21
void add_code_to_previous_line(const std::string &code) override
Add code to the pre-code buffer.
Definition: bpp_string.cpp:28
void add_code_to_next_line(const std::string &code) override
Add code to the post-code buffer.
Definition: bpp_string.cpp:35
bpp_string()
Definition: bpp_string.cpp:13
std::string get_code() const override
Return the contents of the main code buffer as a string.
Definition: bpp_string.cpp:39
std::string get_post_code() const override
Return the contents of the post-code buffer as a string.
Definition: bpp_string.cpp:51
A value assignment statement in Bash++.
Definition: bpp.h:723
bool is_array_assignment() const
Definition: bpp_value_assignment.cpp:47
std::shared_ptr< bpp_entity > nonprimitive_object
Definition: bpp.h:726
bool nonprimitive_assignment
Definition: bpp.h:725
bool is_nonprimitive_assignment() const
Definition: bpp_value_assignment.cpp:35
bpp_value_assignment()
Definition: bpp_value_assignment.cpp:13
bool array_assignment
Definition: bpp.h:728
std::shared_ptr< bpp_entity > get_nonprimitive_object() const
Definition: bpp_value_assignment.cpp:39
bool lvalue_nonprimitive
Definition: bpp.h:727
void set_adding(bool is_adding)
Definition: bpp_value_assignment.cpp:31
void set_lvalue_nonprimitive(bool is_nonprimitive)
Definition: bpp_value_assignment.cpp:23
void set_array_assignment(bool is_array)
Definition: bpp_value_assignment.cpp:27
void set_nonprimitive_assignment(bool is_nonprimitive)
Definition: bpp_value_assignment.cpp:15
bool lvalue_is_nonprimitive() const
Definition: bpp_value_assignment.cpp:43
bool is_adding() const
Definition: bpp_value_assignment.cpp:51
void set_nonprimitive_object(std::shared_ptr< bpp_entity > object)
Definition: bpp_value_assignment.cpp:19
bool adding
Definition: bpp.h:729
Definition: bash_case.cpp:11
static const std::shared_ptr< bpp_method > inaccessible_method
A placeholder for an inaccessible method of a class (scope handling)
Definition: bpp.h:77
static const std::shared_ptr< bpp_datamember > inaccessible_datamember
A placeholder for an inaccessible data member of a class (scope handling)
Definition: bpp.h:71
static const char bpp_nullptr[]
The secret internal value of '@nullptr' in Bash++.
Definition: bpp.h:83
static const std::shared_ptr< bpp_entity > inaccessible_entity
A placeholder for an inaccessible entity (scope handling)
Definition: bpp.h:65
bpp_scope
Definition: bpp.h:19
@ SCOPE_PUBLIC
Definition: bpp.h:20
@ SCOPE_INACCESSIBLE
Definition: bpp.h:23
@ SCOPE_PRIVATE
Definition: bpp.h:22
@ SCOPE_PROTECTED
Definition: bpp.h:21
reference_type
Definition: bpp.h:26
@ ref_method
Definition: bpp.h:28
@ ref_object
Definition: bpp.h:29
@ ref_primitive
Definition: bpp.h:27