TC-4 Code to Write
What is to be done:
Implement the Singletons
type::String,type::Int, andtype::Void. Use templates to factor the code between the three singleton classes, see singleton.
ast::Typableast::TypeConstructorBecause many AST nodes will be annotated with their type, the feature is factored by these two classes. See
ast::Typable, andast::TypeConstructor, for details.ast::Expast::Decast::TyThese are typable.
ast::FunctionDecast::TypeDecast::TyThese build types.
The remaining classes are incomplete.
Pay extra attention to
type::operator==(const Type& a, const Type& b)andtype::Type::compatible_with.
Warning
Types are considered compatible under specific rules. Here is a summary of the main types considered to have type compatibility.
Types |
|
|
|
|
|
|
|---|---|---|---|---|---|---|
|
Same. |
|||||
|
Same or
Inheritance.
|
Assign or
Compare.
…
|
||||
|
Result
& formals.
|
|||||
|
Result
& formals.
|
|||||
|
Assign or
Compare.
…
|
Assign or
Compare.
…
|
||||
|
Assign or
Compare.
…
|
Same. |
- src/type/default-visitor.hxx
- type::GenVisitortype::GenDefaultVisitor
type::Typesare visitable. You must implement the default visitor class template, which walks through the tree of types doing nothing. It’s used as a base class for the type visitors. - src/type/type-checker.*
Of course this is the most tricky part. We hope there are enough comments in there so that you understand what is to be done. Please, post your questions and help us improve it.
It is also the
type::TypeChecker’s job to set therecord_typein thetype::Nilclass.record_typeis holding some information about thetype::Recordtype associated to thetype::Niltype. We choose to handle therecord_typeonly when no error occurred in the type-checking process.- src/type/pretty-printer.*
In order to output nice error messages, the types need to be printed. You must implement a visitor that prints the types, similar to
ast::PrettyPrinter.- src/ast/escapable.* & src/escapes/*
The implementation of TC-E, Computing the Escaping Variables, suggested at TC-3, Bindings, becomes a core assignment at TC-4, Type Checking.
- src/object/type-checker.* & src/object/renamer.* (Optional)
object::TypeCheckerandobject::Renamerinherit fromtype::TypeChecker, respectivelybind::Renamerso as to factor common parts.- src/astclone/cloner.* (Optional)
The
astclone::Clonerclass is used to duplicate an Abstract Syntax Tree. It will be useful for desugaring some constructs and handling extensions.- src/desugar/desugar-visitor.* (Optional)
The
desugar::DesugarVisitorclass is used to desugar some syntactic structures (e.g.forloops, string comparisons, etc.). It inherits fromastclone::Clonerso as to factor common parts. See TC-D, Removing the syntactic sugar from the Abstract Syntax Tree.- src/ast/dumper-dot.* (Optional)
Continue the implementation of the
ast::DumperDotby dumping the types. You will need to implement thedump_typefunction and call it in the relevant nodes.