CodeSonar C++ API
[For improved navigation, enable JavaScript.]
Public Types | Public Member Functions | List of all members
cs::visitor< T > Class Template Referenceabstract

Abstract base class for visitors: functors that carry out actions on elements of the internal representation (IR) at various stages of the analysis. More...

Public Types

typedef T visitee
 The type of IR element to which the visitor is applied. More...
 

Public Member Functions

 visitor ()
 Constructor.
 
 visitor (const visitor &)
 Copy constructor.
 
virtual void operator() (T)=0
 For each IR element of type T that is visited, CodeSonar will invoke this function on the element. More...
 

Detailed Description

template<typename T> class cs::visitor< T >

Abstract base class for visitors: functors that carry out actions on elements of the internal representation (IR) at various stages of the analysis.

Template Parameters
TThe IR element type of interest. Must be one of the following:

The C++ API Getting Started page includes a visitor<point> usage example.

The CodeSonar Plug-In API Tutorial and AST Tutorial provide annotated example plug-ins involving various visitor types, along with installation and testing instructions.

To define a visitor class for IR elements of type T, subclass visitor<T> and define operator() to perform the actions you want the visitor to undertake for each element of type T in the internal representation.

Once you have defined your visitor class, create an instance and add it to the analysis with a suitable analysis::add_*_visitor() invocation. The analysis::add_*_visitor() method you use will depend on the visitor type and the phase in which you want to apply the visitor as shown in the following table.

visitor<project>

visitor<compunit>

visitor<sfileinst>

visitor<procedure>

visitor<point>

visitor<symbol>

(Note that step visitors are defined by step_state objects rather than visitor<T> ones.)

Once you have passed a visitor object to one of these add_*_visitor() methods, do not subsequently delete it. CodeSonar may continue to use it indefinitely.

Unlike visitors of other types, program visitors are not applied during the analysis traversals but at various points before and after traversals. For details, see Visitors: Program Visitors.

Member Typedef Documentation

◆ visitee

template<typename T >
typedef T cs::visitor< T >::visitee

The type of IR element to which the visitor is applied.

Member Function Documentation

◆ operator()()

template<typename T >
virtual void cs::visitor< T >::operator() ( )
pure virtual

For each IR element of type T that is visited, CodeSonar will invoke this function on the element.

When you subclass visitor<T> to create a visitor class, provide a definition for this. (If you don't, the visitor won't do anything!)

The analysis phase in which the visit occurs depends on the method used to add the visitor: see the table of methods above.


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