20#include "llvm/ADT/SmallString.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/FileSystem.h"
23#include "llvm/Support/IOSandbox.h"
24#include "llvm/Support/Path.h"
44using LocationMap = std::map<EntityId, std::vector<SourceLocationRecord>>;
51 if (!Loc.
isValid() ||
SM.isInSystemHeader(Loc))
69 auto SandboxOff = llvm::sys::sandbox::scopedDisable();
70 if (!llvm::sys::path::is_absolute(Abs))
71 if (
auto EC = llvm::sys::fs::make_absolute(Abs))
73 if (
auto EC = llvm::sys::fs::real_path(Abs, Real))
78 R.FilePath = Real.str().str();
87 auto Rec = makeRecord(Loc,
SM);
90 std::optional<EntityId> Id = Extractor.
addEntity(D);
93 Records[*Id].push_back(std::move(*Rec));
102 Records[*RetId].push_back(std::move(*RetRec));
109 handleNamedDecl(Extractor, P, P->getTypeSpecStartLoc(),
SM,
Records);
118 TUSummaryExtractor &Extractor;
119 const SourceManager &SM;
120 LocationMap &Records;
123 EntityVisitor(TUSummaryExtractor &Extractor,
const SourceManager &SM,
124 LocationMap &Records)
125 : Extractor(Extractor), SM(SM), Records(Records) {
126 ShouldVisitTemplateInstantiations =
true;
127 ShouldVisitImplicitCode =
false;
130 bool VisitFunctionDecl(FunctionDecl *FD)
override {
132 handleFunction(Extractor, FD, SM, Records);
136 bool VisitVarDecl(VarDecl *VD)
override {
138 handleNamedDecl(Extractor, VD, VD->
getLocation(), SM, Records);
142 bool VisitFieldDecl(FieldDecl *FD)
override {
144 handleNamedDecl(Extractor, FD, FD->
getLocation(), SM, Records);
148 bool VisitRecordDecl(RecordDecl *RD)
override {
150 handleNamedDecl(Extractor, RD, RD->
getLocation(), SM, Records);
160 void HandleTranslationUnit(ASTContext &Ctx)
override;
163void EntitySourceLocationExtractor::HandleTranslationUnit(
ASTContext &Ctx) {
166 EntityVisitor(*
this,
SM,
Records).TraverseAST(Ctx);
168 for (
auto &[Id, Locs] :
Records) {
169 auto Summary = std::make_unique<EntitySourceLocationsSummary>(
171 [[maybe_unused]]
auto [
Ignored, Inserted] =
172 SummaryBuilder.addSummary(Id, std::move(Summary));
174 "EntitySourceLocations summary inserted twice for same EntityId");
180namespace clang::ssaf {
185static clang::ssaf::TUSummaryExtractorRegistry::Add<
186 EntitySourceLocationExtractor>
188 "Extract per-entity declaration source-locations");
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
llvm::MachO::Records Records
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
SourceLocation getLocation() const
Represents a function declaration or definition.
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
ArrayRef< ParmVarDecl * > parameters() const
This represents a decl that may have a name.
Represents a parameter to a function.
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
SourceLocation getBegin() const
An EntitySourceLocationsSummary contains one SourceLocationRecord per declaration site contributed by...
static constexpr llvm::StringLiteral Name
volatile int EntitySourceLocationExtractorAnchorSource
EntitySourceLocationsSummary buildEntitySourceLocationsSummary(std::vector< SourceLocationRecord > Locs)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
A canonical (file, line, column) triple for one declaration site.