summaryrefslogtreecommitdiffstats
path: root/src/linguist/lupdate/lupdatepreprocessoraction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linguist/lupdate/lupdatepreprocessoraction.cpp')
-rw-r--r--src/linguist/lupdate/lupdatepreprocessoraction.cpp109
1 files changed, 71 insertions, 38 deletions
diff --git a/src/linguist/lupdate/lupdatepreprocessoraction.cpp b/src/linguist/lupdate/lupdatepreprocessoraction.cpp
index 78bcbb721..4d5b9a3b4 100644
--- a/src/linguist/lupdate/lupdatepreprocessoraction.cpp
+++ b/src/linguist/lupdate/lupdatepreprocessoraction.cpp
@@ -1,32 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Linguist of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "lupdatepreprocessoraction.h"
+#include "filesignificancecheck.h"
#include <clang/Lex/MacroArgs.h>
#include <clang/Basic/TokenKinds.h>
@@ -37,9 +13,11 @@ void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
const clang::MacroDefinition &macroDefinition, clang::SourceRange sourceRange,
const clang::MacroArgs *macroArgs)
{
+ Q_UNUSED(macroDefinition);
+
const auto &sm = m_preprocessor.getSourceManager();
llvm::StringRef fileName = sm.getFilename(sourceRange.getBegin());
- if (fileName != m_inputFile)
+ if (!LupdatePrivate::isFileSignificant(fileName.str()))
return;
const QString funcName = QString::fromStdString(m_preprocessor.getSpelling(token));
@@ -54,6 +32,9 @@ void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
+ case TrFunctionAliasManager::Function_QT_TR_NOOP:
+ case TrFunctionAliasManager::Function_QT_TR_NOOP_UTF8:
+ case TrFunctionAliasManager::Function_QT_TR_N_NOOP:
qCDebug(lcClang) << "MacroExpands: Function name:" << funcName;
break;
}
@@ -61,7 +42,8 @@ void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
TranslationRelatedStore store;
store.callType = QStringLiteral("MacroExpands");
store.funcName = funcName;
- store.lupdateLocationFile = QString::fromStdString(fileName);
+ store.lupdateLocationFile = toQt(fileName);
+ store.lupdateInputFile = toQt(m_inputFile);
store.lupdateLocationLine = sm.getExpansionLineNumber(sourceRange.getBegin());
store.locationCol = sm.getExpansionColumnNumber(sourceRange.getBegin());
@@ -84,6 +66,9 @@ void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
+ case TrFunctionAliasManager::Function_QT_TR_NOOP_UTF8:
+ case TrFunctionAliasManager::Function_QT_TR_NOOP:
+ case TrFunctionAliasManager::Function_QT_TR_N_NOOP:
if (!clang::tok::isStringLiteral(kind))
errorArgument = true;
break;
@@ -96,6 +81,7 @@ void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
temp += QString::fromStdString(m_preprocessor.getSpelling(preExpArgument));
}
arguments[i] = temp;
+ qCDebug(lcClang) << "*********** macro argument : " << temp;
}
storeMacroArguments(arguments, &store);
}
@@ -112,10 +98,14 @@ void LupdatePPCallbacks::storeMacroArguments(const std::vector<QString> &args,
if (args.size() == 1)
store->contextArg = args[0];
break;
- // two arguments: the context and the source
+ case TrFunctionAliasManager::Function_QT_TR_NOOP_UTF8:
+ case TrFunctionAliasManager::Function_QT_TR_NOOP:
+ case TrFunctionAliasManager::Function_QT_TR_N_NOOP:
+ if (args.size() >= 1)
+ store->lupdateSource = args[0];
+ break;
case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP:
case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP3:
- Q_FALLTHROUGH();
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
@@ -129,7 +119,6 @@ void LupdatePPCallbacks::storeMacroArguments(const std::vector<QString> &args,
break;
// only one argument (?) the message Id
case TrFunctionAliasManager::Function_QT_TRID_N_NOOP:
- Q_FALLTHROUGH();
case TrFunctionAliasManager::Function_qtTrId:
case TrFunctionAliasManager::Function_QT_TRID_NOOP:
if (args.size() == 1)
@@ -143,22 +132,66 @@ void LupdatePPCallbacks::storeMacroArguments(const std::vector<QString> &args,
void LupdatePPCallbacks::SourceRangeSkipped(clang::SourceRange sourceRange,
clang::SourceLocation endifLoc)
{
+ Q_UNUSED(endifLoc);
+
const auto &sm = m_preprocessor.getSourceManager();
llvm::StringRef fileName = sm.getFilename(sourceRange.getBegin());
- if (fileName != m_inputFile)
+
+ if (!LupdatePrivate::isFileSignificant(fileName.str()))
return;
+
const char *begin = sm.getCharacterData(sourceRange.getBegin());
const char *end = sm.getCharacterData(sourceRange.getEnd());
llvm::StringRef skippedText = llvm::StringRef(begin, end - begin);
- if (ClangCppParser::containsTranslationInformation(skippedText)) {
- qCDebug(lcClang) << "SourceRangeSkipped: skipped text:" << skippedText;
+ if (ClangCppParser::stringContainsTranslationInformation(skippedText)) {
+ qCDebug(lcClang) << "SourceRangeSkipped: skipped text:" << QString::fromStdString(skippedText.str());
unsigned int beginLine = sm.getExpansionLineNumber(sourceRange.getBegin());
unsigned int endLine = sm.getExpansionLineNumber(sourceRange.getEnd());
- qWarning("Code with translation information has been skipped "
- "in file %s between lines %d and %d",
- m_inputFile.c_str(), beginLine, endLine);
+ qWarning("%s Code with translation information has been skipped "
+ "between lines %d and %d",
+ fileName.str().c_str(), beginLine, endLine);
}
+}
+// To list the included files
+#if (LUPDATE_CLANG_VERSION < LUPDATE_CLANG_VERSION_CHECK(14,0,0))
+void LupdatePPCallbacks::InclusionDirective(clang::SourceLocation /*hashLoc*/,
+ const clang::Token & /*includeTok*/, clang::StringRef /*fileName*/, bool /*isAngled*/,
+ clang::CharSourceRange /*filenameRange*/,
+#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(16,0,0))
+ const clang::OptionalFileEntryRef file,
+#elif (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(15,0,0))
+ const clang::Optional<clang::FileEntryRef> file,
+#else
+ const clang::FileEntry *file,
+#endif
+ clang::StringRef /*searchPath*/, clang::StringRef /*relativePath*/,
+ const clang::Module */*imported*/, clang::SrcMgr::CharacteristicKind /*fileType*/)
+{
+ if (!file)
+ return;
+
+ clang::StringRef fileNameRealPath = file->
+#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(15,0,0))
+ getFileEntry().
+#endif
+ tryGetRealPathName();
+ if (!LupdatePrivate::isFileSignificant(fileNameRealPath.str()))
+ return;
+
+ TranslationRelatedStore store;
+ store.callType = QStringLiteral("InclusionDirective");
+ store.lupdateLocationFile = toQt(fileNameRealPath);
+ store.lupdateLocationLine = 1;
+ store.locationCol = 1;
+ store.lupdateInputFile = toQt(m_inputFile);
+ // do not fill the store.funcName. There is no function at this point
+ // the information is retrieved here to look for TRANSLATOR comments in header files
+ // when traversing the AST
+
+ if (store.isValid())
+ m_ppStores.emplace_back(std::move(store));
}
+#endif
QT_END_NAMESPACE