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
astmodule. 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 eithermisc::constify_traitsormisc::id_traits. This allows to define two parallel hierarchies:misc::ConstVisitorandmisc::Visitor, similar tomisc::iteratorandmisc::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
GenDefaultVisitorclass 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>andGenDefaultVisitor<misc::id_traits>.
File: non-object-visitor.* (src/ast/)
Implementation of the
GenNonObjectVisitorclass 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>andGenNonObjectVisitor<misc::id_traits>.
File: object-visitor.* (src/ast/)
Implementation of the
GenObjectVisitorclass 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>andGenObjectVisitor<misc::id_traits>.
File: pretty-printer.* (src/ast/)
The
PrettyPrinterclass, which pretty-prints anASTback into Tiger concrete syntax.
File: typable.* (src/ast/)
This class is not needed before TC-4.
Auxiliary class from which typable
ASTnode 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() constAccessors to the type of this node.
void accept(ConstVisitor& v) constvoid 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
ASTnodes that construct a type (e.g.,ast::ArrayTy). Its interface is similar to that ofast::Typablewith one big difference:ast::TypeConstructoris reponsible for de-allocating that type.void create_type_set(const type::Type*)const type::Type* created_type_get() constAccessors to the created type of this node.
void accept(ConstVisitor& v) constvoid 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
ASTnode 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 includesescape_getandescape_setmethods.