1 #ifndef FORBCC_ARRAY_TYPE_H 2 #define FORBCC_ARRAY_TYPE_H 8 #include <types/type.hpp> 9 #include <templates/shareable.hpp> 24 std::shared_ptr<const type> _item_type;
45 std::string
codename = item_type->codename();
46 std::replace(codename.begin(), codename.end(),
':',
'_');
47 return "_Forb_Array_" + item_type->codename() +
"_D_" + std::to_string(length) +
"_";
60 _item_type(item_type),
62 _size(item_type->
size_of() * length) {
63 assert((length > 0 &&
"The length of the array must be strictly positive!"));
118 bool force_stack)
const override;
122 bool force_stack)
const override;
137 #endif //FORBCC_ARRAY_TYPE_H std::shared_ptr< const type > item_type() const
Returns the type of the items of the given array.
Definition: type_array.hpp:95
type_array()
Empty array type, used to preallocate variables in arrays or to use later assignment operator...
Definition: type_array.hpp:53
virtual std::string codename() const
Returns the codename of the given entity, which is the name of the entity as seen from the global sco...
Definition: entity.hpp:81
void print_var_serialize(code_ostream &out, const std::string &var_name, const serialize &do_undo, bool force_stack) const override
Prints the serialization/deserialization of a variable of the given type.
Definition: type_array.cpp:58
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 &) const override
Does nothing, primitive types do not need to be defined.
Definition: type_array.hpp:92
void print_var_declaration(code_ostream &out, const std::string &var_name) const override
Prints the declaration of a variable of the given type (no semicolon).
Definition: type_array.cpp:15
length_t length() const
Returns the length of the array.
Definition: type_array.hpp:100
size_t alignment() const override
Returns the alignment of the given type.
Definition: type_array.hpp:130
void print_var_lvalue(code_ostream &out, const std::string &var_name, bool is_stack) const override
Print the acquisition of the value of a variable of this type.
Definition: type_array.cpp:31
A template that can be used to ease the declaration of a shared_pointer of a given type...
Definition: shareable.hpp:13
size_t size_of() const override
Returns the size of the given type.
Definition: type_array.hpp:125
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
void print_var_reference(code_ostream &out, const std::string &var_name) const override
Prints the declaration of a reference variable of the given type (no semicolon).
Definition: type_array.cpp:42
void print_var_definition(code_ostream &out, const std::string &var_name, bool force_stack) const override
Print the definition of a variable of this type.
Definition: type_array.cpp:19
Definition: code_ostream.hpp:11
static type_array_list arrays
The list of all known arrays.
Definition: type_array.hpp:40
~type_array() override=default
This class is virtual, so it requires a virtual destructor.
void print_declaration(code_ostream &) const override
Does nothing, primitive types do not need to be declared.
Definition: type_array.hpp:89
Identifies an array of a given type, to be used in forbcc::method or in forbcc::type_struct definitio...
Definition: type_array.hpp:14
void print_var_marshal(code_ostream &out, const std::string &var_name, const marshal &do_undo, bool force_stack) const override
Prints the marshalling/unmarshalling operation of a variable of the given type.
Definition: type_array.cpp:46
type_array & operator=(type_array &&)=default
This class supports moving.
Base class used to define primitive types, custom types (structures) and arrays.
Definition: type.hpp:22
type_array(const std::shared_ptr< const type > &item_type, const length_t length)
Any trivially copyable type can be accepted as an array item type (except another array_type)...
Definition: type_array.hpp:58
static std::string to_identifier(const std::shared_ptr< const type > &item_type, const length_t length)
Converts a pair of item_type and length to an unique identifier, to be used when storing known array ...
Definition: type_array.hpp:43
long length_t
The type of the length attribute (which is a signed type, but values less than zero are considered in...
Definition: type_array.hpp:19