LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
callgraph::CallGraphVisitor Class Reference

Computes the CallGraph. More...

#include <call-graph-visitor.hh>

Inheritance diagram for callgraph::CallGraphVisitor:
Collaboration diagram for callgraph::CallGraphVisitor:

Public Types

typedef ast::DefaultConstVisitor super_type

Public Member Functions

virtual ~CallGraphVisitor ()
const CallGraphcreate (const ast::Ast &tree)
CallGraphcreate (ast::Ast &tree)

Protected Member Functions

virtual void operator() (const ast::CallExp &e) override
virtual void operator() (const ast::FunctionDecs &e) override
virtual void operator() (const ast::FunctionDec &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.
template<typename E >
void accept (E *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

  • How to visit a list of chunks;
  • how to visit chunks of function, var, or type declarations;
  • how to visit a single function, var, or type declaration.
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 Attributes

ast::FunctionDeccaller = nullptr
 Current function.
CallGraphcallgraph = nullptr
 Call graph.

Detailed Description

Computes the CallGraph.

Member Typedef Documentation

Constructor & Destructor Documentation

callgraph::CallGraphVisitor::~CallGraphVisitor ( )
virtual

Member Function Documentation

template<template< typename > class Const>
template<typename E >
void ast::GenVisitor< Const >::accept ( E *  e)
protectedinherited

A convenient shortcut for recurring code like this:

if (e)
e->accept(*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:

template <typename E>
void accept(typename Const<E>::type* e);

won't work directly. Of course, one can help the compiler, providing it with E

accept<ast::NameTy>(e.result_get());

but this is painful.

const CallGraph * callgraph::CallGraphVisitor::create ( const ast::Ast tree)
CallGraph * callgraph::CallGraphVisitor::create ( ast::Ast tree)

References create().

template<template< typename > class Const>
template<typename DecsType >
void ast::GenDefaultVisitor< Const >::decs_visit ( typename Const< DecsType >::type &  e)
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.

void callgraph::CallGraphVisitor::operator() ( const ast::CallExp &  e)
overrideprotectedvirtual
void callgraph::CallGraphVisitor::operator() ( const ast::FunctionDecs e)
overrideprotectedvirtual
void callgraph::CallGraphVisitor::operator() ( const ast::FunctionDec e)
overrideprotectedvirtual
template<template< typename > class Const>
virtual void ast::GenVisitor< Const >::operator() ( typename Const< ClassTy >::type &  )
pure virtualinherited
template<template< typename > class Const>
virtual void ast::GenVisitor< Const >::operator() ( typename Const< MethodCallExp >::type &  )
pure virtualinherited
template<template< typename > class Const>
virtual void ast::GenVisitor< Const >::operator() ( typename Const< MethodDec >::type &  )
pure virtualinherited
template<template< typename > class Const>
virtual void ast::GenVisitor< Const >::operator() ( typename Const< ObjectExp >::type &  )
pure virtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< Ast >::type &  e)
virtualinherited

The entry point: visit e.

Reimplemented from ast::GenVisitor< Const >.

Referenced by operator()(), object::Renamer::operator()(), and translate::Translator::operator()().

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< SimpleVar >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< FieldVar >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< SubscriptVar >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< CastVar >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenNonObjectVisitor< Const >::operator() ( typename Const< ClassTy >::type &  e)
overridevirtualinherited

Implements ast::GenVisitor< Const >.

References unreached.

template<template< typename > class Const>
template<class E >
void ast::GenVisitor< Const >::operator() ( E *  e)
inherited

Helper to visit nodes manipulated via a pointer.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< NilExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenNonObjectVisitor< Const >::operator() ( typename Const< MethodDecs >::type &  e)
overridevirtualinherited

Implements ast::GenVisitor< Const >.

References unreached.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< IntExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenNonObjectVisitor< Const >::operator() ( typename Const< MethodDec >::type &  e)
overridevirtualinherited

Implements ast::GenVisitor< Const >.

References unreached.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< StringExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< CallExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenNonObjectVisitor< Const >::operator() ( typename Const< MethodCallExp >::type &  e)
overridevirtualinherited

Implements ast::GenVisitor< Const >.

References unreached.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< OpExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< RecordExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenNonObjectVisitor< Const >::operator() ( typename Const< ObjectExp >::type &  e)
overridevirtualinherited

Implements ast::GenVisitor< Const >.

References unreached.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< SeqExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< AssignExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< IfExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< WhileExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< ForExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< BreakExp >::type &  )
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< LetExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< ArrayExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< CastExp >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< FieldInit >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< DecsList >::type &  e)
overridevirtualinherited

Visit a list of function, type and/or variables declarations.

Implements ast::GenVisitor< Const >.

References misc::for_each().

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< Decs >::type &  e)
virtualinherited

Visit a Decs chunks.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< VarDecs >::type &  e)
overridevirtualinherited

Visit Var declarations.

Implements ast::GenVisitor< Const >.

template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< VarDec >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< FunctionDec >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< TypeDec >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< NameTy >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< RecordTy >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< ArrayTy >::type &  e)
overridevirtualinherited
template<template< typename > class Const>
void ast::GenDefaultVisitor< Const >::operator() ( typename Const< Field >::type &  e)
overridevirtualinherited

Member Data Documentation

ast::FunctionDec* callgraph::CallGraphVisitor::caller = nullptr
protected

Current function.

Referenced by operator()().

CallGraph* callgraph::CallGraphVisitor::callgraph = nullptr
protected

Call graph.

Referenced by create(), and operator()().


The documentation for this class was generated from the following files: