LRDE Tiger Compiler
1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
|
Computing bindings with support for overloaded functions. More...
#include <binder.hh>
Public Types | |
typedef bind::Binder | super_type |
Super class type. |
Public Member Functions | |
virtual void | operator() (ast::CallExp &e) override |
Visit a function call. | |
void | visit_dec_header (ast::FunctionDec &e) |
Check a function declaration header. | |
virtual void | operator() (ast::FunctionDecs &e) override |
Visit a chunk of function declarations. | |
overfun_bindings_type * | overfun_bindings_get () |
Return the function bindings. | |
const misc::error & | error_get () const |
The error handler. | |
virtual void | operator() (ast::LetExp &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. | |
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. | |
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 |
Type and Function declarations | |
template<class D > | |
void | decs_visit (ast::AnyDecs< D > &e) |
template<class D > | |
void | visit_dec_header (D &e) |
Check a Function or Type declaration header. | |
template<class D > | |
void | visit_dec_body (D &e) |
Check a Function or Type declaration body. |
Protected Member Functions | |
template<typename NodeType , typename DefType > | |
void | def_default (NodeType &e, DefType *def) |
template<typename E > | |
void | accept (E *e) |
Overriden scope manipulations. | |
virtual void | scope_begin () override |
Open a new var, fun, and type scope. | |
virtual void | scope_end () override |
Close the latest var, fun, and type scope. | |
Error handling | |
void | error (const ast::Ast &loc, const std::string &msg) |
Report an error. | |
template<typename T > | |
void | undeclared (const std::string &k, const T &e) |
template<typename T > | |
void | redefinition (const T &e1, const T &e2) |
Private Types | |
typedef OverTable < ast::FunctionDec > | overtable_type |
Private Attributes | |
overtable_type | overfuns_ |
The environment of (overloaded) functions. | |
overfun_bindings_type * | overfun_bindings_ = new overfun_bindings_type() |
The potential function bindings. |
Computing bindings with support for overloaded functions.
This visitor inherits from Binder, but redefines methods dealing with function declarations and uses, to allow overloading.
As overloading requires some knowledge of the type of the arguments of a function, no real function binding is done here. We store all potential function declarations (``homonyms'') for each function call, and we'll let the overload::TypeChecker decide later.
|
private |
Super class type.
|
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.
|
inherited |
When traversing a function (or a type) we both have to bind its body (i.e., we need to enter a new scope and push the arguments in it), and we have to store the function's declaration in the current scope (so that other functions can call it). We first introduce the function's name in the outer environment so that the function can call itself recursively. In the mean time, we also check for uniqueness. Then, as a second step, we process the contents of all the functions belonging to the current chunk. Therefore there are three methods:
decs_visit
() performs the double traversal, composed of the two following functionsvisit_dec_header
() visit the declaration to register the function in the current environment,visit_dec_body
() visits the body. Of course for functions it also inserts the current arguments in the variable table.It turns out that decs_visit
can be written for both functions and types, but of course, traversals of headers and bodies differ. Check a set of definitions: unique names, browse headers, then bodies.
|
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.
|
protectedinherited |
Set the definition site of a node, if it isn't already set (an existing site won't be overwritten).
e | the bound node |
def | the definition |
|
protectedinherited |
Report an error.
|
inherited |
The error handler.
Referenced by overload::bind().
|
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 >.
|
pure virtualinherited |
Implemented in ast::GenNonObjectVisitor< Const >, and ast::GenObjectVisitor< Const >.
|
overridevirtual |
Visit a function call.
References overload::OverTable< T >::get(), overfuns_, and bind::Binder::undeclared().
|
virtualinherited |
The entry point: visit e.
Reimplemented from ast::GenVisitor< Const >.
Referenced by callgraph::CallGraphVisitor::operator()(), object::Renamer::operator()(), and translate::Translator::operator()().
|
overridevirtual |
Visit a chunk of function declarations.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Referenced by object::Binder::operator()().
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
overridevirtualinherited |
Implements ast::GenVisitor< Const >.
|
inherited |
Helper to visit nodes manipulated via a pointer.
|
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 |
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 >.
overfun_bindings_type * overload::Binder::overfun_bindings_get | ( | ) |
|
protectedinherited |
Report a symbol redefinition.
e1 | the first occurrence, the original |
e2 | the invalid duplicate |
|
overrideprotectedvirtual |
Open a new var, fun, and type scope.
Reimplemented from bind::Binder.
References overfuns_, overload::OverTable< T >::scope_begin(), and bind::Binder::scope_begin().
|
overrideprotectedvirtual |
Close the latest var, fun, and type scope.
Reimplemented from bind::Binder.
References overfuns_, overload::OverTable< T >::scope_end(), and bind::Binder::scope_end().
|
protectedinherited |
Report an undefined symbol.
k | the kind of this node (function, variable, type) |
e | the node using an undefined name |
Referenced by operator()().
|
inherited |
Check a Function or Type declaration body.
Reimplemented in object::Binder.
void overload::Binder::visit_dec_header | ( | ast::FunctionDec & | e | ) |
Check a function declaration header.
References ast::Dec::name_get(), overfuns_, and overload::OverTable< T >::put().
|
inherited |
Check a Function or Type declaration header.
Reimplemented in object::Binder.
|
private |
The potential function bindings.
Referenced by overfun_bindings_get().
|
private |
The environment of (overloaded) functions.
Referenced by operator()(), scope_begin(), scope_end(), and visit_dec_header().