Next: , Previous: , Up: Project Layout   [Contents][Index]


3.2.8 The src/ast Directory

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

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: ConstVisitor and Visitor, similar to iterator and 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 of 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: 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 instantiated 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 syntax tree, doing nothing. This visitor is 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 (see 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 (see 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 responsible for de-allocating that type.

void: created_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 (see 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.


Next: , Previous: , Up: Project Layout   [Contents][Index]