LRDE Tiger Compiler
1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
|
#include <class.hh>
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 Type * | attr_type (const misc::symbol &key) const |
Return the attribute type associated to key. | |
const Method * | meth_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 Class * | super_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 Type & | actual () const |
Return the actual type held by THIS. |
Static Public Member Functions | |
static const Class & | object_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 Class * | super_ |
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< Attribute > | attrs_type |
List of Attribute's. | |
typedef std::list< const Method * > | meths_type |
List of Method's. | |
const attrs_type & | attrs_get () const |
Return the list of stored Attributes (read only). | |
const meths_type & | meths_get () const |
Return the list of stored Methods (read only). | |
const Attribute * | attr_find (const misc::symbol &key) const |
Find an attribute using its name, return `nullptr' if not found. | |
const Attribute * | owned_attr_find (const misc::symbol &key) const |
Find an owned attribute using its name, return `nullptr' if not found. | |
const Method * | owned_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. |
Class types.
List of Attributes and Methods.
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.
|
virtualinherited |
Return the actual type held by THIS.
Reimplemented in type::Named.
Referenced by object::TypeChecker::operator()(), and object::DesugarVisitor::recurse_args().
|
inline |
Add an already existing Attribute to the list.
References attrs_.
Referenced by object::TypeChecker::operator()().
|
inline |
|
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()().
|
inline |
Return the list of stored Attributes (read only).
References attrs_.
Referenced by owned_attr_find().
|
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.
|
pure virtualinherited |
Report this on ostr.
Implemented in type::Named, type::Function, and type::Nil.
|
staticprivate |
Return a fresh identifier.
|
inline |
Does this class have actual data (i.e., owned attributes)?
References attrs_.
Referenced by object::DesugarVisitor::operator()().
|
inline |
Return the unique identifier of the class.
References id_.
Referenced by object::DesugarVisitor::operator()().
|
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().
|
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().
|
static |
Return the unique instance of the class type `Object'.
Referenced by object::DesugarVisitor::operator()(), object::TypeChecker::operator()(), object::Renamer::Renamer(), and object::TypeChecker::TypeChecker().
|
inline |
Find an owned attribute using its name, return `nullptr' if not found.
The search is restricted to the class.
References attrs_get().
|
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.
|
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_.
|
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().
|
inline |
Return (the transitive closure of) the list of subclasses.
References subclasses_.
Referenced by object::DesugarVisitor::cast_function(), object::DesugarVisitor::dispatch_switch(), object::DesugarVisitor::operator()(), object::DesugarVisitor::variant_exp(), and object::DesugarVisitor::variant_ty().
|
inline |
Return the type of the super class.
References super_.
Referenced by attr_find(), object::DesugarVisitor::cast_function(), object::DesugarVisitor::operator()(), object::TypeChecker::operator()(), object::DesugarVisitor::variant_exp(), and object::DesugarVisitor::variant_ty().
|
inline |
Set the type of the super class.
References super_.
|
private |
Attributes list.
Referenced by attr_add(), attrs_get(), and has_data().
|
private |
Methods list.
Referenced by meth_add(), and meths_get().
|
mutableprivate |
Sub classes.
Referenced by subclass_add(), subclasses_clear(), and subclasses_get().
|
private |
Super class.
Referenced by super_get(), and super_set().