forb
type.hpp
1 #ifndef FORBCC_TYPE_H
2 #define FORBCC_TYPE_H
3 
4 #include <entity.hpp>
5 #include <module.hpp>
6 
7 namespace forbcc {
9  constexpr size_t max_stack_size = 16 * 1024; // 16 KB
10 
12  enum class marshal {
13  MARSHAL, UNMARSHAL
14  };
15 
17  enum class serialize {
18  SEND, RECV
19  };
20 
22  class type : public entity {
23  public:
24  /* ********************************************** CONSTRUCTORS ********************************************** */
25  public:
27  type() : entity() {};
28 
30  type(const std::shared_ptr<module> &parent, const std::string &name) : entity(parent, name) {};
31 
32  /**************************************************************************************************************/
33  public:
35  ~type() override = default;
36 
38  type(type &&) = default;
39 
41  type &operator=(type &&) = default;
42 
44  type(const type &) = default;
45 
47  type &operator=(const type &) = default;
48 
49  /**************************************************************************************************************/
50 
52  virtual void print_var_declaration(code_ostream &out, const std::string &var_name) const;
53 
55  virtual void print_var_definition(code_ostream &out, const std::string &var_name, bool force_stack) const;
56 
58  virtual void print_var_lvalue(code_ostream &out, const std::string &var_name, bool force_stack) const;
59 
61  void print_var_lvalue(code_ostream &out, const std::string &var_name) const {
62  print_var_lvalue(out, var_name, true);
63  };
64 
66  virtual void print_var_reference(code_ostream &out, const std::string &var_name) const;
67 
69  virtual void print_var_marshal(code_ostream &out, const std::string &var_name,
70  const marshal &do_undo, bool force_stack) const;
71 
73  void print_var_marshal(code_ostream &out, const std::string &var_name, const marshal &do_undo) const {
74  print_var_marshal(out, var_name, do_undo, true);
75  };
76 
78  virtual void print_var_serialize(code_ostream &out, const std::string &var_name,
79  const serialize &do_undo, bool force_stack) const;
80 
82  void print_var_serialize(code_ostream &out, const std::string &var_name, const serialize &do_undo) const {
83  print_var_serialize(out, var_name, do_undo, true);
84  }
85 
87  virtual size_t size_of() const = 0;
88 
90  virtual size_t alignment() const = 0;
91  };
92 
93 } // namespace forbcc
94 
95 #endif //FORBCC_TYPE_H
type()
Empty type, used to preallocate types in arrays or to use later assignment operator.
Definition: type.hpp:27
void print_var_marshal(code_ostream &out, const std::string &var_name, const marshal &do_undo) const
Print the actions needed to either marshal or unmarshal a variable of this type.
Definition: type.hpp:73
void print_var_lvalue(code_ostream &out, const std::string &var_name) const
Print the acquisition of the value of a variable of this type.
Definition: type.hpp:61
void print_var_serialize(code_ostream &out, const std::string &var_name, const serialize &do_undo) const
Print the actions needed to either serialize or deserialize a variable of this type.
Definition: type.hpp:82
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
type(const std::shared_ptr< module > &parent, const std::string &name)
Using constructors from superclass.
Definition: type.hpp:30
Definition: code_ostream.hpp:11
Any code entity that should be generated by the compiler: namespaces, classes, structures, methods, variables.
Definition: entity.hpp:18
Base class used to define primitive types, custom types (structures) and arrays.
Definition: type.hpp:22