Nearly CC
An educational compiler skeleton
Public Member Functions | List of all members
StructType Class Reference

StructType represents a struct type. More...

#include "type.h"

Inheritance diagram for StructType:
Inheritance graph
[legend]
Collaboration diagram for StructType:
Collaboration graph
[legend]

Public Member Functions

 StructType (const std::string &name)
 
std::string get_name () const
 
virtual bool is_same (const Type *other) const
 Equality comparison. More...
 
virtual std::string as_str () const
 Convert to a readable string representation of this type. More...
 
virtual bool is_struct () const
 Check whether the type is a StructType. More...
 
virtual unsigned get_storage_size () const
 Get the number of bytes required to store an instance of this type. More...
 
virtual unsigned get_alignment () const
 Get the storage alignment multiple in bytes for an instance of this type. More...
 
virtual unsigned get_field_offset (const std::string &name) const
 Get the offset of the named field. More...
 
virtual void add_member (const Member &member)
 Add a member. More...
 
virtual unsigned get_num_members () const
 Get the number of members (fields or parameters). More...
 
virtual const Memberget_member (unsigned index) const
 Get the Member with the position indicated by the given index. More...
 
bool is_integral () const
 Return true if the type is an integral (integer) type.
 
const Memberfind_member (const std::string &name) const
 Find named member. More...
 
virtual const Typeget_unqualified_type () const
 Get unqualified type (strip off type qualifiers, if any). More...
 
virtual bool is_basic () const
 Check whether the type is a BasicType. More...
 
virtual bool is_void () const
 Check whether the type represents void. More...
 
virtual bool is_pointer () const
 Check whether the type is a PointerType. More...
 
virtual bool is_array () const
 Check whether the type is an ArrayType. More...
 
virtual bool is_function () const
 Check whether the type is a FunctionType. More...
 
virtual bool is_volatile () const
 Check whether the type is qualified as volatile. More...
 
virtual bool is_const () const
 Check whether the type is qualified as const. More...
 
virtual BasicTypeKind get_basic_type_kind () const
 Get the BasicTypeKind of a BasicType. More...
 
virtual bool is_signed () const
 Check whether the BasicType is a signed type. More...
 
virtual std::shared_ptr< Typeget_base_type () const
 Get the base type. More...
 
virtual unsigned get_array_size () const
 Get the array size (number of elements). More...
 

Detailed Description

StructType represents a struct type.

Each field is represented by a Member.

Member Function Documentation

◆ add_member()

void HasMembers::add_member ( const Member member)
virtualinherited

Add a member.

This should only be called if the type type is a StructType or FunctionType.

Parameters
memberthe member (field or parameter) to add

Reimplemented from Type.

◆ as_str()

std::string StructType::as_str ( ) const
virtual

Convert to a readable string representation of this type.

Returns
a string containing a description of the type

Reimplemented from HasMembers.

◆ find_member()

const Member * Type::find_member ( const std::string &  name) const
inherited

Find named member.

