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 std::unique_ptr<priv> priv_; 42 43 protected: 44 45 traversable_base(); 46 47 bool visiting() const; 48 49 void visiting(bool f); 50 51 public: 52 53 virtual ~traversable_base(); 54 55 /// This virtual method is overloaded and implemented by any single 56 /// type which instance is going to be visited during the traversal 57 /// of translation unit nodes. 58 /// 59 /// The method visits a given node and, for scopes, visits their 60 /// member nodes. Visiting a node means calling the 61 /// ir_node_visitor::visit method with the node passed as an 62 /// argument. 63 /// 64 /// @param v the visitor used during the traverse. 65 /// 66 /// @return true if traversed until the end of the type tree, false 67 /// otherwise. 68 /// 69 /// Note that each class that derives from this one and overloads 70 /// this method will have to define a type for its node visitor 71 /// argument (the one named v). That type will have to derive from 72 /// the node_visitor_base type. In that sense, this new overload 73 /// method will "hide" this one. That is why we are keeping this 74 /// method commented, for documentation purposes. 75 76 // virtual bool traverse(node_visitor_base& v); 77 }; // end class traversable_base 78 79 }// end namespace ir. 80 }//end namespace abigail 81 #endif //__ABG_TRAVERSE_H__ 82