;
30using namespaceapi_notes;
32#define DEBUG_TYPE "API Notes" 33STATISTIC(NumHeaderAPINotes,
"non-framework API notes files loaded");
34STATISTIC(NumPublicFrameworkAPINotes,
"framework public API notes loaded");
35STATISTIC(NumPrivateFrameworkAPINotes,
"framework private API notes loaded");
36STATISTIC(NumFrameworksSearched,
"frameworks searched");
37STATISTIC(NumDirectoriesSearched,
"header directories searched");
38STATISTIC(NumDirectoryCacheHits,
"directory cache hits");
43classPrettyStackTraceDoubleString :
publicllvm::PrettyStackTraceEntry {
44StringRef
First, Second;
47PrettyStackTraceDoubleString(StringRef First, StringRef Second)
49 void print(raw_ostream &OS)
const override{ OS <<
First<< Second; }
54:
SM(
SM), ImplicitAPINotes(LangOpts.APINotes) {}
58 for(
const auto&Entry : Readers) {
59 if(
autoReader = dyn_cast_if_present<APINotesReader *>(Entry.second))
63 deleteCurrentModuleReaders[ReaderKind::Public];
64 deleteCurrentModuleReaders[ReaderKind::Private];
67std::unique_ptr<APINotesReader>
68APINotesManager::loadAPINotes(
FileEntryRefAPINotesFile) {
69PrettyStackTraceDoubleString Trace(
"Loading API notes from ",
84std::unique_ptr<llvm::MemoryBuffer> CompiledBuffer;
88diag::warn_apinotes_message, diag::note_apinotes_message, APINotesFile);
89llvm::raw_svector_ostream OS(APINotesBuffer);
92SMAdapter.getDiagHandler(), SMAdapter.getDiagContext()))
96CompiledBuffer = llvm::MemoryBuffer::getMemBufferCopy(
97StringRef(APINotesBuffer.data(), APINotesBuffer.size()));
102assert(Reader &&
"Could not load the API notes we just generated?");
106std::unique_ptr<APINotesReader>
107APINotesManager::loadAPINotes(StringRef Buffer) {
109std::unique_ptr<llvm::MemoryBuffer> CompiledBuffer;
112diag::warn_apinotes_message, diag::note_apinotes_message, std::nullopt);
113llvm::raw_svector_ostream OS(APINotesBuffer);
116SMAdapter.getDiagHandler(),
117SMAdapter.getDiagContext()))
120CompiledBuffer = llvm::MemoryBuffer::getMemBufferCopy(
121StringRef(APINotesBuffer.data(), APINotesBuffer.size()));
123assert(Reader &&
"Could not load the API notes we just generated?");
127boolAPINotesManager::loadAPINotes(
const DirectoryEntry*HeaderDir,
129assert(!Readers.contains(HeaderDir));
130 if(
autoReader = loadAPINotes(APINotesFile)) {
131Readers[HeaderDir] = Reader.release();
135Readers[HeaderDir] =
nullptr;
141StringRef Basename,
boolWantPublic) {
146StringRef Suffix = WantPublic ?
"":
"_private";
149llvm::sys::path::append(
Path, llvm::Twine(Basename) + Suffix +
"."+
155llvm::StringRef FrameworkPath, llvm::StringRef FrameworkName,
boolPublic) {
159 unsignedFrameworkNameLength =
Path.size();
161StringRef Suffix =
Public?
"":
"_private";
164llvm::sys::path::append(
Path,
"APINotes");
165llvm::sys::path::append(
Path, (llvm::Twine(FrameworkName) + Suffix +
"."+
174 Path.resize(FrameworkNameLength);
175llvm::sys::path::append(
Path, Public ?
"Headers":
"PrivateHeaders");
183 if(loadAPINotes(*HeaderDir, *APINotesFile))
188++NumPublicFrameworkAPINotes;
190++NumPrivateFrameworkAPINotes;
196 if(
File->tryGetRealPathName().empty())
199StringRef RealFileName =
200llvm::sys::path::filename(
File->tryGetRealPathName());
201StringRef RealStem = llvm::sys::path::stem(RealFileName);
202 if(RealStem.ends_with(
"_private"))
205 unsignedDiagID = diag::warn_apinotes_private_case;
207DiagID = diag::warn_apinotes_private_case_system;
216return Submodule->ModuleMapIsPrivate;
232 if(
auto File= findAPINotesFile(Dir, ModuleName, WantPublic)) {
236APINotes.push_back(*
File);
239 if(!ExportedModuleName.empty())
240 if(
auto File= findAPINotesFile(Dir, ExportedModuleName, WantPublic))
241APINotes.push_back(*
File);
257 unsignedPathLen =
Path.size();
259llvm::sys::path::append(
Path,
"Headers");
261tryAPINotes(*APINotesDir,
true);
263 Path.resize(PathLen);
267llvm::sys::path::append(
Path,
"PrivateHeaders");
269tryAPINotes(*PrivateAPINotesDir,
284 if(!APINotes.empty())
290 for(
const auto&SearchPath : SearchPaths) {
292 if(
auto File= findAPINotesFile(*SearchDir, ModuleName)) {
293APINotes.push_back(*
File);
305assert(!CurrentModuleReaders[ReaderKind::Public] &&
306 "Already loaded API notes for the current module?");
309 unsignedNumReaders = 0;
310 for(
auto File: APINotes) {
311CurrentModuleReaders[NumReaders++] = loadAPINotes(
File).release();
316 returnNumReaders > 0;
321 unsignedNumReader = 0;
322 for(
autoBuf : Buffers) {
323 autoReader = loadAPINotes(Buf);
324assert(Reader &&
"Could not load the API notes we just generated?");
326CurrentModuleReaders[NumReader++] = Reader.release();
343 if(!ImplicitAPINotes)
370 autoKnown = Readers.find(*Dir);
373 if(Known != Readers.end()) {
374++NumDirectoryCacheHits;
377 if(Known->second && isa<DirectoryEntryRef>(Known->second)) {
378DirsVisited.insert(*Dir);
379Dir = cast<DirectoryEntryRef>(Known->second);
384 if(
autoReader = dyn_cast_if_present<APINotesReader *>(Known->second))
385Results.push_back(Reader);
391 if(llvm::sys::path::extension(
Path) ==
".framework") {
394 autoFrameworkName = llvm::sys::path::stem(
Path);
395++NumFrameworksSearched;
399loadFrameworkAPINotes(
Path, FrameworkName,
true);
401loadFrameworkAPINotes(
Path, FrameworkName,
false);
403 if(PublicDir || PrivateDir) {
405Readers[*Dir] =
nullptr;
410 if(!DirsVisited.empty()) {
411 if(PublicDir && DirsVisited.back() == *PublicDir) {
412DirsVisited.pop_back();
414}
else if(PrivateDir && DirsVisited.back() == *PrivateDir) {
415DirsVisited.pop_back();
421 if(
autoReader = Readers[*Dir].dyn_cast<APINotesReader *>())
422Results.push_back(Reader);
428llvm::sys::path::append(
432++NumDirectoriesSearched;
434 if(!loadAPINotes(*Dir, *APINotesFile)) {
436 if(
autoReader = Readers[*Dir].dyn_cast<APINotesReader *>())
437Results.push_back(Reader);
444 if(!DirsVisited.insert(*Dir)) {
449StringRef ParentPath = llvm::sys::path::parent_path(
Path);
450 while(llvm::sys::path::stem(ParentPath) ==
"..")
451ParentPath = llvm::sys::path::parent_path(ParentPath);
453Dir = ParentPath.empty() ? std::nullopt
460 for(
const auto Visited: DirsVisited)
461Readers[
Visited] = Dir ? ReaderEntry(*Dir) : ReaderEntry();
static void checkPrivateAPINotesName(DiagnosticsEngine &Diags, const FileEntry *File, const Module *M)
static bool hasPrivateSubmodules(const Module *M)
STATISTIC(NumHeaderAPINotes, "non-framework API notes files loaded")
Defines the Diagnostic-related interfaces.
Defines the clang::FileManager interface and associated types.
llvm::DenseSet< const void * > Visited
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx, QualType Ty)
Defines the clang::LangOptions interface.
Defines the clang::Module class, which describes a module in the source code.
Defines the SourceManager interface.
Defines version macros and version-related utility functions for Clang.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
StringRef getName() const
Cached information about one directory (either on disk or in the virtual file system).
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
StringRef getName() const
The name of this FileEntry.
Cached information about one file (either on disk or in the virtual file system).
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements support for file system lookup, file system caching, and directory search management.
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName, bool CacheFailure=true)
Get a DirectoryEntryRef if it exists, without doing anything on error.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes a module or submodule.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
std::string Name
The name of this module.
llvm::iterator_range< submodule_iterator > submodules()
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
OptionalDirectoryEntryRef Directory
The build directory of this module.
std::string APINotesFile
For the debug info, the path to this module's .apinotes file, if any.
unsigned IsFramework
Whether this is a framework module.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
DiagnosticsEngine & getDiagnostics() const
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
FileManager & getFileManager() const
FileID getOrCreateFileID(FileEntryRef SourceFile, SrcMgr::CharacteristicKind FileCharacter)
Get the FileID for SourceFile if it exists.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
An adapter that can be used to translate diagnostics from one or more llvm::SourceMgr instances to a ...
APINotesManager(SourceManager &SM, const LangOptions &LangOpts)
llvm::SmallVector< FileEntryRef, 2 > getCurrentModuleAPINotes(Module *M, bool LookInModule, ArrayRef< std::string > SearchPaths)
Get FileEntry for the APINotes of the module that is currently being compiled.
ArrayRef< APINotesReader * > getCurrentModuleReaders() const
Retrieve the set of API notes readers for the current module.
bool loadCurrentModuleAPINotesFromBuffer(ArrayRef< StringRef > Buffers)
Load Compiled API notes for current module.
llvm::SmallVector< APINotesReader *, 2 > findAPINotes(SourceLocation Loc)
Find the API notes readers that correspond to the given source location.
bool loadCurrentModuleAPINotes(Module *M, bool LookInModule, ArrayRef< std::string > SearchPaths)
Load the API notes for the current module.
static std::unique_ptr< APINotesReader > Create(std::unique_ptr< llvm::MemoryBuffer > InputBuffer, llvm::VersionTuple SwiftVersion)
Create a new API notes reader from the given member buffer, which contains the contents of a binary A...
bool compileAPINotes(llvm::StringRef YAMLInput, const FileEntry *SourceFile, llvm::raw_ostream &OS, llvm::SourceMgr::DiagHandlerTy DiagHandler=nullptr, void *DiagHandlerCtxt=nullptr)
Converts API notes from YAML format to binary format.
static const constexpr char SOURCE_APINOTES_EXTENSION[]
The file extension used for the source representation of API notes.
@ Public
Represents declarations accessible to all clients.
The JSON file list parser is used to communicate input to InstallAPI.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4