Noeud « Next »: , Noeud « Previous »: T4 Given Code, Noeud « Up »: T4



4.6.4 T4 Code to Write

What is to be done.

symbol::Table< class Entry_T >
Write the class template symbol::Table in src/symbol/table.hh which is a table of symbols dedicated to storing some data which type is Entry_T *. In short, it maps a symbol::Symbol to an Entry_T * (that should ring a bell...). You are encouraged to implement something simple, based on stacks (see std::stack or std::list) and maps (see std::map).

symbol::Table is a class template as it is used by virtually all the AST visitors (e.g., escapes::EscapesVisitor, type::TypeVisitor, translate::TranslateVisitor etc.)

symbol::Table must provide this interface:

— void: scope_begin ()

Open a new scope.

— void: scope_end ()

Close the last scope, forgetting everything since the latest scope_begin ().

— void: put (Symbol key, Entry_T & value)

Associate value to key in the current scope.

— Entry_T *: get (Symbol key) const

If key was associated to some Entry_T in the open scopes, return the most recent insertion. Otherwise return the empty pointer.

— void: print (std::ostream & ostr) const

Send the content of this table on ostr in a readable manner, the top of the stack being displayed last.


src/type/types.hh
The Singletons type::String, type::Int, and type::Void are to be implemented. Using templates would be particularly appreciated to factor the code between the four singleton classes.

type::Named is almost entirely given.

type::Array is even simpler than the four Singletons.

type::Record is somewhat incomplete.

Pay extra attention to the implementation of type::operator== (const Type& a, const Type& b), type::Type::assignable_to and type::Type::comparable_to.

src/type/type-entry.hh
This file is really a empty nutshell, so we give it complete so that you concentrate on things that matter. Nonetheless you will be asked questions on this file, so study it.
src/type/type-env.hh
The constructor of type::TypeEnv must be completed: it must fill the environment with the definition of builtin types and functions. See the Tiger Reference Manual.

The handling of types is left as an example, you still have to implement the variables and functions support.

type::TypeVisitor
Of course this is the most tricky part. I hope there are enough comments in there so that you understand what is to be done. Please, post your questions and help me improve it.
Tasks
Each module Foo exports its tasks via the file foo/foo-tasks.hh. You must clean up your code to use the latest sources for Tasks, and make sure that your configure.ac no longer includes foo/libfoo.hh in src/modules.hh.