diff options
Diffstat (limited to 'src/tools/clangrefactoringbackend/source/sourcelocationsutils.h')
-rw-r--r-- | src/tools/clangrefactoringbackend/source/sourcelocationsutils.h | 71 |
1 files changed, 2 insertions, 69 deletions
diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h b/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h index 8e3dba86b2..eda4accf70 100644 --- a/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h +++ b/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h @@ -34,6 +34,7 @@ #endif #include <clang/Basic/SourceManager.h> +#include <clang/Lex/Lexer.h> #include <llvm/Support/FileSystem.h> #include <llvm/Support/FileUtilities.h> @@ -41,6 +42,7 @@ #pragma GCC diagnostic pop #endif +#include <iterator> #include <cctype> namespace ClangBackEnd { @@ -68,75 +70,6 @@ Utils::SmallString fromNativePath(Container container) return path; } -inline Utils::SmallString getSourceText(const clang::FullSourceLoc &startFullSourceLocation, - uint startOffset, - uint endOffset) -{ - auto startBuffer = startFullSourceLocation.getBufferData(); - const auto bufferSize = endOffset - startOffset; - - return Utils::SmallString(startBuffer.data() + startOffset, bufferSize + 1); -} - -inline void makePrintable(Utils::SmallString &text) -{ - text.replace("\n", " "); - text.replace("\t", " "); - - auto end = std::unique(text.begin(), text.end(), [](char l, char r){ - return std::isspace(l) && std::isspace(r) && l == r; - }); - text.resize(std::distance(text.begin(), end)); -} - -inline void appendSourceRangeToSourceRangesContainer( - const clang::SourceRange &sourceRange, - ClangBackEnd::SourceRangesContainer &sourceRangesContainer, - const clang::SourceManager &sourceManager) -{ - clang::FullSourceLoc startFullSourceLocation(sourceRange.getBegin(), sourceManager); - clang::FullSourceLoc endFullSourceLocation(sourceRange.getEnd(), sourceManager); - if (startFullSourceLocation.isFileID() && endFullSourceLocation.isFileID()) { - const auto startDecomposedLoction = startFullSourceLocation.getDecomposedLoc(); - const auto endDecomposedLoction = endFullSourceLocation.getDecomposedLoc(); - const auto fileId = startDecomposedLoction.first; - const auto startOffset = startDecomposedLoction.second; - const auto endOffset = endDecomposedLoction.second; - const auto fileEntry = sourceManager.getFileEntryForID(fileId); - auto filePath = absolutePath(fileEntry->getName()); - const auto fileName = llvm::sys::path::filename(filePath); - llvm::sys::path::remove_filename(filePath); - Utils::SmallString content = getSourceText(startFullSourceLocation, - startOffset, - endOffset); - makePrintable(content); - - sourceRangesContainer.insertFilePath(fileId.getHashValue(), - fromNativePath(filePath), - fromNativePath(fileName)); - sourceRangesContainer.insertSourceRange(fileId.getHashValue(), - startFullSourceLocation.getSpellingLineNumber(), - startFullSourceLocation.getSpellingColumnNumber(), - startOffset, - endFullSourceLocation.getSpellingLineNumber(), - endFullSourceLocation.getSpellingColumnNumber(), - endOffset, - std::move(content)); - } -} - -inline -void appendSourceRangesToSourceRangesContainer( - ClangBackEnd::SourceRangesContainer &sourceRangesContainer, - const std::vector<clang::SourceRange> &sourceRanges, - const clang::SourceManager &sourceManager) -{ - sourceRangesContainer.reserve(sourceRanges.size()); - - for (const auto &sourceRange : sourceRanges) - appendSourceRangeToSourceRangesContainer(sourceRange, sourceRangesContainer, sourceManager); -} - inline void appendSourceLocationsToSourceLocationsContainer( ClangBackEnd::SourceLocationsContainer &sourceLocationsContainer, |