LRDE Tiger Compiler
1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
|
Perform identifier renaming within an AST (in place), with support for objects. More...
#include <renamer.hh>
Public Types | |
typedef ::bind::Renamer | super_type |
Public Member Functions | |
Renamer () | |
Build a Renamer. | |
template<class E , class Def > | |
void | visit (E &e, const Def *def) |
Process a declaration body or a usage site. | |
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. | |
Visiting definition sites. | |
This method is like bind::Binder's, but prevent the renaming of attributes. | |
virtual void | operator() (ast::VarDec &e) override |
virtual void | operator() (ast::MethodDecs &e) override |
Rename methods. | |
virtual void | operator() (ast::MethodDec &e) override |
Rename a method. | |
virtual void | operator() (ast::TypeDecs &e) override |
Visiting usage sites. | |
virtual void | operator() (ast::MethodCallExp &e) override |
Visiting other object-related nodes. | |
These methods should be part of an ObjectDefaultVisitor, but our current design makes the implementation (and the use) of such a visitor difficult. | |
virtual void | operator() (ast::ClassTy &e) override |
virtual void | operator() (ast::ObjectExp &e) override |
Visiting other non-object related nodes. | |
These method are just wrappers around their homonyms from bind::Renamer, handling within_class_ty_. | |
virtual void | operator() (ast::ForExp &e) override |
virtual void | operator() (ast::FunctionDec &e) override |
Auxiliary routines. | |
Compute the name for this kind of declaration. Take into account the fact that _main and primitive are not to be renamed. | |
template<typename Def > | |
misc::symbol | new_name_compute (const Def &e) |
template<typename Def > | |
misc::symbol | new_name (const Def &e) |
Get the new name of this declaration, possibly create it. | |
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) |
class_names_type * | class_names_ |
Dictionnary mapping class types to their names. | |
bool | within_class_ty_ |
Are we in a class definition? | |
class_names_type * | class_names_get () const |
Get the class names. |
Perform identifier renaming within an AST (in place), with support for objects.
typedef ::bind::Renamer object::Renamer::super_type |
object::Renamer::Renamer | ( | ) |
Build a Renamer.
Reimplemented from bind::Renamer.
References class_names_, type::Class::object_instance(), and misc::put().
|
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.
class_names_type * object::Renamer::class_names_get | ( | ) | const |
|
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.
|
inherited |
Get the new name of this declaration, possibly create it.
The tricky thing is that when visiting a chunk of definitions, we might visit a body using a name not yet renamed (e.g., mutually recursive functions), in which case we must compute the new name of that function on the fly.
Referenced by operator()().
|
inherited |
|
overridevirtual |
References ast::GenDefaultVisitor< Const >::operator()(), and within_class_ty_.
|
overridevirtual |
Rename methods.
|
pure virtualinherited |
Implemented in ast::GenNonObjectVisitor< Const >, and ast::GenObjectVisitor< Const >.
|
overridevirtual |
Rename a method.
References bind::Renamer::visit(), and within_class_ty_.
|
overridevirtual |
In addition to performing the renaming, collect the name of the classes.
|
overridevirtual |
References misc::for_each(), and bind::Renamer::new_name().
|
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 |
|
overridevirtual |
|
virtualinherited |
The entry point: visit e.
Reimplemented from ast::GenVisitor< Const >.
Referenced by callgraph::CallGraphVisitor::operator()(), operator()(), and translate::Translator::operator()().
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtual |
|
overridevirtual |
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
References unreached.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
inherited |
Helper to visit nodes manipulated via a pointer.
|
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 >.
|
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 >.
|
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 >.
|
overridevirtualinherited |
Visit a list of function, type and/or variables declarations.
Implements ast::GenVisitor< Const >.
References misc::for_each().
|
virtualinherited |
Visit a Decs chunks.
|
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 >.
|
inherited |
Process a declaration body or a usage site.
def is the definition site of (must be equal to e if it is a Dec node).
Referenced by operator()().
|
private |
Dictionnary mapping class types to their names.
Referenced by class_names_get(), and Renamer().
|
private |
Are we in a class definition?
Referenced by operator()().