1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright (C) 2013-2020 Red Hat, Inc.
5 
6 /// @file
7 
8 #ifndef __ABG_TRAVERSE_H__
9 #define __ABG_TRAVERSE_H__
10 
11 #include "abg-fwd.h"
12 
13 namespace abigail
14 {
15 
16 namespace ir
17 {
18 
19 /// The base class for the visitor type hierarchy used for traversing
20 /// a hierarchy of nodes.
21 ///
22 /// Client code willing to get notified for a certain kind of node
23 /// during traversal might want to define a visitor class that inherit
24 /// \a node_visitor, define and overload a node_visitor::visit method
25 /// for it, like what is done for the ir_node_visitor::visit set of
26 /// functions, for traversing internal representation nodes.
27 struct node_visitor_base
28 {};
29 
30 /// The interface for types which are feeling social and want to be
31 /// visited during the traversal of a hierarchy of nodes.
32 ///
33 /// It is expected that classes derived from traversable_base define a
34 /// traverse method specialised to the node *visitor* type. Such
35 /// methods should visit nodes recursively, calling
36 /// ir_node_visitor::visit for each node. The method should return
37 /// true until all nodes have been visited.
38 class traversable_base
39 {
40   struct priv;
41   typedef shared_ptr<priv> priv_sptr;
42 
43   priv_sptr priv_;
44 
45 protected:
46 
47   traversable_base();
48 
49   bool visiting() const;
50 
51   void visiting(bool f);
52 
53 public:
54 
55    virtual ~traversable_base();
56 
57   /// This virtual method is overloaded and implemented by any single
58   /// type which instance is going to be visited during the traversal
59   /// of translation unit nodes.
60   ///
61   /// The method visits a given node and, for scopes, visits their
62   /// member nodes.  Visiting a node means calling the
63   /// ir_node_visitor::visit method with the node passed as an
64   /// argument.
65   ///
66   /// @param v the visitor used during the traverse.
67   ///
68   /// @return true if traversed until the end of the type tree, false
69   /// otherwise.
70   ///
71   /// Note that each class that derives from this one and overloads
72   /// this method will have to define a type for its node visitor
73   /// argument (the one named v).  That type will have to derive from
74   /// the node_visitor_base type.  In that sense, this new overload
75   /// method will "hide" this one.  That is why we are keeping this
76   /// method commented, for documentation purposes.
77 
78   // virtual bool traverse(node_visitor_base& v);
79 }; // end class traversable_base
80 
81 }// end namespace ir.
82 }//end namespace abigail
83 #endif //__ABG_TRAVERSE_H__
84