Noeud « Next »: , Noeud « Previous »: T3 Samples, Noeud « Up »: T3



4.5.3 T3 Code To Write

ast::PrintVisitor
Be sure to display the /* escaping */ flag where needed, and only where needed. If you don't pay attention, you might display meaningless flags due to implementation details.
escapes::EscapesVisitor
Write the class escapes::EscapesVisitor in src/escapes/escapes-visitor.hh.

You are suggested to implement three additional classes:

Definition
An abstract class which is used to instantiate the template class symbol::Table into Table <Definition>.
— virtual void: escape_set (void)

Sets the escape to true.

— Variable: int depth_

Depth at which this object has been created.

— int: depth_get () const

Returns the depth associated to this Definition object.


VariableDefinition
Inherits from Definition. It has one additional attribute, a VarDec &. The method escape_set is implemented, and when invoked, set the escapes flags of the corresponding VarDec.
FormalDefinition
Inherits from Definition. To be designed by yourself. Do not forget that the ast class used to register formals is used elsewhere, and it would be a pity that your implementation makes no difference... Be sure to write a test that verifies that your implementation is not abused. I have one such test...

Equip ast
All the sites where variables and formals (i.e., the arguments of the functions being defined, not being used) are introduced must be equipped with the escape_get and escape_set methods. Most probably the code was already given, and is using const_casts; try to use mutable instead.

Modify the code so that each definition of an escaping variable/formal is preceded by the comment /* escaping */ if the flag display_escapes_p is true. See the item “Driver” for an example.