clang 24.0.0git
BuildNamespace.h
Go to the documentation of this file.
1//===- BuildNamespace.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines BuildNamespace and NestedBuildNamespace classes that
10// represent build namespaces in the Scalable Static Analysis Framework.
11//
12// Build namespaces provide an abstraction for grouping program entities (such
13// as those in a shared library or compilation unit) to enable analysis of
14// software projects constructed from individual components.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_MODEL_BUILDNAMESPACE_H
19#define LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_MODEL_BUILDNAMESPACE_H
20
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/raw_ostream.h"
24#include <optional>
25#include <string>
26#include <vector>
27
28namespace clang::ssaf {
29
36
37/// Represents a single namespace in the build process.
38///
39/// A BuildNamespace groups program entities, such as those belonging to a
40/// compilation unit or link unit (e.g., a shared library). Each namespace has a
41/// kind (CompilationUnit or LinkUnit) and a unique identifier name within that
42/// kind.
43///
44/// BuildNamespaces can be composed into NestedBuildNamespace to represent
45/// hierarchical namespace structures that model how software is constructed
46/// from its components.
49 std::string Name;
50
51 auto asTuple() const { return std::tie(Kind, Name); }
52
53public:
54 BuildNamespace(BuildNamespaceKind Kind, llvm::StringRef Name)
55 : Kind(Kind), Name(Name.str()) {}
56
57 /// Creates a BuildNamespace representing a compilation unit.
58 ///
59 /// \param CompilationId The unique identifier for the compilation unit.
60 /// \returns A BuildNamespace with CompilationUnit kind.
61 static BuildNamespace makeCompilationUnit(llvm::StringRef CompilationId);
62
63 bool operator==(const BuildNamespace &Other) const;
64 bool operator!=(const BuildNamespace &Other) const;
65 bool operator<(const BuildNamespace &Other) const;
66
67 friend class EntityLinker;
68 friend class SerializationFormat;
69 friend class TestFixture;
70 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
71 const BuildNamespace &BN);
72};
73
74/// Represents a hierarchical sequence of build namespaces.
75///
76/// A NestedBuildNamespace captures namespace qualification for program entities
77/// by maintaining an ordered sequence of BuildNamespace steps. This models how
78/// entities are organized through multiple steps of the build process, such as
79/// first being part of a compilation unit, then incorporated into a link unit.
80///
81/// For example, an entity might be qualified by a compilation unit namespace
82/// followed by a shared library namespace.
84 std::vector<BuildNamespace> Namespaces;
85
86public:
88
89 explicit NestedBuildNamespace(const std::vector<BuildNamespace> &Namespaces)
90 : Namespaces(Namespaces) {}
91
93 Namespaces.push_back(N);
94 }
95
96 /// Creates a NestedBuildNamespace representing a compilation unit.
97 ///
98 /// \param CompilationId The unique identifier for the compilation unit.
99 /// \returns A NestedBuildNamespace containing a single CompilationUnit
100 /// BuildNamespace.
102 makeCompilationUnit(llvm::StringRef CompilationId);
103
104 /// Creates a new NestedBuildNamespace by appending additional namespace.
105 ///
106 /// \param Namespace The namespace to append.
108 auto Copy = *this;
109 Copy.Namespaces.reserve(Copy.Namespaces.size() +
110 Namespace.Namespaces.size());
111 llvm::append_range(Copy.Namespaces, Namespace.Namespaces);
112 return Copy;
113 }
114
115 bool empty() const;
116
117 bool operator==(const NestedBuildNamespace &Other) const;
118 bool operator!=(const NestedBuildNamespace &Other) const;
119 bool operator<(const NestedBuildNamespace &Other) const;
120
122 friend class TestFixture;
123 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
124 const NestedBuildNamespace &NBN);
125};
126
127llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, BuildNamespaceKind BNK);
128llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const BuildNamespace &BN);
129llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
130 const NestedBuildNamespace &NBN);
131
132} // namespace clang::ssaf
133
134#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_MODEL_BUILDNAMESPACE_H
Represents a single namespace in the build process.
BuildNamespace(BuildNamespaceKind Kind, llvm::StringRef Name)
bool operator<(const BuildNamespace &Other) const
bool operator!=(const BuildNamespace &Other) const
static BuildNamespace makeCompilationUnit(llvm::StringRef CompilationId)
Creates a BuildNamespace representing a compilation unit.
bool operator==(const BuildNamespace &Other) const
friend llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const BuildNamespace &BN)
Represents a multi-architecture static library.
Represents a hierarchical sequence of build namespaces.
NestedBuildNamespace(const std::vector< BuildNamespace > &Namespaces)
static NestedBuildNamespace makeCompilationUnit(llvm::StringRef CompilationId)
Creates a NestedBuildNamespace representing a compilation unit.
NestedBuildNamespace(const BuildNamespace &N)
bool operator<(const NestedBuildNamespace &Other) const
NestedBuildNamespace makeQualified(NestedBuildNamespace Namespace) const
Creates a new NestedBuildNamespace by appending additional namespace.
bool operator!=(const NestedBuildNamespace &Other) const
friend llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const NestedBuildNamespace &NBN)
bool operator==(const NestedBuildNamespace &Other) const
Represents a static library of translation unit summary encodings.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, BuildNamespaceKind BNK)
@ Other
Other implicit parameter.
Definition Decl.h:1774