Skip to content

Commit

Permalink
[find-all-symbols] Save absolute file path instead of relative file p…
Browse files Browse the repository at this point in the history
…ath in SymbolInfo.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19647

llvm-svn: 268019
  • Loading branch information
hokein committed Apr 29, 2016
1 parent e7545b3 commit e5966e7
Showing 1 changed file with 23 additions and 4 deletions.
Expand Up @@ -16,6 +16,7 @@
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"

using namespace clang::ast_matchers;

Expand Down Expand Up @@ -47,19 +48,37 @@ bool SetCommonInfo(const MatchFinder::MatchResult &Result,
SetContext(ND, Symbol);

Symbol->Name = ND->getNameAsString();
SourceLocation Loc = Result.SourceManager->getExpansionLoc(ND->getLocation());

const SourceManager *SM = Result.SourceManager;
SourceLocation Loc = SM->getExpansionLoc(ND->getLocation());
if (!Loc.isValid()) {
llvm::errs() << "Declaration " << ND->getNameAsString() << "("
<< ND->getDeclKindName()
<< ") has invalid declaration location.";
return false;
}
std::string FilePath = Result.SourceManager->getFilename(Loc).str();

Symbol->LineNumber = SM->getExpansionLineNumber(Loc);

llvm::StringRef FilePath = SM->getFilename(Loc);
if (FilePath.empty())
return false;

Symbol->FilePath = FilePath;
Symbol->LineNumber = Result.SourceManager->getExpansionLineNumber(Loc);
llvm::SmallString<128> AbsolutePath;
if (llvm::sys::path::is_absolute(FilePath)) {
AbsolutePath = FilePath;
} else {
auto WorkingDir = SM->getFileManager()
.getVirtualFileSystem()
->getCurrentWorkingDirectory();
if (!WorkingDir)
return false;
AbsolutePath = *WorkingDir;
llvm::sys::path::append(AbsolutePath, FilePath);
}

llvm::sys::path::remove_dots(AbsolutePath, true);
Symbol->FilePath = AbsolutePath.str();
return true;
}
} // namespace
Expand Down

0 comments on commit e5966e7

Please sign in to comment.