1//===- InstallAPI/Context.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#ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
10#define LLVM_CLANG_INSTALLAPI_CONTEXT_H
11
12#include "clang/Basic/Diagnostic.h"
13#include "clang/Basic/FileManager.h"
14#include "clang/InstallAPI/DylibVerifier.h"
15#include "clang/InstallAPI/HeaderFile.h"
16#include "clang/InstallAPI/MachO.h"
17#include "llvm/ADT/DenseMap.h"
18
19namespace clang {
20namespace installapi {
21class FrontendRecordsSlice;
22
23/// Struct used for generating validating InstallAPI.
24/// The attributes captured represent all necessary information
25/// to generate TextAPI output.
26struct InstallAPIContext {
27
28 /// Library attributes that are typically passed as linker inputs.
29 BinaryAttrs BA;
30
31 /// Install names of reexported libraries of a library.
32 LibAttrs Reexports;
33
34 /// All headers that represent a library.
35 HeaderSeq InputHeaders;
36
37 /// Active language mode to parse in.
38 Language LangMode = Language::ObjC;
39
40 /// Active header access type.
41 HeaderType Type = HeaderType::Unknown;
42
43 /// Active TargetSlice for symbol record collection.
44 std::shared_ptr<FrontendRecordsSlice> Slice;
45
46 /// FileManager for all I/O operations.
47 FileManager *FM = nullptr;
48
49 /// DiagnosticsEngine for all error reporting.
50 DiagnosticsEngine *Diags = nullptr;
51
52 /// Verifier when binary dylib is passed as input.
53 std::unique_ptr<DylibVerifier> Verifier = nullptr;
54
55 /// File Path of output location.
56 llvm::StringRef OutputLoc{};
57
58 /// What encoding to write output as.
59 FileType FT = FileType::TBD_V5;
60
61 /// Populate entries of headers that should be included for TextAPI
62 /// generation.
63 void addKnownHeader(const HeaderFile &H);
64
65 /// Record visited files during frontend actions to determine whether to
66 /// include their declarations for TextAPI generation.
67 ///
68 /// \param FE Header that is being parsed.
69 /// \param PP Preprocesser used for querying how header was imported.
70 /// \return Access level of header if it should be included for TextAPI
71 /// generation.
72 std::optional<HeaderType> findAndRecordFile(const FileEntry *FE,
73 const Preprocessor &PP);
74
75private:
76 using HeaderMap = llvm::DenseMap<const FileEntry *, HeaderType>;
77
78 // Collection of parsed header files and their access level. If set to
79 // HeaderType::Unknown, they are not used for TextAPI generation.
80 HeaderMap KnownFiles;
81
82 // Collection of expected header includes and the access level for them.
83 llvm::DenseMap<StringRef, HeaderType> KnownIncludes;
84};
85
86/// Lookup the dylib or TextAPI file location for a system library or framework.
87/// The search paths provided are searched in order.
88/// @rpath based libraries are not supported.
89///
90/// \param InstallName The install name for the library.
91/// \param FrameworkSearchPaths Search paths to look up frameworks with.
92/// \param LibrarySearchPaths Search paths to look up dylibs with.
93/// \param SearchPaths Fallback search paths if library was not found in earlier
94/// paths.
95/// \return The full path of the library.
96std::string findLibrary(StringRef InstallName, FileManager &FM,
97 ArrayRef<std::string> FrameworkSearchPaths,
98 ArrayRef<std::string> LibrarySearchPaths,
99 ArrayRef<std::string> SearchPaths);
100} // namespace installapi
101} // namespace clang
102
103#endif // LLVM_CLANG_INSTALLAPI_CONTEXT_H
104

source code of clang/include/clang/InstallAPI/Context.h