Coverage Report

Created: 2026-03-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmSourceFileLocation.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 "cmConfigure.h" // IWYU pragma: keep
6
7
#include <string>
8
9
#include "cmSourceFileLocationKind.h"
10
11
class cmMakefile;
12
13
/** \class cmSourceFileLocation
14
 * \brief cmSourceFileLocation tracks knowledge about a source file location
15
 *
16
 * Source files can be referenced by a variety of names.  The
17
 * directory and/or extension may be omitted leading to a certain
18
 * level of ambiguity about the source file location.  This class is
19
 * used by cmSourceFile to keep track of what is known about the
20
 * source file location.  Each reference may add some information
21
 * about the directory or extension of the file.
22
 */
23
class cmSourceFileLocation
24
{
25
public:
26
  /**
27
   * Construct for a source file created in a given cmMakefile
28
   * instance with an initial name.
29
   */
30
  cmSourceFileLocation(
31
    cmMakefile const* mf, std::string const& name,
32
    cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
33
  cmSourceFileLocation();
34
  cmSourceFileLocation(cmSourceFileLocation const& loc);
35
36
  cmSourceFileLocation& operator=(cmSourceFileLocation const&) = delete;
37
38
  /**
39
   * Return whether the given source file location could refers to the
40
   * same source file as this location given the level of ambiguity in
41
   * each location.
42
   */
43
  bool Matches(cmSourceFileLocation const& loc);
44
45
  /**
46
   * Explicitly state that the source file is located in the source tree.
47
   */
48
  void DirectoryUseSource();
49
50
  /**
51
   * Explicitly state that the source file is located in the build tree.
52
   */
53
  void DirectoryUseBinary();
54
55
  /**
56
   * Return whether the directory containing the source is ambiguous.
57
   */
58
0
  bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
59
60
  /**
61
   * Return whether the extension of the source name is ambiguous.
62
   */
63
0
  bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
64
65
  /**
66
   * Get the directory containing the file as best is currently known.
67
   * If DirectoryIsAmbiguous() returns false this will be a full path.
68
   * Otherwise it will be a relative path (possibly empty) that is
69
   * either with respect to the source or build tree.
70
   */
71
0
  std::string const& GetDirectory() const { return this->Directory; }
72
73
  /**
74
   * Get the file name as best is currently known.  If
75
   * ExtensionIsAmbiguous() returns true this name may not be the
76
   * final name (but could be).  Otherwise the returned name is the
77
   * final name.
78
   */
79
0
  std::string const& GetName() const { return this->Name; }
80
81
  /**
82
   * Get the full file path composed of GetDirectory() and GetName().
83
   */
84
  std::string GetFullPath() const;
85
86
  /**
87
   * Get the cmMakefile instance for which the source file was created.
88
   */
89
0
  cmMakefile const* GetMakefile() const { return this->Makefile; }
90
91
private:
92
  cmMakefile const* const Makefile = nullptr;
93
  bool AmbiguousDirectory = true;
94
  bool AmbiguousExtension = true;
95
  std::string Directory;
96
  std::string Name;
97
98
  bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
99
100
  // Update the location with additional knowledge.
101
  void Update(cmSourceFileLocation const& loc);
102
  void UpdateExtension(std::string const& name);
103
};