Cerata
A library to generate structural hardware designs
cerata::Record Class Reference

A Record type containing zero or more fields. More...

#include <type.h>

+ Inheritance diagram for cerata::Record:
+ Collaboration diagram for cerata::Record:

Public Member Functions

bool IsPhysical () const override
 Return true if the Type has an immediate physical representation, false otherwise.
 
bool IsGeneric () const override
 Return true if the Type is a generic type.
 
bool IsNested () const override
 Return true if the Type is a nested, false otherwise.
 
 Record (std::string name, std::vector< std::shared_ptr< Field >> fields={})
 Record constructor.
 
RecordAddField (const std::shared_ptr< Field > &field, std::optional< size_t > index=std::nullopt)
 Add a field to this Record.
 
bool Has (const std::string &name) const
 Return true if record has field with name name.
 
Fieldat (const std::string &name) const
 Return the field with a specific name.
 
Fieldat (size_t i) const
 Return the field at index i contained by this record.
 
Fieldoperator[] (size_t i) const
 Return the field at index i contained by this record.
 
Fieldoperator[] (const std::string &name) const
 Return the field with name name contained by this record.
 
std::vector< std::shared_ptr< Field > > fields () const
 Return all fields contained by this record.
 
size_t num_fields () const
 Return the number of fields in this record.
 
bool IsEqual (const Type &other) const override
 Determine if this Type is exactly equal to an other Type.
 
std::vector< Node * > GetGenerics () const override
 Return all nodes that potentially parametrize the fields of this record.
 
std::vector< Type * > GetNested () const override
 Obtain any nested types.
 
std::shared_ptr< TypeCopy (const NodeMap &rebinding) const override
 Make a copy of the type, and rebind any type generic nodes that are keys in the rebinding to their values. More...
 
std::string ToStringFieldNames () const
 Return the names of the fields as a comma separated string.
 
- Public Member Functions inherited from cerata::Type
 Type (std::string name, ID id)
 Type constructor. More...
 
ID id () const
 Return the Type ID.
 
bool Is (ID type_id) const
 Return true if the Type ID is type_id, false otherwise.
 
virtual std::optional< Node * > width () const
 Return the width of the type, if it is synthesizable.
 
std::string ToString (bool show_meta=false, bool show_mappers=false) const
 Return the Type ID as a human-readable string.
 
std::vector< std::shared_ptr< TypeMapper > > mappers () const
 Return possible type mappers.
 
void AddMapper (const std::shared_ptr< TypeMapper > &mapper, bool remove_existing=true)
 Add a type mapper.
 
std::optional< std::shared_ptr< TypeMapper > > GetMapper (Type *other, bool generate_implicit=true)
 Get a mapper to another type, if it exists. Generates one, if possible, when generate_implicit = true.
 
int RemoveMappersTo (Type *other)
 Remove all mappers to a specific type.
 
std::optional< std::shared_ptr< TypeMapper > > GetMapper (const std::shared_ptr< Type > &other)
 Get a mapper to another type, if it exists.
 
virtual bool CanGenerateMapper (const Type &other) const
 Check if a mapper can be generated to another specific type.
 
virtual std::shared_ptr< TypeMapperGenerateMapper (Type *other)
 Generate a new mapper to a specific other type. Should be checked with CanGenerateMapper first, or throws.
 
virtual std::shared_ptr< TypeCopy () const
 Make a copy of the type without rebinding. More...
 
std::shared_ptr< Typeoperator() (std::vector< Node * > nodes)
 Make a copy of the type, and rebind any type generic nodes in order of the GetGenerics call. More...
 
std::shared_ptr< Typeoperator() (const std::vector< std::shared_ptr< Node >> &nodes)
 Make a copy of the type, and rebind any type generic nodes in order of the GetGenerics call. More...
 
- Public Member Functions inherited from cerata::Named
 Named (std::string name)
 Named constructor.
 
std::string name () const
 Return the name of the object.
 
void SetName (std::string name)
 Change the name of the object.
 
virtual ~Named ()=default
 Destructor.
 

Protected Attributes

std::vector< std::shared_ptr< Field > > fields_
 The fields of this Record.
 
- Protected Attributes inherited from cerata::Type
ID id_
 Type ID.
 
std::vector< std::shared_ptr< TypeMapper > > mappers_
 A list of mappers that can map this type to another type.
 

Additional Inherited Members

- Public Types inherited from cerata::Type
enum  ID {
  BIT, VECTOR, INTEGER, STRING,
  BOOLEAN, RECORD
}
 The Type ID. Used for convenient type checking. More...
 
- Public Attributes inherited from cerata::Type
std::unordered_map< std::string, std::string > meta
 KV storage for metadata of tools or specific backend implementations.
 

Detailed Description

A Record type containing zero or more fields.

Definition at line 301 of file type.h.

Member Function Documentation

◆ Copy()

std::shared_ptr< Type > cerata::Record::Copy ( const NodeMap rebinding) const
overridevirtual

Make a copy of the type, and rebind any type generic nodes that are keys in the rebinding to their values.

This is useful in case type generic nodes are on some instance graph and have to be copied over to a component graph, or vice versa. In that case, the new graph has to copy over these nodes and rebind the type generic nodes.

Returns
A copy of the type.

Implements cerata::Type.

Definition at line 446 of file type.cc.


The documentation for this class was generated from the following files: