The src/ast Directory
Namespace ast, delivered from TC-1/2 to TC-5. Implementation of the abstract syntax tree.
The file ast/README.txt gives an overview of the involved class hierarchy.
File: local.am (src/ast/)
The Makefile configuration relative to the
src/ast/directory. It is responsible for the integration into thelibtclibrary with everything exported from theastmodule, and the linkage of the directory’s unit tests in the test-suite.
File: libast.* (src/ast/)
The interface of the
astmodule. It exports procedures to print theAST.
File: tasks.* (src/ast/)
The tasks relative to the
astmodule (see: The src/task Directory).
File: fwd.hh (src/ast/)
Forward declarations for the
astmodule.
Files: *.* (src/ast/)
Each
ASTnode has its set of classes to represent it along its information.
File: default-visitor.* (src/ast/)
Implementation of 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: dumper-dot.* (src/ast/)
The
DumperDotclass, which dump anASTusing the graphvizdotformat.
File: location.hh (src/ast/)
Imports Bison’s
parse::location.
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-1/2-Parser FAQ). It is instantiated 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: visitor.* (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: 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 responsible 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.Moreover, it must save its definition site, meaning the function in which it was declared. This is crucial for the
llvmtranslate::EscapesCollectorin TC-L.
File: test-ast.cc (src/ast/)
The unit tests.