The src/ast Directory

Namespace ast, delivered for TC-2. Implementation of the abstract syntax tree. The file ast/README.txt gives an overview of the involved class hierarchy.

File: libast.* (src/ast/)

The interface of the ast module. It exports procedures to print the AST.

File: location.hh (src/ast/)

Imports Bison’s parse::location.

File: visitor.hh (src/ast/)

Abstract base class of the compiler’s visitor hierarchy. Actually, it defines a class template GenVisitor, which expects an argument which can be either misc::constify_traits or misc::id_traits. This allows to define two parallel hierarchies: misc::ConstVisitor and misc::Visitor, similar to misc::iterator and misc::const_iterator.

The understanding of the template programming used is not required at this stage as it is quite delicate, and goes far beyond your (average) current understanding of templates.

File: default-visitor.* (src/ast/)

Implementation if the GenDefaultVisitor class template, which walks the abstract syntax tree, doing nothing. This visitor does not define visit methods for nodes related to object-oriented constructs (classes, methods, etc.); thus it is an abstract class, and is solely used as a basis for deriving other visitors. It is instantiated twice: GenDefaultVisitor<misc::constify_traits> and GenDefaultVisitor<misc::id_traits>.

File: dumper-dot.* (src/ast/)

The DumperDot class, which dump an AST using the graphviz dot format.

File: non-object-visitor.* (src/ast/)

Implementation of the GenNonObjectVisitor class template, which walks the abstract syntax tree, doing nothing, but aborting on nodes related to object-oriented constructs (classes, methods, etc.). This visitor is abstract and is solely used as a basis for deriving other visitors (see TC-2 FAQ). It is instanciated twice: GenNonObjectVisitor<misc::constify_traits> and GenNonObjectVisitor<misc::id_traits>.

File: object-visitor.* (src/ast/)

Implementation of the GenObjectVisitor class template, which walks object-related nodes of an abstract and is solely used as a basis for deriving other visitors. It is instantiated twice: GenObjectVisitor<misc::constify_traits> and GenObjectVisitor<misc::id_traits>.

File: pretty-printer.* (src/ast/)

The PrettyPrinter class, which pretty-prints an AST back into Tiger concrete syntax.

File: typable.* (src/ast/)

This class is not needed before TC-4.

Auxiliary class from which typable AST node classes should derive. It has a simple interface made to manage a pointer to the type of the node:

void type_set(const type::Type*)
const type::Type* type_get() const

Accessors to the type of this node.

void accept(ConstVisitor& v) const
void accept(Visitor& v)

These methods are abstract, as in ast::AST.

File: type-constructor.* (src/ast/)

This class is not needed before TC-4.

Auxiliary class from which should derive AST nodes that construct a type (e.g., ast::ArrayTy). Its interface is similar to that of ast::Typable with one big difference: ast::TypeConstructor is reponsible for de-allocating that type.

void create_type_set(const type::Type*)
const type::Type* created_type_get() const

Accessors to the created type of this node.

void accept(ConstVisitor& v) const
void accept(Visitor& v)

It is convenient to be able to visit these, but it is not needed.

File: escapable.* (src/ast/)

This class is needed only for TC-E.

Auxiliary class from which AST node classes that denote the declaration of variables and formal arguments should derive. Its role is to encode a single Boolean value: whether the variable escapes or not. The natural interface includes escape_get and escape_set methods.

Moreover, it must save its definition site, meaning the function in which it was declared. This is crucial for the EscapesCollector in TC-L.