forb
type_struct.hpp
1 #ifndef FORBCC_CUSTOM_TYPE_H
2 #define FORBCC_CUSTOM_TYPE_H
3 
4 #include <string>
5 #include <map>
6 
7 #include <templates/ordered_unique_list.hpp>
8 #include <templates/shareable.hpp>
9 
10 #include <types/type.hpp>
11 #include <module.hpp>
12 #include <variable.hpp>
13 
14 namespace forbcc {
16  class type_struct : public type, public shareable<type_struct>, public ordered_unique_list<variable> {
17  private:
19  size_t _size = 0;
20 
23  size_t _alignment = 0;
24 
25  /* ********************************************** CONSTRUCTORS ********************************************** */
26  public:
28  type_struct() : type() {};
29 
31  type_struct(const std::shared_ptr<module> &parent, const std::string &name) : type(parent, name) {};
32 
33  /**************************************************************************************************************/
34 
36  ~type_struct() override = default;
37 
39  type_struct(type_struct &&) = default;
40 
42  type_struct &operator=(type_struct &&) = default;
43 
45  type_struct(const type_struct &) = default;
46 
48  type_struct &operator=(const type_struct &) = default;
49 
50  /**************************************************************************************************************/
51 
53  void print_declaration(code_ostream &out) const override;
54 
56  void print_definition(code_ostream &out) const override;
57 
58  // Print the definition of a variable of this type
59  // void print_var_definition(code_ostream &out, const std::string &var_name, bool force_stack) const override;
60 
61  // Print the acquisition of the value of a variable of this type
62  // void print_var_lvalue(code_ostream &out, const std::string &var_name, bool is_stack) const override;
63 
65  bool insert(std::string key, const variable &value) override;
66 
68  size_t size_of() const override {
69  return _size;
70  };
71 
73  size_t alignment() const override {
74  return _alignment;
75  };
76 
77 
78  };
79 
80 } // namespace forbcc
81 
82 #endif //FORBCC_CUSTOM_TYPE_H
bool insert(std::string key, const variable &value) override
Wraps odered_unique_list::insert method adding a few operations to calculate structure size and align...
Definition: type_struct.cpp:57
size_t alignment() const override
Returns the alignment of the given type.
Definition: type_struct.hpp:73
size_t size_of() const override
Returns the size of the given type.
Definition: type_struct.hpp:68
Structure types are basically structures defined by the user that can be transferred between library ...
Definition: type_struct.hpp:16
A template that can be used to declare a list of unique ordered items.
Definition: ordered_unique_list.hpp:16
void print_definition(code_ostream &out) const override
Custom types define a partial specialization of the marshal/unmarshal templates.
Definition: type_struct.cpp:27
type_struct(const std::shared_ptr< module > &parent, const std::string &name)
Using constructors from superclass.
Definition: type_struct.hpp:31
A template that can be used to ease the declaration of a shared_pointer of a given type...
Definition: shareable.hpp:13
std::shared_ptr< entity > parent() const
Returns the parent of the given entity.
Definition: entity.hpp:63
void print_declaration(code_ostream &out) const override
Custom types require a declaration of course.
Definition: type_struct.cpp:8
std::string name() const
Returns the name of the given entity.
Definition: entity.hpp:68
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
type_struct & operator=(type_struct &&)=default
This class supports moving.
Definition: code_ostream.hpp:11
Represents either an attribute of a forbcc::type_struct class or an automatic variable declared withi...
Definition: variable.hpp:13
~type_struct() override=default
This class is virtual, so it requires a virtual destructor.
type_struct()
Empty structure type, used to preallocate variables in arrays or to use later assignment operator...
Definition: type_struct.hpp:28
Base class used to define primitive types, custom types (structures) and arrays.
Definition: type.hpp:22