Parameters
namename of the member to return
Returns
pointer to a named Member (or a null pointer if the named member doesn't exist)

◆ get_alignment()

unsigned StructType::get_alignment ( ) const
virtual

Get the storage alignment multiple in bytes for an instance of this type.

I.e., the start address of an instance of this type in memory must be aligned on a multiple of the returned value. Throws an exception if called on a FunctionType.

Returns
the storage alignment multiple in bytes for an instance of this type

Implements Type.

◆ get_array_size()

unsigned Type::get_array_size ( ) const
virtualinherited

Get the array size (number of elements).

Throws an exception if the type isn't an ArrayType.

Returns
the array size (number of elements)

Reimplemented in ArrayType, and QualifiedType.

◆ get_base_type()

std::shared_ptr< Type > Type::get_base_type ( ) const
virtualinherited

Get the base type.

For a FunctionType, the base type is the return type. For a PointerType, the base type is the pointed-to type. For an ArrayType, the base type is the element type.

Returns
the base type

Reimplemented in HasBaseType.

◆ get_basic_type_kind()

BasicTypeKind Type::get_basic_type_kind ( ) const
virtualinherited

Get the BasicTypeKind of a BasicType.

Returns
the BasicTypeKind of this basic type (throws an exception if this type is not a basic type)

Reimplemented in BasicType, and QualifiedType.

◆ get_field_offset()

unsigned StructType::get_field_offset ( const std::string &  name) const
virtual

Get the offset of the named field.

Throws an exception if the type is not a StructType.

Parameters
namethe name of a field
Returns
the offset of the field in bytes

Reimplemented from Type.

◆ get_member()

const Member & HasMembers::get_member ( unsigned  index) const
virtualinherited

Get the Member with the position indicated by the given index.

The index should be between 0 (inclusive) and the number of members (exclusive.)

Parameters
index
Returns
reference to the member at the given index

Reimplemented from Type.

◆ get_num_members()

unsigned HasMembers::get_num_members ( ) const
virtualinherited

Get the number of members (fields or parameters).

Throws an exception if this type isn't a StructType or FunctionType.

Returns
the number of members

Reimplemented from Type.

◆ get_storage_size()

unsigned StructType::get_storage_size ( ) const
virtual

Get the number of bytes required to store an instance of this type.

Throws an exception if called on a FunctionType.

Returns
the number of bytes required to store an instance of this type

Implements Type.

◆ get_unqualified_type()

const Type * Type::get_unqualified_type ( ) const
virtualinherited

Get unqualified type (strip off type qualifiers, if any).

Returns
The unqualified type

Reimplemented in QualifiedType.

◆ is_array()

bool Type::is_array ( ) const
virtualinherited

Check whether the type is an ArrayType.

Returns
true if this an ArrayType, false otherwise

Reimplemented in ArrayType, and QualifiedType.

◆ is_basic()

bool Type::is_basic ( ) const
virtualinherited

Check whether the type is a BasicType.

Returns
true if this type represents a basic type (int, char, etc., including qualified variants like const char), false otherwise

Reimplemented in BasicType, and QualifiedType.

◆ is_const()

bool Type::is_const ( ) const
virtualinherited

Check whether the type is qualified as const.

Returns
true if this is a const-qualified type, false otherwise

Reimplemented in QualifiedType.

◆ is_function()

bool Type::is_function ( ) const
virtualinherited

Check whether the type is a FunctionType.

Returns
true if this is a FunctionType, false otherwise

Reimplemented in FunctionType, and QualifiedType.

◆ is_pointer()

bool Type::is_pointer ( ) const
virtualinherited

Check whether the type is a PointerType.

Returns
true if this is a PointerType, false otherwise

Reimplemented in PointerType, and QualifiedType.

◆ is_same()

bool StructType::is_same ( const Type other) const
virtual

Equality comparison.

Returns
true IFF the other type represents exactly the same type as this one

Implements Type.

◆ is_signed()

bool Type::is_signed ( ) const
virtualinherited

Check whether the BasicType is a signed type.

Returns
true if this basic type is signed, false if it's unsigned (throws an exception if this is not a basic type)

Reimplemented in BasicType, and QualifiedType.

◆ is_struct()

bool StructType::is_struct ( ) const
virtual

Check whether the type is a StructType.

Returns
true if this is a StructType, false otherwise

Reimplemented from Type.

◆ is_void()

bool Type::is_void ( ) const
virtualinherited

Check whether the type represents void.

Returns
true if this type represents void, false otherwise

Reimplemented in BasicType, and QualifiedType.

◆ is_volatile()

bool Type::is_volatile ( ) const
virtualinherited

Check whether the type is qualified as volatile.

Returns
true if this is a volatile-qualified type, false otherwise

Reimplemented in QualifiedType.


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