LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
type::Named Class Reference

Named types. More...

#include <named.hh>

Inheritance diagram for type::Named:
Collaboration diagram for type::Named:

Public Member Functions

virtual bool compatible_with (const Type &other) const override
 Whether two types are "compatible".
virtual std::ostream & dump (std::ostream &ostr) const override
 Print type redirections.
Ctor & dtor.
 Named (misc::symbol name)
 Construct a Named type.
 Named (misc::symbol name, const Type *type)
 Construct a Named type.
 ~Named ()
 Destroy this object, but not the Type pointed to.
Accessors.
const Typetype_get () const
 Return the user defined type's structure.
void type_set (const Type *type)
 Set the defined type's structure.
void type_set (const Type *type) const
 Set the defined type's structure.
misc::symbol name_get () const
 Return the name of this type.
void name_set (const misc::symbol &name)
 (Re)set the name of this type.
Type resolution.
const Typeactual () const
 The type pointed to ultimately.
bool sound () const
 Check that the definition of this named type is sound, i.e. that there is no recursive dependency.

Protected Attributes

misc::symbol name_
 Name of the defined type.
const Typetype_
 The Type pointed to.

Detailed Description

Named types.

Named types are used when new types are defined, i.e., in Example: let type name_ = type_.

Constructor & Destructor Documentation

type::Named::Named ( misc::symbol  name)
inline

Construct a Named type.

Parameters
nameuser defined type's identifier.
type::Named::Named ( misc::symbol  name,
const Type type 
)
inline

Construct a Named type.

Parameters
nameuser defined type's identifier.
typedefined type's structure

References type_set().

type::Named::~Named ( )

Destroy this object, but not the Type pointed to.

Member Function Documentation

const Type & type::Named::actual ( ) const
inlinevirtual

The type pointed to ultimately.

Reimplemented from type::Type.

virtual bool type::Named::compatible_with ( const Type other) const
overridevirtual

Whether two types are "compatible".

I.e., whether "a = b", "a <> b", "a := b" are correctly typed with a of type this, and b of type other).

By default two types are compatible (in the sense of "=" and "<>", not wrt an order) only when they are equal.

In the case of assignment, "rec := nil" is valid, but "nil := rec" is not, which suggest that we should have a non commutative assignment specific compatibility check. But since "nil := ..." is incorrect syntactically, that is not needed.

Reimplemented from type::Type.

virtual std::ostream& type::Named::dump ( std::ostream &  ostr) const
overridevirtual

Print type redirections.

Implements type::Type.

misc::symbol type::Named::name_get ( ) const
inline

Return the name of this type.

References name_.

void type::Named::name_set ( const misc::symbol name)
inline

(Re)set the name of this type.

References name_.

bool type::Named::sound ( ) const

Check that the definition of this named type is sound, i.e. that there is no recursive dependency.

const Type * type::Named::type_get ( ) const
inline

Return the user defined type's structure.

References type_.

void type::Named::type_set ( const Type type)
inline

Set the defined type's structure.

References type_.

Referenced by Named().

void type::Named::type_set ( const Type type) const
inline

Set the defined type's structure.

This is the version which is used by TypeChecker which needs to assign a value to the Named type.

References type_.

Member Data Documentation

misc::symbol type::Named::name_
protected

Name of the defined type.

Referenced by name_get(), and name_set().

const Type* type::Named::type_
mutableprotected

The Type pointed to.

"Mutable const" because most of the time types are handled as const objects. But Named types are built in two steps: first they are built without any value for type_ (by TypeChecker::visit_dec_header <ast::FunctionDec>), and then they are completed (by TypeChecker::visit_dec_body <ast::FunctionDec>). Because the second step of the construction is actually seen as a modification by the C++ type system, we have it accept it thanks to mutable.

Referenced by type_get(), and type_set().


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