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

Class types. More...

#include <class.hh>

Inheritance diagram for type::Class:
Collaboration diagram for type::Class:

Public Member Functions

bool has_data () const
 Does this class have actual data (i.e., owned attributes)?
virtual bool compatible_with (const Type &other) const
 Whether two types are "compatible".
virtual std::ostream & dump (std::ostream &ostr) const =0
 Report this on ostr.
Constructor.
 Class (const Class *super=nullptr)
 Construct a Class.
Attribute and Method elementary manipulation.
const Typeattr_type (const misc::symbol &key) const
 Return the attribute type associated to key.
const Methodmeth_type (const misc::symbol &key) const
 Return the method type associated to key.
Accessors.
unsigned id_get () const
 Return the unique identifier of the class.
const Classsuper_get () const
 Return the type of the super class.
void super_set (const Class *type)
 Set the type of the super class.
const std::list< const Class * > & subclasses_get () const
 Return (the transitive closure of) the list of subclasses.
void subclass_add (const Class *subclass) const
 Add a class to the list of subclasses.
void subclasses_clear () const
 Erase all the subclasses.
Type resolution.
bool sound () const
 Check that the definition of this class is sound, i.e. that there is no recursive inheritance.
Accessors.
virtual const Typeactual () const
 Return the actual type held by THIS.

Static Public Member Functions

static const Classobject_instance ()
 Return the unique instance of the class type `Object'.

Static Private Member Functions

static unsigned fresh_id ()
 Return a fresh identifier.

Private Attributes

unsigned id_
 Class unique identifier.
const Classsuper_
 Super class.
std::list< const Class * > subclasses_
 Sub classes.
attrs_type attrs_
 Attributes list.
meths_type meths_
 Methods list.

Internal Attribute list manipulators.

typedef std::list< Attributeattrs_type
 List of Attribute's.
typedef std::list< const Method * > meths_type
 List of Method's.
const attrs_typeattrs_get () const
 Return the list of stored Attributes (read only).
const meths_typemeths_get () const
 Return the list of stored Methods (read only).
const Attributeattr_find (const misc::symbol &key) const
 Find an attribute using its name, return `nullptr' if not found.
const Attributeowned_attr_find (const misc::symbol &key) const
 Find an owned attribute using its name, return `nullptr' if not found.
const Methodowned_meth_find (const misc::symbol &key) const
 Find an owned method using its name, return `nullptr' if not found.
void attr_add (const Attribute &attr)
 Add an already existing Attribute to the list.
void attr_add (const ast::VarDec *def)
 Create a Attribute then add it to the list.
void meth_add (const Method *method)
 Add an already existing Method to the list.

Detailed Description

Class types.

List of Attributes and Methods.

Member Typedef Documentation

typedef std::list<Attribute> type::Class::attrs_type

List of Attribute's.

typedef std::list<const Method*> type::Class::meths_type

List of Method's.

Constructor & Destructor Documentation

type::Class::Class ( const Class super = nullptr)

Construct a Class.

Parameters
superSuper class.

Member Function Documentation

const Type & type::Type::actual ( ) const
virtualinherited

Return the actual type held by THIS.

Reimplemented in type::Named.

Referenced by object::TypeChecker::operator()(), and object::DesugarVisitor::recurse_args().

void type::Class::attr_add ( const Attribute attr)
inline

Add an already existing Attribute to the list.

References attrs_.

Referenced by object::TypeChecker::operator()().

void type::Class::attr_add ( const ast::VarDec def)
inline

Create a Attribute then add it to the list.

References attrs_.

const Attribute * type::Class::attr_find ( const misc::symbol key) const
inline

Find an attribute using its name, return `nullptr' if not found.

The search is performed throughtout the super classes.

References super_get().

const Type* type::Class::attr_type ( const misc::symbol key) const

Return the attribute type associated to key.

Referenced by object::TypeChecker::operator()().

const Class::attrs_type & type::Class::attrs_get ( ) const
inline

Return the list of stored Attributes (read only).

References attrs_.

Referenced by owned_attr_find().

bool type::Type::compatible_with ( const Type other) const
virtualinherited

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 in type::Named, and type::Nil.

virtual std::ostream& type::Type::dump ( std::ostream &  ostr) const
pure virtualinherited

Report this on ostr.

Implemented in type::Named, type::Function, and type::Nil.

unsigned type::Class::fresh_id ( )
staticprivate

Return a fresh identifier.

bool type::Class::has_data ( ) const
inline

Does this class have actual data (i.e., owned attributes)?

References attrs_.

Referenced by object::DesugarVisitor::operator()().

unsigned type::Class::id_get ( ) const
inline

Return the unique identifier of the class.

References id_.

Referenced by object::DesugarVisitor::operator()().

void type::Class::meth_add ( const Method method)
inline

Add an already existing Method to the list.

References meths_.

Referenced by object::TypeChecker::visit_dec_header().

const Method* type::Class::meth_type ( const misc::symbol key) const

Return the method type associated to key.

Referenced by object::TypeChecker::visit_dec_header().

const Class::meths_type & type::Class::meths_get ( ) const
inline

Return the list of stored Methods (read only).

References meths_.

Referenced by object::DesugarVisitor::operator()(), owned_meth_find(), and object::TypeChecker::visit_dec_header().

const Class & type::Class::object_instance ( )
static
const Attribute * type::Class::owned_attr_find ( const misc::symbol key) const
inline

Find an owned attribute using its name, return `nullptr' if not found.

The search is restricted to the class.

References attrs_get().

const Method * type::Class::owned_meth_find ( const misc::symbol key) const
inline

Find an owned method using its name, return `nullptr' if not found.

The search is restricted to the class.

References meths_get().

bool type::Class::sound ( ) const

Check that the definition of this class is sound, i.e. that there is no recursive inheritance.

void type::Class::subclass_add ( const Class subclass) const
inline

Add a class to the list of subclasses.

Although this method alters this, it is const, since types are mostly manipulated as const entities.

References subclasses_.

void type::Class::subclasses_clear ( ) const
inline

Erase all the subclasses.

This method is const for the same reason as type::Class::subclass_add.

References subclasses_.

Referenced by object::TypeChecker::TypeChecker().

const std::list< const Class * > & type::Class::subclasses_get ( ) const
inline
void type::Class::super_set ( const Class type)
inline

Set the type of the super class.

References super_.

Member Data Documentation

attrs_type type::Class::attrs_
private

Attributes list.

Referenced by attr_add(), attrs_get(), and has_data().

unsigned type::Class::id_
private

Class unique identifier.

Referenced by id_get().

meths_type type::Class::meths_
private

Methods list.

Referenced by meth_add(), and meths_get().

std::list<const Class*> type::Class::subclasses_
mutableprivate

Sub classes.

Referenced by subclass_add(), subclasses_clear(), and subclasses_get().

const Class* type::Class::super_
private

Super class.

Referenced by super_get(), and super_set().


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