Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmLinkItemGraphVisitor.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#include <map>
6
#include <set>
7
#include <string>
8
#include <utility>
9
10
#include "cmLinkItem.h"
11
12
class cmGeneratorTarget;
13
14
/** \class cmLinkItemGraphVisitor
15
 * \brief Visits a graph of linked items.
16
 *
17
 * Allows to visit items and dependency links (direct and indirect) between
18
 * those items.
19
 * This abstract class takes care of the graph traversal, making sure that:
20
 *   - it terminates even in the presence of cycles;
21
 *   - it visits every object once (and only once);
22
 *   - it visits the objects in the same order every time.
23
 *
24
 * Children classes only have to implement OnItem() etc. to handle whatever
25
 * logic they care about.
26
 */
27
class cmLinkItemGraphVisitor
28
{
29
public:
30
0
  virtual ~cmLinkItemGraphVisitor() = default;
31
32
  virtual void VisitGraph(std::string const& name) = 0;
33
34
  void VisitItem(cmLinkItem const& item);
35
36
protected:
37
  enum class DependencyType
38
  {
39
    LinkInterface,
40
    LinkPublic,
41
    LinkPrivate,
42
    Object,
43
    Utility
44
  };
45
46
  virtual void OnItem(cmLinkItem const& item) = 0;
47
48
  virtual void OnDirectLink(cmLinkItem const& depender,
49
                            cmLinkItem const& dependee, DependencyType dt) = 0;
50
51
  virtual void OnIndirectLink(cmLinkItem const& depender,
52
                              cmLinkItem const& dependee) = 0;
53
54
private:
55
  std::set<std::string> VisitedItems;
56
57
  std::set<std::pair<std::string, std::string>> VisitedLinks;
58
59
  void VisitLinks(cmLinkItem const& item, cmLinkItem const& rootItem);
60
  void VisitLinks(cmLinkItem const& item, cmLinkItem const& rootItem,
61
                  std::string const& config);
62
63
  using Dependency = std::pair<DependencyType, cmLinkItem>;
64
  using DependencyMap = std::map<std::string, Dependency>;
65
66
  bool ItemVisited(cmLinkItem const& item);
67
  bool LinkVisited(cmLinkItem const& depender, cmLinkItem const& dependee);
68
69
  static void GetDependencies(cmGeneratorTarget const& target,
70
                              std::string const& config,
71
                              DependencyMap& dependencies);
72
};