LRDE Tiger Compiler
1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
|
#include <named.hh>
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 Type * | type_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 Type & | actual () 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 Type * | type_ |
The Type pointed to. |
Named types.
Named types are used when new types are defined, i.e., in Example: let type name_ = type_.
|
inline |
Construct a Named type.
name | user defined type's identifier. |
|
inline |
Construct a Named type.
name | user defined type's identifier. |
type | defined type's structure |
References type_set().
type::Named::~Named | ( | ) |
Destroy this object, but not the Type pointed to.
|
inlinevirtual |
The type pointed to ultimately.
Reimplemented from type::Type.
|
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.
|
overridevirtual |
Print type redirections.
Implements type::Type.
|
inline |
Return the name of this type.
References 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.
|
inline |
Return the user defined type's structure.
References type_.
|
inline |
|
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_.
|
protected |
Name of the defined type.
Referenced by name_get(), and name_set().
|
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().