LRDE Tiger Compiler
1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
|
Translate an ast::Ast into High level tree::Tree code. More...
#include <translator.hh>
Public Types | |
typedef ast::DefaultConstVisitor | super_type |
Super class. |
Public Member Functions | |
Translator () | |
virtual | ~Translator () |
virtual void | operator() (const ast::Ast &e) override |
Run the translation. | |
tree::Fragments * | fragments_get () |
Return the translation. Ownership is transfered to the receiver. | |
rExp | translate (const ast::Ast &node) |
Run this visitor on node, and return its translation. | |
template<typename T > | |
std::list< rExp > | translate (const std::list< T * > &es) |
The list of translations of es members. | |
virtual void | operator() (const ast::VarDec &e) override |
virtual void | operator() (typename Const< Ast >::type &e) |
The entry point: visit e. | |
virtual void | operator() (typename Const< ClassTy >::type &)=0 |
virtual void | operator() (typename Const< MethodCallExp >::type &)=0 |
virtual void | operator() (typename Const< MethodDec >::type &)=0 |
virtual void | operator() (typename Const< ObjectExp >::type &)=0 |
template<class E > | |
void | operator() (E *e) |
Helper to visit nodes manipulated via a pointer. | |
Forbid copying this visitor: do not implement the copy | |
ctor nor the assignment operator. Copying is forbidden because deep-copy is not implemented, and the dtor deletes the level_ attribute, which is allocated by the ctor. | |
Translator (const Translator &) | |
Translator & | operator= (const Translator &) |
Lvalues | |
virtual void | operator() (const ast::SimpleVar &e) override |
virtual void | operator() (const ast::FieldVar &e) override |
virtual void | operator() (const ast::SubscriptVar &e) override |
virtual void | operator() (const ast::CastVar &e) override |
Expressions | |
virtual void | operator() (const ast::NilExp &) override |
virtual void | operator() (const ast::IntExp &e) override |
virtual void | operator() (const ast::StringExp &e) override |
virtual void | operator() (const ast::RecordExp &e) override |
virtual void | operator() (const ast::CallExp &e) override |
virtual void | operator() (const ast::OpExp &e) override |
virtual void | operator() (const ast::SeqExp &e) override |
virtual void | operator() (const ast::AssignExp &e) override |
virtual void | operator() (const ast::IfExp &e) override |
virtual void | operator() (const ast::WhileExp &e) override |
virtual void | operator() (const ast::ForExp &e) override |
virtual void | operator() (const ast::BreakExp &) override |
virtual void | operator() (const ast::LetExp &e) override |
virtual void | operator() (const ast::ArrayExp &e) override |
virtual void | operator() (const ast::CastExp &e) override |
Chunks of declarations | |
virtual void | operator() (const ast::VarDecs &e) override |
virtual void | operator() (const ast::TypeDecs &) override |
virtual void | operator() (const ast::FunctionDecs &e) override |
Function Declaration | |
virtual void | operator() (const ast::FunctionDec &) override |
void | visit_function_dec_header (const ast::FunctionDec &e) |
void | visit_function_dec_body (const ast::FunctionDec &e) |
Visit Variable related nodes. | |
virtual void | operator() (typename Const< SimpleVar >::type &e) override |
virtual void | operator() (typename Const< FieldVar >::type &e) override |
virtual void | operator() (typename Const< SubscriptVar >::type &e) override |
virtual void | operator() (typename Const< CastVar >::type &e) override |
Visit Expression related nodes. | |
virtual void | operator() (typename Const< NilExp >::type &e) override |
virtual void | operator() (typename Const< IntExp >::type &e) override |
virtual void | operator() (typename Const< StringExp >::type &e) override |
virtual void | operator() (typename Const< CallExp >::type &e) override |
virtual void | operator() (typename Const< OpExp >::type &e) override |
virtual void | operator() (typename Const< RecordExp >::type &e) override |
virtual void | operator() (typename Const< SeqExp >::type &e) override |
virtual void | operator() (typename Const< AssignExp >::type &e) override |
virtual void | operator() (typename Const< IfExp >::type &e) override |
virtual void | operator() (typename Const< WhileExp >::type &e) override |
virtual void | operator() (typename Const< ForExp >::type &e) override |
virtual void | operator() (typename Const< BreakExp >::type &) override |
virtual void | operator() (typename Const< LetExp >::type &e) override |
virtual void | operator() (typename Const< ArrayExp >::type &e) override |
virtual void | operator() (typename Const< CastExp >::type &e) override |
virtual void | operator() (typename Const< FieldInit >::type &e) override |
Visit Declaration related nodes. | |
Visiting declarations is simple, but there are many clauses. This is because in Tiger, the declarations are processed by chunks (a chunk of Function declarations, then Var or Type, then ...). So we have to explain
| |
virtual void | operator() (typename Const< DecsList >::type &e) override |
Visit a list of function, type and/or variables declarations. | |
virtual void | operator() (typename Const< Decs >::type &e) |
Visit a Decs chunks. | |
virtual void | operator() (typename Const< VarDecs >::type &e) override |
Visit Var declarations. | |
virtual void | operator() (typename Const< VarDec >::type &e) override |
virtual void | operator() (typename Const< FunctionDec >::type &e) override |
virtual void | operator() (typename Const< TypeDec >::type &e) override |
template<typename DecsType > | |
void | decs_visit (typename Const< DecsType >::type &e) |
Visit a chunk (i.e., a list of Function, Var, and Type decs). | |
Visit Type related nodes. | |
virtual void | operator() (typename Const< NameTy >::type &e) override |
virtual void | operator() (typename Const< RecordTy >::type &e) override |
virtual void | operator() (typename Const< ArrayTy >::type &e) override |
Visit Field related nodes. | |
virtual void | operator() (typename Const< Field >::type &e) override |
Object-related visits. | |
The methods should not be used, since this visitor is for the non-object flavor of the language. | |
virtual void | operator() (typename Const< ClassTy >::type &e) override |
virtual void | operator() (typename Const< MethodDecs >::type &e) override |
virtual void | operator() (typename Const< MethodDec >::type &e) override |
virtual void | operator() (typename Const< MethodCallExp >::type &e) override |
virtual void | operator() (typename Const< ObjectExp >::type &e) override |
Protected Member Functions | |
template<typename E > | |
void | accept (E *e) |
Protected Attributes | |
rExp | exp_ |
The translation of the last visited node. | |
std::stack< std::list< rExp > > | exps_ |
The translations of all the pending declarations. | |
tree::Fragments * | fragments_ |
The fragments translated so far (functions and string literals). | |
Level * | level_ |
The current level (related to FunctionDec nestings). | |
std::map< const ast::Exp *, temp::Label > | loop_end_label_ |
For each loop, the address immediately after it. | |
std::map< const ast::Ast *, const Access * > | var_access_ |
Access for each "variable" (VarDec, Field). | |
std::map< const ast::Ast *, const Level * > | fun_level_ |
Level for each function. | |
std::map< const ast::Ast *, temp::Label > | fun_label_ |
Label for each function. |
Translate an ast::Ast into High level tree::Tree code.
Super class.
translate::Translator::Translator | ( | ) |
translate::Translator::Translator | ( | const Translator & | ) |
|
virtual |
References fun_level_, and level_.
|
protectedinherited |
A convenient shortcut for recurring code like this:
However, the drawback of this approach is that it doesn't take care of the constness, and any const violation will be reported within the body of this method, not at its corresponding call site.
We cannot use the misc/select_const.hh approach here, since the compiler cannot resolve a function overloaded or specialized on an associated type of a template. E.g., writing accept like this:
won't work directly. Of course, one can help the compiler, providing it with E
but this is painful.
|
inlineinherited |
Visit a chunk (i.e., a list of Function, Var, and Type decs).
It is exactly the same in the three cases, so the code is factored via a template method.
tree::Fragments * translate::Translator::fragments_get | ( | ) |
Return the translation. Ownership is transfered to the receiver.
References fragments_.
Referenced by translate::translate().
|
pure virtualinherited |
Implemented in ast::GenNonObjectVisitor< Const >, and ast::GenObjectVisitor< Const >.
|
pure virtualinherited |
Implemented in ast::GenNonObjectVisitor< Const >, and ast::GenObjectVisitor< Const >.
|
pure virtualinherited |
Implemented in ast::GenNonObjectVisitor< Const >, and ast::GenObjectVisitor< Const >.
|
overridevirtual |
Run the translation.
References exp_, and translate().
|
pure virtualinherited |
Implemented in ast::GenNonObjectVisitor< Const >, and ast::GenObjectVisitor< Const >.
|
virtualinherited |
The entry point: visit e.
Reimplemented from ast::GenVisitor< Const >.
Referenced by callgraph::CallGraphVisitor::operator()(), object::Renamer::operator()(), and operator()().
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
References ast::SimpleVar::def_get(), exp_, level_, translate::simple_var(), and var_access_.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
References unreached.
|
overridevirtual |
References exp_, translate::field_var(), and translate().
|
overridevirtual |
|
inherited |
Helper to visit nodes manipulated via a pointer.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
References unreached.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
References unreached.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
References unreached.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
References unreached.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
References exp_, and translate::nil_exp().
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
References exp_, translate::record_exp(), and translate().
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
References translate::call_exp(), exp_, fun_label_, fun_level_, level_, translate::static_link(), and translate().
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
References parse::tasks::l, ast::OpExp::left_get(), ast::OpExp::right_get(), and translate().
|
overridevirtual |
References translate::eseq_exp(), exp_, translate::seq_exp(), and translate().
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
References translate::break_exp(), exp_, and loop_end_label_.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
|
overridevirtualinherited |
Visit a list of function, type and/or variables declarations.
Implements ast::GenVisitor< Const >.
References misc::for_each().
|
overridevirtual |
References ast::AnyDecs< D >::decs_get(), exps_, and translate().
|
overridevirtual |
|
overridevirtual |
|
virtualinherited |
Visit a Decs chunks.
|
overridevirtual |
References unreached.
|
overridevirtual |
|
overridevirtualinherited |
Visit Var declarations.
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
Translator& translate::Translator::operator= | ( | const Translator & | ) |
Run this visitor on node, and return its translation.
It is also guaranteed that exp_ is set to it. More generally, this routine saves from direct calls to accept.
References ast::Ast::accept(), and exp_.
Referenced by operator()(), translate(), and visit_function_dec_body().
std::list< rExp > translate::Translator::translate | ( | const std::list< T * > & | es | ) |
The list of translations of es members.
References translate().
void translate::Translator::visit_function_dec_body | ( | const ast::FunctionDec & | e | ) |
References ast::FunctionDec::body_get(), ast::AnyDecs< D >::decs_get(), exp_, ast::FunctionDec::formals_get(), translate::Level::formals_get(), fragments_, translate::Level::frame_get(), fun_label_, fun_level_, translate::function_dec(), level_, translate::procedure_dec(), ast::FunctionDec::result_get(), translate(), and var_access_.
void translate::Translator::visit_function_dec_header | ( | const ast::FunctionDec & | e | ) |
|
protected |
The translation of the last visited node.
Referenced by operator()(), translate(), and visit_function_dec_body().
|
protected |
The translations of all the pending declarations.
Referenced by operator()().
|
protected |
The fragments translated so far (functions and string literals).
Referenced by fragments_get(), and visit_function_dec_body().
|
protected |
Label for each function.
Referenced by operator()(), visit_function_dec_body(), and visit_function_dec_header().
Level for each function.
Referenced by operator()(), visit_function_dec_body(), visit_function_dec_header(), and ~Translator().
|
protected |
The current level (related to FunctionDec nestings).
Referenced by operator()(), visit_function_dec_body(), visit_function_dec_header(), and ~Translator().
|
protected |
For each loop, the address immediately after it.
Referenced by operator()().
Access for each "variable" (VarDec, Field).
Referenced by operator()(), and visit_function_dec_body().