summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLucie GĂ©rard <lucie.gerard@qt.io>2019-11-08 12:29:27 +0100
committerLucie Gerard <lucie.gerard@qt.io>2020-02-19 10:37:28 +0100
commit402ebd2dbb121dc2dfe8866b663c9c7c6e80200c (patch)
treeb54cd1d5567c039fb5dc6151646d5c544887f835 /src
parentf685da95bd841c212142c9ba5ce9cad64640af2f (diff)
Rewrite how the source location is stored in PP stores
Recreate and cache the source location while processing the AST. Storing the source location from the PP run is not reliable and thus not the same during PP and AST processing. Change-Id: I7d096ce1fca139b916ebc0a0cbdd6a2f461a03de Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/linguist/lupdate/clangtoolastreader.cpp11
-rw-r--r--src/linguist/lupdate/cpp_clang.h19
-rw-r--r--src/linguist/lupdate/lupdatepreprocessoraction.cpp1
3 files changed, 24 insertions, 7 deletions
diff --git a/src/linguist/lupdate/clangtoolastreader.cpp b/src/linguist/lupdate/clangtoolastreader.cpp
index 8d384e89a..ceff09523 100644
--- a/src/linguist/lupdate/clangtoolastreader.cpp
+++ b/src/linguist/lupdate/clangtoolastreader.cpp
@@ -469,7 +469,8 @@ void LupdateVisitor::processPreprocessorCalls()
void LupdateVisitor::processPreprocessorCall(TranslationRelatedStore store)
{
- const std::vector<QString> rawComments = rawCommentsFromSourceLocation(store.callLocation);
+ const std::vector<QString> rawComments = rawCommentsFromSourceLocation(store
+ .callLocation(m_context->getSourceManager()));
for (const auto &rawComment : rawComments)
setInfoFromRawComment(rawComment, &store);
@@ -516,7 +517,7 @@ void LupdateVisitor::findContextForTranslationStoresFromPP(clang::NamedDecl *nam
for (TranslationRelatedStore &store : m_noopTranslationMacroAll) {
if (!store.contextArg.isEmpty())
continue;
- clang::SourceLocation sourceLoc = store.callLocation;
+ clang::SourceLocation sourceLoc = store.callLocation(sm);
if (!sourceLoc.isValid())
continue;
if (LupdatePrivate::isPointWithin(namedDeclaration->getSourceRange(), sourceLoc, sm)) {
@@ -537,7 +538,7 @@ void LupdateVisitor::findContextForTranslationStoresFromPP(clang::NamedDecl *nam
qCDebug(lcClang) << " Declaration Location " <<
namedDeclaration->getSourceRange().printToString(sm);
qCDebug(lcClang) << " Macro Location "
- << store.callLocation.printToString(sm);
+ << sourceLoc.printToString(sm);
qCDebug(lcClang) << " Context namedDeclaration->getQualifiedNameAsString() "
<< namedDeclaration->getQualifiedNameAsString();
qCDebug(lcClang) << " Context LupdatePrivate::contextForNoopMacro "
@@ -549,7 +550,7 @@ void LupdateVisitor::findContextForTranslationStoresFromPP(clang::NamedDecl *nam
}
for (TranslationRelatedStore &store : m_qDeclareTrMacroAll) {
- clang::SourceLocation sourceLoc = store.callLocation;
+ clang::SourceLocation sourceLoc = store.callLocation(sm);
if (!sourceLoc.isValid())
continue;
if (LupdatePrivate::isPointWithin(namedDeclaration->getSourceRange(), sourceLoc, sm)) {
@@ -562,7 +563,7 @@ void LupdateVisitor::findContextForTranslationStoresFromPP(clang::NamedDecl *nam
qCDebug(lcClang) << " Declaration Location " <<
namedDeclaration->getSourceRange().printToString(sm);
qCDebug(lcClang) << " Macro Location "
- << store.callLocation.printToString(sm);
+ << sourceLoc.printToString(sm);
qCDebug(lcClang) << " Context namedDeclaration->getQualifiedNameAsString() "
<< store.contextRetrieved;
qCDebug(lcClang) << " Context LupdatePrivate::contextForNoopMacro "
diff --git a/src/linguist/lupdate/cpp_clang.h b/src/linguist/lupdate/cpp_clang.h
index acc0157da..eabf2d830 100644
--- a/src/linguist/lupdate/cpp_clang.h
+++ b/src/linguist/lupdate/cpp_clang.h
@@ -43,6 +43,7 @@
#endif
#include <clang/Basic/SourceLocation.h>
+#include <clang/Basic/SourceManager.h>
#if defined(Q_CC_MSVC)
# pragma warning(pop)
@@ -84,13 +85,29 @@ struct TranslationRelatedStore
QString lupdateComment;
QString lupdateExtraComment;
QString lupdatePlural;
- clang::SourceLocation callLocation;
+ clang::SourceLocation sourceLocation;
bool isValid() const
{
return !lupdateLocationFile.isEmpty() && (lupdateLocationLine > -1) && (locationCol > -1);
}
+ clang::SourceLocation callLocation(const clang::SourceManager &sourceManager)
+ {
+ if (sourceLocation.isInvalid()) {
+ auto sourceFile = sourceManager.getFileManager()
+ .getFile(lupdateLocationFile.toStdString());
+#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(10,0,0))
+ sourceLocation = sourceManager.translateFileLineCol(sourceFile.get(),
+ lupdateLocationLine, locationCol);
+#else
+ sourceLocation = sourceManager.translateFileLineCol(sourceFile, lupdateLocationLine,
+ locationCol);
+#endif
+ }
+ return sourceLocation;
+ }
+
void printStore() const
{
qCDebug(lcClang) << "------------------ Printing Store----------------------------------\n";
diff --git a/src/linguist/lupdate/lupdatepreprocessoraction.cpp b/src/linguist/lupdate/lupdatepreprocessoraction.cpp
index 3e48ffdfe..feba49942 100644
--- a/src/linguist/lupdate/lupdatepreprocessoraction.cpp
+++ b/src/linguist/lupdate/lupdatepreprocessoraction.cpp
@@ -64,7 +64,6 @@ void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
store.lupdateLocationFile = QString::fromStdString(fileName);
store.lupdateLocationLine = sm.getExpansionLineNumber(sourceRange.getBegin());
store.locationCol = sm.getExpansionColumnNumber(sourceRange.getBegin());
- store.callLocation = sourceRange.getBegin();
if (macroArgs) {
std::vector<QString> arguments(macroArgs->getNumMacroArguments());