Nearly CC
An educational compiler skeleton
Public Member Functions | List of all members
HasBaseType Class Referenceabstract

Common base class for QualifiedType, FunctionType, PointerType, and ArrayType. More...

#include "type.h"

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

Public Member Functions

 HasBaseType (const std::shared_ptr< Type > &base_type)
 
virtual std::shared_ptr< Typeget_base_type () const
 Get the base type. 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 bool is_same (const Type *other) const =0
 Equality comparison. More...
 
virtual std::string as_str () const =0
 Convert to a readable string representation of this type. 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_struct () const
 Check whether the type is a StructType. 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 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...
 
virtual unsigned get_field_offset (const std::string &name) const
 Get the offset of the named field. More...
 
virtual unsigned get_array_size () const
 Get the array size (number of elements). More...
 
virtual unsigned get_storage_size () const =0
 Get the number of bytes required to store an instance of this type. More...
 
virtual unsigned get_alignment () const =0
 Get the storage alignment multiple in bytes for an instance of this type. More...
 

Detailed Description

Common base class for QualifiedType, FunctionType, PointerType, and ArrayType.

Member Function Documentation

◆ add_member()

void Type::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 in QualifiedType, and HasMembers.

◆ as_str()

virtual std::string Type::as_str ( ) const
pure virtualinherited

Convert to a readable string representation of this type.

Returns
a string containing a description of the type

Implemented in ArrayType, PointerType, FunctionType, StructType, BasicType, QualifiedType, and 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()

virtual unsigned Type::get_alignment ( ) const
pure virtualinherited

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

Implemented in ArrayType, PointerType, FunctionType, StructType, BasicType, and QualifiedType.

◆ 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 > HasBaseType::get_base_type ( ) const
virtual

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 from Type.

◆ 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 Type::get_field_offset ( const std::string &  name) const
virtualinherited

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 in StructType.

◆ get_member()

const Member & Type::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 in QualifiedType, and HasMembers.

◆ get_num_members()

unsigned Type::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 in QualifiedType, and HasMembers.

◆ get_storage_size()

virtual unsigned Type::get_storage_size ( ) const
pure virtualinherited

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

Implemented in ArrayType, PointerType, FunctionType, StructType, BasicType, and QualifiedType.

◆ 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()

virtual bool Type::is_same ( const Type other) const
pure virtualinherited

Equality comparison.

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

Implemented in ArrayType, PointerType, FunctionType, StructType, BasicType, and QualifiedType.

◆ 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 Type::is_struct ( ) const
virtualinherited

Check whether the type is a StructType.

Returns
true if this is a StructType, false otherwise

Reimplemented in StructType, and QualifiedType.

◆ 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: