clang 18.0.0git
ExtractAPIConsumer.cpp
Go to the documentation of this file.
1//===- ExtractAPI/ExtractAPIConsumer.cpp ------------------------*- 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/// \file
10/// This file implements the ExtractAPIAction, and ASTConsumer to collect API
11/// information.
12///
13//===----------------------------------------------------------------------===//
14
18#include "clang/AST/DeclObjC.h"
33#include "clang/Lex/MacroInfo.h"
37#include "llvm/ADT/DenseSet.h"
38#include "llvm/ADT/STLExtras.h"
39#include "llvm/ADT/SmallString.h"
40#include "llvm/ADT/SmallVector.h"
41#include "llvm/Support/Casting.h"
42#include "llvm/Support/Error.h"
43#include "llvm/Support/FileSystem.h"
44#include "llvm/Support/MemoryBuffer.h"
45#include "llvm/Support/Path.h"
46#include "llvm/Support/Regex.h"
47#include "llvm/Support/raw_ostream.h"
48#include <memory>
49#include <optional>
50#include <utility>
51
52using namespace clang;
53using namespace extractapi;
54
55namespace {
56
57std::optional<std::string> getRelativeIncludeName(const CompilerInstance &CI,
58 StringRef File,
59 bool *IsQuoted = nullptr) {
60 assert(CI.hasFileManager() &&
61 "CompilerInstance does not have a FileNamager!");
62
63 using namespace llvm::sys;
64 // Matches framework include patterns
65 const llvm::Regex Rule("/(.+)\\.framework/(.+)?Headers/(.+)");
66
67 const auto &FS = CI.getVirtualFileSystem();
68
69 SmallString<128> FilePath(File.begin(), File.end());
70 FS.makeAbsolute(FilePath);
71 path::remove_dots(FilePath, true);
72 FilePath = path::convert_to_slash(FilePath);
73 File = FilePath;
74
75 // Checks whether `Dir` is a strict path prefix of `File`. If so returns
76 // the prefix length. Otherwise return 0.
77 auto CheckDir = [&](llvm::StringRef Dir) -> unsigned {
78 llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
79 FS.makeAbsolute(DirPath);
80 path::remove_dots(DirPath, true);
81 Dir = DirPath;
82 for (auto NI = path::begin(File), NE = path::end(File),
83 DI = path::begin(Dir), DE = path::end(Dir);
84 /*termination condition in loop*/; ++NI, ++DI) {
85 // '.' components in File are ignored.
86 while (NI != NE && *NI == ".")
87 ++NI;
88 if (NI == NE)
89 break;
90
91 // '.' components in Dir are ignored.
92 while (DI != DE && *DI == ".")
93 ++DI;
94
95 // Dir is a prefix of File, up to '.' components and choice of path
96 // separators.
97 if (DI == DE)
98 return NI - path::begin(File);
99
100 // Consider all path separators equal.
101 if (NI->size() == 1 && DI->size() == 1 &&
102 path::is_separator(NI->front()) && path::is_separator(DI->front()))
103 continue;
104
105 // Special case Apple .sdk folders since the search path is typically a
106 // symlink like `iPhoneSimulator14.5.sdk` while the file is instead
107 // located in `iPhoneSimulator.sdk` (the real folder).
108 if (NI->endswith(".sdk") && DI->endswith(".sdk")) {
109 StringRef NBasename = path::stem(*NI);
110 StringRef DBasename = path::stem(*DI);
111 if (DBasename.startswith(NBasename))
112 continue;
113 }
114
115 if (*NI != *DI)
116 break;
117 }
118 return 0;
119 };
120
121 unsigned PrefixLength = 0;
122
123 // Go through the search paths and find the first one that is a prefix of
124 // the header.
125 for (const auto &Entry : CI.getHeaderSearchOpts().UserEntries) {
126 // Note whether the match is found in a quoted entry.
127 if (IsQuoted)
128 *IsQuoted = Entry.Group == frontend::Quoted;
129
130 if (auto EntryFile = CI.getFileManager().getOptionalFileRef(Entry.Path)) {
131 if (auto HMap = HeaderMap::Create(*EntryFile, CI.getFileManager())) {
132 // If this is a headermap entry, try to reverse lookup the full path
133 // for a spelled name before mapping.
134 StringRef SpelledFilename = HMap->reverseLookupFilename(File);
135 if (!SpelledFilename.empty())
136 return SpelledFilename.str();
137
138 // No matching mapping in this headermap, try next search entry.
139 continue;
140 }
141 }
142
143 // Entry is a directory search entry, try to check if it's a prefix of File.
144 PrefixLength = CheckDir(Entry.Path);
145 if (PrefixLength > 0) {
146 // The header is found in a framework path, construct the framework-style
147 // include name `<Framework/Header.h>`
148 if (Entry.IsFramework) {
150 Rule.match(File, &Matches);
151 // Returned matches are always in stable order.
152 if (Matches.size() != 4)
153 return std::nullopt;
154
155 return path::convert_to_slash(
156 (Matches[1].drop_front(Matches[1].rfind('/') + 1) + "/" +
157 Matches[3])
158 .str());
159 }
160
161 // The header is found in a normal search path, strip the search path
162 // prefix to get an include name.
163 return path::convert_to_slash(File.drop_front(PrefixLength));
164 }
165 }
166
167 // Couldn't determine a include name, use full path instead.
168 return std::nullopt;
169}
170
171std::optional<std::string> getRelativeIncludeName(const CompilerInstance &CI,
172 FileEntryRef FE,
173 bool *IsQuoted = nullptr) {
174 return getRelativeIncludeName(CI, FE.getNameAsRequested(), IsQuoted);
175}
176
177struct LocationFileChecker {
178 bool operator()(SourceLocation Loc) {
179 // If the loc refers to a macro expansion we need to first get the file
180 // location of the expansion.
181 auto &SM = CI.getSourceManager();
182 auto FileLoc = SM.getFileLoc(Loc);
183 FileID FID = SM.getFileID(FileLoc);
184 if (FID.isInvalid())
185 return false;
186
187 OptionalFileEntryRef File = SM.getFileEntryRefForID(FID);
188 if (!File)
189 return false;
190
191 if (KnownFileEntries.count(*File))
192 return true;
193
194 if (ExternalFileEntries.count(*File))
195 return false;
196
197 // Try to reduce the include name the same way we tried to include it.
198 bool IsQuoted = false;
199 if (auto IncludeName = getRelativeIncludeName(CI, *File, &IsQuoted))
200 if (llvm::any_of(KnownFiles,
201 [&IsQuoted, &IncludeName](const auto &KnownFile) {
202 return KnownFile.first.equals(*IncludeName) &&
203 KnownFile.second == IsQuoted;
204 })) {
205 KnownFileEntries.insert(*File);
206 return true;
207 }
208
209 // Record that the file was not found to avoid future reverse lookup for
210 // the same file.
211 ExternalFileEntries.insert(*File);
212 return false;
213 }
214
215 LocationFileChecker(const CompilerInstance &CI,
216 SmallVector<std::pair<SmallString<32>, bool>> &KnownFiles)
217 : CI(CI), KnownFiles(KnownFiles), ExternalFileEntries() {
218 for (const auto &KnownFile : KnownFiles)
219 if (auto FileEntry = CI.getFileManager().getFile(KnownFile.first))
220 KnownFileEntries.insert(*FileEntry);
221 }
222
223private:
224 const CompilerInstance &CI;
225 SmallVector<std::pair<SmallString<32>, bool>> &KnownFiles;
226 llvm::DenseSet<const FileEntry *> KnownFileEntries;
227 llvm::DenseSet<const FileEntry *> ExternalFileEntries;
228};
229
230struct BatchExtractAPIVisitor : ExtractAPIVisitor<BatchExtractAPIVisitor> {
231 bool shouldDeclBeIncluded(const Decl *D) const {
232 bool ShouldBeIncluded = true;
233 // Check that we have the definition for redeclarable types.
234 if (auto *TD = llvm::dyn_cast<TagDecl>(D))
235 ShouldBeIncluded = TD->isThisDeclarationADefinition();
236 else if (auto *Interface = llvm::dyn_cast<ObjCInterfaceDecl>(D))
237 ShouldBeIncluded = Interface->isThisDeclarationADefinition();
238 else if (auto *Protocol = llvm::dyn_cast<ObjCProtocolDecl>(D))
239 ShouldBeIncluded = Protocol->isThisDeclarationADefinition();
240
241 ShouldBeIncluded = ShouldBeIncluded && LCF(D->getLocation());
242 return ShouldBeIncluded;
243 }
244
245 BatchExtractAPIVisitor(LocationFileChecker &LCF, ASTContext &Context,
246 APISet &API)
247 : ExtractAPIVisitor<BatchExtractAPIVisitor>(Context, API), LCF(LCF) {}
248
249private:
250 LocationFileChecker &LCF;
251};
252
253class WrappingExtractAPIConsumer : public ASTConsumer {
254public:
255 WrappingExtractAPIConsumer(ASTContext &Context, APISet &API)
256 : Visitor(Context, API) {}
257
258 void HandleTranslationUnit(ASTContext &Context) override {
259 // Use ExtractAPIVisitor to traverse symbol declarations in the context.
260 Visitor.TraverseDecl(Context.getTranslationUnitDecl());
261 }
262
263private:
264 ExtractAPIVisitor<> Visitor;
265};
266
267class ExtractAPIConsumer : public ASTConsumer {
268public:
269 ExtractAPIConsumer(ASTContext &Context,
270 std::unique_ptr<LocationFileChecker> LCF, APISet &API)
271 : Visitor(*LCF, Context, API), LCF(std::move(LCF)) {}
272
273 void HandleTranslationUnit(ASTContext &Context) override {
274 // Use ExtractAPIVisitor to traverse symbol declarations in the context.
275 Visitor.TraverseDecl(Context.getTranslationUnitDecl());
276 }
277
278private:
279 BatchExtractAPIVisitor Visitor;
280 std::unique_ptr<LocationFileChecker> LCF;
281};
282
283class MacroCallback : public PPCallbacks {
284public:
285 MacroCallback(const SourceManager &SM, APISet &API, Preprocessor &PP)
286 : SM(SM), API(API), PP(PP) {}
287
288 void MacroDefined(const Token &MacroNameToken,
289 const MacroDirective *MD) override {
290 auto *MacroInfo = MD->getMacroInfo();
291
293 return;
294
295 auto SourceLoc = MacroNameToken.getLocation();
296 if (SM.isWrittenInBuiltinFile(SourceLoc) ||
297 SM.isWrittenInCommandLineFile(SourceLoc))
298 return;
299
300 PendingMacros.emplace_back(MacroNameToken, MD);
301 }
302
303 // If a macro gets undefined at some point during preprocessing of the inputs
304 // it means that it isn't an exposed API and we should therefore not add a
305 // macro definition for it.
306 void MacroUndefined(const Token &MacroNameToken, const MacroDefinition &MD,
307 const MacroDirective *Undef) override {
308 // If this macro wasn't previously defined we don't need to do anything
309 // here.
310 if (!Undef)
311 return;
312
313 llvm::erase_if(PendingMacros, [&MD, this](const PendingMacro &PM) {
314 return MD.getMacroInfo()->isIdenticalTo(*PM.MD->getMacroInfo(), PP,
315 /*Syntactically*/ false);
316 });
317 }
318
319 void EndOfMainFile() override {
320 for (auto &PM : PendingMacros) {
321 // `isUsedForHeaderGuard` is only set when the preprocessor leaves the
322 // file so check for it here.
323 if (PM.MD->getMacroInfo()->isUsedForHeaderGuard())
324 continue;
325
326 if (!shouldMacroBeIncluded(PM))
327 continue;
328
329 StringRef Name = PM.MacroNameToken.getIdentifierInfo()->getName();
330 PresumedLoc Loc = SM.getPresumedLoc(PM.MacroNameToken.getLocation());
331 StringRef USR =
332 API.recordUSRForMacro(Name, PM.MacroNameToken.getLocation(), SM);
333
334 API.addMacroDefinition(
335 Name, USR, Loc,
338 SM.isInSystemHeader(PM.MacroNameToken.getLocation()));
339 }
340
341 PendingMacros.clear();
342 }
343
344protected:
345 struct PendingMacro {
346 Token MacroNameToken;
347 const MacroDirective *MD;
348
349 PendingMacro(const Token &MacroNameToken, const MacroDirective *MD)
350 : MacroNameToken(MacroNameToken), MD(MD) {}
351 };
352
353 virtual bool shouldMacroBeIncluded(const PendingMacro &PM) { return true; }
354
355 const SourceManager &SM;
356 APISet &API;
357 Preprocessor &PP;
359};
360
361class APIMacroCallback : public MacroCallback {
362public:
363 APIMacroCallback(const SourceManager &SM, APISet &API, Preprocessor &PP,
364 LocationFileChecker &LCF)
365 : MacroCallback(SM, API, PP), LCF(LCF) {}
366
367 bool shouldMacroBeIncluded(const PendingMacro &PM) override {
368 // Do not include macros from external files
369 return LCF(PM.MacroNameToken.getLocation());
370 }
371
372private:
373 LocationFileChecker &LCF;
374};
375
376} // namespace
377
379 if (!OS)
380 return;
381
382 // Setup a SymbolGraphSerializer to write out collected API information in
383 // the Symbol Graph format.
384 // FIXME: Make the kind of APISerializer configurable.
385 SymbolGraphSerializer SGSerializer(*API, IgnoresList);
386 SGSerializer.serialize(*OS);
387 OS.reset();
388}
389
390std::unique_ptr<raw_pwrite_stream>
391ExtractAPIAction::CreateOutputFile(CompilerInstance &CI, StringRef InFile) {
392 std::unique_ptr<raw_pwrite_stream> OS;
393 OS = CI.createDefaultOutputFile(/*Binary=*/false, InFile,
394 /*Extension=*/"json",
395 /*RemoveFileOnSignal=*/false);
396 if (!OS)
397 return nullptr;
398 return OS;
399}
400
401std::unique_ptr<ASTConsumer>
403 OS = CreateOutputFile(CI, InFile);
404
405 if (!OS)
406 return nullptr;
407
409
410 // Now that we have enough information about the language options and the
411 // target triple, let's create the APISet before anyone uses it.
412 API = std::make_unique<APISet>(
413 CI.getTarget().getTriple(),
414 CI.getFrontendOpts().Inputs.back().getKind().getLanguage(), ProductName);
415
416 auto LCF = std::make_unique<LocationFileChecker>(CI, KnownInputFiles);
417
418 CI.getPreprocessor().addPPCallbacks(std::make_unique<APIMacroCallback>(
419 CI.getSourceManager(), *API, CI.getPreprocessor(), *LCF));
420
421 // Do not include location in anonymous decls.
423 Policy.AnonymousTagLocations = false;
424 CI.getASTContext().setPrintingPolicy(Policy);
425
426 if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
427 llvm::handleAllErrors(
429 CI.getFileManager())
430 .moveInto(IgnoresList),
431 [&CI](const IgnoresFileNotFound &Err) {
432 CI.getDiagnostics().Report(
433 diag::err_extract_api_ignores_file_not_found)
434 << Err.Path;
435 });
436 }
437
438 return std::make_unique<ExtractAPIConsumer>(CI.getASTContext(),
439 std::move(LCF), *API);
440}
441
442bool ExtractAPIAction::PrepareToExecuteAction(CompilerInstance &CI) {
443 auto &Inputs = CI.getFrontendOpts().Inputs;
444 if (Inputs.empty())
445 return true;
446
447 if (!CI.hasFileManager())
448 if (!CI.createFileManager())
449 return false;
450
451 auto Kind = Inputs[0].getKind();
452
453 // Convert the header file inputs into a single input buffer.
454 SmallString<256> HeaderContents;
455 bool IsQuoted = false;
456 for (const FrontendInputFile &FIF : Inputs) {
457 if (Kind.isObjectiveC())
458 HeaderContents += "#import";
459 else
460 HeaderContents += "#include";
461
462 StringRef FilePath = FIF.getFile();
463 if (auto RelativeName = getRelativeIncludeName(CI, FilePath, &IsQuoted)) {
464 if (IsQuoted)
465 HeaderContents += " \"";
466 else
467 HeaderContents += " <";
468
469 HeaderContents += *RelativeName;
470
471 if (IsQuoted)
472 HeaderContents += "\"\n";
473 else
474 HeaderContents += ">\n";
475 KnownInputFiles.emplace_back(static_cast<SmallString<32>>(*RelativeName),
476 IsQuoted);
477 } else {
478 HeaderContents += " \"";
479 HeaderContents += FilePath;
480 HeaderContents += "\"\n";
481 KnownInputFiles.emplace_back(FilePath, true);
482 }
483 }
484
486 CI.getVerboseOutputStream() << getInputBufferName() << ":\n"
487 << HeaderContents << "\n";
488
489 Buffer = llvm::MemoryBuffer::getMemBufferCopy(HeaderContents,
490 getInputBufferName());
491
492 // Set that buffer up as our "real" input in the CompilerInstance.
493 Inputs.clear();
494 Inputs.emplace_back(Buffer->getMemBufferRef(), Kind, /*IsSystem*/ false);
495
496 return true;
497}
498
499void ExtractAPIAction::EndSourceFileAction() { ImplEndSourceFileAction(); }
500
501std::unique_ptr<ASTConsumer>
503 StringRef InFile) {
504 auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
505 if (!OtherConsumer)
506 return nullptr;
507
508 CreatedASTConsumer = true;
509
510 OS = CreateOutputFile(CI, InFile);
511 if (!OS)
512 return nullptr;
513
515
516 // Now that we have enough information about the language options and the
517 // target triple, let's create the APISet before anyone uses it.
518 API = std::make_unique<APISet>(
519 CI.getTarget().getTriple(),
520 CI.getFrontendOpts().Inputs.back().getKind().getLanguage(), ProductName);
521
522 CI.getPreprocessor().addPPCallbacks(std::make_unique<MacroCallback>(
523 CI.getSourceManager(), *API, CI.getPreprocessor()));
524
525 // Do not include location in anonymous decls.
527 Policy.AnonymousTagLocations = false;
528 CI.getASTContext().setPrintingPolicy(Policy);
529
530 if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
531 llvm::handleAllErrors(
533 CI.getFileManager())
534 .moveInto(IgnoresList),
535 [&CI](const IgnoresFileNotFound &Err) {
536 CI.getDiagnostics().Report(
537 diag::err_extract_api_ignores_file_not_found)
538 << Err.Path;
539 });
540 }
541
542 auto WrappingConsumer =
543 std::make_unique<WrappingExtractAPIConsumer>(CI.getASTContext(), *API);
544 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
545 Consumers.push_back(std::move(OtherConsumer));
546 Consumers.push_back(std::move(WrappingConsumer));
547
548 return std::make_unique<MultiplexConsumer>(std::move(Consumers));
549}
550
551void WrappingExtractAPIAction::EndSourceFileAction() {
552 // Invoke wrapped action's method.
554
555 if (CreatedASTConsumer) {
557 }
558}
559
560std::unique_ptr<raw_pwrite_stream>
561WrappingExtractAPIAction::CreateOutputFile(CompilerInstance &CI,
562 StringRef InFile) {
563 std::unique_ptr<raw_pwrite_stream> OS;
564 std::string OutputDir = CI.getFrontendOpts().SymbolGraphOutputDir;
565
566 // The symbol graphs need to be generated as a side effect of regular
567 // compilation so the output should be dumped in the directory provided with
568 // the command line option.
569 llvm::SmallString<128> OutFilePath(OutputDir);
570 auto Seperator = llvm::sys::path::get_separator();
571 auto Infilename = llvm::sys::path::filename(InFile);
572 OutFilePath.append({Seperator, Infilename});
573 llvm::sys::path::replace_extension(OutFilePath, "json");
574 // StringRef outputFilePathref = *OutFilePath;
575
576 // don't use the default output file
577 OS = CI.createOutputFile(/*OutputPath=*/OutFilePath, /*Binary=*/false,
578 /*RemoveFileOnSignal=*/true,
579 /*UseTemporary=*/true,
580 /*CreateMissingDirectories=*/true);
581 if (!OS)
582 return nullptr;
583 return OS;
584}
This file defines the APIRecord-based structs and the APISet class.
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
#define SM(sm)
Definition: Cuda.cpp:80
This file defines the ExtractAPVisitor AST visitation interface.
This file defines the ExtractAPIAction and WrappingExtractAPIAction frontend actions.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines the PPCallbacks interface.
Defines the clang::Preprocessor interface.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
This file defines the SymbolGraphSerializer class.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: ASTConsumer.h:66
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1065
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:689
void setPrintingPolicy(const clang::PrintingPolicy &Policy)
Definition: ASTContext.h:693
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
FileManager * createFileManager(IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Create the file manager and replace any existing one with it.
raw_ostream & getVerboseOutputStream()
Get the current stream for verbose output.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="", bool RemoveFileOnSignal=true, bool CreateMissingDirectories=false, bool ForceUseTemporary=false)
Create the default output file (from the invocation's options) and add it to the list of tracked outp...
FileManager & getFileManager() const
Return the current file manager to the caller.
std::unique_ptr< raw_pwrite_stream > createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, bool UseTemporary, bool CreateMissingDirectories=false)
Create a new output file, optionally deriving the output path name, and add it to the list of tracked...
Preprocessor & getPreprocessor() const
Return the current preprocessor.
ASTContext & getASTContext() const
FrontendOptions & getFrontendOpts()
HeaderSearchOptions & getHeaderSearchOpts()
TargetInfo & getTarget() const
llvm::vfs::FileSystem & getVirtualFileSystem() const
SourceManager & getSourceManager() const
Return the current source manager.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
SourceLocation getLocation() const
Definition: DeclBase.h:444
std::string ProductName
The product this action is extracting API information for.
std::unique_ptr< llvm::MemoryBuffer > Buffer
The synthesized input buffer that contains all the provided input header files.
extractapi::APIIgnoresList IgnoresList
The list of symbols to ignore during serialization.
void ImplEndSourceFileAction()
Implements EndSourceFileAction for Symbol-Graph generation.
std::unique_ptr< extractapi::APISet > API
A representation of the APIs this action extracts.
std::unique_ptr< raw_pwrite_stream > OS
A stream to the output file of this action.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:57
StringRef getNameAsRequested() const
The name of this FileEntry, as originally requested without applying any remappings for VFS 'use-exte...
Definition: FileEntry.h:68
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:366
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isInvalid() const
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:234
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
An input file for the front end.
std::string ProductName
The name of the product the input files belong too.
std::string SymbolGraphOutputDir
SmallVector< FrontendInputFile, 0 > Inputs
The input files and their types.
std::vector< std::string > ExtractAPIIgnoresFileList
static std::unique_ptr< HeaderMap > Create(FileEntryRef FE, FileManager &FM)
This attempts to load the specified file as a header map.
Definition: HeaderMap.cpp:51
unsigned Verbose
Whether header search information should be output as for -v.
std::vector< Entry > UserEntries
User specified include entries.
A description of the current definition of a macro.
Definition: MacroInfo.h:590
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
Definition: MacroInfo.h:606
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:416
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition: MacroInfo.h:217
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
virtual void EndOfMainFile()
Callback invoked when the end of the main file is reached.
Definition: PPCallbacks.h:185
virtual void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD, const MacroDirective *Undef)
Hook called whenever a macro #undef is seen.
Definition: PPCallbacks.h:322
virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD)
Hook called whenever a macro definition is seen.
Definition: PPCallbacks.h:312
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Represents an unpacked "presumed" location which can be presented to the user.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1218
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:131
void EndSourceFileAction() override
Callback at the end of processing a single input.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create ExtractAPI consumer multiplexed on another consumer.
APISet holds the set of API records collected from given inputs.
Definition: API.h:1190
static DeclarationFragments getSubHeadingForMacro(StringRef Name)
Build a sub-heading for macro Name.
static DeclarationFragments getFragmentsForMacro(StringRef Name, const MacroDirective *MD)
Build DeclarationFragments for a macro.
The RecursiveASTVisitor to traverse symbol declarations and collect API information.
bool shouldDeclBeIncluded(const Decl *D) const
The visitor that organizes API information in the Symbol Graph format.
Object serialize()
Serialize the APIs in APISet in the Symbol Graph format.
Defines the clang::TargetInfo interface.
@ Quoted
'#include ""' paths, added by 'gcc -iquote'.
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Definition: Format.h:5226
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned AnonymousTagLocations
When printing an anonymous tag name, also print the location of that entity (e.g.,...
static llvm::Expected< APIIgnoresList > create(const FilePathList &IgnoresFilePathList, FileManager &FM)
The API to use for generating from the files at IgnoresFilePathList.