File 0001-lupdate-remove-clang-parser.patch of Package qt6-tools
From 28425b933db432f0a2b7c1976d3fa5885bc6a8d3 Mon Sep 17 00:00:00 2001
From: Masoud Jami <masoud.jami@qt.io>
Date: Tue, 4 Feb 2025 10:04:01 +0100
Subject: [PATCH] lupdate: remove clang parser
Clang is a full-blown C++ parser, which means that lupdate/clang
cannot skip over uninteresting things. It's needs the full
picture of the project, including include paths and defines.
While, lupdate only needs to understand the context of
a translatable string, and nothing more.
As a result, not only the clang-based parser in lupdate has
slower performance compared to the default parser, also,
it must retrieve the compiler's default include
paths and platform defines, and all this is sometimes breaking
unexpectedly (the autotests for lupdate/clang have often been
the culprit of flakiness in the qttools repository).
Also, lupdate/clang can only see the code that is
compiled for the current platform, whereas the default parser
extracts all of these strings:
\#if defined(Q_OS_WIN)
show(tr("I'm on Windows!"));
\#elif defined(Q_OS_LINUX)
show(tr("I'm on Linux!"));
\#else
show(tr("I'm on some other OS!"));
\#endif
Altogether, because of the points above, lupdate/clang has
no users, and makes maintenance more difficult. Removing
it simplifies the tool and avoids these problems.
Fixes: QTBUG-130096
Fixes: QTBUG-131481
Fixes: QTBUG-130006
Change-Id: I6b41f59f97af58cdb793ec797c8718f78e8bc8a0
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
---
REUSE.toml | 2 -
configure.cmake | 28 -
.../linguist/doc/src/linguist-manual.qdoc | 20 -
src/linguist/lupdate/CMakeLists.txt | 35 -
src/linguist/lupdate/clangtoolastreader.cpp | 892 ------------------
src/linguist/lupdate/clangtoolastreader.h | 154 ---
src/linguist/lupdate/cpp_clang.cpp | 742 ---------------
src/linguist/lupdate/cpp_clang.h | 303 ------
.../lupdate/filesignificancecheck.cpp | 66 --
src/linguist/lupdate/filesignificancecheck.h | 64 --
.../lupdate/lupdatepreprocessoraction.cpp | 197 ----
.../lupdate/lupdatepreprocessoraction.h | 122 ---
src/linguist/lupdate/main.cpp | 328 +++----
tests/auto/linguist/lupdate/CMakeLists.txt | 9 -
.../expectedoutput.txt | 0
.../good/lacksqobject_clang_parser/main.cpp | 75 --
.../lacksqobject_clang_parser/project.pro | 3 -
.../project.ts.result | 31 -
.../good/parsecontexts_clang_parser/main.cpp | 266 ------
.../parsecontexts_clang_parser/project.pro | 3 -
.../project.ts.result | 177 ----
.../parsecpp2_clang_parser/expectedoutput.txt | 3 -
.../good/parsecpp2_clang_parser/main.cpp | 141 ---
.../good/parsecpp2_clang_parser/main.h | 36 -
.../good/parsecpp2_clang_parser/project.pro | 3 -
.../parsecpp2_clang_parser/project.ts.result | 83 --
.../parsecpp_clang_only/expectedoutput.txt | 5 -
.../good/parsecpp_clang_only/lupdatecmd | 1 -
.../good/parsecpp_clang_only/my_include.h | 33 -
.../good/parsecpp_clang_only/project.pro | 9 -
.../parsecpp_clang_only/project.ts.result | 319 -------
.../test_QT_TR_NOOP_context.cpp | 165 ----
.../test_QT_TR_NOOP_context_bis.cpp | 165 ----
.../test_QT_TR_NOOP_context_with_comments.h | 36 -
.../test_contain_only_alias.cpp | 35 -
.../parsecpp_clang_only/test_header_only.cpp | 28 -
.../parsecpp_clang_only/test_header_only.h | 39 -
.../test_isolatedComments.cpp | 84 --
.../test_isolatedComments.h | 33 -
.../test_line_directive.cpp | 7 -
.../test_sameLineComments.cpp | 54 --
.../parsecpp_clang_parser/expectedoutput.txt | 2 -
.../good/parsecpp_clang_parser/finddialog.cpp | 169 ----
.../good/parsecpp_clang_parser/included.cpp | 31 -
.../good/parsecpp_clang_parser/main.cpp | 690 --------------
.../good/parsecpp_clang_parser/my_include.h | 6 -
.../parsecpp_clang_parser/notincluded.cpp | 31 -
.../good/parsecpp_clang_parser/project.pro | 7 -
.../parsecpp_clang_parser/project.ts.result | 666 -------------
.../good/prefix_clang_parser/main.cpp | 56 --
.../testdata/good/prefix_clang_parser/main.h | 48 -
.../good/prefix_clang_parser/project.pro | 3 -
.../prefix_clang_parser/project.ts.result | 47 -
.../expectedoutput.txt | 1 -
.../good/preprocess_clang_parser/main.cpp | 62 --
.../good/preprocess_clang_parser/project.pro | 3 -
.../preprocess_clang_parser/project.ts.result | 29 -
tests/auto/linguist/lupdate/tst_lupdate.cpp | 138 +--
58 files changed, 181 insertions(+), 6604 deletions(-)
delete mode 100644 src/linguist/lupdate/clangtoolastreader.cpp
delete mode 100644 src/linguist/lupdate/clangtoolastreader.h
delete mode 100644 src/linguist/lupdate/cpp_clang.cpp
delete mode 100644 src/linguist/lupdate/cpp_clang.h
delete mode 100644 src/linguist/lupdate/filesignificancecheck.cpp
delete mode 100644 src/linguist/lupdate/filesignificancecheck.h
delete mode 100644 src/linguist/lupdate/lupdatepreprocessoraction.cpp
delete mode 100644 src/linguist/lupdate/lupdatepreprocessoraction.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/expectedoutput.txt
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/main.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.ts.result
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/main.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.ts.result
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/expectedoutput.txt
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.ts.result
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/lupdatecmd
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_with_comments.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_contain_only_alias.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_line_directive.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_sameLineComments.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/expectedoutput.txt
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/finddialog.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/included.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/main.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/my_include.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/notincluded.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.ts.result
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.h
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.ts.result
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/expectedoutput.txt
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/main.cpp
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.pro
delete mode 100644 tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.ts.result
diff --git a/REUSE.toml b/REUSE.toml
index 0ff8a4c..ec25c51 100644
--- a/REUSE.toml
+++ b/REUSE.toml
@@ -62,8 +62,6 @@ path = ["tests/**.ts*",
"tests/auto/linguist/lconvert/data/untranslated.qm",
"tests/auto/linguist/lrelease/testdata/dupes.errors",
"tests/auto/linguist/lupdate/testdata/good/language/main.cpp",
- "tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_line_directive.cpp",
- "tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/my_include.h",
"tests/auto/linguist/lupdate/testdata/good/proparsing2/include.h",
"src/qdoc/qdoc/tests/**xml",
"src/qdoc/qdoc/tests/**.html",
diff --git a/configure.cmake b/configure.cmake
index c90348c..03b0922 100644
--- a/configure.cmake
+++ b/configure.cmake
@@ -45,10 +45,6 @@ qt_feature("qdoc" PRIVATE
PURPOSE "QDoc is Qt's documentation generator for C++ and QML projects."
CONDITION TARGET Qt::QmlPrivate AND QT_FEATURE_clang AND QT_FEATURE_commandlineparser AND QT_FEATURE_thread AND QT_LIB_CLANG_VERSION VERSION_GREATER_EQUAL QDOC_MINIMUM_CLANG_VERSION
)
-qt_feature("clangcpp" PRIVATE
- LABEL "Clang-based lupdate parser"
- CONDITION QT_FEATURE_clang_rtti AND (NOT MSVC OR MSVC_VERSION LESS "1939" OR QT_LIB_CLANG_VERSION_MAJOR GREATER_EQUAL "16")
-)
qt_feature("designer" PRIVATE
LABEL "Qt Widgets Designer"
PURPOSE "Qt Widgets Designer is the Qt tool for designing and building graphical user interfaces (GUIs) with Qt Widgets. You can compose and customize your windows or dialogs in a what-you-see-is-what-you-get (WYSIWYG) manner, and test them using different styles and resolutions."
@@ -99,7 +95,6 @@ qt_feature("qtplugininfo" PRIVATE
qt_configure_add_summary_section(NAME "Qt Tools")
qt_configure_add_summary_entry(ARGS "assistant")
qt_configure_add_summary_entry(ARGS "clang")
-qt_configure_add_summary_entry(ARGS "clangcpp")
qt_configure_add_summary_entry(ARGS "designer")
qt_configure_add_summary_entry(ARGS "distancefieldgenerator")
#qt_configure_add_summary_entry(ARGS "kmap2qmap")
@@ -166,29 +161,6 @@ qt_configure_add_report_entry(
CONDITION QT_LIB_CLANG_VERSION VERSION_LESS QDOC_MINIMUM_CLANG_VERSION
)
-set(clangcpp_warn_msg "")
-if(QT_FEATURE_clang AND NOT QT_FEATURE_clang_rtti)
- string(APPEND clangcpp_warn_msg
- "LLVM was found, but it was not built with RTTI support.
-Consider using a different prebuilt LLVM package or building LLVM with RTTI support to
-enable the Clang-based lupdate parser.
-Configuring LLVM with RTTI support can be done by setting the LLVM_ENABLE_RTTI CMake
-variable to ON. See https://llvm.org/docs/CMake.html#building-llvm-with-cmake
-and https://llvm.org/docs/CMake.html#llvm-related-variables for details.
-"
- )
-endif()
-string(APPEND clangcpp_warn_msg
- "The Clang-based lupdate parser will not be available. "
- "Suitable LLVM and Clang C++ libraries have not been found. "
- "You will need to set the FEATURE_clangcpp CMake variable to ON to re-evaluate this check."
-)
-qt_configure_add_report_entry(
- TYPE WARNING
- MESSAGE "${clangcpp_warn_msg}"
- CONDITION NOT QT_FEATURE_clangcpp
-)
-
qt_configure_add_report_entry(
TYPE WARNING
MESSAGE "Qt Assistant will not be compiled because it requires Qt Network."
diff --git a/src/linguist/linguist/doc/src/linguist-manual.qdoc b/src/linguist/linguist/doc/src/linguist-manual.qdoc
index a34c971..23382bf 100644
--- a/src/linguist/linguist/doc/src/linguist-manual.qdoc
+++ b/src/linguist/linguist/doc/src/linguist-manual.qdoc
@@ -351,26 +351,6 @@
\row
\li \c {-version}
\li Display the version of \c lupdate and exit.
- \row
- \li \c {-clang-parser [compilation-database-dir]}
- \li Use clang to parse .cpp files. Otherwise, use a custom
- parser. This option needs a clang compilation database
- (\c compile_commands.json) for the files to be parsed.
- Specify the path to the directory containing this file
- on the command line, directly after the \c -clang-parser
- option, or in the project file.
-
- When using qmake, set the \c LUPDATE_COMPILE_COMMANDS_PATH
- variable in the .pro file.
-
- A directory specified on the command line takes precedence. If you
- do not specify a path, \c lupdate searches for the compilation
- database from all parent paths of the first input file.
- \row
- \li \c {-project-roots <directory>...}
- \li Specify one or more project root directories. Only files
- below a project root are considered for translation when
- using the \c -clang-parser option.
\endtable
\section1 Examples
diff --git a/src/linguist/lupdate/CMakeLists.txt b/src/linguist/lupdate/CMakeLists.txt
index 56d4ad3..33171a8 100644
--- a/src/linguist/lupdate/CMakeLists.txt
+++ b/src/linguist/lupdate/CMakeLists.txt
@@ -70,40 +70,5 @@ qt_internal_extend_target(${target_name} CONDITION NOT TARGET Qt::QmlPrivate
QT_NO_QML
)
-qt_internal_extend_target(${target_name} CONDITION QT_FEATURE_clangcpp
- SOURCES
- clangtoolastreader.cpp clangtoolastreader.h
- cpp_clang.cpp cpp_clang.h
- filesignificancecheck.cpp filesignificancecheck.h
- lupdatepreprocessoraction.cpp lupdatepreprocessoraction.h
- synchronized.h
- DEFINES
- # special case begin
- # remove these
- #(CLANG_RESOURCE_DIR=\"/clang//include\")
- #(LUPDATE_CLANG_VERSION_STR=\"\")
- #LUPDATE_CLANG_VERSION_MAJOR=
- #LUPDATE_CLANG_VERSION_MINOR=
- #LUPDATE_CLANG_VERSION_PATCH=
- # in favor of these
- LUPDATE_CLANG_VERSION_STR="\"${QT_LIB_CLANG_VERSION}\""
- LUPDATE_CLANG_VERSION_MAJOR=${QT_LIB_CLANG_VERSION_MAJOR}
- LUPDATE_CLANG_VERSION_MINOR=${QT_LIB_CLANG_VERSION_MINOR}
- LUPDATE_CLANG_VERSION_PATCH=${QT_LIB_CLANG_VERSION_PATCH}
- # special case end
- LIBRARIES
- WrapLibClang::WrapLibClang
-)
-
-if(QT_FEATURE_clangcpp)
- # If libclangTooling.a is not built with -fPIE enabled we cannot link it to lupdate.
- # TODO: Re-enable PIE once clang is built with PIE in provisioning.
- set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE FALSE)
-endif()
-
qt_internal_extend_target(${target_name} CONDITION MSVC
DEFINES _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
-
-if(QT_FEATURE_clangcpp)
- set_property(SOURCE clangtoolastreader.cpp PROPERTY SKIP_AUTOMOC ON)
-endif()
diff --git a/src/linguist/lupdate/clangtoolastreader.cpp b/src/linguist/lupdate/clangtoolastreader.cpp
deleted file mode 100644
index 3db9e0d..0000000
--- a/src/linguist/lupdate/clangtoolastreader.cpp
+++ /dev/null
@@ -1,892 +0,0 @@
-// Copyright (C) 2019 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "clangtoolastreader.h"
-#include "filesignificancecheck.h"
-#include "translator.h"
-
-#include <QLibraryInfo>
-
-QT_BEGIN_NAMESPACE
-
-namespace LupdatePrivate
-{
- void exploreChildrenForFirstStringLiteral(clang::Stmt* stmt, QString &context)
- {
- // only exploring the children until the context has been found.
- if (!stmt || !context.isEmpty())
- return;
-
- for (auto it = stmt->child_begin() ; it !=stmt->child_end() ; it++) {
- if (!context.isEmpty())
- break;
- clang::Stmt *child = *it;
- clang::StringLiteral *stringLit = llvm::dyn_cast_or_null<clang::StringLiteral>(child);
- if (stringLit) {
- context = toQt(stringLit->getString());
- return;
- }
- exploreChildrenForFirstStringLiteral(child, context);
- }
- return;
- }
-
- // Checks if the tr method is supported by the CXXRecordDecl
- // Either because Q_OBJECT or Q_DECLARE_FUNCTIONS(MyContext) is declared with this CXXRecordDecl
- // In case of Q_DECLARE_FUNCTIONS the context is read in the tr Method children with function exploreChildrenForFirstStringLiteral
- // Q_DECLARE_FUNCTIONS trace in the AST is:
- // - a public AccessSpecDecl pointing to src/corelib/kernel/qcoreapplication.h
- // - a CXXMethodDecl called tr with a children that is a StringLiteral. This is the context
- // Q_OBJECT trace in the AST is:
- // - a public AccessSpecDecl pointing to src/corelib/kernel/qtmetamacros.h
- // - a CXXMethodDecl called tr WITHOUT a StringLiteral among its children.
- bool isQObjectOrQDeclareTrFunctionMacroDeclared(clang::CXXRecordDecl *recordDecl, QString &context, const clang::SourceManager &sm)
- {
- if (!recordDecl)
- return false;
-
- bool tr_method_present = false;
- bool access_for_qobject = false;
- bool access_for_qdeclaretrfunction = false;
-
- for (auto decl : recordDecl->decls()) {
- clang::AccessSpecDecl *accessSpec = llvm::dyn_cast<clang::AccessSpecDecl>(decl);
- clang::CXXMethodDecl *method = llvm::dyn_cast<clang::CXXMethodDecl>(decl);
-
- if (!accessSpec && !method)
- continue;
- if (method) {
- // Look for method with name 'tr'
- std::string name = method->getNameAsString();
- if (name == "tr") {
- tr_method_present = true;
- // if nothing is found and the context remains empty, it's ok, it's probably a Q_OBJECT.
- exploreChildrenForFirstStringLiteral(method->getBody(), context);
- }
- } else if (accessSpec) {
- if (!accessSpec->getBeginLoc().isValid())
- continue;
- QString location = QString::fromStdString(
- sm.getSpellingLoc(accessSpec->getBeginLoc()).printToString(sm));
- qsizetype indexLast = location.lastIndexOf(QLatin1String(":"));
- qsizetype indexBeforeLast = location.lastIndexOf(QLatin1String(":"), indexLast-1);
- location.truncate(indexBeforeLast);
- const QString qtInstallDirPath = QLibraryInfo::path(QLibraryInfo::PrefixPath);
- const QString accessForQDeclareTrFunctions = QStringLiteral("qcoreapplication.h");
- const QString accessForQObject = QStringLiteral("qtmetamacros.h");
- // Qt::CaseInsensitive because of potential discrepancy in Windows with D:/ and d:/
- if (location.startsWith(qtInstallDirPath, Qt::CaseInsensitive)) {
- if (location.endsWith(accessForQDeclareTrFunctions))
- access_for_qdeclaretrfunction = true;
- if (location.endsWith(accessForQObject))
- access_for_qobject = true;
- }
- }
- }
-
- bool access_to_qtbase = false;
- // if the context is still empty then it cannot be a Q_DECLARE_TR_FUNCTION.
- if (context.isEmpty())
- access_to_qtbase = access_for_qobject;
- else
- access_to_qtbase = access_for_qdeclaretrfunction;
-
- return tr_method_present && access_to_qtbase;
- }
-
- QString exploreBases(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm);
- QString lookForContext(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm)
- {
- QString context;
- if (isQObjectOrQDeclareTrFunctionMacroDeclared(recordDecl, context, sm)) {
- return context.isEmpty() ? QString::fromStdString(recordDecl->getQualifiedNameAsString()) : context;
- } else {
- // explore the bases of this CXXRecordDecl
- // the base class AA takes precedent over B (reproducing tr context behavior)
- /*
- class AA {Q_OBJECT};
- class A : public AA {};
- class B {
- Q_OBJECT
- class C : public A
- {
- QString c_tr = tr("context is AA");
- const char * c_noop = QT_TR_NOOP("context should be AA");
- }
- };
- */
- // For recordDecl corresponding to class C, the following gives access to class A
- return exploreBases(recordDecl, sm);
- }
- }
-
- // Gives access to the class or struct the CXXRecordDecl is inheriting from
- QString exploreBases(clang::CXXRecordDecl *recordDecl, const clang::SourceManager &sm)
- {
- QString context;
- for (auto base : recordDecl->bases()) {
- const clang::Type *type = base.getType().getTypePtrOrNull();
- if (!type) continue;
- clang::CXXRecordDecl *baseDecl = type->getAsCXXRecordDecl();
- if (!baseDecl)
- continue;
- context = lookForContext(baseDecl, sm);
- if (!context.isEmpty())
- return context;
- }
- return context;
- }
-
- // QT_TR_NOOP location is within the the NamedDecl range
- // Look for the RecordDecl (class or struct) the NamedDecl belongs to
- // and the related classes until Q_OBJECT macro declaration or Q_DECLARE_TR_FUNCTIONS is found.
- // The first class where Q_OBJECT or Q_DECLARE_TR_FUNCTIONS is declared is the context.
- // The goal is to reproduce the behavior exibited by the new parser for tr function.
- // tr function and QT_TR_NOOP, when next to each other in code, should always have the same context!
- //
- // The old parser does not do this.
- // If a Q_OBJECT macro cannot be found in the first class
- // a warning is emitted and the class is used as context regardless.
- // This is the behavior for tr function and QT_TR_NOOP
- // This is not correct.
- QString contextForNoopMacro(clang::NamedDecl *namedDecl, const clang::SourceManager &sm)
- {
- QString context;
- clang::DeclContext *decl = namedDecl->getDeclContext();
- if (!decl)
- return context;
- while (decl) {
- qCDebug(lcClang) << "--------------------- decl kind name: " << decl->getDeclKindName();
- if (clang::isa<clang::CXXRecordDecl>(decl)) {
- clang::CXXRecordDecl *recordDecl = llvm::dyn_cast<clang::CXXRecordDecl>(decl);
-
- context = lookForContext(recordDecl, sm);
-
- if (!context.isEmpty())
- return context;
- }
- decl = decl->getParent(); // Brings to the class or struct decl is nested in, if it exists.
- }
-
- // If no context has been found: do not emit a warning here.
- // because more than one NamedDecl can include the QT_TR_NOOP macro location
- // in the following, class A and class B and c_noop will.
- /*
- class A {
- class B
- {
- Q_OBJECT
- const char * c_noop = QT_TR_NOOP("context is B");
- }
- };
- */
- // calling contextForNoopMacro on NamedDecl corresponding to class A
- // no context will be found, but it's ok because the context will be found
- // when the function is called on c_noop.
- return context;
- }
-
-
- QString contextForFunctionDecl(clang::FunctionDecl *func, const std::string &funcName)
- {
- std::string context;
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(10,0,0))
- {
- llvm::raw_string_ostream tmp(context);
- func->printQualifiedName(tmp);
- }
-#else
- context = func->getQualifiedNameAsString();
-#endif
- return QString::fromStdString(context.substr(0, context.find("::" + funcName, 0)));
- }
-
- static bool capture(const QRegularExpression &exp, const QString &line, QString *i, QString *c)
- {
- i->clear(), c->clear();
- auto result = exp.match(line);
- if (!result.hasMatch())
- return false;
-
- *i = result.captured(QLatin1String("identifier"));
- *c = result.captured(QStringLiteral("comment")).trimmed();
-
- if (*i == QLatin1String("%"))
- *c = LupdatePrivate::cleanQuote(c->toStdString(), QuoteCompulsary::Left);
-
- return !c->isEmpty();
- }
-
- bool hasQuote(llvm::StringRef source)
- {
- return source.contains("\"");
- }
-
- bool trFunctionPresent(llvm::StringRef text)
- {
- if (text.contains(llvm::StringRef("qtTrId(")))
- return true;
- if (text.contains(llvm::StringRef("tr(")))
- return true;
- if (text.contains(llvm::StringRef("trUtf8(")))
- return true;
- if (text.contains(llvm::StringRef("translate(")))
- return true;
- if (text.contains(llvm::StringRef("Q_DECLARE_TR_FUNCTIONS(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TR_N_NOOP(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRID_N_NOOP(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRANSLATE_N_NOOP(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRANSLATE_N_NOOP3(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TR_NOOP(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRID_NOOP(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRANSLATE_NOOP(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRANSLATE_NOOP3(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TR_NOOP_UTF8(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRANSLATE_NOOP_UTF8(")))
- return true;
- if (text.contains(llvm::StringRef("QT_TRANSLATE_NOOP3_UTF8(")))
- return true;
- return false;
- }
-
- bool isPointWithin(const clang::SourceRange &sourceRange, const clang::SourceLocation &point,
- const clang::SourceManager &sm)
- {
- clang::SourceLocation start = sourceRange.getBegin();
- clang::SourceLocation end = sourceRange.getEnd();
- return point == start || point == end || (sm.isBeforeInTranslationUnit(start, point)
- && sm.isBeforeInTranslationUnit(point, end));
- }
-
- class BeforeThanCompare
- {
- const clang::SourceManager &SM;
-
- public:
- explicit BeforeThanCompare(const clang::SourceManager &SM) : SM(SM) { }
-
- bool operator()(const clang::RawComment &LHS, const clang::RawComment &RHS)
- {
- return SM.isBeforeInTranslationUnit(LHS.getBeginLoc(), RHS.getBeginLoc());
- }
-
- bool operator()(const clang::RawComment *LHS, const clang::RawComment *RHS)
- {
- return operator()(*LHS, *RHS);
- }
- };
-}
-
-/*
- The visit call expression function is called automatically after the
- visitor TraverseAST function is called. This is the function where the
- "tr", "trUtf8", "qtIdTr", "translate" functions are picked up in the AST.
- Previously mentioned functions are always part of a CallExpression.
-*/
-bool LupdateVisitor::VisitCallExpr(clang::CallExpr *callExpression)
-{
- const auto fullLocation = m_context->getFullLoc(callExpression->getBeginLoc());
- if (fullLocation.isInvalid())
- return true;
- clang::FunctionDecl *func = callExpression->getDirectCallee();
- if (!func)
- return true;
- clang::QualType q = callExpression->getType();
- if (!q.getTypePtrOrNull())
- return true;
-
- struct {
- unsigned Line;
- std::string Filename;
- } info;
-
- const auto funcName = QString::fromStdString(func->getNameInfo().getAsString());
-
- // Only continue if the function a translation function (TODO: deal with alias function...)
- switch (trFunctionAliasManager.trFunctionByName(funcName)) {
- case TrFunctionAliasManager::Function_tr:
- case TrFunctionAliasManager::Function_trUtf8:
- case TrFunctionAliasManager::Function_translate:
- case TrFunctionAliasManager::Function_qtTrId:{
-
- const auto &sm = m_context->getSourceManager();
- const auto fileLoc = sm.getFileLoc(callExpression->getBeginLoc());
- if (fileLoc.isInvalid() || !fileLoc.isFileID())
- return true;
- // not using line directive (# line)
- auto presumedLoc = sm.getPresumedLoc(fileLoc, false);
- if (presumedLoc.isInvalid())
- return true;
- info = { presumedLoc.getLine(), presumedLoc.getFilename() };
- } break;
- default:
- return true;
- }
-
- // Checking that the CallExpression is from the input file we're interested in
- if (!LupdatePrivate::isFileSignificant(info.Filename))
- return true;
-
- qCDebug(lcClang) << "************************** VisitCallExpr ****************";
- // Retrieving the information needed to fill the lupdate translator.
- // Function independent retrieve
- TranslationRelatedStore store;
- store.callType = QStringLiteral("ASTRead_CallExpr");
- store.funcName = funcName;
- store.lupdateLocationFile = QString::fromStdString(info.Filename);
- store.lupdateLocationLine = info.Line;
- store.contextRetrieved = LupdatePrivate::contextForFunctionDecl(func, funcName.toStdString());
-
- qCDebug(lcClang) << "CallType : ASTRead_CallExpr";
- qCDebug(lcClang) << "Function name : " << store.funcName;
- qCDebug(lcClang) << "File location : " << store.lupdateLocationFile;
- qCDebug(lcClang) << "Line : " << store.lupdateLocationLine;
- qCDebug(lcClang) << "Context retrieved : " << store.contextRetrieved;
-
- // Here we gonna need to retrieve the comments around the function call
- // //: //* //~ Things like that
- const std::vector<QString> rawComments = rawCommentsForCallExpr(callExpression);
- for (const auto &rawComment : rawComments) {
- setInfoFromRawComment(rawComment, &store);
- qCDebug(lcClang) << "Raw comments :" << rawComment;
- }
-
- clang::LangOptions langOpts;
- langOpts.CPlusPlus = true;
- clang::PrintingPolicy policy(langOpts);
- std::vector<std::string> arguments(callExpression->getNumArgs(), "");
- for (unsigned int i = 0; i < callExpression->getNumArgs(); i++) {
- auto arg = callExpression->getArg(i);
- llvm::raw_string_ostream temp(arguments[i]);
- arg->printPretty(temp, nullptr, policy);
- }
-
- // Function dependent retrieve!
- switch (trFunctionAliasManager.trFunctionByName(funcName)) {
- case TrFunctionAliasManager::Function_tr:
- case TrFunctionAliasManager::Function_trUtf8:
- if (arguments.size() != 3 || !LupdatePrivate::hasQuote(arguments[0]))
- return true;
- store.lupdateSource = LupdatePrivate::cleanQuote(arguments[0]);
- store.lupdateComment = LupdatePrivate::cleanQuote(arguments[1]);
- store.lupdatePlural = QString::fromStdString(arguments[2]);
- qCDebug(lcClang) << "Source : " << store.lupdateSource;
- qCDebug(lcClang) << "Comment : " << store.lupdateComment;
- qCDebug(lcClang) << "Plural : " << store.lupdatePlural;
- break;
- case TrFunctionAliasManager::Function_translate:
- if (arguments.size() != 4 || !LupdatePrivate::hasQuote(arguments[0])
- || !LupdatePrivate::hasQuote(arguments[1])) {
- return true;
- }
- store.contextArg = LupdatePrivate::cleanQuote(arguments[0]);
- store.lupdateSource = LupdatePrivate::cleanQuote(arguments[1]);
- store.lupdateComment = LupdatePrivate::cleanQuote(arguments[2]);
- store.lupdatePlural = QString::fromStdString(arguments[3]);
- qCDebug(lcClang) << "Context Arg : " << store.contextArg;
- qCDebug(lcClang) << "Source : " << store.lupdateSource;
- qCDebug(lcClang) << "Comment : " << store.lupdateComment;
- qCDebug(lcClang) << "Plural : " << store.lupdatePlural;
- break;
- case TrFunctionAliasManager::Function_qtTrId:
- if (arguments.size() != 2 || !LupdatePrivate::hasQuote(arguments[0]))
- return true;
- store.lupdateId = LupdatePrivate::cleanQuote(arguments[0]);
- store.lupdatePlural = QString::fromStdString(arguments[1]);
- qCDebug(lcClang) << "ID : " << store.lupdateId;
- qCDebug(lcClang) << "Plural : " << store.lupdatePlural;
- break;
- }
- // locationCol needs to be set for the store to be considered valid (but really only needed for PP calls, to reconstruct location)
- store.locationCol = 0;
- m_trCalls.emplace_back(std::move(store));
- return true;
-}
-
-void LupdateVisitor::processIsolatedComments()
-{
- auto &sourceMgr = m_context->getSourceManager();
- processIsolatedComments(sourceMgr.getMainFileID()) ;
-}
-
-/*
- Retrieve the comments not associated with tr calls.
-*/
-void LupdateVisitor::processIsolatedComments(const clang::FileID file)
-{
- qCDebug(lcClang) << "==== processIsolatedComments ====";
- auto &sourceMgr = m_context->getSourceManager();
-
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(10,0,0))
- const auto commentsInThisFile = m_context->Comments.getCommentsInFile(file);
- if (!commentsInThisFile)
- return;
-
- std::vector<clang::RawComment *> tmp;
- for (const auto &commentInFile : *commentsInThisFile)
- tmp.emplace_back(commentInFile.second);
- clang::ArrayRef<clang::RawComment *> rawComments = tmp;
-#else
- Q_UNUSED(file);
- clang::ArrayRef<clang::RawComment *> rawComments = m_context->getRawCommentList().getComments();
-#endif
-
- // If there are no comments anywhere, we won't find anything.
- if (rawComments.empty())
- return;
-
- // Searching for the comments of the form:
- // /* TRANSLATOR CONTEXT
- // whatever */
- // They are not associated to any tr calls
- // Each one needs its own entry in the m_stores->AST translation store
- for (const auto &rawComment : rawComments) {
- if (!LupdatePrivate::isFileSignificant(sourceMgr.getFilename(rawComment->getBeginLoc()).str()))
- continue;
- // Comments not separated by an empty line will be part of the same Raw comments
- // Each one needs to be saved with its line number.
- // The store is used here only to pass this information.
- TranslationRelatedStore store;
- store.lupdateLocationLine = sourceMgr.getPresumedLoc(rawComment->getBeginLoc(), false).getLine();
- store.lupdateLocationFile = QString::fromStdString(
- sourceMgr.getPresumedLoc(rawComment->getBeginLoc(), false).getFilename());
- QString comment = toQt(rawComment->getRawText(sourceMgr));
- qCDebug(lcClang) << " raw Comment : \n" << comment;
- setInfoFromRawComment(comment, &store);
- }
-}
-
-/*
- Retrieve the comments associated with the CallExpression.
-*/
-std::vector<QString> LupdateVisitor::rawCommentsForCallExpr(const clang::CallExpr *callExpr) const
-{
- if (!m_context)
- return {};
- return rawCommentsFromSourceLocation(m_context->getFullLoc(callExpr->getBeginLoc()));
-}
-
-std::vector<QString> LupdateVisitor::rawCommentsFromSourceLocation(
- clang::SourceLocation sourceLocation) const
-{
- if (!m_context)
- return {};
- if (sourceLocation.isInvalid() || !sourceLocation.isFileID()) {
- qCDebug(lcClang) << "The declaration does not map directly to a location in a file,"
- " early return.";
- return {};
- }
- auto &sourceMgr = m_context->getSourceManager();
-
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(10,0,0))
- const clang::FileID file = sourceMgr.getDecomposedLoc(sourceLocation).first;
- const auto commentsInThisFile = m_context->Comments.getCommentsInFile(file);
- if (!commentsInThisFile)
- return {};
-
- std::vector<clang::RawComment *> tmp;
- for (const auto &commentInFile : *commentsInThisFile)
- tmp.emplace_back(commentInFile.second);
- clang::ArrayRef<clang::RawComment *> rawComments = tmp;
-#else
- clang::ArrayRef<clang::RawComment *> rawComments = m_context->getRawCommentList().getComments();
-#endif
-
- // If there are no comments anywhere, we won't find anything.
- if (rawComments.empty())
- return {};
-
- // Create a dummy raw comment with the source location of the declaration.
- clang::RawComment commentAtDeclarationLocation(sourceMgr,
- clang::SourceRange(sourceLocation), m_context->getLangOpts().CommentOpts, false);
-
- // Create a functor object to compare the source location of the comment and the declaration.
- const LupdatePrivate::BeforeThanCompare compareSourceLocation(sourceMgr);
- // Find the comment that occurs just after or within this declaration. Possible findings:
- // QObject::tr(/* comment 1 */ "test"); //: comment 2 -> finds "//: comment 1"
- // QObject::tr("test"); //: comment 1 -> finds "//: comment 1"
- // QObject::tr("test");
- // //: comment 1 -> finds "//: comment 1"
- // /*: comment 1 */ QObject::tr("test"); -> finds no trailing comment
- auto comment = std::lower_bound(rawComments.begin(), rawComments.end(),
- &commentAtDeclarationLocation, compareSourceLocation);
-
- // We did not find any comment before the declaration.
- if (comment == rawComments.begin())
- return {};
-
- // Decompose the location for the declaration and find the beginning of the file buffer.
- std::pair<clang::FileID, unsigned> declLocDecomp = sourceMgr.getDecomposedLoc(sourceLocation);
-
- // Get the text buffer from the beginning of the file up through the declaration's begin.
- bool invalid = false;
- const char *buffer = sourceMgr.getBufferData(declLocDecomp.first, &invalid).data();
- if (invalid) {
- qCDebug(lcClang).nospace() << "An error occurred fetching the source buffer of file: "
- << toQt(sourceMgr.getFilename(sourceLocation));
- return {};
- }
-
- std::vector<QString> retrievedRawComments;
- auto lastDecompLoc = declLocDecomp.second;
- const auto declLineNum = sourceMgr.getLineNumber(declLocDecomp.first, declLocDecomp.second);
- do {
- std::advance(comment, -1);
-
- // Decompose the end of the comment.
- std::pair<clang::FileID, unsigned> commentEndDecomp
- = sourceMgr.getDecomposedLoc((*comment)->getSourceRange().getEnd());
-
- // If the comment and the declaration aren't in the same file, then they aren't related.
- if (declLocDecomp.first != commentEndDecomp.first) {
- qCDebug(lcClang) << "Comment and the declaration aren't in the same file. Comment '"
- << toQt((*comment)->getRawText(sourceMgr)) << "' is ignored, return.";
- return retrievedRawComments;
- }
-
- // Current lupdate ignores comments on the same line before the declaration.
- // void Class42::hello(int something /*= 17 */, QString str = Class42::tr("eyo"))
- bool sameLineComment = false;
- if (declLineNum == sourceMgr.getLineNumber(commentEndDecomp.first, commentEndDecomp.second))
- sameLineComment = true;
-
- // Extract text between the comment and declaration.
- llvm::StringRef text(buffer + commentEndDecomp.second,
- lastDecompLoc - commentEndDecomp.second);
-
- // There should be no other declarations or preprocessor directives between
- // comment and declaration.
- if (text.find_first_of(";}#@") != llvm::StringRef::npos) {
- qCDebug(lcClang) << "Found another declaration or preprocessor directive between"
- " comment and declaration, break.";
- break;
- }
- if (sameLineComment && text.find_first_of(",") != llvm::StringRef::npos) {
- qCDebug(lcClang) << "Comment ends on same line as the declaration and is separated "
- "from the tr call by a ','. Comment '"
- << toQt((*comment)->getRawText(sourceMgr))
- << "' is ignored, continue.";
- continue; // if there is a comment on the previous line it should be picked up
- }
-
- // There should be no other translation function between comment and declaration.
- if (LupdatePrivate::trFunctionPresent(text)) {
- qCDebug(lcClang) << "Found another translation function between comment and "
- "declaration, break.";
- break;
- }
-
- retrievedRawComments.emplace(retrievedRawComments.begin(),
- toQt((*comment)->getRawText(sourceMgr)));
- lastDecompLoc = sourceMgr.getDecomposedLoc((*comment)->getSourceRange().getBegin()).second;
- } while (comment != rawComments.begin());
-
- return retrievedRawComments;
-}
-
-/*
- Read the raw comments and split them according to the prefix.
- Fill the corresponding variables in the TranslationRelatedStore.
-*/
-void LupdateVisitor::setInfoFromRawComment(const QString &commentString,
- TranslationRelatedStore *store)
-{
- const QStringList commentLines = commentString.split(QLatin1Char('\n'));
-
- static const QRegularExpression
- cppStyle(
- QStringLiteral("^\\/\\/(?<identifier>[:=~%]|(\\s*?TRANSLATOR))\\s+(?<comment>.+)$"));
- static const QRegularExpression
- cStyleSingle(
- QStringLiteral("^\\/\\*(?<identifier>[:=~%]|(\\s*?TRANSLATOR))\\s+(?<comment>.+)\\*\\/$"));
- static const QRegularExpression
- cStyleMultiBegin(
- QStringLiteral("^\\/\\*(?<identifier>[:=~%]|(\\s*?TRANSLATOR))\\s+(?<comment>.*)$"));
-
- static const QRegularExpression isSpace(QStringLiteral("\\s+"));
- static const QRegularExpression idefix(
- QStringLiteral("^\\/\\*(?<identifier>[:=~%]|(\\s*?TRANSLATOR))"));
-
- bool save = false;
- bool sawStarPrefix = false;
- bool sourceIdentifier = false;
-
- int storeLine = store->lupdateLocationLine;
- int lineExtra = storeLine - 1;
-
- QString comment, identifier;
- for (auto line : commentLines) {
- line = line.trimmed();
- lineExtra++;
- if (!sawStarPrefix) {
- if (line.startsWith(QStringLiteral("//"))) {
- // Process C++ style comment.
- save = LupdatePrivate::capture(cppStyle, line, &identifier, &comment);
- storeLine = lineExtra;
- } else if (line.startsWith(QLatin1String("/*")) && line.endsWith(QLatin1String("*/"))) {
- // Process C style comment on a single line.
- storeLine = lineExtra;
- save = LupdatePrivate::capture(cStyleSingle, line, &identifier, &comment);
- } else if (line.startsWith(QLatin1String("/*"))) {
- storeLine = lineExtra;
- sawStarPrefix = true; // Start processing a multi line C style comment.
-
- auto result = idefix.match(line);
- if (!result.hasMatch())
- continue; // No identifier found.
- identifier = result.captured(QLatin1String("identifier"));
-
- // The line is not just opening, try grab the comment.
- if (line.size() > (identifier.size() + 3))
- LupdatePrivate::capture(cStyleMultiBegin, line, &identifier, &comment);
- sourceIdentifier = (identifier == QLatin1String("%"));
- }
- } else {
- if (line.endsWith(QLatin1String("*/"))) {
- sawStarPrefix = false; // Finished processing a multi line C style comment.
- line = line.remove(QLatin1String("*/")).trimmed(); // Still there can be something.
- }
-
- if (sourceIdentifier) {
- line = LupdatePrivate::cleanQuote(line.toStdString(),
- LupdatePrivate::QuoteCompulsary::Left);
- }
-
- if (!line.isEmpty() && !comment.isEmpty() && !sourceIdentifier)
- comment.append(QLatin1Char(' '));
-
- comment += line;
- save = !sawStarPrefix && !comment.isEmpty();
- }
- if (!save)
- continue;
-
- // To avoid processing the non TRANSLATOR comments when setInfoFromRawComment in called
- // from processIsolatedComments
- if (!store->funcName.isEmpty()) {
- if (identifier == QStringLiteral(":")) {
- if (!store->lupdateExtraComment.isEmpty())
- store->lupdateExtraComment.append(QLatin1Char(' '));
- store->lupdateExtraComment += comment;
- } else if (identifier == QStringLiteral("=")) {
- if (!store->lupdateIdMetaData.isEmpty())
- store->lupdateIdMetaData.append(QLatin1Char(' '));
- store->lupdateIdMetaData = comment; // Only the last one is to be picked up.
- } else if (identifier == QStringLiteral("~")) {
- auto first = comment.section(isSpace, 0, 0);
- auto second = comment.mid(first.size()).trimmed();
- if (!second.isEmpty())
- store->lupdateAllMagicMetaData.insert(first, second);
- } else if (identifier == QLatin1String("%")) {
- store->lupdateSourceWhenId += comment;
- }
- } else if (identifier.trimmed() == QStringLiteral("TRANSLATOR")) {
- // separate the comment in two in order to get the context
- // then save it as a new entry in m_stores.
- // reminder: TRANSLATOR comments are isolated comments not linked to any tr call
- qCDebug(lcClang) << "Comment = " << comment;
- TranslationRelatedStore newStore;
- // need a funcName name in order to get handeled in fillTranslator
- newStore.funcName = QStringLiteral("TRANSLATOR");
- auto index = comment.indexOf(QStringLiteral(" "));
- if (index >= 0) {
- newStore.contextArg = comment.left(index).trimmed();
- newStore.lupdateComment = comment.mid(index).trimmed();
- }
- newStore.lupdateLocationFile = store->lupdateLocationFile;
- newStore.lupdateLocationLine = storeLine;
- newStore.locationCol = 0;
- newStore.printStore();
- m_trCalls.emplace_back(std::move(newStore));
- }
-
- save = false;
- comment.clear();
- identifier.clear();
- }
-}
-
-void LupdateVisitor::processPreprocessorCalls()
-{
- QString inputFile = toQt(m_inputFile);
- for (const auto &store : m_stores->Preprocessor) {
- if (store.lupdateInputFile == inputFile)
- processPreprocessorCall(store);
- }
-
- // Processing the isolated comments (TRANSLATOR) in the files included in the main input file.
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- for (const clang::FileEntry *file : m_preprocessor->getIncludedFiles()) {
- auto &sourceMgr = m_context->getSourceManager();
-
- clang::StringRef fileNameRealPath = file->tryGetRealPathName();
- if (!LupdatePrivate::isFileSignificant(fileNameRealPath.str())
- || fileNameRealPath.str() == m_inputFile)
- continue;
-
- auto sourceFile = sourceMgr.getFileManager()
- .getFile(fileNameRealPath);
- auto sourceLocation = sourceMgr.translateFileLineCol(sourceFile.get(), 1, 1);
- const clang::FileID fileId = sourceMgr.getDecomposedLoc(sourceLocation).first;
- processIsolatedComments(fileId);
- }
-#endif
-
- if (m_qDeclareTrMacroAll.size() > 0 || m_noopTranslationMacroAll.size() > 0)
- m_macro = true;
-}
-
-void LupdateVisitor::processPreprocessorCall(TranslationRelatedStore store)
-{
- // To get the comments around the macros
- const std::vector<QString> rawComments = rawCommentsFromSourceLocation(store
- .callLocation(m_context->getSourceManager()));
- // to pick up the raw comments in the files collected from the preprocessing.
- for (const auto &rawComment : rawComments)
- setInfoFromRawComment(rawComment, &store);
-
- // Processing the isolated comments (TRANSLATOR) in the files included in the main input file.
-#if (LUPDATE_CLANG_VERSION < LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- if (store.callType.contains(QStringLiteral("InclusionDirective"))) {
- auto &sourceMgr = m_context->getSourceManager();
- const clang::FileID file = sourceMgr.getDecomposedLoc(store.callLocation(sourceMgr)).first;
- processIsolatedComments(file);
- return;
- }
-#endif
-
- if (store.isValid()) {
- if (store.funcName.contains(QStringLiteral("Q_DECLARE_TR_FUNCTIONS")))
- m_qDeclareTrMacroAll.emplace_back(std::move(store));
- else
- m_noopTranslationMacroAll.emplace_back(std::move(store));
- store.printStore();
- }
-}
-
-bool LupdateVisitor::VisitNamedDecl(clang::NamedDecl *namedDeclaration)
-{
- if (!m_macro)
- return true;
- auto fullLocation = m_context->getFullLoc(namedDeclaration->getBeginLoc());
- if (!fullLocation.isValid() || !fullLocation.getFileEntry())
- return true;
-
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(18,0,0))
- auto fileEntry = fullLocation.getFileEntryRef();
- if (fileEntry && !LupdatePrivate::isFileSignificant(fileEntry->getName().str()))
- return true;
-#else
- if (!LupdatePrivate::isFileSignificant(fullLocation.getFileEntry()->getName().str()))
- return true;
-#endif
-
- qCDebug(lcClang) << "NamedDecl Name: " << QString::fromStdString(namedDeclaration->getQualifiedNameAsString());
- qCDebug(lcClang) << "NamedDecl source: " << QString::fromStdString(namedDeclaration->getSourceRange().printToString(
- m_context->getSourceManager()));
- // Checks if there is a macro located within the range of this NamedDeclaration
- // in order to find a context for the macro
- findContextForTranslationStoresFromPP(namedDeclaration);
- return true;
-}
-
-void LupdateVisitor::findContextForTranslationStoresFromPP(clang::NamedDecl *namedDeclaration)
-{
- qCDebug(lcClang) << "=================findContextForTranslationStoresFromPP===================";
- qCDebug(lcClang) << "m_noopTranslationMacroAll " << m_noopTranslationMacroAll.size();
- qCDebug(lcClang) << "m_qDeclareTrMacroAll " << m_qDeclareTrMacroAll.size();
- clang::SourceManager &sm = m_context->getSourceManager();
-
- // Looking for NOOP context only in the input file
- // because we are not interested in the NOOP from all related file
- // Once QT_TR_NOOP are gone this step can be removes because the only
- // QT_...NOOP left will have an context as argument
- for (TranslationRelatedStore &store : m_noopTranslationMacroAll) {
- if (!store.contextArg.isEmpty())
- continue;
- clang::SourceLocation sourceLoc = store.callLocation(sm);
- if (!sourceLoc.isValid())
- continue;
- if (LupdatePrivate::isPointWithin(namedDeclaration->getSourceRange(), sourceLoc, sm)) {
-
- store.contextRetrieved = LupdatePrivate::contextForNoopMacro(namedDeclaration, sm);
- qCDebug(lcClang) << "------------------------------------------NOOP Macro in range ---";
- qCDebug(lcClang) << "Range " << QString::fromStdString(namedDeclaration->getSourceRange().printToString(sm));
- qCDebug(lcClang) << "Point " << QString::fromStdString(sourceLoc.printToString(sm));
- qCDebug(lcClang) << "=========== Visit Named Declaration =============================";
- qCDebug(lcClang) << " Declaration Location " <<
- QString::fromStdString(namedDeclaration->getSourceRange().printToString(sm));
- qCDebug(lcClang) << " Macro Location "
- << QString::fromStdString(sourceLoc.printToString(sm));
- qCDebug(lcClang) << " Context namedDeclaration->getQualifiedNameAsString() "
- << QString::fromStdString(namedDeclaration->getQualifiedNameAsString());
- qCDebug(lcClang) << " Context LupdatePrivate::contextForNoopMacro "
- << store.contextRetrieved;
- qCDebug(lcClang) << " Context Retrieved " << store.contextRetrieved;
- qCDebug(lcClang) << "=================================================================";
- store.printStore();
- }
- }
-
- for (TranslationRelatedStore &store : m_qDeclareTrMacroAll) {
- clang::SourceLocation sourceLoc = store.callLocation(sm);
- if (!sourceLoc.isValid())
- continue;
- if (LupdatePrivate::isPointWithin(namedDeclaration->getSourceRange(), sourceLoc, sm)) {
- store.contextRetrieved = QString::fromStdString(
- namedDeclaration->getQualifiedNameAsString());
- qCDebug(lcClang) << "------------------------------------------DECL Macro in range ---";
- qCDebug(lcClang) << "Range " << QString::fromStdString(namedDeclaration->getSourceRange().printToString(sm));
- qCDebug(lcClang) << "Point " << QString::fromStdString(sourceLoc.printToString(sm));
- qCDebug(lcClang) << "=========== Visit Named Declaration =============================";
- qCDebug(lcClang) << " Declaration Location " <<
- QString::fromStdString(namedDeclaration->getSourceRange().printToString(sm));
- qCDebug(lcClang) << " Macro Location "
- << QString::fromStdString(sourceLoc.printToString(sm));
- qCDebug(lcClang) << " Context namedDeclaration->getQualifiedNameAsString() "
- << store.contextRetrieved;
- qCDebug(lcClang) << " Context Retrieved " << store.contextRetrieved;
- qCDebug(lcClang) << "=================================================================";
- store.printStore();
- }
- }
-}
-
-void LupdateVisitor::generateOutput()
-{
- qCDebug(lcClang) << "=================generateOutput============================";
- m_noopTranslationMacroAll.erase(std::remove_if(m_noopTranslationMacroAll.begin(),
- m_noopTranslationMacroAll.end(), [](const TranslationRelatedStore &store) {
- // Macros not located in the currently visited file are missing context (and it's normal),
- // so an output is only generated for macros present in the currently visited file.
- // If context could not be found, it is warned against in ClangCppParser::collectMessages
- // (where it is possible to order the warnings and print them consistantly)
- if (!LupdatePrivate::isFileSignificant(store.lupdateLocationFile.toStdString()))
- return true;
- return false;
- }), m_noopTranslationMacroAll.end());
-
- m_stores->QNoopTranlsationWithContext.emplace_bulk(std::move(m_noopTranslationMacroAll));
-
- m_qDeclareTrMacroAll.erase(std::remove_if(m_qDeclareTrMacroAll.begin(),
- m_qDeclareTrMacroAll.end(), [](const TranslationRelatedStore &store) {
- // only fill if a context has been retrieved in the file we're currently visiting
- return store.contextRetrieved.isEmpty();
- }), m_qDeclareTrMacroAll.end());
- m_stores->QDeclareTrWithContext.emplace_bulk(std::move(m_qDeclareTrMacroAll));
-
- processIsolatedComments();
- m_stores->AST.emplace_bulk(std::move(m_trCalls));
-}
-
-QT_END_NAMESPACE
diff --git a/src/linguist/lupdate/clangtoolastreader.h b/src/linguist/lupdate/clangtoolastreader.h
deleted file mode 100644
index a848321..0000000
--- a/src/linguist/lupdate/clangtoolastreader.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright (C) 2019 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef CLANG_TOOL_AST_READER_H
-#define CLANG_TOOL_AST_READER_H
-
-#include "cpp_clang.h"
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_MSVC(4100)
-QT_WARNING_DISABLE_MSVC(4146)
-QT_WARNING_DISABLE_MSVC(4267)
-QT_WARNING_DISABLE_MSVC(4624)
-QT_WARNING_DISABLE_GCC("-Wnonnull")
-
-#include <clang/AST/RecursiveASTVisitor.h>
-#include <clang/Frontend/CompilerInstance.h>
-#include <clang/Frontend/FrontendActions.h>
-#include <clang/Tooling/Tooling.h>
-
-QT_WARNING_POP
-
-#include <iostream>
-#include <memory>
-
-QT_BEGIN_NAMESPACE
-
-class Translator;
-
-class LupdateVisitor : public clang::RecursiveASTVisitor<LupdateVisitor>
-{
-public:
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- explicit LupdateVisitor(clang::ASTContext *context,
- clang::Preprocessor *preprocessor, Stores *stores)
- : m_context(context)
- , m_preprocessor(preprocessor)
- , m_stores(stores)
-#else
- explicit LupdateVisitor(clang::ASTContext *context, Stores *stores)
- : m_context(context)
- , m_stores(stores)
-#endif
- {
- m_inputFile = m_context->getSourceManager().getFileEntryRefForID(
- m_context->getSourceManager().getMainFileID())->getName();
- }
-
- bool VisitCallExpr(clang::CallExpr *callExpression);
- void processPreprocessorCalls();
- bool VisitNamedDecl(clang::NamedDecl *namedDeclaration);
- void findContextForTranslationStoresFromPP(clang::NamedDecl *namedDeclaration);
- void generateOutput();
-
-private:
- std::vector<QString> rawCommentsForCallExpr(const clang::CallExpr *callExpr) const;
- std::vector<QString> rawCommentsFromSourceLocation(clang::SourceLocation sourceLocation) const;
-
- void setInfoFromRawComment(const QString &commentString, TranslationRelatedStore *store);
-
- void processPreprocessorCall(TranslationRelatedStore store);
- void processIsolatedComments();
- void processIsolatedComments(const clang::FileID file);
-
- clang::ASTContext *m_context = nullptr;
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- clang::Preprocessor *m_preprocessor = nullptr;
-#endif
- std::string m_inputFile;
-
- Stores *m_stores = nullptr;
-
- TranslationStores m_trCalls;
- TranslationStores m_qDeclareTrMacroAll;
- TranslationStores m_noopTranslationMacroAll;
- bool m_macro = false;
-};
-
-class LupdateASTConsumer : public clang::ASTConsumer
-{
-public:
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- explicit LupdateASTConsumer(clang::ASTContext *context, clang::Preprocessor *preprocessor,
- Stores *stores)
- : m_visitor(context, preprocessor, stores)
-#else
- explicit LupdateASTConsumer(clang::ASTContext *context, Stores *stores)
- : m_visitor(context, stores)
-#endif
- {}
-
- // This method is called when the ASTs for entire translation unit have been
- // parsed.
- void HandleTranslationUnit(clang::ASTContext &context) override
- {
- m_visitor.processPreprocessorCalls();
- bool traverse = m_visitor.TraverseAST(context);
- qCDebug(lcClang) << "TraverseAST: " << traverse;
- m_visitor.generateOutput();
- }
-
-private:
- LupdateVisitor m_visitor;
-};
-
-class LupdateFrontendAction : public clang::ASTFrontendAction
-{
-public:
- LupdateFrontendAction(Stores *stores)
- : m_stores(stores)
- {}
-
- std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
- clang::CompilerInstance &compiler, llvm::StringRef /* inFile */) override
- {
- #if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- auto consumer = new LupdateASTConsumer(&compiler.getASTContext(),
- &compiler.getPreprocessor(), m_stores);
- #else
- auto consumer = new LupdateASTConsumer(&compiler.getASTContext(), m_stores);
- #endif
- return std::unique_ptr<clang::ASTConsumer>(consumer);
- }
-
-private:
- Stores *m_stores = nullptr;
-};
-
-class LupdateToolActionFactory : public clang::tooling::FrontendActionFactory
-{
-public:
- LupdateToolActionFactory(Stores *stores)
- : m_stores(stores)
- {}
-
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(10,0,0))
- std::unique_ptr<clang::FrontendAction> create() override
- {
- return std::make_unique<LupdateFrontendAction>(m_stores);
- }
-#else
- clang::FrontendAction *create() override
- {
- return new LupdateFrontendAction(m_stores);
- }
-#endif
-
-private:
- Stores *m_stores = nullptr;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/linguist/lupdate/cpp_clang.cpp b/src/linguist/lupdate/cpp_clang.cpp
deleted file mode 100644
index df9f5df..0000000
--- a/src/linguist/lupdate/cpp_clang.cpp
+++ /dev/null
@@ -1,742 +0,0 @@
-// Copyright (C) 2019 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "cpp_clang.h"
-#include "clangtoolastreader.h"
-#include "filesignificancecheck.h"
-#include "lupdatepreprocessoraction.h"
-#include "synchronized.h"
-#include "translator.h"
-
-#include <QLibraryInfo>
-#include <QtCore/qdir.h>
-#include <QtCore/qfileinfo.h>
-#include <QtCore/qjsonarray.h>
-#include <QtCore/qjsondocument.h>
-#include <QtCore/qjsonobject.h>
-#include <QtCore/qscopeguard.h>
-#include <QtCore/QProcess>
-#include <QStandardPaths>
-#include <QtTools/private/qttools-config_p.h>
-
-#include <clang/Tooling/CompilationDatabase.h>
-
-#include <algorithm>
-#include <limits>
-#include <thread>
-#include <iostream>
-#include <cstdlib>
-
-#include <cstdio>
-#include <memory>
-#include <stdexcept>
-#include <string>
-#include <array>
-
-using clang::tooling::CompilationDatabase;
-
-QT_BEGIN_NAMESPACE
-
-using namespace Qt::StringLiterals;
-
-Q_LOGGING_CATEGORY(lcClang, "qt.lupdate.clang");
-
-static QString getSysCompiler()
-{
- QStringList candidates;
- if (const char* local_compiler = std::getenv("CXX")) {
- candidates.push_back(QLatin1String(local_compiler));
- } else {
- candidates = {
-#ifdef Q_OS_WIN
- QStringLiteral("cl"),
-#endif
- QStringLiteral("clang++"),
- QStringLiteral("gcc")
- };
- }
- QString sysCompiler;
- for (const QString &comp : candidates) {
-
- sysCompiler = QStandardPaths::findExecutable(comp);
- if (!sysCompiler.isEmpty())
- break;
- }
- return sysCompiler;
-}
-
-static QByteArrayList getMSVCIncludePathsFromEnvironment()
-{
- QList<QByteArray> pathList;
- if (const char* includeEnv = std::getenv("INCLUDE")) {
- QByteArray includeList = QByteArray::fromRawData(includeEnv, strlen(includeEnv));
- pathList = includeList.split(';');
- }
- for (auto it = pathList.begin(); it != pathList.end(); ++it) {
- it->prepend("-isystem");
- }
- return pathList;
-}
-
-static QStringList getProjectDirsFromEnvironment()
-{
- QList<QByteArray> dirList;
- QStringList rootdirs;
- if (const char* includeEnv = std::getenv("LUPDATE_ROOT_DIRS")) {
- QByteArray includeList = QByteArray::fromRawData(includeEnv, strlen(includeEnv));
- dirList = includeList.split(';');
-
- for (auto dir : dirList) {
- rootdirs.append(QString::fromStdString(dir.toStdString()));
- }
- }
- return rootdirs;
-}
-
-
-static QByteArray frameworkSuffix()
-{
- return QByteArrayLiteral(" (framework directory)");
-}
-
-QByteArrayList getIncludePathsFromCompiler()
-{
-
- QList<QByteArray> pathList;
- QString compiler = getSysCompiler();
- if (compiler.isEmpty()) {
- qWarning("lupdate: Could not determine system compiler.");
- return pathList;
- }
-
- const QFileInfo fiCompiler(compiler);
- const QString compilerName
-
-#ifdef Q_OS_WIN
- = fiCompiler.completeBaseName();
-#else
- = fiCompiler.fileName();
-#endif
-
- if (compilerName == QLatin1String("cl"))
- return getMSVCIncludePathsFromEnvironment();
-
- if (compilerName != QLatin1String("gcc") && compilerName != QLatin1String("clang++")) {
- qWarning("lupdate: Unknown compiler %s", qPrintable(compiler));
- return pathList;
- }
-
- const QStringList compilerFlags = {
- QStringLiteral("-E"), QStringLiteral("-x"), QStringLiteral("c++"),
- QStringLiteral("-"), QStringLiteral("-v")
- };
-
- QProcess proc;
- proc.setStandardInputFile(proc.nullDevice());
- proc.start(compiler, compilerFlags);
- proc.waitForFinished(30000);
- QByteArray buffer = proc.readAllStandardError();
- proc.kill();
-
- // ### TODO: Merge this with qdoc's getInternalIncludePaths()
- const QByteArrayList stdErrLines = buffer.split('\n');
- bool isIncludeDir = false;
- for (const QByteArray &line : stdErrLines) {
- if (isIncludeDir) {
- if (line.startsWith(QByteArrayLiteral("End of search list"))) {
- isIncludeDir = false;
- } else {
- QByteArray prefix("-isystem");
- QByteArray headerPath{line.trimmed()};
- if (headerPath.endsWith(frameworkSuffix())) {
- headerPath.truncate(headerPath.size() - frameworkSuffix().size());
- prefix = QByteArrayLiteral("-F");
- }
- pathList.append(prefix + headerPath);
- }
- } else if (line.startsWith(QByteArrayLiteral("#include <...> search starts here"))) {
- isIncludeDir = true;
- }
- }
-
- return pathList;
-}
-
-std::vector<std::string> ClangCppParser::getAliasFunctionDefinition()
-{
- QStringList aliases = trFunctionAliasManager.listAliases();
- std::vector<std::string> results;
- for (QString alias : aliases) {
- std::string definition = "-D" + alias.toStdString();
- switch (trFunctionAliasManager.trFunctionByName(alias)) {
- case TrFunctionAliasManager::Function_QT_TR_N_NOOP:
- definition += "(x)=QT_TR_N_NOOP(x)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_trUtf8:
- case TrFunctionAliasManager::Function_tr:
- definition += "=tr";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TR_NOOP:
- definition += "(x)=QT_TR_NOOP(x)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TR_NOOP_UTF8:
- definition += "(x)=QT_TR_NOOP_UTF8(x)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP:
- definition += "(scope,x)=QT_TRANSLATE_N_NOOP(scope,x)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP3:
- definition += "(scope, x, comment)=QT_TRANSLATE_N_NOOP3(scope, x, comment)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_translate:
- definition += "=QCoreApplication::translate";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_findMessage:
- definition += "=findMessage";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
- definition += "(scope,x)=QT_TRANSLATE_NOOP(scope,x)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
- definition += "(scope,x)=QT_TRANSLATE_NOOP_UTF8(scope,x)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
- definition += "(scope, x, comment)=QT_TRANSLATE_NOOP3(scope, x, comment)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
- definition += "(scope, x, comment)=QT_TRANSLATE_NOOP3_UTF8(scope, x, comment)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_qtTrId:
- definition += "=qtTrId";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_QT_TRID_N_NOOP:
- case TrFunctionAliasManager::Function_QT_TRID_NOOP:
- definition += "(id)=QT_TRID_NOOP(id)";
- results.push_back(definition);
- break;
- case TrFunctionAliasManager::Function_Q_DECLARE_TR_FUNCTIONS:
- definition += "(context)=Q_DECLARE_TR_FUNCTIONS(context)";
- results.push_back(definition);
- break;
- default:
- break;
- }
- }
- return results;
-}
-
-static std::vector<std::string> aliasDefinition;
-
-static clang::tooling::ArgumentsAdjuster getClangArgumentAdjuster()
-{
- const QByteArrayList compilerIncludeFlags = getIncludePathsFromCompiler();
- return [=](const clang::tooling::CommandLineArguments &args, llvm::StringRef /*unused*/) {
- clang::tooling::CommandLineArguments adjustedArgs(args);
- clang::tooling::CommandLineArguments adjustedArgsTemp;
-
- adjustedArgsTemp.push_back("-fparse-all-comments");
- adjustedArgsTemp.push_back("-nostdinc");
-
-#if defined(Q_PROCESSOR_X86) || defined(Q_OS_MACOS)
- // Turn off SSE support to avoid usage of gcc builtins.
- // TODO: Look into what Qt Creator does.
- // Pointers: HeaderPathFilter::removeGccInternalIncludePaths()
- // and gccInstallDir() in gcctoolchain.cpp
- // Also needed for Macs (and if libclang is built for X86)
- // No need for CLANG_RESOURCE_DIR when this is part of the argument.
- adjustedArgsTemp.push_back("-mno-sse");
-#endif
-
-#ifdef Q_OS_WIN
- adjustedArgsTemp.push_back("-fms-compatibility-version=19");
- adjustedArgsTemp.push_back("-DQ_COMPILER_UNIFORM_INIT"); // qtbase + clang-cl hack
- // avoid constexpr error connected with offsetof (QTBUG-97380)
- adjustedArgsTemp.push_back("-D_CRT_USE_BUILTIN_OFFSETOF");
-#endif
- adjustedArgsTemp.push_back("-Wno-everything");
-
- for (const QByteArray &flag : compilerIncludeFlags)
- adjustedArgsTemp.push_back(flag.data());
-
- for (auto alias : aliasDefinition) {
- adjustedArgsTemp.push_back(alias);
- }
-
- clang::tooling::CommandLineArguments::iterator it = llvm::find(adjustedArgs, "--");
- adjustedArgs.insert(it, adjustedArgsTemp.begin(), adjustedArgsTemp.end());
- return adjustedArgs;
- };
-}
-
-bool ClangCppParser::stringContainsTranslationInformation(llvm::StringRef ba)
-{
- // pre-process the files by a simple text search if there is any occurrence
- // of things we are interested in
- constexpr llvm::StringLiteral qDeclareTrFunction("Q_DECLARE_TR_FUNCTIONS(");
- constexpr llvm::StringLiteral qtTrNoop("QT_TR_NOOP(");
- constexpr llvm::StringLiteral qtTrNoopUTF8("QT_TR_NOOP)UTF8(");
- constexpr llvm::StringLiteral qtTrNNoop("QT_TR_N_NOOP(");
- constexpr llvm::StringLiteral qtTrIdNoop("QT_TRID_NOOP(");
- constexpr llvm::StringLiteral qtTrIdNNoop("QT_TRID_N_NOOP(");
- constexpr llvm::StringLiteral qtTranslateNoop("QT_TRANSLATE_NOOP(");
- constexpr llvm::StringLiteral qtTranslateNoopUTF8("QT_TRANSLATE_NOOP_UTF8(");
- constexpr llvm::StringLiteral qtTranslateNNoop("QT_TRANSLATE_N_NOOP(");
- constexpr llvm::StringLiteral qtTranslateNoop3("QT_TRANSLATE_NOOP3(");
- constexpr llvm::StringLiteral qtTranslateNoop3UTF8("QT_TRANSLATE_NOOP3_UTF8(");
- constexpr llvm::StringLiteral qtTranslateNNoop3("QT_TRANSLATE_N_NOOP3(");
- constexpr llvm::StringLiteral translatorComment("TRANSLATOR ");
- constexpr llvm::StringLiteral qtTrId("qtTrId(");
- constexpr llvm::StringLiteral tr("tr(");
- constexpr llvm::StringLiteral trUtf8("trUtf8(");
- constexpr llvm::StringLiteral translate("translate(");
-
- const size_t pos = ba.find_first_of("QT_TR");
- const auto baSliced = ba.slice(pos, llvm::StringRef::npos);
- if (pos != llvm::StringRef::npos) {
- if (baSliced.contains(qtTrNoop) || baSliced.contains(qtTrNoopUTF8) || baSliced.contains(qtTrNNoop)
- || baSliced.contains(qtTrIdNoop) || baSliced.contains(qtTrIdNNoop)
- || baSliced.contains(qtTranslateNoop) || baSliced.contains(qtTranslateNoopUTF8)
- || baSliced.contains(qtTranslateNNoop) || baSliced.contains(qtTranslateNoop3)
- || baSliced.contains(qtTranslateNoop3UTF8) || baSliced.contains(qtTranslateNNoop3))
- return true;
- }
-
- if (ba.contains(qDeclareTrFunction) || ba.contains(translatorComment) || ba.contains(qtTrId) || ba.contains(tr)
- || ba.contains(trUtf8) || ba.contains(translate))
- return true;
-
- for (QString alias : trFunctionAliasManager.listAliases()) {
- if (ba.contains(qPrintable(alias)))
- return true;
- }
-
-
- return false;
-}
-
-static bool generateCompilationDatabase(const QString &outputFilePath, const ConversionData &cd)
-{
- QJsonArray commandObjects;
- const QString buildDir = QDir::currentPath();
- const QString fakefileName = QLatin1String("dummmy.cpp");
- QJsonObject obj;
- obj[QLatin1String("file")] = fakefileName;
- obj[QLatin1String("directory")] = buildDir;
- QJsonArray args = {
- QLatin1String("clang++"),
- QLatin1String("-std=gnu++17"),
- #ifndef Q_OS_WIN
- QLatin1String("-fPIC"),
- #endif
- };
-
-#if defined(Q_OS_MACOS) && QT_CONFIG(framework)
- const QString installPath = QLibraryInfo::path(QLibraryInfo::LibrariesPath);
- QString arg = QLatin1String("-F") + installPath;
- args.push_back(arg);
-#endif
-
- for (const QString &path : cd.m_includePath) {
- QString arg = QLatin1String("-I") + path;
- args.push_back(std::move(arg));
- }
-
- obj[QLatin1String("arguments")] = args;
- commandObjects.append(obj);
-
- QJsonDocument doc(commandObjects);
- QFile file(outputFilePath);
- if (!file.open(QIODevice::WriteOnly))
- return false;
- file.write(doc.toJson());
- return true;
-}
-
-// Sort messages in such a way that they appear in the same order like in the given file list.
-static void sortMessagesByFileOrder(ClangCppParser::TranslatorMessageVector &messages,
- const QStringList &files)
-{
- // first sort messages by line number
- std::stable_sort(messages.begin(), messages.end(),
- [&](const TranslatorMessage &lhs, const TranslatorMessage &rhs) {
- auto i = lhs.lineNumber();
- auto k = rhs.lineNumber();
- return i < k;
- });
-
- QHash<QString, QStringList::size_type> indexByPath;
- for (const TranslatorMessage &m : messages)
- indexByPath[m.fileName()] = std::numeric_limits<QStringList::size_type>::max();
-
- for (QStringList::size_type i = 0; i < files.size(); ++i)
- indexByPath[files[i]] = i;
-
- std::stable_sort(messages.begin(), messages.end(),
- [&](const TranslatorMessage &lhs, const TranslatorMessage &rhs) {
- auto i = indexByPath.value(lhs.fileName());
- auto k = indexByPath.value(rhs.fileName());
- return i < k;
- });
-}
-
-bool ClangCppParser::hasAliases()
-{
- QStringList listAlias = trFunctionAliasManager.listAliases();
- if (listAlias.size() > 0)
- return true;
- return false;
-}
-
-void ClangCppParser::loadCPP(Translator &translator, const QStringList &files, ConversionData &cd,
- bool *fail)
-{
- FileSignificanceCheck::create();
- auto cleanup = qScopeGuard(FileSignificanceCheck::destroy);
- FileSignificanceCheck::the()->setExclusionRegExes(cd.m_excludes);
- if (cd.m_rootDirs.size() > 0)
- FileSignificanceCheck::the()->setRootDirectories(cd.m_rootDirs);
- else
- FileSignificanceCheck::the()->setRootDirectories(getProjectDirsFromEnvironment());
-
- if (hasAliases())
- aliasDefinition = getAliasFunctionDefinition();
-
- // pre-process the files by a simple text search if there is any occurrence
- // of things we are interested in
- qCDebug(lcClang) << "Load CPP \n";
- std::vector<std::string> sources;
- for (const QString &filename : files) {
- qCDebug(lcClang) << "File: " << filename << " \n";
- sources.emplace_back(filename.toStdString());
- }
-
- std::string errorMessage;
- std::unique_ptr<CompilationDatabase> db;
- if (cd.m_compilationDatabaseDir.isEmpty()) {
- db = CompilationDatabase::autoDetectFromDirectory(".", errorMessage);
- if (!db && !files.isEmpty()) {
- db = CompilationDatabase::autoDetectFromSource(files.first().toStdString(),
- errorMessage);
- }
- } else {
- db = CompilationDatabase::autoDetectFromDirectory(cd.m_compilationDatabaseDir.toStdString(),
- errorMessage);
- }
-
- if (!db) {
- const QString dbFilePath = QStringLiteral("compile_commands.json");
- qCDebug(lcClang) << "Generating compilation database" << dbFilePath;
- if (!generateCompilationDatabase(dbFilePath, cd)) {
- *fail = true;
- cd.appendError(u"Cannot generate compilation database."_s);
- return;
- }
- errorMessage.clear();
- db = CompilationDatabase::loadFromDirectory(".", errorMessage);
- }
-
- if (!db) {
- *fail = true;
- cd.appendError(QString::fromStdString(errorMessage));
- return;
- }
-
- TranslationStores ast, qdecl, qnoop;
- Stores stores(ast, qdecl, qnoop);
-
- std::vector<std::thread> producers;
- ReadSynchronizedRef<std::string> ppSources(sources);
- WriteSynchronizedRef<TranslationRelatedStore> ppStore(stores.Preprocessor);
- size_t idealProducerCount = std::min(ppSources.size(), size_t(std::thread::hardware_concurrency()));
- clang::tooling::ArgumentsAdjuster argumentsAdjusterSyntaxOnly =
- clang::tooling::getClangSyntaxOnlyAdjuster();
- clang::tooling::ArgumentsAdjuster argumentsAdjusterLocal = getClangArgumentAdjuster();
- clang::tooling::ArgumentsAdjuster argumentsAdjuster =
- clang::tooling::combineAdjusters(argumentsAdjusterLocal, argumentsAdjusterSyntaxOnly);
-
- for (size_t i = 0; i < idealProducerCount; ++i) {
- std::thread producer([&ppSources, &db, &ppStore, &argumentsAdjuster]() {
- std::string file;
- while (ppSources.next(&file)) {
- clang::tooling::ClangTool tool(*db, file);
- tool.appendArgumentsAdjuster(argumentsAdjuster);
- tool.run(new LupdatePreprocessorActionFactory(&ppStore));
- }
- });
- producers.emplace_back(std::move(producer));
- }
- for (auto &producer : producers)
- producer.join();
- producers.clear();
-
- ReadSynchronizedRef<std::string> astSources(sources);
- idealProducerCount = std::min(astSources.size(), size_t(std::thread::hardware_concurrency()));
- for (size_t i = 0; i < idealProducerCount; ++i) {
- std::thread producer([&astSources, &db, &stores, &argumentsAdjuster]() {
- std::string file;
- while (astSources.next(&file)) {
- clang::tooling::ClangTool tool(*db, file);
- tool.appendArgumentsAdjuster(argumentsAdjuster);
- tool.run(new LupdateToolActionFactory(&stores));
- }
- });
- producers.emplace_back(std::move(producer));
- }
- for (auto &producer : producers)
- producer.join();
- producers.clear();
-
- TranslationStores finalStores;
- WriteSynchronizedRef<TranslationRelatedStore> wsv(finalStores);
-
- ReadSynchronizedRef<TranslationRelatedStore> rsv(ast);
- ClangCppParser::correctAstTranslationContext(rsv, wsv, qdecl);
-
- ReadSynchronizedRef<TranslationRelatedStore> rsvQNoop(qnoop);
- //unlike ast translation context, qnoop context don't need to be corrected
- //(because Q_DECLARE_TR_FUNCTION context is already applied).
- ClangCppParser::finalize(rsvQNoop, wsv);
-
- TranslatorMessageVector messages;
- for (auto &store : finalStores)
- ClangCppParser::collectMessages(messages, store);
-
- sortMessagesByFileOrder(messages, files);
-
- for (TranslatorMessage &msg : messages) {
- if (!msg.warning().isEmpty()) {
- std::cerr << qPrintable(msg.warning());
- if (msg.warningOnly() == true)
- continue;
- }
- translator.extend(std::move(msg), cd);
- }
-}
-
-void ClangCppParser::collectMessages(TranslatorMessageVector &result,
- TranslationRelatedStore &store)
-{
- if (!store.isValid(true)) {
- if (store.lupdateWarning.isEmpty())
- return;
- // The message needs to be added to the results so that the warning can be ordered
- // and printed in a consistent way.
- // the message won't appear in the .ts file
- result.push_back(translatorMessage(store, store.lupdateIdMetaData, false, false, true));
- return;
- }
-
- qCDebug(lcClang) << "---------------------------------------------------------------Filling translator for " << store.funcName;
- qCDebug(lcClang) << " contextRetrieved " << store.contextRetrieved;
- qCDebug(lcClang) << " source " << store.lupdateSource;
-
- bool plural = false;
- switch (trFunctionAliasManager.trFunctionByName(store.funcName)) {
- // handle tr
- case TrFunctionAliasManager::Function_QT_TR_N_NOOP:
- plural = true;
- Q_FALLTHROUGH();
- case TrFunctionAliasManager::Function_tr:
- case TrFunctionAliasManager::Function_trUtf8:
- case TrFunctionAliasManager::Function_QT_TR_NOOP:
- case TrFunctionAliasManager::Function_QT_TR_NOOP_UTF8:
- if (!store.lupdateSourceWhenId.isEmpty()) {
- std::stringstream warning;
- warning << qPrintable(store.lupdateLocationFile) << ":"
- << store.lupdateLocationLine << ":"
- << store.locationCol << ": "
- << "//% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n";
- store.lupdateWarning.append(QString::fromStdString(warning.str()));
- qCDebug(lcClang) << "//% is ignored when using tr function\n";
- }
- if (store.contextRetrieved.isEmpty() && store.contextArg.isEmpty()) {
- std::stringstream warning;
- warning << qPrintable(store.lupdateLocationFile) << ":"
- << store.lupdateLocationLine << ":"
- << store.locationCol << ": "
- << qPrintable(store.funcName) << " cannot be called without context."
- << " The call is ignored (missing Q_OBJECT maybe?)\n";
- store.lupdateWarning.append(QString::fromStdString(warning.str()));
- qCDebug(lcClang) << "tr() cannot be called without context \n";
- // The message need to be added to the results so that the warning can be ordered
- // and printed in a consistent way.
- // the message won't appear in the .ts file
- result.push_back(translatorMessage(store, store.lupdateIdMetaData, plural, false, true));
- } else
- result.push_back(translatorMessage(store, store.lupdateIdMetaData, plural, false));
- break;
-
- // handle translate and findMessage
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP3:
- plural = true;
- Q_FALLTHROUGH();
- case TrFunctionAliasManager::Function_translate:
- case TrFunctionAliasManager::Function_findMessage:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
- if (!store.lupdateSourceWhenId.isEmpty()) {
- std::stringstream warning;
- warning << qPrintable(store.lupdateLocationFile) << ":"
- << store.lupdateLocationLine << ":"
- << store.locationCol << ": "
- << "//% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n";
- store.lupdateWarning.append(QString::fromStdString(warning.str()));
- qCDebug(lcClang) << "//% is ignored when using translate function\n";
- }
- result.push_back(translatorMessage(store, store.lupdateIdMetaData, plural, false));
- break;
-
- // handle qtTrId
- case TrFunctionAliasManager::Function_QT_TRID_N_NOOP:
- plural = true;
- Q_FALLTHROUGH();
- case TrFunctionAliasManager::Function_qtTrId:
- case TrFunctionAliasManager::Function_QT_TRID_NOOP:
- if (!store.lupdateIdMetaData.isEmpty()) {
- std::stringstream warning;
- warning << qPrintable(store.lupdateLocationFile) << ":"
- << store.lupdateLocationLine << ":"
- << store.locationCol << ": "
- << "//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n";
- store.lupdateWarning.append(QString::fromStdString(warning.str()));
- qCDebug(lcClang) << "//= is ignored when using qtTrId function \n";
- }
- result.push_back(translatorMessage(store, store.lupdateId, plural, true));
- break;
- default:
- if (store.funcName == QStringLiteral("TRANSLATOR"))
- result.push_back(translatorMessage(store, store.lupdateIdMetaData, plural, false));
- }
-}
-
-static QString ensureCanonicalPath(const QString &filePath)
-{
- QFileInfo fi(filePath);
- if (fi.isRelative())
- fi.setFile(QDir::current().absoluteFilePath(filePath));
- return fi.canonicalFilePath();
-}
-
-TranslatorMessage ClangCppParser::translatorMessage(const TranslationRelatedStore &store,
- const QString &id, bool plural, bool isId, bool isWarningOnly)
-{
- if (isWarningOnly) {
- TranslatorMessage msg;
- // msg filled with file name and line number should be enough for the message ordering
- msg.setFileName(ensureCanonicalPath(store.lupdateLocationFile));
- msg.setLineNumber(store.lupdateLocationLine);
- msg.setWarning(store.lupdateWarning);
- msg.setWarningOnly(isWarningOnly);
- return msg;
- }
-
- QString context;
- if (!isId) {
- context = ParserTool::transcode(store.contextArg.isEmpty() ? store.contextRetrieved
- : store.contextArg);
- }
-
- TranslatorMessage msg(context,
- ParserTool::transcode(isId ? store.lupdateSourceWhenId
- : store.lupdateSource),
- ParserTool::transcode(store.lupdateComment),
- QString(),
- ensureCanonicalPath(store.lupdateLocationFile),
- store.lupdateLocationLine,
- QStringList(),
- TranslatorMessage::Type::Unfinished,
- (plural ? plural : !store.lupdatePlural.isEmpty()));
-
- if (!store.lupdateAllMagicMetaData.empty())
- msg.setExtras(store.lupdateAllMagicMetaData);
- msg.setExtraComment(ParserTool::transcode(store.lupdateExtraComment));
- msg.setId(ParserTool::transcode(id));
- if (!store.lupdateWarning.isEmpty())
- msg.setWarning(store.lupdateWarning);
- return msg;
-}
-
-#define START_THREADS(RSV, WSV) \
- std::vector<std::thread> producers; \
- const size_t idealProducerCount = std::min(RSV.size(), size_t(std::thread::hardware_concurrency())); \
- \
- for (size_t i = 0; i < idealProducerCount; ++i) { \
- std::thread producer([&]() { \
- TranslationRelatedStore store; \
- while (RSV.next(&store)) { \
- if (!store.contextArg.isEmpty()) { \
- WSV.emplace_back(std::move(store)); \
- continue; \
- }
-
-#define JOIN_THREADS(WSV) \
- WSV.emplace_back(std::move(store)); \
- } \
- }); \
- producers.emplace_back(std::move(producer)); \
- } \
- \
- for (auto &producer : producers) \
- producer.join();
-
-void ClangCppParser::finalize(ReadSynchronizedRef<TranslationRelatedStore> &ast,
- WriteSynchronizedRef<TranslationRelatedStore> &newAst)
-{
- START_THREADS(ast, newAst)
- JOIN_THREADS(newAst)
-}
-
-void ClangCppParser::correctAstTranslationContext(ReadSynchronizedRef<TranslationRelatedStore> &ast,
- WriteSynchronizedRef<TranslationRelatedStore> &newAst, const TranslationStores &qDecl)
-{
- START_THREADS(ast, newAst)
-
- // If there is a Q_DECLARE_TR_FUNCTION the context given there takes
- // priority over the retrieved context. The retrieved context for
- // Q_DECLARE_TR_FUNCTION (where the macro was) has to fit the retrieved
- // context of the tr function if there is already a argument giving the
- // context, it has priority
- for (const auto &declareStore : qDecl) {
- qCDebug(lcClang) << "----------------------------";
- qCDebug(lcClang) << "Tr call context retrieved " << store.contextRetrieved;
- qCDebug(lcClang) << "Tr call source " << store.lupdateSource;
- qCDebug(lcClang) << "- DECLARE context retrieved " << declareStore.contextRetrieved;
- qCDebug(lcClang) << "- DECLARE context Arg " << declareStore.contextArg;
- if (declareStore.contextRetrieved.isEmpty())
- continue;
- if (!declareStore.contextRetrieved.startsWith(store.contextRetrieved))
- continue;
- if (store.contextRetrieved == declareStore.contextRetrieved) {
- qCDebug(lcClang) << "* Tr call context retrieved " << store.contextRetrieved;
- qCDebug(lcClang) << "* Tr call source " << store.lupdateSource;
- qCDebug(lcClang) << "* DECLARE context retrieved " << declareStore.contextRetrieved;
- qCDebug(lcClang) << "* DECLARE context Arg " << declareStore.contextArg;
- store.contextRetrieved = declareStore.contextArg;
- // store.contextArg should never be overwritten.
- break;
- }
- }
-
- JOIN_THREADS(newAst)
-}
-
-#undef START_THREADS
-#undef JOIN_THREADS
-
-QT_END_NAMESPACE
diff --git a/src/linguist/lupdate/cpp_clang.h b/src/linguist/lupdate/cpp_clang.h
deleted file mode 100644
index 12c6611..0000000
--- a/src/linguist/lupdate/cpp_clang.h
+++ /dev/null
@@ -1,303 +0,0 @@
-// Copyright (C) 2019 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef CLANG_CPP_H
-#define CLANG_CPP_H
-
-#include "lupdate.h"
-#include "synchronized.h"
-
-#include <QtCore/qloggingcategory.h>
-#include <QtCore/qregularexpression.h>
-#include <QtCore/qstring.h>
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_MSVC(4100)
-QT_WARNING_DISABLE_MSVC(4146)
-QT_WARNING_DISABLE_MSVC(4267)
-QT_WARNING_DISABLE_MSVC(4624)
-QT_WARNING_DISABLE_GCC("-Wnonnull")
-
-#include <llvm/ADT/StringRef.h>
-#include <clang/Basic/SourceLocation.h>
-#include <clang/Basic/SourceManager.h>
-#include <clang/Basic/FileManager.h>
-
-QT_WARNING_POP
-
-#include <vector>
-#include <iostream>
-#include <sstream>
-
-QT_BEGIN_NAMESPACE
-
-Q_DECLARE_LOGGING_CATEGORY(lcClang)
-
-inline QString toQt(llvm::StringRef str)
-{
- return QString::fromUtf8(str.data(), str.size());
-}
-
-#define LUPDATE_CLANG_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
-#define LUPDATE_CLANG_VERSION LUPDATE_CLANG_VERSION_CHECK(LUPDATE_CLANG_VERSION_MAJOR, \
- LUPDATE_CLANG_VERSION_MINOR, LUPDATE_CLANG_VERSION_PATCH)
-
-// Local storage of translation information (information from the AST and linguist side)
-struct TranslationRelatedStore
-{
- QString callType;
- QString rawCode;
- QString funcName;
- qint64 locationCol = -1;
- QString contextArg;
- QString contextRetrieved;
- QString lupdateSource;
- QString lupdateLocationFile;
- QString lupdateInputFile; // file associated to the running of the tool
- qint64 lupdateLocationLine = -1;
- QString lupdateId;
- QString lupdateSourceWhenId;
- QString lupdateIdMetaData;
- QString lupdateMagicMetaData;
- QHash<QString, QString> lupdateAllMagicMetaData;
- QString lupdateComment;
- QString lupdateExtraComment;
- QString lupdatePlural;
- QString lupdateWarning;
- clang::SourceLocation sourceLocation;
-
- bool isValid(bool printwarning = false)
- {
- switch (trFunctionAliasManager.trFunctionByName(funcName)) {
- // only one argument: the source
- case TrFunctionAliasManager::Function_Q_DECLARE_TR_FUNCTIONS:
- if (contextArg.isEmpty()) {
- if (printwarning) {
- std::stringstream warning;
- warning << qPrintable(lupdateLocationFile) << ":"
- << lupdateLocationLine << ":"
- << locationCol << ": "
- << " \'" << qPrintable(funcName)
- << "\' cannot be called without context."
- << " The call is ignored." <<std::endl;
- lupdateWarning.append(QString::fromStdString(warning.str()));
- }
- return false;
- }
- break;
- case TrFunctionAliasManager::Function_tr:
- case TrFunctionAliasManager::Function_trUtf8:
- break;
- // two arguments: the context and the source
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP3:
- case TrFunctionAliasManager::Function_translate:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
- if (contextArg.isEmpty()) {
- if (printwarning) {
- std::stringstream warning;
- warning << qPrintable(lupdateLocationFile) << ":"
- << lupdateLocationLine << ":"
- << locationCol << ": "
- << " \'" << qPrintable(funcName)
- << "\' cannot be called without context."
- << " The call is ignored." << std::endl;
- lupdateWarning.append(QString::fromStdString(warning.str()));
- }
- return false;
- }
- // not sure if the third argument is compulsory
- break;
- // only one argument (?) the message Id
- case TrFunctionAliasManager::Function_QT_TRID_N_NOOP:
- case TrFunctionAliasManager::Function_qtTrId:
- case TrFunctionAliasManager::Function_QT_TRID_NOOP:
- if (lupdateId.isEmpty()) {
- if (printwarning) {
- std::stringstream warning;
- warning << qPrintable(lupdateLocationFile) << ":"
- << lupdateLocationLine << ":"
- << locationCol << ": "
- << " \'" << qPrintable(funcName)
- << "\' cannot be called without Id."
- << " The call is ignored." << std::endl;
- lupdateWarning.append(QString::fromStdString(warning.str()));
- }
- return false;
- }
- break;
- default:
- if (funcName == QStringLiteral("TRANSLATOR") && lupdateComment.isEmpty()) {
- if (printwarning) {
- std::stringstream warning;
- warning << qPrintable(lupdateLocationFile) << ":"
- << lupdateLocationLine << ":"
- << locationCol << ": "
- << qPrintable(funcName)
- << " cannot be called without comment."
- << " The call is ignored." << std::endl;
- lupdateWarning.append(QString::fromStdString(warning.str()));
- }
- return false;
- }
- }
- 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";
- qCDebug(lcClang)
- << "callType : " << callType << "\n"
- << "rawCode : \n" << rawCode << "\n"
- << "funcName : " << funcName << "\n"
- << "LocationCol : " << locationCol << "\n"
- << "contextArg : " << contextArg << "\n"
- << "contextRetrieved : " << contextRetrieved << "\n"
- << "lupdateSource : " << lupdateSource << "\n"
- << "lupdateLocationFile : " << lupdateLocationFile << "\n"
- << "lupdateLocationLine : " << lupdateLocationLine << "\n"
- << "lupdateId : " << lupdateId << "\n"
- << "lupdateIdMetaData : " << lupdateIdMetaData << "\n"
- << "lupdateMagicMetaData: " << lupdateMagicMetaData << "\n"
- << "lupdateComment : " << lupdateComment << "\n"
- << "lupdateExtraComment : " << lupdateExtraComment << "\n"
- << "lupdatePlural : " << lupdatePlural;
- qCDebug(lcClang) << "-------------------------------------------------------------------\n";
- }
-};
-using TranslationStores = std::vector<TranslationRelatedStore>;
-
-struct Stores
-{
- Stores(TranslationStores &a, TranslationStores &qd, TranslationStores &qn)
- : AST(a)
- , QDeclareTrWithContext(qd)
- , QNoopTranlsationWithContext(qn)
- {}
-
- TranslationStores Preprocessor;
- WriteSynchronizedRef<TranslationRelatedStore> AST;
- WriteSynchronizedRef<TranslationRelatedStore> QDeclareTrWithContext;
- WriteSynchronizedRef<TranslationRelatedStore> QNoopTranlsationWithContext; // or with warnings that need to be
- //displayed in the same order, always
-};
-
-namespace LupdatePrivate
-{
- inline QString fixedLineEndings(const QString &s)
- {
-#ifdef Q_OS_WIN
- QString result = s;
- result.replace(QLatin1String("\r\n"), QLatin1String("\n"));
- return result;
-#else
- return s;
-#endif
- }
-
- enum QuoteCompulsary
- {
- None = 0x01,
- Left = 0x02, // Left quote is mandatory
- Right = 0x04, // Right quote is mandatory
- LeftAndRight = Left | Right // Both quotes are mandatory
- };
-
- /*
- Removes the quotes around the lupdate extra, ID meta data, magic and
- ID prefix comments and source string literals.
- Depending on the given compulsory option, quotes can be unbalanced and
- still some text is returned. This is to mimic the old lupdate behavior.
- */
- inline QString cleanQuote(llvm::StringRef s, QuoteCompulsary quote)
- {
- if (s.empty())
- return {};
- s = s.trim();
- if (!s.consume_front("\"") && ((quote & Left) != 0))
- return {};
- if (!s.consume_back("\"") && ((quote & Right) != 0))
- return {};
- return fixedLineEndings(toQt(s));
- }
-
- /*
- Removes the quotes and a possible existing string literal prefix
- for a given string literal coming from the source code. Do not use
- to clean the quotes around the lupdate translator specific comments.
- */
- inline QString cleanQuote(const std::string &token)
- {
- if (token.empty())
- return {};
-
- const QString string = fixedLineEndings(QString::fromStdString(token).trimmed());
- const int index = string.indexOf(QLatin1Char('"'));
- if (index <= 0)
- return LupdatePrivate::cleanQuote(token, QuoteCompulsary::LeftAndRight);
-
- QRegularExpressionMatch result;
- if (string.at(index - 1) == QLatin1Char('R')) {
- static const QRegularExpression rawStringLiteral {
- QStringLiteral(
- "(?:\\bu8|\\b[LuU])??R\\\"([^\\(\\)\\\\ ]{0,16})\\((?<characters>.*)\\)\\1\\\""
- ), QRegularExpression::DotMatchesEverythingOption };
- result = rawStringLiteral.match(string);
- } else {
- static const QRegularExpression stringLiteral {
- QStringLiteral(
- "(?:\\bu8|\\b[LuU])+?\\\"(?<characters>[^\\\"\\\\]*(?:\\\\.[^\\\"\\\\]*)*)\\\""
- )
- };
- result = stringLiteral.match(string);
- }
- if (result.hasMatch())
- return result.captured(QStringLiteral("characters"));
- return string;
- }
-}
-
-namespace ClangCppParser
-{
- void loadCPP(Translator &translator, const QStringList &filenames, ConversionData &cd,
- bool *fail);
-
- using TranslatorMessageVector = std::vector<TranslatorMessage>;
- void collectMessages(TranslatorMessageVector &result, TranslationRelatedStore &store);
- TranslatorMessage translatorMessage(const TranslationRelatedStore &store,
- const QString &id, bool plural, bool isID, bool isWarningOnly = false);
-
- void correctAstTranslationContext(ReadSynchronizedRef<TranslationRelatedStore> &ast,
- WriteSynchronizedRef<TranslationRelatedStore> &newAst, const TranslationStores &qDecl);
- void finalize(ReadSynchronizedRef<TranslationRelatedStore> &ast,
- WriteSynchronizedRef<TranslationRelatedStore> &newAst);
-
- bool stringContainsTranslationInformation(llvm::StringRef ba);
- bool hasAliases();
- std::vector<std::string> getAliasFunctionDefinition();
-
-}
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/linguist/lupdate/filesignificancecheck.cpp b/src/linguist/lupdate/filesignificancecheck.cpp
deleted file mode 100644
index 65ae303..0000000
--- a/src/linguist/lupdate/filesignificancecheck.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "filesignificancecheck.h"
-
-QT_BEGIN_NAMESPACE
-
-FileSignificanceCheck *FileSignificanceCheck::m_instance = nullptr;
-
-void FileSignificanceCheck::setRootDirectories(const QStringList &paths)
-{
- const size_t pathsSize = static_cast<size_t>(paths.size());
- m_rootDirs.resize(pathsSize);
- for (size_t i = 0; i < pathsSize; ++i)
- m_rootDirs[i].setPath(paths.at(i));
-}
-
-void FileSignificanceCheck::setExclusionRegExes(const QVector<QRegularExpression> &expressions)
-{
- m_exclusionRegExes = expressions;
-}
-
-/*
- * Return true if the given source file is significant for lupdate.
- * A file is considered insignificant if
- * - it's not within any project root
- * - it's excluded
- *
- * This method is called from multiple threads.
- * Results are cached.
- */
-bool FileSignificanceCheck::isFileSignificant(const std::string &filePath) const
-{
- // cache lookup
- {
- QReadLocker locker(&m_cacheLock);
- auto it = m_cache.find(filePath);
- if (it != m_cache.end())
- return it->second;
- }
-
- // cache miss
- QWriteLocker locker(&m_cacheLock);
- QString file = QString::fromUtf8(filePath);
- QString cleanFile = QDir::cleanPath(file);
- for (const QRegularExpression &rx : m_exclusionRegExes) {
- if (rx.match(cleanFile).hasMatch()) {
- m_cache.insert({filePath, false});
- return false;
- }
- }
-
- for (const QDir &rootDir : m_rootDirs) {
- QString relativeFilePath = rootDir.relativeFilePath(file);
- if (!relativeFilePath.startsWith(QLatin1String("../"))
- && QFileInfo(relativeFilePath).isRelative()) {
- m_cache.insert({filePath, true});
- return true;
- }
- }
-
- m_cache.insert({filePath, false});
- return false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/linguist/lupdate/filesignificancecheck.h b/src/linguist/lupdate/filesignificancecheck.h
deleted file mode 100644
index 6f6590b..0000000
--- a/src/linguist/lupdate/filesignificancecheck.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef FILESIGNIFICANCECHECK_H
-#define FILESIGNIFICANCECHECK_H
-
-#include <QtCore/qdir.h>
-#include <QtCore/qreadwritelock.h>
-#include <QtCore/qregularexpression.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qvector.h>
-
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-QT_BEGIN_NAMESPACE
-
-class FileSignificanceCheck
-{
-public:
- FileSignificanceCheck() = default;
-
- static void create()
- {
- m_instance = new FileSignificanceCheck;
- }
-
- static void destroy()
- {
- delete m_instance;
- m_instance = nullptr;
- }
-
- static FileSignificanceCheck *the()
- {
- return m_instance;
- }
-
- void setRootDirectories(const QStringList &paths);
- void setExclusionRegExes(const QVector<QRegularExpression> &expressions);
-
- bool isFileSignificant(const std::string &filePath) const;
-
-private:
- static FileSignificanceCheck *m_instance;
- std::vector<QDir> m_rootDirs;
- QVector<QRegularExpression> m_exclusionRegExes;
- mutable std::unordered_map<std::string, bool> m_cache;
- mutable QReadWriteLock m_cacheLock;
-};
-
-namespace LupdatePrivate {
-
-inline bool isFileSignificant(const std::string &filePath)
-{
- return FileSignificanceCheck::the()->isFileSignificant(filePath);
-}
-
-} // namespace LupdatePrivate
-
-QT_END_NAMESPACE
-
-#endif // header guard
diff --git a/src/linguist/lupdate/lupdatepreprocessoraction.cpp b/src/linguist/lupdate/lupdatepreprocessoraction.cpp
deleted file mode 100644
index 4d5b9a3..0000000
--- a/src/linguist/lupdate/lupdatepreprocessoraction.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-// 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>
-
-QT_BEGIN_NAMESPACE
-
-void LupdatePPCallbacks::MacroExpands(const clang::Token &token,
- const clang::MacroDefinition ¯oDefinition, clang::SourceRange sourceRange,
- const clang::MacroArgs *macroArgs)
-{
- Q_UNUSED(macroDefinition);
-
- const auto &sm = m_preprocessor.getSourceManager();
- llvm::StringRef fileName = sm.getFilename(sourceRange.getBegin());
- if (!LupdatePrivate::isFileSignificant(fileName.str()))
- return;
-
- const QString funcName = QString::fromStdString(m_preprocessor.getSpelling(token));
- switch (trFunctionAliasManager.trFunctionByName(funcName)) {
- default:
- return;
- case TrFunctionAliasManager::Function_Q_DECLARE_TR_FUNCTIONS:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP3:
- case TrFunctionAliasManager::Function_QT_TRID_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
- 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;
- }
-
- TranslationRelatedStore store;
- store.callType = QStringLiteral("MacroExpands");
- store.funcName = funcName;
- store.lupdateLocationFile = toQt(fileName);
- store.lupdateInputFile = toQt(m_inputFile);
- store.lupdateLocationLine = sm.getExpansionLineNumber(sourceRange.getBegin());
- store.locationCol = sm.getExpansionColumnNumber(sourceRange.getBegin());
-
- if (macroArgs) {
- std::vector<QString> arguments(macroArgs->getNumMacroArguments());
- for (unsigned i = 0; i < macroArgs->getNumMacroArguments(); i++) {
- auto preExpArguments = const_cast<clang::MacroArgs*>(macroArgs)->getPreExpArgument(i,
- m_preprocessor);
- QString temp;
- bool errorArgument = false;
- for (const auto &preExpArgument : preExpArguments) {
- const auto kind = preExpArgument.getKind();
- switch (trFunctionAliasManager.trFunctionByName(funcName)) {
- default:
- break;
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_N_NOOP3:
- case TrFunctionAliasManager::Function_QT_TRID_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
- 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;
- }
- if (errorArgument)
- break;
- if (clang::tok::isStringLiteral(kind))
- temp += LupdatePrivate::cleanQuote(m_preprocessor.getSpelling(preExpArgument));
- else
- temp += QString::fromStdString(m_preprocessor.getSpelling(preExpArgument));
- }
- arguments[i] = temp;
- qCDebug(lcClang) << "*********** macro argument : " << temp;
- }
- storeMacroArguments(arguments, &store);
- }
- if (store.isValid())
- m_ppStores.emplace_back(std::move(store));
-}
-
-void LupdatePPCallbacks::storeMacroArguments(const std::vector<QString> &args,
- TranslationRelatedStore *store)
-{
- switch (trFunctionAliasManager.trFunctionByName(store->funcName)) {
- // only one argument: the context with no "
- case TrFunctionAliasManager::Function_Q_DECLARE_TR_FUNCTIONS:
- if (args.size() == 1)
- store->contextArg = args[0];
- break;
- 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:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP_UTF8:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3:
- case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP3_UTF8:
- if (args.size() >= 2) {
- store->contextArg = args[0];
- store->lupdateSource = args[1];
- }
- if (args.size() == 3)
- store->lupdateComment = args[2];
- break;
- // only one argument (?) the message Id
- case TrFunctionAliasManager::Function_QT_TRID_N_NOOP:
- case TrFunctionAliasManager::Function_qtTrId:
- case TrFunctionAliasManager::Function_QT_TRID_NOOP:
- if (args.size() == 1)
- store->lupdateId = args[0];
- break;
- }
-}
-
-// Hook called when a source range is skipped.
-// Emit a warning if translation information is found within this range.
-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 (!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::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("%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
diff --git a/src/linguist/lupdate/lupdatepreprocessoraction.h b/src/linguist/lupdate/lupdatepreprocessoraction.h
deleted file mode 100644
index f373248..0000000
--- a/src/linguist/lupdate/lupdatepreprocessoraction.h
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#ifndef LUPDATEPREPROCESSORACTION_H
-#define LUPDATEPREPROCESSORACTION_H
-
-#include "cpp_clang.h"
-#include "synchronized.h"
-
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_MSVC(4100)
-QT_WARNING_DISABLE_MSVC(4146)
-QT_WARNING_DISABLE_MSVC(4267)
-QT_WARNING_DISABLE_MSVC(4624)
-QT_WARNING_DISABLE_GCC("-Wnonnull")
-
-#include <clang/Frontend/CompilerInstance.h>
-#include <clang/Frontend/FrontendActions.h>
-#include <clang/Tooling/Tooling.h>
-#include <clang/Lex/PPCallbacks.h>
-#include <clang/Lex/Preprocessor.h>
-
-QT_WARNING_POP
-
-#include <memory>
-
-QT_BEGIN_NAMESPACE
-
-class LupdatePPCallbacks : public clang::PPCallbacks
-{
-public:
- LupdatePPCallbacks(WriteSynchronizedRef<TranslationRelatedStore> *stores, clang::Preprocessor &pp)
- : m_preprocessor(pp)
- , m_stores(stores)
- {
- const auto &sm = m_preprocessor.getSourceManager();
- m_inputFile = sm.getFileEntryRefForID(sm.getMainFileID())->getName();
- }
-
- ~LupdatePPCallbacks() override
- {
- m_stores->emplace_bulk(std::move(m_ppStores));
- }
-
-private:
- void MacroExpands(const clang::Token &token, const clang::MacroDefinition ¯oDefinition,
- clang::SourceRange sourceRange, const clang::MacroArgs *macroArgs) override;
-
- void storeMacroArguments(const std::vector<QString> &args, TranslationRelatedStore *store);
-
- void SourceRangeSkipped(clang::SourceRange sourceRange, clang::SourceLocation endifLoc) override;
-#if (LUPDATE_CLANG_VERSION < LUPDATE_CLANG_VERSION_CHECK(14,0,0))
- void 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*/) override;
-#endif
-
- std::string m_inputFile;
- clang::Preprocessor &m_preprocessor;
-
- TranslationStores m_ppStores;
- WriteSynchronizedRef<TranslationRelatedStore> *m_stores { nullptr };
-};
-
-class LupdatePreprocessorAction : public clang::PreprocessOnlyAction
-{
-public:
- LupdatePreprocessorAction(WriteSynchronizedRef<TranslationRelatedStore> *stores)
- : m_stores(stores)
- {}
-
-private:
- void ExecuteAction() override
- {
- auto &preprocessor = getCompilerInstance().getPreprocessor();
- preprocessor.SetSuppressIncludeNotFoundError(true);
- auto callbacks = new LupdatePPCallbacks(m_stores, preprocessor);
- preprocessor.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(callbacks));
-
- clang::PreprocessOnlyAction::ExecuteAction();
- }
-
-private:
- WriteSynchronizedRef<TranslationRelatedStore> *m_stores { nullptr };
-};
-
-class LupdatePreprocessorActionFactory : public clang::tooling::FrontendActionFactory
-{
-public:
- explicit LupdatePreprocessorActionFactory(WriteSynchronizedRef<TranslationRelatedStore> *stores)
- : m_stores(stores)
- {}
-
-#if (LUPDATE_CLANG_VERSION >= LUPDATE_CLANG_VERSION_CHECK(10,0,0))
- std::unique_ptr<clang::FrontendAction> create() override
- {
- return std::make_unique<LupdatePreprocessorAction>(m_stores);
- }
-#else
- clang::FrontendAction *create() override
- {
- return new LupdatePreprocessorAction(m_stores);
- }
-#endif
-
-private:
- WriteSynchronizedRef<TranslationRelatedStore> *m_stores { nullptr };
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/linguist/lupdate/main.cpp b/src/linguist/lupdate/main.cpp
index 881f23b..633ba47 100644
--- a/src/linguist/lupdate/main.cpp
+++ b/src/linguist/lupdate/main.cpp
@@ -3,9 +3,6 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "lupdate.h"
-#if QT_CONFIG(clangcpp)
-#include "cpp_clang.h"
-#endif
#include <profileutils.h>
#include <projectdescriptionreader.h>
@@ -27,9 +24,8 @@
using namespace Qt::StringLiterals;
-bool useClangToParseCpp = false;
QString commandLineCompilationDatabaseDir; // for the path to the json file passed as a command line argument.
- // Has priority over what is in the .pro file and passed to the project.
+ // Has priority over what is in the .pro file and passed to the project.
QStringList rootDirs;
// Can't have an array of QStaticStringData<N> for different N, so
@@ -48,7 +44,7 @@ static const QString defaultTrFunctionNames[] = {
};
Q_STATIC_ASSERT((TrFunctionAliasManager::NumTrFunctions == sizeof defaultTrFunctionNames / sizeof *defaultTrFunctionNames));
-static int trFunctionByDefaultName(const QString &trFunctionName)
+static int trFunctionByDefaultName(const QString& trFunctionName)
{
for (int i = 0; i < TrFunctionAliasManager::NumTrFunctions; ++i)
if (trFunctionName == defaultTrFunctionNames[i])
@@ -63,9 +59,9 @@ TrFunctionAliasManager::TrFunctionAliasManager()
m_trFunctionAliases[i].push_back(defaultTrFunctionNames[i]);
}
-TrFunctionAliasManager::~TrFunctionAliasManager() {}
+TrFunctionAliasManager::~TrFunctionAliasManager() { }
-int TrFunctionAliasManager::trFunctionByName(const QString &trFunctionName) const
+int TrFunctionAliasManager::trFunctionByName(const QString& trFunctionName) const
{
ensureTrFunctionHashUpdated();
// this function needs to be fast
@@ -73,9 +69,9 @@ int TrFunctionAliasManager::trFunctionByName(const QString &trFunctionName) cons
return it == m_nameToTrFunctionMap.cend() ? -1 : *it;
}
-void TrFunctionAliasManager::modifyAlias(int trFunction, const QString &alias, Operation op)
+void TrFunctionAliasManager::modifyAlias(int trFunction, const QString& alias, Operation op)
{
- QList<QString> &list = m_trFunctionAliases[trFunction];
+ QList<QString>& list = m_trFunctionAliases[trFunction];
if (op == SetAlias)
list.clear();
list.push_back(alias);
@@ -89,13 +85,13 @@ void TrFunctionAliasManager::ensureTrFunctionHashUpdated() const
NameToTrFunctionMap nameToTrFunctionMap;
for (int i = 0; i < NumTrFunctions; ++i)
- for (const QString &alias : m_trFunctionAliases[i])
+ for (const QString& alias : m_trFunctionAliases[i])
nameToTrFunctionMap[alias] = TrFunction(i);
// commit:
m_nameToTrFunctionMap.swap(nameToTrFunctionMap);
}
-const TrFunctionAliasManager::NameToTrFunctionMap &TrFunctionAliasManager::nameToTrFunctionMap() const
+const TrFunctionAliasManager::NameToTrFunctionMap& TrFunctionAliasManager::nameToTrFunctionMap() const
{
ensureTrFunctionHashUpdated();
return m_nameToTrFunctionMap;
@@ -115,10 +111,7 @@ QStringList TrFunctionAliasManager::availableFunctionsWithAliases() const
QStringList result;
result.reserve(NumTrFunctions);
for (int i = 0; i < NumTrFunctions; ++i)
- result.push_back(defaultTrFunctionNames[i] +
- QLatin1String(" (=") +
- m_trFunctionAliases[i].join(QLatin1Char('=')) +
- QLatin1Char(')'));
+ result.push_back(defaultTrFunctionNames[i] + QLatin1String(" (=") + m_trFunctionAliases[i].join(QLatin1Char('=')) + QLatin1Char(')'));
return result;
}
@@ -127,7 +120,7 @@ QStringList TrFunctionAliasManager::listAliases() const
QStringList result;
result.reserve(NumTrFunctions);
for (int i = 0; i < NumTrFunctions; ++i) {
- for (int ii = 1; ii < m_trFunctionAliases[i].size() ; ii++) {
+ for (int ii = 1; ii < m_trFunctionAliases[i].size(); ii++) {
// ii = 0 is the default name. Not listed here
result.push_back(m_trFunctionAliases[i][ii]);
}
@@ -137,7 +130,7 @@ QStringList TrFunctionAliasManager::listAliases() const
TrFunctionAliasManager trFunctionAliasManager;
-QString ParserTool::transcode(const QString &str)
+QString ParserTool::transcode(const QString& str)
{
static const char tab[] = "abfnrtv";
static const char backTab[] = "\a\b\f\n\r\t\v";
@@ -185,7 +178,7 @@ QString ParserTool::transcode(const QString &str)
}
out += oct.toUInt(0, 8);
} else {
- const char *p = strchr(tab, c);
+ const char* p = strchr(tab, c);
out += !p ? c : backTab[p - tab];
}
} else {
@@ -197,20 +190,20 @@ QString ParserTool::transcode(const QString &str)
static QString m_defaultExtensions;
-static void printOut(const QString & out)
+static void printOut(const QString& out)
{
std::cout << qPrintable(out);
}
-static void printErr(const QString & out)
+static void printErr(const QString& out)
{
std::cerr << qPrintable(out);
}
static void printWarning(UpdateOptions options,
- const QString &msg,
- const QString &warningMsg = {},
- const QString &errorMsg = {})
+ const QString& msg,
+ const QString& warningMsg = {},
+ const QString& errorMsg = {})
{
QString text = msg;
if (options & Werror) {
@@ -226,11 +219,11 @@ static void printWarning(UpdateOptions options,
printErr(text);
}
-static void recursiveFileInfoList(const QDir &dir,
- const QSet<QString> &nameFilters, QDir::Filters filter,
- QFileInfoList *fileinfolist)
+static void recursiveFileInfoList(const QDir& dir,
+ const QSet<QString>& nameFilters, QDir::Filters filter,
+ QFileInfoList* fileinfolist)
{
- for (const QFileInfo &fi : dir.entryInfoList(filter))
+ for (const QFileInfo& fi : dir.entryInfoList(filter))
if (fi.isDir())
recursiveFileInfoList(QDir(fi.absoluteFilePath()), nameFilters, filter, fileinfolist);
else if (nameFilters.contains(fi.suffix()))
@@ -311,74 +304,60 @@ static void printUsage()
" Specify the output file(s). This will override the TRANSLATIONS.\n"
" -version\n"
" Display the version of lupdate and exit.\n"
- " -clang-parser [compilation-database-dir]\n"
- " Use clang to parse cpp files. Otherwise a custom parser is used.\n"
- " This option needs a clang compilation database (compile_commands.json)\n"
- " for the files that needs to be parsed.\n"
- " The path to the directory containing this file can be specified on the \n"
- " command line, directly after the -clang-parser option, or in the .pro file\n"
- " by setting the variable LUPDATE_COMPILE_COMMANDS_PATH.\n"
- " A directory specified on the command line takes precedence.\n"
- " If no path is given, the compilation database will be searched\n"
- " in all parent paths of the first input file.\n"
- " -project-roots <directory>...\n"
- " Specify one or more project root directories.\n"
- " Only files below a project root are considered for translation when using\n"
- " the -clang-parser option.\n"
" @lst-file\n"
" Read additional file names (one per line) or includepaths (one per\n"
- " line, and prefixed with -I) from lst-file.\n"
- ).arg(m_defaultExtensions,
- trFunctionAliasManager.availableFunctionsWithAliases()
- .join(QLatin1String("\n "))));
+ " line, and prefixed with -I) from lst-file.\n")
+ .arg(m_defaultExtensions,
+ trFunctionAliasManager.availableFunctionsWithAliases()
+ .join(QLatin1String("\n "))));
}
-static bool handleTrFunctionAliases(const QString &arg)
+static bool handleTrFunctionAliases(const QString& arg)
{
- for (const QString &pair : arg.split(QLatin1Char(','), Qt::SkipEmptyParts)) {
+ for (const QString& pair : arg.split(QLatin1Char(','), Qt::SkipEmptyParts)) {
const int equalSign = pair.indexOf(QLatin1Char('='));
if (equalSign < 0) {
printErr(QStringLiteral("tr-function mapping '%1' in -tr-function-alias is missing the '='.\n").arg(pair));
return false;
}
- const bool plusEqual = equalSign > 0 && pair[equalSign-1] == QLatin1Char('+');
- const int trFunctionEnd = plusEqual ? equalSign-1 : equalSign;
+ const bool plusEqual = equalSign > 0 && pair[equalSign - 1] == QLatin1Char('+');
+ const int trFunctionEnd = plusEqual ? equalSign - 1 : equalSign;
const QString trFunctionName = pair.left(trFunctionEnd).trimmed();
- const QString alias = pair.mid(equalSign+1).trimmed();
+ const QString alias = pair.mid(equalSign + 1).trimmed();
const int trFunction = trFunctionByDefaultName(trFunctionName);
if (trFunction < 0) {
printErr(QStringLiteral("Unknown tr-function '%1' in -tr-function-alias option.\n"
- "Available tr-functions are: %2")
- .arg(trFunctionName, availableFunctions().join(QLatin1Char(','))));
+ "Available tr-functions are: %2")
+ .arg(trFunctionName, availableFunctions().join(QLatin1Char(','))));
return false;
}
if (alias.isEmpty()) {
printErr(QStringLiteral("Empty alias for tr-function '%1' in -tr-function-alias option.\n")
- .arg(trFunctionName));
+ .arg(trFunctionName));
return false;
}
trFunctionAliasManager.modifyAlias(trFunction, alias,
- plusEqual ? TrFunctionAliasManager::AddAlias : TrFunctionAliasManager::SetAlias);
+ plusEqual ? TrFunctionAliasManager::AddAlias : TrFunctionAliasManager::SetAlias);
}
return true;
}
-static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFileNames,
- const QStringList &alienFiles,
- const QString &sourceLanguage, const QString &targetLanguage,
- UpdateOptions options, bool *fail)
+static void updateTsFiles(const Translator& fetchedTor, const QStringList& tsFileNames,
+ const QStringList& alienFiles,
+ const QString& sourceLanguage, const QString& targetLanguage,
+ UpdateOptions options, bool* fail)
{
for (int i = 0; i < fetchedTor.messageCount(); i++) {
- const TranslatorMessage &msg = fetchedTor.constMessage(i);
+ const TranslatorMessage& msg = fetchedTor.constMessage(i);
if (!msg.id().isEmpty() && msg.sourceText().isEmpty()) {
printWarning(options,
- "Message with id '%1' has no source.\n"_L1.arg(msg.id()));
+ "Message with id '%1' has no source.\n"_L1.arg(msg.id()));
if (options & Werror)
return;
}
}
QList<Translator> aliens;
- for (const QString &fileName : alienFiles) {
+ for (const QString& fileName : alienFiles) {
ConversionData cd;
Translator tor;
if (!tor.load(fileName, cd, QLatin1String("auto"))) {
@@ -391,7 +370,7 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
}
QDir dir;
QString err;
- for (const QString &fileName : tsFileNames) {
+ for (const QString& fileName : tsFileNames) {
QString fn = dir.relativeFilePath(fileName);
ConversionData cd;
Translator tor;
@@ -406,19 +385,19 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
cd.clearErrors();
if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode()) {
printWarning(options,
- "Specified target language '%1' disagrees with"
- " existing file's language '%2'.\n"_L1
- .arg(targetLanguage, tor.languageCode()),
- u"Ignoring.\n"_s);
+ "Specified target language '%1' disagrees with"
+ " existing file's language '%2'.\n"_L1
+ .arg(targetLanguage, tor.languageCode()),
+ u"Ignoring.\n"_s);
if (options & Werror)
return;
}
if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode()) {
printWarning(options,
- "Specified source language '%1' disagrees with"
- " existing file's language '%2'.\n"_L1
- .arg(sourceLanguage, tor.sourceLanguageCode()),
- u"Ignoring.\n"_s);
+ "Specified source language '%1' disagrees with"
+ " existing file's language '%2'.\n"_L1
+ .arg(sourceLanguage, tor.sourceLanguageCode()),
+ u"Ignoring.\n"_s);
if (options & Werror)
return;
}
@@ -438,7 +417,8 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
QStringList forms;
if (!getNumerusInfo(l, c, 0, &forms, 0)) {
printErr(QStringLiteral("File %1 won't be updated: it contains translation but the"
- " target language is not recognized\n").arg(fileName));
+ " target language is not recognized\n")
+ .arg(fileName));
continue;
}
}
@@ -490,7 +470,7 @@ static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFil
}
}
-static bool readFileContent(const QString &filePath, QByteArray *content, QString *errorString)
+static bool readFileContent(const QString& filePath, QByteArray* content, QString* errorString)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
@@ -501,7 +481,7 @@ static bool readFileContent(const QString &filePath, QByteArray *content, QStrin
return true;
}
-static bool readFileContent(const QString &filePath, QString *content, QString *errorString)
+static bool readFileContent(const QString& filePath, QString* content, QString* errorString)
{
QByteArray ba;
if (!readFileContent(filePath, &ba, errorString))
@@ -510,11 +490,11 @@ static bool readFileContent(const QString &filePath, QString *content, QString *
return true;
}
-static void removeExcludedSources(Projects &projects)
+static void removeExcludedSources(Projects& projects)
{
- for (Project &project : projects) {
- for (const QRegularExpression &rx : project.excluded) {
- for (auto it = project.sources.begin(); it != project.sources.end(); ) {
+ for (Project& project : projects) {
+ for (const QRegularExpression& rx : project.excluded) {
+ for (auto it = project.sources.begin(); it != project.sources.end();) {
if (rx.match(*it).hasMatch())
it = project.sources.erase(it);
else
@@ -525,7 +505,7 @@ static void removeExcludedSources(Projects &projects)
}
}
-static QStringList getResources(const QString &resourceFile)
+static QStringList getResources(const QString& resourceFile)
{
if (!QFile::exists(resourceFile))
return QStringList();
@@ -538,13 +518,13 @@ static QStringList getResources(const QString &resourceFile)
ReadQrcResult rqr = readQrcFile(resourceFile, content);
if (rqr.hasError()) {
printErr(QStringLiteral("lupdate error: %1:%2: %3\n")
- .arg(resourceFile, QString::number(rqr.line), rqr.errorString));
+ .arg(resourceFile, QString::number(rqr.line), rqr.errorString));
}
return rqr.files;
}
// Remove .qrc files from the project and return them as absolute paths.
-static QStringList extractQrcFiles(Project &project)
+static QStringList extractQrcFiles(Project& project)
{
auto it = project.sources.begin();
QStringList qrcFiles;
@@ -562,15 +542,15 @@ static QStringList extractQrcFiles(Project &project)
}
// Replace all .qrc files in the project with their content.
-static void expandQrcFiles(Project &project)
+static void expandQrcFiles(Project& project)
{
- for (const QString &qrcFile : extractQrcFiles(project))
+ for (const QString& qrcFile : extractQrcFiles(project))
project.sources << getResources(qrcFile);
}
-static bool processTs(Translator &fetchedTor, const QString &file, ConversionData &cd)
+static bool processTs(Translator& fetchedTor, const QString& file, ConversionData& cd)
{
- for (const Translator::FileFormat &fmt : std::as_const(Translator::registeredFileFormats())) {
+ for (const Translator::FileFormat& fmt : std::as_const(Translator::registeredFileFormats())) {
if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) {
Translator tor;
if (tor.load(file, cd, fmt.extension)) {
@@ -587,22 +567,22 @@ static bool processTs(Translator &fetchedTor, const QString &file, ConversionDat
return false;
}
-static void processSources(Translator &fetchedTor, const QStringList &sourceFiles,
- ConversionData &cd, UpdateOptions options, bool *fail)
+static void processSources(Translator& fetchedTor, const QStringList& sourceFiles,
+ ConversionData& cd, UpdateOptions options)
{
#ifdef QT_NO_QML
bool requireQmlSupport = false;
#endif
QStringList sourceFilesCpp;
- for (const auto &sourceFile : sourceFiles) {
+ for (const auto& sourceFile : sourceFiles) {
if (sourceFile.endsWith(QLatin1String(".java"), Qt::CaseInsensitive))
loadJava(fetchedTor, sourceFile, cd);
else if (sourceFile.endsWith(QLatin1String(".ui"), Qt::CaseInsensitive)
- || sourceFile.endsWith(QLatin1String(".jui"), Qt::CaseInsensitive))
+ || sourceFile.endsWith(QLatin1String(".jui"), Qt::CaseInsensitive))
loadUI(fetchedTor, sourceFile, cd);
#ifndef QT_NO_QML
else if (sourceFile.endsWith(QLatin1String(".js"), Qt::CaseInsensitive)
- || sourceFile.endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) {
+ || sourceFile.endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) {
loadQScript(fetchedTor, sourceFile, cd);
} else if (sourceFile.endsWith(QLatin1String(".mjs"), Qt::CaseInsensitive)) {
loadJSModule(fetchedTor, sourceFile, cd);
@@ -610,9 +590,9 @@ static void processSources(Translator &fetchedTor, const QStringList &sourceFile
loadQml(fetchedTor, sourceFile, cd);
#else
else if (sourceFile.endsWith(QLatin1String(".qml"), Qt::CaseInsensitive)
- || sourceFile.endsWith(QLatin1String(".js"), Qt::CaseInsensitive)
- || sourceFile.endsWith(QLatin1String(".mjs"), Qt::CaseInsensitive)
- || sourceFile.endsWith(QLatin1String(".qs"), Qt::CaseInsensitive))
+ || sourceFile.endsWith(QLatin1String(".js"), Qt::CaseInsensitive)
+ || sourceFile.endsWith(QLatin1String(".mjs"), Qt::CaseInsensitive)
+ || sourceFile.endsWith(QLatin1String(".qs"), Qt::CaseInsensitive))
requireQmlSupport = true;
#endif // QT_NO_QML
else if (sourceFile.endsWith(u".py", Qt::CaseInsensitive))
@@ -624,7 +604,7 @@ static void processSources(Translator &fetchedTor, const QStringList &sourceFile
#ifdef QT_NO_QML
if (requireQmlSupport) {
printWarning(options, u"missing qml/javascript support\n"_s,
- u"Some files have been ignored.\n"_s);
+ u"Some files have been ignored.\n"_s);
if (options & Werror)
return;
}
@@ -632,31 +612,22 @@ static void processSources(Translator &fetchedTor, const QStringList &sourceFile
Q_UNUSED(options)
#endif
- if (useClangToParseCpp) {
-#if QT_CONFIG(clangcpp)
- ClangCppParser::loadCPP(fetchedTor, sourceFilesCpp, cd, fail);
-#else
- *fail = true;
- printErr(QStringLiteral("lupdate error: lupdate was built without clang support."));
-#endif
- }
- else
- loadCPP(fetchedTor, sourceFilesCpp, cd);
+ loadCPP(fetchedTor, sourceFilesCpp, cd);
if (!cd.error().isEmpty())
printErr(cd.error());
}
-static QSet<QString> projectRoots(const QString &projectFile, const QStringList &sourceFiles)
+static QSet<QString> projectRoots(const QString& projectFile, const QStringList& sourceFiles)
{
const QString proPath = QFileInfo(projectFile).path();
QSet<QString> sourceDirs;
sourceDirs.insert(proPath + QLatin1Char('/'));
- for (const QString &sf : sourceFiles)
+ for (const QString& sf : sourceFiles)
sourceDirs.insert(sf.left(sf.lastIndexOf(QLatin1Char('/')) + 1));
QStringList rootList = sourceDirs.values();
rootList.sort();
- for (int prev = 0, curr = 1; curr < rootList.size(); )
+ for (int prev = 0, curr = 1; curr < rootList.size();)
if (rootList.at(curr).startsWith(rootList.at(prev)))
rootList.removeAt(curr);
else
@@ -664,27 +635,25 @@ static QSet<QString> projectRoots(const QString &projectFile, const QStringList
return QSet<QString>(rootList.cbegin(), rootList.cend());
}
-class ProjectProcessor
-{
+class ProjectProcessor {
public:
- ProjectProcessor(const QString &sourceLanguage,
- const QString &targetLanguage)
- : m_sourceLanguage(sourceLanguage),
- m_targetLanguage(targetLanguage)
+ ProjectProcessor(const QString& sourceLanguage,
+ const QString& targetLanguage)
+ : m_sourceLanguage(sourceLanguage)
+ , m_targetLanguage(targetLanguage)
{
}
- void processProjects(bool topLevel, UpdateOptions options, const Projects &projects,
- bool nestComplain, Translator *parentTor, bool *fail) const
+ void processProjects(bool topLevel, UpdateOptions options, const Projects& projects,
+ bool nestComplain, Translator* parentTor, bool* fail) const
{
- for (const Project &prj : projects)
+ for (const Project& prj : projects)
processProject(options, prj, topLevel, nestComplain, parentTor, fail);
}
private:
-
- void processProject(UpdateOptions options, const Project &prj, bool topLevel,
- bool nestComplain, Translator *parentTor, bool *fail) const
+ void processProject(UpdateOptions options, const Project& prj, bool topLevel,
+ bool nestComplain, Translator* parentTor, bool* fail) const
{
QString codecForSource = prj.codec.toLower();
@@ -693,13 +662,13 @@ private:
|| codecForSource == QLatin1String("utf16")) {
options |= SourceIsUtf16;
} else if (codecForSource == QLatin1String("utf-8")
- || codecForSource == QLatin1String("utf8")) {
+ || codecForSource == QLatin1String("utf8")) {
options &= ~SourceIsUtf16;
} else {
printWarning(
- options,
- "Codec for source '%1' is invalid.\n"_L1.arg(codecForSource),
- u"Falling back to UTF-8.\n"_s);
+ options,
+ "Codec for source '%1' is invalid.\n"_L1.arg(codecForSource),
+ u"Falling back to UTF-8.\n"_s);
if (options & Werror)
return;
options &= ~SourceIsUtf16;
@@ -729,16 +698,16 @@ private:
if (parentTor) {
if (topLevel) {
printWarning(options, u"Existing top level."_s,
- "TS files from command line will "
- "override TRANSLATIONS in %1.\n"_L1.arg(projectFile),
- u"Terminating the operation.\n"_s);
+ "TS files from command line will "
+ "override TRANSLATIONS in %1.\n"_L1.arg(projectFile),
+ u"Terminating the operation.\n"_s);
if (options & Werror)
return;
goto noTrans;
} else if (nestComplain) {
printWarning(options,
- "TS files from command line "
- "prevent recursing into %1.\n"_L1.arg(projectFile));
+ "TS files from command line "
+ "prevent recursing into %1.\n"_L1.arg(projectFile));
return;
}
}
@@ -750,29 +719,28 @@ private:
}
Translator tor;
processProjects(false, options, prj.subProjects, false, &tor, fail);
- processSources(tor, sources, cd, options, fail);
+ processSources(tor, sources, cd, options);
updateTsFiles(tor, tsFiles, QStringList(), m_sourceLanguage, m_targetLanguage,
- options, fail);
+ options, fail);
return;
}
-
- noTrans:
+ noTrans:
if (!parentTor) {
if (topLevel) {
printWarning(options, u"no TS files specified."_s,
- "Only diagnostics will be produced for %1.\n"_L1.arg(projectFile),
- u"Terminating the operation.\n"_s);
+ "Only diagnostics will be produced for %1.\n"_L1.arg(projectFile),
+ u"Terminating the operation.\n"_s);
if (options & Werror)
return;
}
Translator tor;
processProjects(false, options, prj.subProjects, nestComplain, &tor, fail);
- processSources(tor, sources, cd, options, fail);
+ processSources(tor, sources, cd, options);
} else {
processProjects(false, options, prj.subProjects, nestComplain, parentTor, fail);
- processSources(*parentTor, sources, cd, options, fail);
+ processSources(*parentTor, sources, cd, options);
}
}
@@ -780,7 +748,7 @@ private:
QString m_targetLanguage;
};
-int main(int argc, char **argv)
+int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
#ifndef QT_BOOTSTRAPPED
@@ -814,8 +782,7 @@ int main(int argc, char **argv)
QString targetLanguage;
QString sourceLanguage;
- UpdateOptions options =
- Verbose | // verbose is on by default starting with Qt 4.2
+ UpdateOptions options = Verbose | // verbose is on by default starting with Qt 4.2
HeuristicSameText | HeuristicSimilarText;
int numFiles = 0;
bool metTsFlag = false;
@@ -830,8 +797,8 @@ int main(int argc, char **argv)
for (int i = 1; i < args.size(); ++i) {
QString arg = args.at(i);
if (arg == QLatin1String("-help")
- || arg == QLatin1String("--help")
- || arg == QLatin1String("-h")) {
+ || arg == QLatin1String("--help")
+ || arg == QLatin1String("-h")) {
printUsage();
return 0;
} else if (arg == QLatin1String("-list-languages")) {
@@ -841,7 +808,7 @@ int main(int argc, char **argv)
options |= PluralOnly;
continue;
} else if (arg == QLatin1String("-noobsolete")
- || arg == QLatin1String("-no-obsolete")) {
+ || arg == QLatin1String("-no-obsolete")) {
options |= NoObsolete;
continue;
} else if (arg == QLatin1String("-silent")) {
@@ -927,7 +894,7 @@ int main(int argc, char **argv)
recursiveScan = true;
continue;
} else if (arg == QLatin1String("-no-sort")
- || arg == QLatin1String("-nosort")) {
+ || arg == QLatin1String("-nosort")) {
options |= NoSort;
continue;
} else if (arg == QLatin1String("-version")) {
@@ -989,26 +956,9 @@ int main(int argc, char **argv)
}
continue;
}
-#if QT_CONFIG(clangcpp)
- else if (arg == QLatin1String("-clang-parser")) {
- useClangToParseCpp = true;
- // the option after -clang-parser is optional
- if ((i + 1) != argc && !args[i + 1].startsWith(QLatin1String("-"))) {
- i++;
- commandLineCompilationDatabaseDir = args[i];
- }
- continue;
- } else if (arg == QLatin1String("-project-roots")) {
- while ((i + 1) != argc && !args[i + 1].startsWith(QLatin1String("-"))) {
- i++;
- rootDirs << args[i];
- }
- rootDirs.removeDuplicates();
- continue;
- }
-#endif
+
else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) {
- printErr(QStringLiteral("Unrecognized option '%1'.\n").arg(arg));
+ printErr("Unrecognized option '%1'.\n"_L1.arg(arg));
return 1;
}
@@ -1017,7 +967,7 @@ int main(int argc, char **argv)
QFile lstFile(arg.mid(1));
if (!lstFile.open(QIODevice::ReadOnly)) {
printErr(QStringLiteral("lupdate error: List file '%1' is not readable.\n")
- .arg(lstFile.fileName()));
+ .arg(lstFile.fileName()));
return 1;
}
while (!lstFile.atEnd()) {
@@ -1037,17 +987,17 @@ int main(int argc, char **argv)
files << arg;
}
if (metTsFlag) {
- for (const QString &file : std::as_const(files)) {
+ for (const QString& file : std::as_const(files)) {
bool found = false;
- for (const Translator::FileFormat &fmt : std::as_const(Translator::registeredFileFormats())) {
+ for (const Translator::FileFormat& fmt : std::as_const(Translator::registeredFileFormats())) {
if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) {
QFileInfo fi(file);
if (!fi.exists() || fi.isWritable()) {
tsFileNames.append(QFileInfo(file).absoluteFilePath());
} else {
printWarning(options,
- "For some reason, '%1' is not writable.\n"_L1
- .arg(file));
+ "For some reason, '%1' is not writable.\n"_L1
+ .arg(file));
if (options & Werror)
return 1;
}
@@ -1057,7 +1007,7 @@ int main(int argc, char **argv)
}
if (!found) {
printErr(QStringLiteral("lupdate error: File '%1' has no recognized extension.\n")
- .arg(file));
+ .arg(file));
return 1;
}
}
@@ -1065,7 +1015,7 @@ int main(int argc, char **argv)
} else if (metXTsFlag) {
alienFiles += files;
} else {
- for (const QString &file : std::as_const(files)) {
+ for (const QString& file : std::as_const(files)) {
QFileInfo fi(file);
if (!fi.exists()) {
printErr(QStringLiteral("lupdate error: File '%1' does not exist.\n").arg(file));
@@ -1093,7 +1043,7 @@ int main(int argc, char **argv)
QFileInfoList fileinfolist;
recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist);
int scanRootLen = dir.absolutePath().size();
- for (const QFileInfo &fi : std::as_const(fileinfolist)) {
+ for (const QFileInfo& fi : std::as_const(fileinfolist)) {
QString fn = QDir::cleanPath(fi.absoluteFilePath());
if (fn.endsWith(QLatin1String(".qrc"), Qt::CaseInsensitive)) {
resourceFiles << fn;
@@ -1101,12 +1051,12 @@ int main(int argc, char **argv)
sourceFiles << fn;
if (!fn.endsWith(QLatin1String(".java"))
- && !fn.endsWith(QLatin1String(".jui"))
- && !fn.endsWith(QLatin1String(".ui"))
- && !fn.endsWith(QLatin1String(".js"))
- && !fn.endsWith(QLatin1String(".mjs"))
- && !fn.endsWith(QLatin1String(".qs"))
- && !fn.endsWith(QLatin1String(".qml"))) {
+ && !fn.endsWith(QLatin1String(".jui"))
+ && !fn.endsWith(QLatin1String(".ui"))
+ && !fn.endsWith(QLatin1String(".js"))
+ && !fn.endsWith(QLatin1String(".mjs"))
+ && !fn.endsWith(QLatin1String(".qs"))
+ && !fn.endsWith(QLatin1String(".qml"))) {
int offset = 0;
int depth = 0;
do {
@@ -1137,7 +1087,7 @@ int main(int argc, char **argv)
if (!targetLanguage.isEmpty() && tsFileNames.size() != 1) {
printWarning(options,
- u"-target-language usually only makes sense with exactly one TS file.\n"_s);
+ u"-target-language usually only makes sense with exactly one TS file.\n"_s);
if (options & Werror)
return 1;
}
@@ -1165,20 +1115,20 @@ int main(int argc, char **argv)
}
if (projectDescription.empty()) {
printErr(QStringLiteral("lupdate error:"
- " Could not find project descriptions in %1.\n")
- .arg(projectDescriptionFile));
+ " Could not find project descriptions in %1.\n")
+ .arg(projectDescriptionFile));
return 1;
}
removeExcludedSources(projectDescription);
- for (Project &project : projectDescription)
+ for (Project& project : projectDescription)
expandQrcFiles(project);
}
if (projectDescription.empty()) {
if (tsFileNames.isEmpty()) {
printWarning(options, u"no TS files specified."_s,
- u"Only diagnostics will be produced.\n"_s,
- u"Terminating the operation.\n"_s);
+ u"Only diagnostics will be produced.\n"_s,
+ u"Terminating the operation.\n"_s);
if (options & Werror)
return 1;
}
@@ -1192,15 +1142,15 @@ int main(int argc, char **argv)
cd.m_allCSources = allCSources;
cd.m_compilationDatabaseDir = commandLineCompilationDatabaseDir;
cd.m_rootDirs = rootDirs;
- for (const QString &resource : std::as_const(resourceFiles))
+ for (const QString& resource : std::as_const(resourceFiles))
sourceFiles << getResources(resource);
- processSources(fetchedTor, sourceFiles, cd, options, &fail);
+ processSources(fetchedTor, sourceFiles, cd, options);
updateTsFiles(fetchedTor, tsFileNames, alienFiles,
- sourceLanguage, targetLanguage, options, &fail);
+ sourceLanguage, targetLanguage, options, &fail);
} else {
if (!sourceFiles.isEmpty() || !resourceFiles.isEmpty() || !includePath.isEmpty()) {
printErr(QStringLiteral("lupdate error:"
- " Both project and source files / include paths specified.\n"));
+ " Both project and source files / include paths specified.\n"));
return 1;
}
QString errorString;
@@ -1208,14 +1158,14 @@ int main(int argc, char **argv)
if (!tsFileNames.isEmpty()) {
Translator fetchedTor;
projectProcessor.processProjects(true, options, projectDescription, true, &fetchedTor,
- &fail);
+ &fail);
if (!fail) {
updateTsFiles(fetchedTor, tsFileNames, alienFiles,
- sourceLanguage, targetLanguage, options, &fail);
+ sourceLanguage, targetLanguage, options, &fail);
}
} else {
projectProcessor.processProjects(true, options, projectDescription, false, nullptr,
- &fail);
+ &fail);
}
}
return fail ? 1 : 0;
diff --git a/tests/auto/linguist/lupdate/CMakeLists.txt b/tests/auto/linguist/lupdate/CMakeLists.txt
index ee57b32..cf0a04b 100644
--- a/tests/auto/linguist/lupdate/CMakeLists.txt
+++ b/tests/auto/linguist/lupdate/CMakeLists.txt
@@ -7,11 +7,6 @@ if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
-if(CMAKE_VERSION VERSION_LESS "3.19" AND MSVC AND QT_FEATURE_debug_and_release)
- message(WARNING "tst_lupdate will not be built in this configuration.")
- return()
-endif()
-
#####################################################################
## tst_lupdate Test:
#####################################################################
@@ -23,7 +18,3 @@ qt_internal_add_test(tst_lupdate
Qt::Tools
Qt::CorePrivate
)
-
-# The recursive tests take a bit longer for the clang-based parser.
-# Increase the test timeout.
-set_property(TEST tst_lupdate APPEND PROPERTY ENVIRONMENT "QTEST_FUNCTION_TIMEOUT=900000")
diff --git a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/expectedoutput.txt
deleted file mode 100644
index e69de29..0000000
diff --git a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/main.cpp b/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/main.cpp
deleted file mode 100644
index 640f208..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/main.cpp
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// IMPORTANT!!!! If you want to add testdata to this file,
-// always add it to the end in order to not change the linenumbers of translations!!!
-
-#define QTCORE <QtCore>
-#include QTCORE // Hidden from lupdate, but compiles
-
-//
-// Test 'lacks Q_OBJECT' reporting on namespace scopes
-//
-
-class B : public QObject {
- //Q_OBJECT
- void foo();
-};
-
-void B::foo() {
- tr("Bla", "::B");
-}
-
-
-class C : public QObject {
- //Q_OBJECT
- void foo() {
- tr("Bla", "::C");
- }
-};
-
-
-namespace nsB {
-
- class B : public QObject {
- //Q_OBJECT
- void foo();
- };
-
- void B::foo() {
- tr("Bla", "nsB::B");
- }
-
- class C : public QObject {
- //Q_OBJECT
- void foo() {
- tr("Bla", "nsB::C");
- }
- };
-}
-
diff --git a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.pro b/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.pro
deleted file mode 100644
index 759bea0..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-SOURCES = main.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.ts.result
deleted file mode 100644
index 66a33a3..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/lacksqobject_clang_parser/project.ts.result
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name>QObject</name>
- <message>
- <location filename="main.cpp" line="45"/>
- <source>Bla</source>
- <comment>::B</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="52"/>
- <source>Bla</source>
- <comment>::C</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="65"/>
- <source>Bla</source>
- <comment>nsB::B</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="71"/>
- <source>Bla</source>
- <comment>nsB::C</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/main.cpp
deleted file mode 100644
index 7a5fff9..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/main.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// IMPORTANT!!!! If you want to add testdata to this file,
-// always add it to the end in order to not change the linenumbers of translations!!!
-#include <QtCore>
-#include <QtGui>
-#include <QtWidgets/QMainWindow>
-//
-// Test namespace scoping
-//
-
-class D : public QObject {
- Q_OBJECT
- public:
- QString foo() {
- return tr("test", "D");
- }
-
-};
-
-namespace A {
-
- class C : public QObject {
- Q_OBJECT
- public:
- void foo();
- };
-
- void C::foo() {
- tr("Bla", "A::C");
- }
-
- void goo() {
- C::tr("Bla", "A::C"); // Is identical to the previous tr(), (same context, sourcetext and comment,
- // so it should not add another entry to the list of messages)
- }
-
- void goo2() {
- C::tr("Bla 2", "A::C"); //Should be in the same namespace as the previous tr()
- }
-
-}
-
-
-namespace X {
-
- class D : public QObject {
- Q_OBJECT
- public:
-
- };
-
- class E : public QObject {
- Q_OBJECT
- public:
- void foo() { D::tr("foo", "D"); } // Note that this is X::D from 440 on
- };
-
-
- namespace Y {
- class E : public QObject {
- Q_OBJECT
-
- };
-
- class C : public QObject {
- Q_OBJECT
- void foo();
- };
-
- void C::foo() {
- tr("Bla", "X::Y::C");
- }
-
- void goo() {
- D::tr("Bla", "X::D"); //This should be assigned to the X::D context
- }
-
- void goo2() {
- E::tr("Bla", "X::Y::E"); //This should be assigned to the X::Y::E context
- Y::E::tr("Bla", "X::Y::E"); //This should be assigned to the X::Y::E context
- }
-
- }; // namespace Y
-
- class F : public QObject {
- Q_OBJECT
- inline void inlinefunc() {
- tr("inline function", "X::F");
- }
- };
-} // namespace X
-
-namespace ico {
- namespace foo {
- class A : public QObject {
- A();
- };
-
- A::A() {
- tr("myfoo", "ico::foo::A");
- QObject::tr("task 161186", "QObject");
- }
- }
-}
-
-namespace AA {
-class C {};
-}
-
-/**
- * the context of a message should not be affected by any inherited classes
- *
- * Keep this disabled for now, but at a long-term range it should work.
- */
-namespace Gui {
- class MainWindow : public QMainWindow,
- public AA::C
- {
- Q_OBJECT
-public:
- MainWindow()
- {
- tr("More bla", "Gui::MainWindow");
- }
-
- };
-} //namespace Gui
-
-
-namespace A1 {
- class AB : public QObject {
- Q_OBJECT
- public:
-
- friend class OtherClass;
-
- QString inlineFuncAfterFriendDeclaration() const {
- return tr("inlineFuncAfterFriendDeclaration", "A1::AB");
- }
- };
- class B : AB {
- Q_OBJECT
- public:
- QString foo() const { return tr("foo", "A1::B"); }
- };
-
- // This is valid C++ too....
- class V : virtual AB {
- Q_OBJECT
- public:
- QString bar() const { return tr("bar", "A1::V"); }
- };
-
- class W : virtual public AB {
- Q_OBJECT
- public:
- QString baz() const { return tr("baz", "A1::W"); }
- };
-}
-
-class ForwardDecl;
-
-
-class B1 : public QObject {
-};
-
-class C1 : public QObject {
-};
-
-namespace A1 {
-
-class B2 : public QObject {
-};
-
-}
-
-void func1()
-{
- B1::tr("test TRANSLATOR comment (1)", "B1");
-
-}
-
-using namespace A1;
-/*
- TRANSLATOR A1::B2
-*/
-void func2()
-{
- B2::tr("test TRANSLATOR comment (2)", "A1::B2");
- C1::tr("test TRANSLATOR comment (3)", "C1");
-}
-
-void func3()
-{
- B2::tr("test TRANSLATOR comment (4)", "A1::B2");
-}
-
-/*
- TRANSLATOR B2
- This is a comment to the translator.
-*/
-void func4()
-{
- B2::tr("test TRANSLATOR comment (5)", "A1::B2");
-}
-
-namespace A1 {
-namespace B3 {
-class C2 : public QObject {
-QString foo();
-};
-}
-}
-
-namespace D1 = A1::B3;
-using namespace D1;
-
-// TRANSLATOR A1::B3::C2
-QString C2::foo()
-{
- return tr("test TRANSLATOR comment (6)", "A1::B3::C2"); // 4.4 screws up
-}
-namespace Fooish {
- struct toto {
- Q_DECLARE_TR_FUNCTIONS(Bears::And::Spiders)
- QString bar(); };
-}
-
-QString Fooish::toto::bar()
-{
- return tr("whatever the context", "Bears::And::Spiders");
-}
-
-
-int main(int /*argc*/, char ** /*argv*/) {
- return 0;
-}
-
-//#include "main.moc"
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.pro
deleted file mode 100644
index 759bea0..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-SOURCES = main.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.ts.result
deleted file mode 100644
index 6ff4df1..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecontexts_clang_parser/project.ts.result
+++ /dev/null
@@ -1,177 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name>A1::AB</name>
- <message>
- <location filename="main.cpp" line="165"/>
- <source>inlineFuncAfterFriendDeclaration</source>
- <comment>A1::AB</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>A1::B</name>
- <message>
- <location filename="main.cpp" line="171"/>
- <source>foo</source>
- <comment>A1::B</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>A1::V</name>
- <message>
- <location filename="main.cpp" line="178"/>
- <source>bar</source>
- <comment>A1::V</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>A1::W</name>
- <message>
- <location filename="main.cpp" line="184"/>
- <source>baz</source>
- <comment>A1::W</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>A::C</name>
- <message>
- <location filename="main.cpp" line="56"/>
- <location filename="main.cpp" line="60"/>
- <source>Bla</source>
- <comment>A::C</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="65"/>
- <source>Bla 2</source>
- <comment>A::C</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Bears::And::Spiders</name>
- <message>
- <location filename="main.cpp" line="258"/>
- <source>whatever the context</source>
- <comment>Bears::And::Spiders</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>D</name>
- <message>
- <location filename="main.cpp" line="42"/>
- <source>test</source>
- <comment>D</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Gui::MainWindow</name>
- <message>
- <location filename="main.cpp" line="150"/>
- <source>More bla</source>
- <comment>Gui::MainWindow</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>QObject</name>
- <message>
- <location filename="main.cpp" line="127"/>
- <source>myfoo</source>
- <comment>ico::foo::A</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="128"/>
- <source>task 161186</source>
- <comment>QObject</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="206"/>
- <source>test TRANSLATOR comment (1)</source>
- <comment>B1</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="216"/>
- <source>test TRANSLATOR comment (2)</source>
- <comment>A1::B2</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="217"/>
- <source>test TRANSLATOR comment (3)</source>
- <comment>C1</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="222"/>
- <source>test TRANSLATOR comment (4)</source>
- <comment>A1::B2</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="231"/>
- <source>test TRANSLATOR comment (5)</source>
- <comment>A1::B2</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="248"/>
- <source>test TRANSLATOR comment (6)</source>
- <comment>A1::B3::C2</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>X::D</name>
- <message>
- <location filename="main.cpp" line="82"/>
- <source>foo</source>
- <comment>D</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="102"/>
- <source>Bla</source>
- <comment>X::D</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>X::F</name>
- <message>
- <location filename="main.cpp" line="115"/>
- <source>inline function</source>
- <comment>X::F</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>X::Y::C</name>
- <message>
- <location filename="main.cpp" line="98"/>
- <source>Bla</source>
- <comment>X::Y::C</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>X::Y::E</name>
- <message>
- <location filename="main.cpp" line="106"/>
- <location filename="main.cpp" line="107"/>
- <source>Bla</source>
- <comment>X::Y::E</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/expectedoutput.txt
deleted file mode 100644
index 5546bcc..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/expectedoutput.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp2_clang_parser[/\\]main.cpp:107:0: //% cannot be used with tr\(\) / QT_TR_NOOP\(\)\. Ignoring
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp2_clang_parser[/\\]main.cpp:110:0: //% cannot be used with translate\(\) / QT_TRANSLATE_NOOP\(\)\. Ignoring
-lupdate warning: Message with id 'no_source' has no source\.
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.cpp
deleted file mode 100644
index 9333378..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// IMPORTANT!!!! If you want to add testdata to this file,
-// always add it to the end in order to not change the linenumbers of translations!!!
-
-// nothing here
-
-// sickness: multi-\
-line c++ comment } (with brace)
-
-//#define This is a closing brace } which was ignored
-//} // complain here
-
-//#define This is another \
-// closing brace } which was ignored
-//} // complain here
-
-//#define This is another /* comment in } define */\
-// something /* comment )
-// spanning {multiple} lines */ \
-// closing brace } which was ignored
-//} // complain here
-
-//#define This is another // comment in } define \
-// something } comment
-//} // complain here
-#include <QtCore>
-
-
-// Nested class in same file
-class TopLevel {
- Q_OBJECT
-
- class Nested;
-};
-
-class TopLevel::Nested {
- void foo();
-};
-
-void TopLevel::Nested::foo()
-{
- TopLevel::tr("TopLevel");
-}
-
-// Nested class in other file
-#include "main.h"
-
-class TopLevel2::Nested {
- void foo();
-};
-
-void TopLevel2::Nested::foo()
-{
- TopLevel2::tr("TopLevel2");
-}
-
-
-
-namespace NameSpace {
-class ToBeUsed;
-}
-
-// using statement before class definition
-using NameSpace::ToBeUsed;
-
-class NameSpace::ToBeUsed {
- Q_OBJECT
- void caller();
-};
-
-void ToBeUsed::caller()
-{
- tr("NameSpace::ToBeUsed");
-}
-#include <QtWidgets/QApplication>
-
-bool me = false;
-// QTBUG-11818
-//% "Foo"
-QString s1 = QObject::tr("Hello World");
-QString s2 = QObject::tr("Hello World");
-//% "Bar"
-QString s3 = QApplication::translate("QObject", "Hello World");
-QString s4 = QApplication::translate("QObject", "Hello World");
-//% "Baz"
-bool clear = me;
-QString s5 = QObject::tr("Hello World");
-
-
-
-// QTBUG-11843: complain about missing source in id-based messages
-QString s6 = qtTrId("no_source");
-
-QString s7 = QObject::tr(R"(simple one)" R"delim(enter
-)delim" R"delim(with delimiter )delim inside)delim" u8R"(with quote " inside)");
-
-QLatin1String not_translated(R"(
- This is a test string
-)");
-const char valid[] = QT_TRANSLATE_NOOP("global", R"(
-"The time has come," the Walrus said,
-"To talk of many things:
-Of shoes - and ships - and sealing-wax -
-Of cabbages - and kings -
-And why the sea is boiling hot -
-And whether pigs have wings."
-)");
-
-const QString nodelimiter(QObject::tr(R"(
- This is a test string
-)"));
-const QString withdelimiter = QObject::tr(R"delim(
-This is a test string
-)delim");
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.h
deleted file mode 100644
index ccdefda..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/main.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// IMPORTANT!!!! If you want to add testdata to this file,
-// always add it to the end in order to not change the linenumbers of translations!!!
-#include <QtCore>
-class TopLevel2 {
- Q_OBJECT
-
- class Nested;
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.pro
deleted file mode 100644
index 759bea0..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-SOURCES = main.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.ts.result
deleted file mode 100644
index 0710915..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp2_clang_parser/project.ts.result
+++ /dev/null
@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name></name>
- <message id="no_source">
- <location filename="main.cpp" line="119"/>
- <source></source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>NameSpace::ToBeUsed</name>
- <message>
- <location filename="main.cpp" line="100"/>
- <source>NameSpace::ToBeUsed</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>QObject</name>
- <message>
- <location filename="main.cpp" line="107"/>
- <location filename="main.cpp" line="108"/>
- <location filename="main.cpp" line="110"/>
- <location filename="main.cpp" line="111"/>
- <location filename="main.cpp" line="114"/>
- <source>Hello World</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="121"/>
- <source>simple oneenter
-with delimiter )delim insidewith quote " inside</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="136"/>
- <source>
- This is a test string
-</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="139"/>
- <source>
-This is a test string
-</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>TopLevel</name>
- <message>
- <location filename="main.cpp" line="69"/>
- <source>TopLevel</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>TopLevel2</name>
- <message>
- <location filename="main.cpp" line="81"/>
- <source>TopLevel2</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>global</name>
- <message>
- <location filename="main.cpp" line="127"/>
- <source>
-"The time has come," the Walrus said,
-"To talk of many things:
-Of shoes - and ships - and sealing-wax -
-Of cabbages - and kings -
-And why the sea is boiling hot -
-And whether pigs have wings."
-</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt
deleted file mode 100644
index 4ce39f6..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/expectedoutput.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context.cpp:51:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context.cpp:91:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context_bis.cpp:51:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_QT_TR_NOOP_context_bis.cpp:91:26: QT_TR_NOOP cannot be called without context\. The call is ignored \(missing Q_OBJECT maybe\?\)
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_only[/\\]test_isolatedComments.cpp:84:0: TRANSLATOR cannot be called without comment. The call is ignored.
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/lupdatecmd
deleted file mode 100644
index e8aa3b3..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/lupdatecmd
+++ /dev/null
@@ -1 +0,0 @@
-lupdate project.pro -tr-function-alias QT_TRANSLATE_NOOP+=ma_fonction_a_moi
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h
deleted file mode 100644
index bd6cc0c..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/my_include.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-
-class Foo
-{
- Q_OBJECT
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro
deleted file mode 100644
index e9e5188..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-SOURCES += test_QT_TR_NOOP_context.cpp
-SOURCES += test_QT_TR_NOOP_context_bis.cpp
-SOURCES += test_isolatedComments.cpp
-SOURCES += test_sameLineComments.cpp
-SOURCES += test_contain_only_alias.cpp
-SOURCES += test_line_directive.cpp
-SOURCES += test_header_only.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result
deleted file mode 100644
index 47bd60e..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/project.ts.result
+++ /dev/null
@@ -1,319 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name>Class</name>
- <message>
- <location filename="test_header_only.h" line="36"/>
- <source>translation_in_hearder</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>CommentOnSameLineExtraComment</name>
- <message>
- <location filename="test_sameLineComments.cpp" line="46"/>
- <source>extra comment before translation. , and = in between</source>
- <extracomment>other extra comment</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_sameLineComments.cpp" line="47"/>
- <source>extra comment before translation. = in between</source>
- <extracomment>extra2</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_sameLineComments.cpp" line="50"/>
- <source>extra comment before translation</source>
- <extracomment>extra3</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_sameLineComments.cpp" line="53"/>
- <source>extra comment before translation. ; in between</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>CommentOnSameLineMetaDataComment</name>
- <message id="other metaData">
- <location filename="test_sameLineComments.cpp" line="35"/>
- <source>meta data comment before translation. , and = in between</source>
- <translation type="unfinished"></translation>
- </message>
- <message id="metaData2">
- <location filename="test_sameLineComments.cpp" line="36"/>
- <source>meta data comment before translation. = in between</source>
- <translation type="unfinished"></translation>
- </message>
- <message id="metaData3">
- <location filename="test_sameLineComments.cpp" line="39"/>
- <source>meta data comment before translation</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Foo</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="37"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="37"/>
- <source>context Foo. noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>FooChild</name>
- <message>
- <location filename="test_QT_TR_NOOP_context_with_comments.h" line="35"/>
- <source>context FooChild. noop with comments</source>
- <extracomment>Some comments</extracomment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedNumber1</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="59"/>
- <source></source>
- <comment>blabla</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedNumber2</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="60"/>
- <source></source>
- <comment>blabla</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedNumber3</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="61"/>
- <source></source>
- <comment>blabla</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedNumber4</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="62"/>
- <source></source>
- <comment>// whatever we have here</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedNumber5</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="69"/>
- <source></source>
- <comment>// whatever2 we2 have2 here2</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedOnSameLineOne</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="76"/>
- <source></source>
- <comment>blabla</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>GluedOnSameLineTwo</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="76"/>
- <source></source>
- <comment>blabla</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>IN_NESTED</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="61"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="61"/>
- <source>context IN_NESTED. tr</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="62"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="62"/>
- <source>context IN_NESTED. noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>MULTIPLELINE</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="32"/>
- <source></source>
- <comment>first line second line</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>MultipleAppearance</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="55"/>
- <source></source>
- <comment>first appearance</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_isolatedComments.cpp" line="57"/>
- <source></source>
- <comment>second appearance</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>MultipleLineFourthTry</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="48"/>
- <source></source>
- <comment>first line second line</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>MultipleLineSecondTry</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="36"/>
- <source></source>
- <comment>first line second line</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>MultipleLineThirdTry</name>
- <message>
- <location filename="test_isolatedComments.cpp" line="42"/>
- <source></source>
- <comment>first line second line</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>ONLY_Q</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="44"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="44"/>
- <source>context ONLY_Q. noop</source>
- <translation type="unfinished"></translation>
- </message>
- <message numerus="yes">
- <location filename="test_QT_TR_NOOP_context.cpp" line="45"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="45"/>
- <source>context ONLY_Q. noop N</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-<context>
- <name>QObject</name>
- <message>
- <location filename="test_line_directive.cpp" line="3"/>
- <source>blabla 1</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_line_directive.cpp" line="7"/>
- <source>blabla 2</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>WithQDeclareTr::Nested</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="74"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="74"/>
- <source>context WithQDeclareTr::Nested. tr</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="75"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="75"/>
- <source>context WithQDeclareTr::Nested. noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>inHeader</name>
- <message>
- <location filename="test_isolatedComments.h" line="29"/>
- <source></source>
- <comment>how to pick this up Not triggering visit from AST visitor</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>my_arg</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="63"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="63"/>
- <source>context my_arg. translate_noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>test2::BB</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="114"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="114"/>
- <source>context test2::BB. tr</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="115"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="115"/>
- <source>context test2::BB. noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>test3::D</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="137"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="137"/>
- <source>context test3::D. tr</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="138"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="138"/>
- <source>context test3::D. noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>test4::A::B::C</name>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="158"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="158"/>
- <source>context is test4::A::B::C. tr</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="test_QT_TR_NOOP_context.cpp" line="159"/>
- <location filename="test_QT_TR_NOOP_context_bis.cpp" line="159"/>
- <source>context is test4::A::B::C. noop</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>zscope</name>
- <message>
- <location filename="test_contain_only_alias.cpp" line="33"/>
- <source>string_a_moi</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp
deleted file mode 100644
index 0eca1e6..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-#include "my_include.h"
-
-int X = 111222332444;
-
-// Q_OBJECT declared in an other file
-class FooChild : public Foo
-{
- const char *c_noop = QT_TR_NOOP("context Foo. noop");
-};
-
-// No Q_OBJECT. Q_DECLARE_TR_FUNCTIONS. It is enough for tr, it is enough for QT_TR_NOOP
-class OnlyQDeclare
-{
- Q_DECLARE_TR_FUNCTIONS(ONLY_Q)
- const char *c_noop = QT_TR_NOOP("context ONLY_Q. noop");
- const char *c_noop_n = QT_TR_N_NOOP("context ONLY_Q. noop N");
-};
-
-// Show the message warning that the QT_TR_NOOP is ignored because no context could be found.
-class Nothing
-{
- const char *c_noop = QT_TR_NOOP("context Nothing. noop with no Q_OBJECT nor Q_DECLARE_TR_FUNCTIONS");
-};
-
-// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
-class WithQObject
-{
- Q_OBJECT
- class Nested
- {
- Q_DECLARE_TR_FUNCTIONS(IN_NESTED)
- QString c_tr = tr("context IN_NESTED. tr");
- const char *c_noop = QT_TR_NOOP("context IN_NESTED. noop");
- const char *c_noop_translate = QT_TRANSLATE_NOOP("my_arg", "context my_arg. translate_noop");
- };
-};
-
-// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
-class WithQDeclareTr
-{
- Q_DECLARE_TR_FUNCTIONS(A_CONTEXT)
- class Nested
- {
- Q_OBJECT
- QString c_tr = tr("context WithQDeclareTr::Nested. tr");
- const char *c_noop = QT_TR_NOOP("context WithQDeclareTr::Nested. noop");
- };
-};
-
-// Case where Q_OBJECT is not seen. Behavior reproduces tr function behavior
-namespace test1 {
- class AA
- {
- Q_OBJECT
- public:
- class A {};
- };
-
- class B : public AA::A
- {
- //QString c_tr = tr(" the Q_OBJECT is not seen"); // this will generate an error.
- const char *c_noop = QT_TR_NOOP("the Q_OBJECT is not seen"); // Once exploring the bases of B (that is AA:A)
- // we are not looking for the parents
- // AA is the parent of A in terms of CXXContextDecl::getParent()
- // This reproduced tr behavior.
- };
-}
-
-namespace test2 {
- class AA
- {
- Q_OBJECT
- public:
- class A {};
- };
-
- class C {};
-
- class BB
- {
- Q_OBJECT
- public:
- class B : public AA::A, public C
- {
- QString c_tr = tr("context test2::BB. tr");
- const char *c_noop = QT_TR_NOOP("context test2::BB. noop");
- };
- };
-}
-
-namespace test3 {
- class AA
- {
- Q_OBJECT
- public:
- class A {};
- };
-
- class D {Q_OBJECT};
- class C : public D {};
-
- class BB
- {
- Q_OBJECT
- public:
- class B : public AA::A, public C
- {
- QString c_tr = tr("context test3::D. tr");
- const char *c_noop = QT_TR_NOOP("context test3::D. noop");
- };
- };
-}
-
-namespace test4 {
-
- class A
- {
- Q_OBJECT
- public:
- class B
- {
- public:
- class C
- {
- Q_OBJECT
- public:
- class D
- {
- QString c_tr = tr("context is test4::A::B::C. tr");
- const char *c_noop = QT_TR_NOOP("context is test4::A::B::C. noop");
- };
- };
- };
- };
-
-}
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp
deleted file mode 100644
index 7d30a38..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_bis.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-#include "my_include.h"
-// Testing with two files to check that patch https://codereview.qt-project.org/c/qt/qttools/+/338709/1..3 still works
-int X = 111222332444;
-
-// Q_OBJECT declared in an other file
-class FooChild : public Foo
-{
- const char *c_noop = QT_TR_NOOP("context Foo. noop");
-};
-
-// No Q_OBJECT. Q_DECLARE_TR_FUNCTIONS. It is enough for tr, it is enough for QT_TR_NOOP
-class OnlyQDeclare
-{
- Q_DECLARE_TR_FUNCTIONS(ONLY_Q)
- const char *c_noop = QT_TR_NOOP("context ONLY_Q. noop");
- const char *c_noop_n = QT_TR_N_NOOP("context ONLY_Q. noop N");
-};
-
-// Show the message warning that the QT_TR_NOOP is ignored because no context could be found.
-class Nothing
-{
- const char *c_noop = QT_TR_NOOP("context Nothing. noop with no Q_OBJECT nor Q_DECLARE_TR_FUNCTIONS");
-};
-
-// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
-class WithQObject
-{
- Q_OBJECT
- class Nested
- {
- Q_DECLARE_TR_FUNCTIONS(IN_NESTED)
- QString c_tr = tr("context IN_NESTED. tr");
- const char *c_noop = QT_TR_NOOP("context IN_NESTED. noop");
- const char *c_noop_translate = QT_TRANSLATE_NOOP("my_arg", "context my_arg. translate_noop");
- };
-};
-
-// The closest Q_OBJECT or Q_DECLARE_TR_FUNCTIONS gives the context
-class WithQDeclareTr
-{
- Q_DECLARE_TR_FUNCTIONS(A_CONTEXT)
- class Nested
- {
- Q_OBJECT
- QString c_tr = tr("context WithQDeclareTr::Nested. tr");
- const char *c_noop = QT_TR_NOOP("context WithQDeclareTr::Nested. noop");
- };
-};
-
-// Case where Q_OBJECT is not seen. Behavior reproduces tr function behavior
-namespace test1 {
- class AA
- {
- Q_OBJECT
- public:
- class A {};
- };
-
- class B : public AA::A
- {
- //QString c_tr = tr(" the Q_OBJECT is not seen"); // this will generate an error.
- const char *c_noop = QT_TR_NOOP("the Q_OBJECT is not seen"); // Once exploring the bases of B (that is AA:A)
- // we are not looking for the parents
- // AA is the parent of A in terms of CXXContextDecl::getParent()
- // This reproduced tr behavior.
- };
-}
-
-namespace test2 {
- class AA
- {
- Q_OBJECT
- public:
- class A {};
- };
-
- class C {};
-
- class BB
- {
- Q_OBJECT
- public:
- class B : public AA::A, public C
- {
- QString c_tr = tr("context test2::BB. tr");
- const char *c_noop = QT_TR_NOOP("context test2::BB. noop");
- };
- };
-}
-
-namespace test3 {
- class AA
- {
- Q_OBJECT
- public:
- class A {};
- };
-
- class D {Q_OBJECT};
- class C : public D {};
-
- class BB
- {
- Q_OBJECT
- public:
- class B : public AA::A, public C
- {
- QString c_tr = tr("context test3::D. tr");
- const char *c_noop = QT_TR_NOOP("context test3::D. noop");
- };
- };
-}
-
-namespace test4 {
-
- class A
- {
- Q_OBJECT
- public:
- class B
- {
- public:
- class C
- {
- Q_OBJECT
- public:
- class D
- {
- QString c_tr = tr("context is test4::A::B::C. tr");
- const char *c_noop = QT_TR_NOOP("context is test4::A::B::C. noop");
- };
- };
- };
- };
-
-}
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_with_comments.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_with_comments.h
deleted file mode 100644
index 59da401..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_QT_TR_NOOP_context_with_comments.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-
-class FooChild
-{
- Q_OBJECT
- //: Some comments
- const char *c_noop = QT_TR_NOOP("context FooChild. noop with comments");
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_contain_only_alias.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_contain_only_alias.cpp
deleted file mode 100644
index 3af8c48..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_contain_only_alias.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#ifndef MYOBJECT_H
-#define MYOBJECT_H
-
-#include <QtCore>
-const char *c_2 = ma_fonction_a_moi("zscope", "string_a_moi");
-
-#endif
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.cpp
deleted file mode 100644
index 01b0f6d..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include "test_header_only.h"
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.h
deleted file mode 100644
index 3f8c1b0..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_header_only.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-
-class Class
-{
- Q_OBJECT
- void function()
- {
- tr("translation_in_hearder");
- }
-
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.cpp
deleted file mode 100644
index 6677145..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore/QtCore>
-#include "test_isolatedComments.h"
-#include "test_QT_TR_NOOP_context_with_comments.h"
-
-/* TRANSLATOR MULTIPLELINE
- first line
- second line
- */
-/* TRANSLATOR
- MultipleLineSecondTry
- first line
- second line
- */
-
-/* TRANSLATOR
- MultipleLineThirdTry first
- line
- second line
- */
-
-/* TRANSLATOR
- MultipleLineFourthTry first
- line
- second line
- */
-
-
-/* TRANSLATOR MultipleAppearance first appearance */
-
-/* TRANSLATOR MultipleAppearance second appearance */
-
-/* TRANSLATOR GluedNumber1 blabla */
-/* TRANSLATOR GluedNumber2 blabla */
-// TRANSLATOR GluedNumber3 blabla
-/*TRANSLATOR
-GluedNumber4
- // whatever
- we
- have
- here
-*/
-/* TRANSLATOR GluedNumber5
- // whatever2
- we2
- have2
- here2
-*/
-
-/* TRANSLATOR GluedOnSameLineOne blabla*/ /* TRANSLATOR GluedOnSameLineTwo blabla*/
-// TRANSLATORMISSINGSPACE this will not be picked up by clang cpp parser
-// oooTRANSLATOR SomethingBeforeTranslator this should not be picked up
-// ooo TRANSLATOR SomethingBeforeTranslatorTwo this should not be picked up
-/* ooo TRANSLATOR SomethingBeforeTranslatorThree this should not be picked up */
-/* ~ TRANSLATOR SomethingBeforeTranslatorFour this
- should not be picked up */
-// The following comment should be ignored because the comment part is empty
-/* TRANSLATOR onlyContext */
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.h
deleted file mode 100644
index 94817de..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_isolatedComments.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/* TRANSLATOR
- inHeader
- how to pick this up
- Not triggering visit from AST visitor
- */
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_line_directive.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_line_directive.cpp
deleted file mode 100644
index ed3fc95..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_line_directive.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <QtCore>
-
-QString t1 = QObject::tr("blabla 1");
-
-#line 1 "toto.cpp"
-
-QString t2 = QObject::tr("blabla 2");
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_sameLineComments.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_sameLineComments.cpp
deleted file mode 100644
index 6f0ddef..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_only/test_sameLineComments.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore/QtCore>
-
-class CommentOnSameLineMetaDataComment
-{
- Q_OBJECT
- //= other metaData
- void hello(int something /*= metaData1 */, QString str = tr("meta data comment before translation. , and = in between"));
- void hellobis(/*= metaData2 */QString str = tr("meta data comment before translation. = in between"));
- void hellobiss()
- {
- hellobis(/*= metaData3*/ tr("meta data comment before translation"));
- }
-};
-class CommentOnSameLineExtraComment
-{
- Q_OBJECT
- //: other extra comment
- void hello(int something /*: extra1 */, QString str = tr("extra comment before translation. , and = in between"));
- void hellobis(/*: extra2 */QString str = tr("extra comment before translation. = in between"));
- void hellobiss()
- {
- hellobis(/*: extra3*/ tr("extra comment before translation"));
- }
- //: other extra comment
- QString toto/*: extra4*/; QString titi = tr("extra comment before translation. ; in between");
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/expectedoutput.txt
deleted file mode 100644
index dee7276..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/expectedoutput.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]parsecpp_clang_parser[/\\]main.cpp:406:0: 'translate' cannot be called without context. The call is ignored.
-lupdate warning: Message with id 'yet_another_id' has no source.
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/finddialog.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/finddialog.cpp
deleted file mode 100644
index 66e6152..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/finddialog.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-//#include "finddialog.h" nothing is picked up from there
-//#include "mainwindow.h"
-//#include "tabbedbrowser.h"
-//#include "helpwindow.h"
-#include <QtCore>
-#include <QtWidgets/QTextBrowser>
-#include <QTextCursor>
-#include <QtWidgets/QStatusBar>
-#include <QtWidgets/QLineEdit>
-#include <QDateTime>
-#include <QtWidgets/QGridLayout>
-#include <QtWidgets/QMainWindow>
-class FindDialog
-{ Q_OBJECT
- FindDialog(QMainWindow *parent);
- void findButtonClicked();
- void doFind(bool forward);
- void statusMessage(const QString &message);
- //QMainWindow *mainWindow() const;
- void reset();
-
-
-};
-
-
-FindDialog::FindDialog(QMainWindow *parent)
-{
- //auto contentsWidget = new QWidget(this);
- //ui.setupUi(contentsWidget);
- //ui.comboFind->setModel(new CaseSensitiveModel(0, 1, ui.comboFind));
-
- //QVBoxLayout *l = new QVBoxLayout(this);
- //l->setContentsMargins(QMargins());
- //l->setSpacing(0);
- //l->addWidget(contentsWidget);
-
- auto lastBrowser = 0;
- auto onceFound = false;
- //findExpr.clear();
-
- auto sb = new QStatusBar;
- //l->addWidget(sb);
-
- sb->showMessage(tr("Enter the text you are looking for."));
-
- //connect(ui.findButton, SIGNAL(clicked()), this, SLOT(findButtonClicked()));
- //connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
-}
-
-//FindDialog::~FindDialog()
-//{
-//}
-
-//void FindDialog::findButtonClicked()
-//{
-// doFind(ui.radioForward->isChecked());
-//}
-
-void FindDialog::doFind(bool forward)
-{
- //QTextBrowser *browser = static_cast<QTextBrowser*>(mainWindow()->browsers()->currentBrowser());
- //sb->clearMessage();
-
- //if (ui.comboFind->currentText() != findExpr || lastBrowser != browser)
- // onceFound = false;
- //findExpr = ui.comboFind->currentText();
- bool onceFound = false;
- //QTextDocument::FindFlags flags = 0;
- /*
- if (ui.checkCase->isChecked())
- flags |= QTextDocument::FindCaseSensitively;
-
- if (ui.checkWords->isChecked())
- flags |= QTextDocument::FindWholeWords;
-
- QTextCursor c = browser->textCursor();
- if (!c.hasSelection()) {
- if (forward)
- c.movePosition(QTextCursor::Start);
- else
- c.movePosition(QTextCursor::End);
-
- browser->setTextCursor(c);
- }
-
- QTextDocument::FindFlags options;
- if (forward == false)
- flags |= QTextDocument::FindBackward;
- */
- QTextCursor found;//browser->document()->find(findExpr, c, flags);
- if (found.isNull()) {
- if (onceFound) {
- if (forward)
- statusMessage(tr("Search reached end of the document"));
- else
- statusMessage(tr("Search reached start of the document"));
- } else {
- statusMessage(tr( "Text not found" ));
- }
- } else {
- //browser->setTextCursor(found);
- }
- onceFound |= !found.isNull();
- //lastBrowser = browser;
-}
-
-//bool FindDialog::hasFindExpression() const
-//{
-// return !findExpr.isEmpty();
-//}
-
-void FindDialog::statusMessage(const QString &message)
-{ /*
- if (isVisible())
- sb->showMessage(message);
- else
- static_cast<MainWindow*>(parent())->statusBar()->showMessage(message, 2000); */
-}
-
-//QMainWindow *FindDialog::mainWindow() const
-//{
-// return static_cast<MainWindow*>(parentWidget());
-//}
-
-void FindDialog::reset()
-{
- //ui.comboFind->setFocus();
- //ui.comboFind->lineEdit()->setSelection(
- // 0, ui.comboFind->lineEdit()->text().length());
-
- QString s = QCoreApplication::translate("QCoreApplication", "with comment", "comment");
- QString s1 = QCoreApplication::translate("QCoreApplication", "empty comment", "");
- QString s2 = QCoreApplication::translate("QCoreApplication", "null comment", 0);
- QString s3 = tr("null comment");
-
- QString s4 = QCoreApplication::translate("QCoreApplication", "encoding, using QCoreApplication", 0);
- QString s5 = QCoreApplication::translate("QCoreApplication", "encoding, using QApplication", 0);
-
- QString s6 = QCoreApplication::translate("Kåntekst", "encoding, using QApplication", 0);
- QString s7 = QCoreApplication::translate("QTranslator", "Key", "disambiguation");
-}
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/included.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/included.cpp
deleted file mode 100644
index ff7fe37..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/included.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-class MyClass2{
- QString toto = QObject::tr("message from #included .cpp file");
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/main.cpp
deleted file mode 100644
index 0b70f3b..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/main.cpp
+++ /dev/null
@@ -1,690 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// IMPORTANT!!!! If you want to add testdata to this file,
-// always add it to the end in order to not change the linenumbers of translations!!!
-int main(int argc, char **argv)
-{
- //Size size = QSize(1,1);
-}
-#include <QtCore>
-QString qt_detectRTLLanguage()
-{
- return QCoreApplication::tr("QT_LAYOUT_DIRECTION",
- "Translate this string to the string 'LTR' in left-to-right"
- " languages or to 'RTL' in right-to-left languages (such as Hebrew"
- " and Arabic) to get proper widget layout.");// == QLatin1String("RTL");
-}
-
-
-class Dialog2
-{
- Q_OBJECT
- void func();
- void func3();
- int getCount() const { return 2; }
-
-};
-
-void Dialog2::func()
-{
- int n = getCount();
- tr("%n files", "plural form", n);
- tr("%n cars", 0, n);
- tr("&Find %n cars", 0, n);
- tr("Search in %n items?", 0, n);
- tr("%1. Search in %n items?", 0, n);
- tr("Age: %1");
- tr("There are %n house(s)", "Plurals and function call", getCount());
-
-
-
-
- QCoreApplication::translate("Plurals, QCoreApplication", "%n house(s)", "Plurals and identifier", n);
- QCoreApplication::translate("Plurals, QCoreApplication", "%n car(s)", "Plurals and literal number", 1);
- QCoreApplication::translate("Plurals, QCoreApplication", "%n horse(s)", "Plurals and function call", getCount());
-
-
-
-
-
-
-
-
- QTranslator trans;
- trans.translate("QTranslator", "Simple");
- trans.translate("QTranslator", "Simple", 0);
- trans.translate("QTranslator", "Simple with comment", "with comment");
- trans.translate("QTranslator", "Plural without comment", 0, 1);
- trans.translate("QTranslator", "Plural with comment", "comment 1", n);
- trans.translate("QTranslator", "Plural with comment", "comment 2", getCount());
-
-
-
-
-
-
-
-
-
-
-
-
-}
-
-
-
-
-/* This is actually a test of how many alternative ways a struct/class can be found in a source file.
- * Due to the simple parser in lupdate, it will actually not treat the remaining lines in the define
- * as a macro, which is a case the 'Tok_Class' parser block might not consider, and it might loop infinite
- * if it just tries to fetch the next token until it gets a '{' or a ';'. Another pitfall is that the
- * context of tr("func3") might not be parsed, it won't resume normal evaluation until the '{' after the function
- * signature.
- *
- */
-typedef struct S_
-{
-int a;
-} S, *SPtr;
-class ForwardDecl;
-
-
-#define FT_DEFINE_SERVICE( name ) \
- typedef struct FT_Service_ ## name ## Rec_ \
- FT_Service_ ## name ## Rec ; \
- typedef struct FT_Service_ ## name ## Rec_ \
- const * FT_Service_ ## name ; \
- struct FT_Service_ ## name ## Rec_
-
-
-
-
-void Dialog2::func3()
-{
- tr("func3");
-}
-
-
-
-
-namespace Gui { class BaseClass {}; }
-
-
-class TestClass : QObject {
- Q_OBJECT
-
-
- inline QString inlineFunc1() {
- return tr("inline function", "TestClass");
- }
-
- QString inlineFunc2() {
- return tr("inline function 2", "TestClass");
- }
-
- static inline QString staticInlineFunc() {
- return tr("static inline function", "TestClass");
- }
-
- class NoQObject : public Gui::BaseClass {
- public:
- inline QString hello() { return QString("hello"); }
-
- };
-
-};
-
-
-class Testing : QObject {
- Q_OBJECT
-
- inline QString f1() {
- //: this is an extra comment for the translator
- return tr("extra-commented string");
- return tr("not extra-commented string");
- /*: another extra-comment */
- return tr("another extra-commented string");
- /*: blah! */
- return QCoreApplication::translate("scope", "works in translate, too", "blabb", 0);
- }
-
-};
-
-//: extra comment for NOOP
-//: which spans multiple lines
-const char *c_1 = QT_TRANSLATE_NOOP("scope", "string") /*: complain & ignore */; // 4.4 says the line of this is at the next statement
-//: extra comment for NOOP3
-const char *c_2[2] = QT_TRANSLATE_NOOP3_UTF8("scope", "string", "comment"); // 4.4 doesn't see this
-
-const char *c_3 = QT_TRANSLATE_NOOP("scope", "string " // this is an interleaved comment
- "continuation on next line");
-
-
-class TestingTake17 : QObject {
- Q_OBJECT
-
- void function(void)
- {
- //: random comment
- //= this_is_an_id
- //~ loc-layout_id fooish_bar
- //~ po-ignore_me totally foo-barred nonsense
- tr("something cool");
-
- tr("less cool");
-
- //= another_id
- tr("even more cool");
- }
-};
-
-
-
-
-//: again an extra comment, this time for id-based NOOP
-//% "This is supposed\tto be quoted \" newline\n"
-//% "backslashed \\ stuff."
-const char *c_4 = QT_TRID_NOOP("this_a_id");
-
-//~ some thing
-//% "This needs to be here. Really."
-QString test = qtTrId("this_another_id", 2);
-
-
-
-class YetAnotherTest : QObject {
- Q_OBJECT
-
- void function(void)
- {
- //
- //:
- //=
- //~
- //#
- //=============
- //~~~~~~~~~~~~~
- //:::::::::::::
- tr("nothing");
- }
-};
-
-
-
-//: This is a message without a source string
-QString test1 = qtTrId("yet_another_id");
-
-
-
-// QTBUG-9276: context in static initializers
-class Bogus : QObject {
- Q_OBJECT
- static const char * const s_stringss[];
- static const char * const s_strings[];
-
-};
-const char * const Bogus::s_strings[] = {
- QT_TR_NOOP("this should be in Bogus")
-};
-
-const char * const Bogus::s_stringss[] = {
- QT_TR_NOOP("this should be in Bogus")
-};
-
-void bogosity()
-{
- // no spaces here. test collateral damage from ignoring equal sign
- QString toto=QObject::tr("just QObject");
-}
-
-
-
-namespace Internal {
-
-class Message : public QObject
-{
- Q_OBJECT
-public:
- Message(QObject *parent = 0);
-};
-
-} // The temporary closing of the namespace triggers the problem
-
-namespace Internal {
-
-static inline QString message1()
-{
- return Message::tr("message1"); // Had no namespace
-}
-
-static inline QString message2()
-{
- return Message::tr("message2"); // Already had namespace
-}
-
-}
-
-
-
-// QTBUG-11426: operator overloads
-class LotsaFun : public QObject
-{
- Q_OBJECT
-public:
- LotsaFun *operator<<(int i);
-};
-
-LotsaFun *LotsaFun::operator<<(int i)
-{
- tr("this is inside operator<<");
- return this;
-}
-
-
-
-// QTBUG-12683: define in re-opened namespace
-namespace NameSchpace {
-
-class YetMoreFun : public QObject
-{
- Q_OBJECT
-public:
- void funStuff();
-};
-
-}
-
-namespace NameSchpace {
-
-#define somevar 1
-
-void YetMoreFun::funStuff()
-{
- tr("funStuff!");
-}
-
-}
-
-
-
-// QTBUG-29998: tr() macro inside square brackets
-void blubb()
-{
- QMap<QString, QString> d;
- d[LotsaFun::tr("bracketed")] = "plain";
-}
-
-
-
-// QTBUG-9276 part 2: QT_TR_NOOP in static member initializers
-class TestClass2
-{
- Q_DECLARE_TR_FUNCTIONS(TestClass);
-
-public:
- static const char TEST_STRING[];
-};
-
-const char TestClass2::TEST_STRING[] = QT_TR_NOOP("Test value");
-
-
-
-// derivation from namespaced class
-class Class42 : public NameSchpace::YetMoreFun, Gui::BaseClass
-{
- Q_OBJECT
- void foo();
- Class42() :
- NameSchpace::YetMoreFun(),
- Gui::BaseClass()
- {
- tr("does that make sense?");
- }
- void hello(int something, QString str);
-};
-
-
-void Class42::foo()
-{
- tr("and does that?");
-}
-
-
-
-// QTBUG-11866: magic comment parsing is too greedy
-void Class42::hello(int something /*= 17 */, QString str = Class42::tr("eyo"))
-{
-}
-
-
-
-// QTBUG-27974: strings from included sources are not collected
-#include "included.cpp"
-
-// test TR_EXCLUDE
-#include "notincluded.cpp"
-
-
-
-// failure to update index on insertion messes up subsequent de-duplication
-void dupeFail()
-{
- // First just the Id.
- qtTrId("dupe_id");
-
- // Then with source
- //% "This is the source"
- qtTrId("dupe_id");
-
- // Finally, same source, but without ID.
- QCoreApplication::translate("", "This is the source");
-}
-
-
-
-// QTBUG-42735: lupdate confused by `final` specifier (C++11)
-namespace Abc {
-
-class NamespacedFinalClass;
-
-}
-
-class FinalClass final : public QObject
-{
- Q_OBJECT
-
- class SubClass final
- {
- void f()
- {
- tr("nested class context with final");
- }
- };
-
- void f()
- {
- tr("class context with final");
- }
-};
-
-class Abc::NamespacedFinalClass final : public QObject
-{
- Q_OBJECT
-
- void f()
- {
- tr("namespaced class with final");
- }
-};
-
-
-
-// QTBUG-48776: lupdate fails to recognize translator comment in ternary
-// operator construct
-void ternary()
-{
- const auto aaa =
- true ?
- //: comment, aaa, true
- QObject::tr("ternary, true, aaa") :
- QObject::tr("ternary, failure, aaa");
-
- const auto bbb =
- true ?
- //: comment, bbb, true
- QObject::tr("ternary, bbb, true") :
- //: comment, bbb, false
- QObject::tr("ternary, bbb, false");
-}
-
-class TernaryClass : public QObject
-{
- Q_OBJECT
-
- void f()
- {
- const auto ccc =
- true ?
- //: comment, ccc, true
- tr("ternary, ccc, true") :
- tr("ternary, ccc, false");
-
- const auto ddd =
- true ?
- //: comment, ddd, true
- tr("ternary, ddd, true") :
- //: comment, ddd, false
- tr("ternary, ddd, false");
- }
-};
-
-
-
-// QTBUG-47467: lupdate confused by nullptr in case of plural forms
-void nullptrInPlural()
-{
- QObject::tr("%n nullptr(s)", nullptr, 3);
- QCoreApplication::translate("Plurals, nullptr", "%n car(s)", nullptr, 1);
-}
-
-class nullptrClass : public QObject
-{
- Q_OBJECT
-
- void f()
- {
- tr("%n car(s)", nullptr, 2);
- }
-};
-
-
-
-// QTBUG-34265: lupdate does not detect NULL and Q_NULLPTR as 0 when being passed as context
-void nullMacroInPlural()
-{
- QObject::tr("%n NULL(s)", NULL, 3);
- QObject::tr("%n Q_NULLPTR(s)", Q_NULLPTR, 3);
-}
-
-
-
-// QTBUG-34128: lupdate ignores tr() calls in constructor if a member is
-// initialized with C++11 initializer list
-class ListInitializationClass : public NameSchpace::YetMoreFun, Gui::BaseClass
-{
- Q_OBJECT
-
- ListInitializationClass() :
- NameSchpace::YetMoreFun(),
- Gui::BaseClass{ },
- a{ 0 },
- b(1),
- c(tr("Hello World"))
- {
- tr("ListInitializationClass in-class constructor");
- }
-
- ListInitializationClass(int a);
-
- ListInitializationClass(int a, int b, int c);
-
- int a;
- int b;
- QString c;
-};
-
-ListInitializationClass::ListInitializationClass(int a)// :
-// b{ { 2, 3 }}[a]
-{
- tr("ListInitializationClass out-of-class single member initializer");
-}
-
-ListInitializationClass::ListInitializationClass(int a, int b, int c) :
- NameSchpace::YetMoreFun{ },
- Gui::BaseClass(),
- a{ 2 + (a/3) },
- b(b),
- c{ tr("%n item(s)", Q_NULLPTR, c) }
-{
- tr("ListInitializationClass out-of-class multi member initializer");
-}
-
-
-
-// QTBUG-42166: lupdate is confused by C++11 lambdas in constructor initializer lists
-class LambdaMemberClass : public Gui::BaseClass
-{
- Q_OBJECT
-
- LambdaMemberClass() :
- Gui::BaseClass(),
- a{ [](){ /*std::cout << */QObject::tr("Hello"); } },
- b([](){ /*std::cout << "World\n";*/ })
- {
- tr("LambdaMemberClass in-class constructor");
- }
-
- LambdaMemberClass(void *);
-
- std::function<void()> a;
- std::function<void()> b;
-};
-
-LambdaMemberClass::LambdaMemberClass(void *) :
- Gui::BaseClass{ },
- a([](){ /*std::cout <<*/ QObject::tr("Hallo "); }),
- b{ [](){ /*std::cout << "Welt\n";*/ } }
-{
- tr("LambdaMemberClass out-of-class constructor");
-}
-
-
-
-// Template parameters in base class initialization
-class TemplateClass : QVarLengthArray<char, sizeof(std::size_t)>, std::vector<int>
-{
- Q_DECLARE_TR_FUNCTIONS(TemplateClass)
- QString member;
-
-public:
- TemplateClass() :
- QVarLengthArray<char, sizeof(std::size_t)>(),
- std::vector<int>(3),
- member(tr("TemplateClass() in-class member initialization"))
- {
- tr("TemplateClass() in-class body");
- }
-
- TemplateClass(void *);
- TemplateClass(int);
-};
-
-// supported: combination of parens in base class template parameter with direct initialization (parens)
-TemplateClass::TemplateClass(void *) :
- QVarLengthArray<char, sizeof(std::size_t)>(),
- std::vector<int>{ 1, 2 },
- member{ tr("TemplateClass(void *) out-of-class member initialization") }
-{
- tr("TemplateClass(void *) out-of-class body");
-}
-
-// not supported: combination of parens in base class template parameter with list initialization (braces)
-TemplateClass::TemplateClass(int) :
- QVarLengthArray<char, sizeof(std::size_t)>{ 3, 4, 5 },
- member(tr("[unsupported] TemplateClass(int) out-of-class member initialization"))
-{
- tr("[unsupported] TemplateClass(int) out-of-class body");
-}
-
-
-
-// Related to QTBUG-53644, adapted from qglobal.h.
-// Namespace Private must be parsed correctly for TranslatedAfterPrivate to work.
-namespace Private {
- template <class T> struct Class1 { T t; };
- template <class T> struct Class1<T &> : Class1<T> {};
- template <class T> struct Class2 { enum { Value = sizeof(T) }; };
-} // namespace Private
-class TranslatedAfterPrivate
-{
- Q_OBJECT
- TranslatedAfterPrivate()
- {
- tr("Must be in context TranslatedAfterPrivate");
- }
-};
-
-#include<QObject>
-class AClass {
- QString aa = QObject::tr("message after system include without space");
-};
-#include"qobject.h"
-class AAClass {
- QString aa = QObject::tr("message after local include without space");
-};
-
-
-// QTBUG-35164: handling of \uNNNN escapes
-QString unicodeEscape()
-{
- return QCoreApplication::tr("Context", "soft\u00ADhyphen");
-}
-
-
-
-// QTBUG-63364: C++17 nested namespaces
-namespace Outer::Inner {
-
-class Class
-{
- Q_OBJECT
- void function()
- {
- tr("MoreFunStuff!");
- }
-};
-
-}
-
-
-
-// test of translation for _N_ family
-static const char * const test_string_n1[] = {
- QT_TRANSLATE_N_NOOP("scope", "string %n")
-};
-
-static const char * const test_string_n2[] =
- QT_TRANSLATE_N_NOOP3("scope", "string %n", "comment")
-;
-class testing { Q_OBJECT
- void test(); };
-void testing::test() { static const char * const test_string_n3[] = {
- QT_TR_N_NOOP("%n test")
- };
-}
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/my_include.h b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/my_include.h
deleted file mode 100644
index 1c609d1..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/my_include.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <QtCore>
-
-class Foo
-{
- Q_OBJECT
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/notincluded.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/notincluded.cpp
deleted file mode 100644
index 3f502ff..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/notincluded.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-class MyClass{
- QString toto = QObject::tr("message from #included .cpp file");
-};
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.pro
deleted file mode 100644
index 0fd8a96..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-SOURCES += main.cpp
-SOURCES += finddialog.cpp
-SOURCES += excluded.cpp
-
-TR_EXCLUDE = $$PWD/excluded.* $$PWD/notincluded.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.ts.result
deleted file mode 100644
index ad871b2..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp_clang_parser/project.ts.result
+++ /dev/null
@@ -1,666 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name></name>
- <message id="this_a_id">
- <location filename="main.cpp" line="213"/>
- <source>This is supposed to be quoted " newline
-backslashed \ stuff.</source>
- <extracomment>again an extra comment, this time for id-based NOOP</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message id="this_another_id" numerus="yes">
- <location filename="main.cpp" line="217"/>
- <source>This needs to be here. Really.</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- <extra-some>thing</extra-some>
- </message>
- <message id="yet_another_id">
- <location filename="main.cpp" line="241"/>
- <source></source>
- <extracomment>This is a message without a source string</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message id="dupe_id">
- <location filename="main.cpp" line="399"/>
- <location filename="main.cpp" line="403"/>
- <source>This is the source</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Abc::NamespacedFinalClass</name>
- <message>
- <location filename="main.cpp" line="442"/>
- <source>namespaced class with final</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Bogus</name>
- <message>
- <location filename="main.cpp" line="253"/>
- <location filename="main.cpp" line="257"/>
- <source>this should be in Bogus</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Class42</name>
- <message>
- <location filename="main.cpp" line="367"/>
- <source>does that make sense?</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="375"/>
- <source>and does that?</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="381"/>
- <source>eyo</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Dialog2</name>
- <message numerus="yes">
- <location filename="main.cpp" line="57"/>
- <source>%n files</source>
- <comment>plural form</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="58"/>
- <source>%n cars</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="59"/>
- <source>&Find %n cars</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="60"/>
- <source>Search in %n items?</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="61"/>
- <source>%1. Search in %n items?</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message>
- <location filename="main.cpp" line="62"/>
- <source>Age: %1</source>
- <translation type="unfinished"></translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="63"/>
- <source>There are %n house(s)</source>
- <comment>Plurals and function call</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message>
- <location filename="main.cpp" line="130"/>
- <source>func3</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>FinalClass</name>
- <message>
- <location filename="main.cpp" line="426"/>
- <source>nested class context with final</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="432"/>
- <source>class context with final</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>FindDialog</name>
- <message>
- <location filename="finddialog.cpp" line="72"/>
- <source>Enter the text you are looking for.</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="122"/>
- <source>Search reached end of the document</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="124"/>
- <source>Search reached start of the document</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="126"/>
- <source>Text not found</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="162"/>
- <source>null comment</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Internal::Message</name>
- <message>
- <location filename="main.cpp" line="283"/>
- <source>message1</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="288"/>
- <source>message2</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Kåntekst</name>
- <message>
- <location filename="finddialog.cpp" line="167"/>
- <source>encoding, using QApplication</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>LambdaMemberClass</name>
- <message>
- <location filename="main.cpp" line="570"/>
- <source>LambdaMemberClass in-class constructor</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="584"/>
- <source>LambdaMemberClass out-of-class constructor</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>ListInitializationClass</name>
- <message>
- <location filename="main.cpp" line="528"/>
- <source>Hello World</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="530"/>
- <source>ListInitializationClass in-class constructor</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="545"/>
- <source>ListInitializationClass out-of-class single member initializer</source>
- <translation type="unfinished"></translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="553"/>
- <source>%n item(s)</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message>
- <location filename="main.cpp" line="555"/>
- <source>ListInitializationClass out-of-class multi member initializer</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>LotsaFun</name>
- <message>
- <location filename="main.cpp" line="305"/>
- <source>this is inside operator<<</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="340"/>
- <source>bracketed</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>NameSchpace::YetMoreFun</name>
- <message>
- <location filename="main.cpp" line="329"/>
- <source>funStuff!</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Outer::Inner::Class</name>
- <message>
- <location filename="main.cpp" line="669"/>
- <source>MoreFunStuff!</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Plurals, QCoreApplication</name>
- <message numerus="yes">
- <location filename="main.cpp" line="68"/>
- <source>%n house(s)</source>
- <comment>Plurals and identifier</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="69"/>
- <source>%n car(s)</source>
- <comment>Plurals and literal number</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="70"/>
- <source>%n horse(s)</source>
- <comment>Plurals and function call</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-<context>
- <name>Plurals, nullptr</name>
- <message numerus="yes">
- <location filename="main.cpp" line="493"/>
- <source>%n car(s)</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-<context>
- <name>QCoreApplication</name>
- <message>
- <location filename="finddialog.cpp" line="159"/>
- <source>with comment</source>
- <comment>comment</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="160"/>
- <source>empty comment</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="161"/>
- <source>null comment</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="164"/>
- <source>encoding, using QCoreApplication</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="finddialog.cpp" line="165"/>
- <source>encoding, using QApplication</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="38"/>
- <source>QT_LAYOUT_DIRECTION</source>
- <comment>Translate this string to the string 'LTR' in left-to-right languages or to 'RTL' in right-to-left languages (such as Hebrew and Arabic) to get proper widget layout.</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="656"/>
- <source>Context</source>
- <comment>softhyphen</comment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>QObject</name>
- <message>
- <location filename="main.cpp" line="263"/>
- <source>just QObject</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="455"/>
- <source>ternary, true, aaa</source>
- <extracomment>comment, aaa, true</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="456"/>
- <source>ternary, failure, aaa</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="461"/>
- <source>ternary, bbb, true</source>
- <extracomment>comment, bbb, true</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="463"/>
- <source>ternary, bbb, false</source>
- <extracomment>comment, bbb, false</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="492"/>
- <source>%n nullptr(s)</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="511"/>
- <source>%n NULL(s)</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="512"/>
- <source>%n Q_NULLPTR(s)</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message>
- <location filename="main.cpp" line="567"/>
- <source>Hello</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="581"/>
- <source>Hallo </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="645"/>
- <source>message after system include without space</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="649"/>
- <source>message after local include without space</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="included.cpp" line="30"/>
- <source>message from #included .cpp file</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>QTranslator</name>
- <message>
- <location filename="finddialog.cpp" line="168"/>
- <source>Key</source>
- <comment>disambiguation</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="80"/>
- <location filename="main.cpp" line="81"/>
- <source>Simple</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="82"/>
- <source>Simple with comment</source>
- <comment>with comment</comment>
- <translation type="unfinished"></translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="83"/>
- <source>Plural without comment</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="84"/>
- <source>Plural with comment</source>
- <comment>comment 1</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="85"/>
- <source>Plural with comment</source>
- <comment>comment 2</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-<context>
- <name>TemplateClass</name>
- <message>
- <location filename="main.cpp" line="599"/>
- <source>TemplateClass() in-class member initialization</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="601"/>
- <source>TemplateClass() in-class body</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="612"/>
- <source>TemplateClass(void *) out-of-class member initialization</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="614"/>
- <source>TemplateClass(void *) out-of-class body</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="620"/>
- <source>[unsupported] TemplateClass(int) out-of-class member initialization</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="622"/>
- <source>[unsupported] TemplateClass(int) out-of-class body</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>TernaryClass</name>
- <message>
- <location filename="main.cpp" line="475"/>
- <source>ternary, ccc, true</source>
- <extracomment>comment, ccc, true</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="476"/>
- <source>ternary, ccc, false</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="481"/>
- <source>ternary, ddd, true</source>
- <extracomment>comment, ddd, true</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="483"/>
- <source>ternary, ddd, false</source>
- <extracomment>comment, ddd, false</extracomment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>TestClass</name>
- <message>
- <location filename="main.cpp" line="144"/>
- <source>inline function</source>
- <comment>TestClass</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="148"/>
- <source>inline function 2</source>
- <comment>TestClass</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="152"/>
- <source>static inline function</source>
- <comment>TestClass</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="354"/>
- <source>Test value</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Testing</name>
- <message>
- <location filename="main.cpp" line="169"/>
- <source>extra-commented string</source>
- <extracomment>this is an extra comment for the translator</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="170"/>
- <source>not extra-commented string</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="172"/>
- <source>another extra-commented string</source>
- <extracomment>another extra-comment</extracomment>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>TestingTake17</name>
- <message id="this_is_an_id">
- <location filename="main.cpp" line="198"/>
- <source>something cool</source>
- <extracomment>random comment</extracomment>
- <translation type="unfinished"></translation>
- <extra-loc-layout_id>fooish_bar</extra-loc-layout_id>
- <extra-po-ignore_me>totally foo-barred nonsense</extra-po-ignore_me>
- </message>
- <message>
- <location filename="main.cpp" line="200"/>
- <source>less cool</source>
- <translation type="unfinished"></translation>
- </message>
- <message id="another_id">
- <location filename="main.cpp" line="203"/>
- <source>even more cool</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>TranslatedAfterPrivate</name>
- <message>
- <location filename="main.cpp" line="639"/>
- <source>Must be in context TranslatedAfterPrivate</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>YetAnotherTest</name>
- <message>
- <location filename="main.cpp" line="234"/>
- <source>nothing</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>nullptrClass</name>
- <message numerus="yes">
- <location filename="main.cpp" line="502"/>
- <source>%n car(s)</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-<context>
- <name>scope</name>
- <message numerus="yes">
- <location filename="main.cpp" line="174"/>
- <source>works in translate, too</source>
- <comment>blabb</comment>
- <extracomment>blah!</extracomment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message>
- <location filename="main.cpp" line="181"/>
- <source>string</source>
- <extracomment>extra comment for NOOP which spans multiple lines</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="183"/>
- <source>string</source>
- <comment>comment</comment>
- <extracomment>extra comment for NOOP3</extracomment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="185"/>
- <source>string continuation on next line</source>
- <translation type="unfinished"></translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="679"/>
- <source>string %n</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
- <message numerus="yes">
- <location filename="main.cpp" line="683"/>
- <source>string %n</source>
- <comment>comment</comment>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-<context>
- <name>testing</name>
- <message numerus="yes">
- <location filename="main.cpp" line="688"/>
- <source>%n test</source>
- <translation type="unfinished">
- <numerusform></numerusform>
- </translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.cpp b/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.cpp
deleted file mode 100644
index 05d46a3..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include "main.h"
-
-QString foo()
-{
- return QCoreApplication::translate("Foo","XXX","YYY");
-}
-
-Foo::Foo()
-{
- tr("CTOR");
-}
-
-void Foo::bar()
-{
- tr("BAR");
-}
-
-class BitFields : public QObject
-{
- int bits : 20;
- QString str = tr("text BitFields");
-};
-
-Bibi::Bibi()
-{
- //int bits : 32;
- tr("text Bibi");
- Babebi::tr("text Babebi");
-}
diff --git a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.h b/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.h
deleted file mode 100644
index 063d513..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/main.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-#include <QtCore>
-
-class Foo
-{
- Q_OBJECT
- Foo();
- void bar();
-};
-
-class Bibi
-{
- Q_OBJECT
- Bibi();
-
-};
-
-class Babebi
-{
-Q_OBJECT
-};
-
diff --git a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.pro b/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.pro
deleted file mode 100644
index 759bea0..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-SOURCES = main.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.ts.result
deleted file mode 100644
index 5af02f7..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/prefix_clang_parser/project.ts.result
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name>Babebi</name>
- <message>
- <location filename="main.cpp" line="55"/>
- <source>text Babebi</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Bibi</name>
- <message>
- <location filename="main.cpp" line="54"/>
- <source>text Bibi</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>Foo</name>
- <message>
- <location filename="main.cpp" line="32"/>
- <source>XXX</source>
- <comment>YYY</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="37"/>
- <source>CTOR</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="42"/>
- <source>BAR</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>QObject</name>
- <message>
- <location filename="main.cpp" line="48"/>
- <source>text BitFields</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/expectedoutput.txt
deleted file mode 100644
index fe7615b..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/expectedoutput.txt
+++ /dev/null
@@ -1 +0,0 @@
-.*[/\\]lupdate[/\\]testdata[/\\]good[/\\]preprocess_clang_parser[/\\]main.cpp Code with translation information has been skipped between lines .. and ..
diff --git a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/main.cpp b/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/main.cpp
deleted file mode 100644
index bc20bef..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/main.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// IMPORTANT!!!! If you want to add testdata to this file,
-// always add it to the end in order to not change the linenumbers of translations!!!
-#include <QtWidgets/QApplication>
-
-void func1() {
- QApplication::tr("Hello world", "Platform-independent file");
-}
-
-
-
-
-void func2() {
-#ifdef Q_OS_WIN
- QApplication::tr("KindType", "The other option has been skipped");
-#else
- QApplication::tr("KindType", "The other option has been skipped");
-#endif
-
-}
-
-
-
-void stringconcatenation()
-{
- QApplication::tr("One string,"
- " three"
- " lines");
-
- QApplication::tr("a backslash followed by newline \
-should be ignored \
-and the next line should be syntactically considered to be \
-on the same line");
-
-}
diff --git a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.pro b/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.pro
deleted file mode 100644
index c96859b..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-SOURCES += main.cpp
-
-TRANSLATIONS = project.ts
diff --git a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.ts.result
deleted file mode 100644
index 666dc0f..0000000
--- a/tests/auto/linguist/lupdate/testdata/good/preprocess_clang_parser/project.ts.result
+++ /dev/null
@@ -1,29 +0,0 @@
-.*
-<!DOCTYPE TS>
-<TS version="2.1">
-<context>
- <name>QApplication</name>
- <message>
- <location filename="main.cpp" line="34"/>
- <source>Hello world</source>
- <comment>Platform-independent file</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line=.*/>
- <source>KindType</source>
- <comment>The other option has been skipped</comment>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="53"/>
- <source>One string, three lines</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="main.cpp" line="57"/>
- <source>a backslash followed by newline should be ignored and the next line should be syntactically considered to be on the same line</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-</TS>
diff --git a/tests/auto/linguist/lupdate/tst_lupdate.cpp b/tests/auto/linguist/lupdate/tst_lupdate.cpp
index ec8e9c1..364066e 100644
--- a/tests/auto/linguist/lupdate/tst_lupdate.cpp
+++ b/tests/auto/linguist/lupdate/tst_lupdate.cpp
@@ -8,11 +8,11 @@
#include <QtCore/QByteArray>
#include <QtCore/QDebug>
#include <QtCore/QDir>
-#include <QtCore/QFile>
#include <QtCore/QElapsedTimer>
-#include <QtCore/private/qconfig_p.h>
+#include <QtCore/QFile>
#include <QtCore/QSet>
#include <QtCore/QSysInfo>
+#include <QtCore/private/qconfig_p.h>
#include <QtTest/QtTest>
#include <QtTools/private/qttools-config_p.h>
@@ -22,12 +22,9 @@
using namespace Qt::Literals::StringLiterals;
-// The slowest test (clang-proparsing) has been observed to take 22s in COIN/Linux.
-// Windows does not run the clang tests.
static constexpr int TIMEOUT = 120000;
-class tst_lupdate : public QObject
-{
+class tst_lupdate : public QObject {
Q_OBJECT
public:
tst_lupdate();
@@ -47,11 +44,10 @@ private:
QElapsedTimer m_timer;
qint64 m_maxElapsed = -1;
- static void doCompare(QList<QStringView> actual, const QString &expectedFn, bool err);
- void doCompare(const QString &actualFn, const QString &expectedFn, bool err);
+ static void doCompare(QList<QStringView> actual, const QString& expectedFn, bool err);
+ void doCompare(const QString& actualFn, const QString& expectedFn, bool err);
};
-
tst_lupdate::tst_lupdate()
{
m_timer.start();
@@ -66,7 +62,7 @@ void tst_lupdate::cleanupTestCase()
qInfo().noquote().nospace() << "max elapsed: " << m_maxElapsed << "ms";
}
-static bool prepareMatch(QStringView expect, QString *tmpl, qsizetype *require, qsizetype *accept)
+static bool prepareMatch(QStringView expect, QString* tmpl, qsizetype* require, qsizetype* accept)
{
if (expect.startsWith(QLatin1Char('\\'))) {
*tmpl = expect.sliced(1).toString();
@@ -90,7 +86,7 @@ static bool prepareMatch(QStringView expect, QString *tmpl, qsizetype *require,
*tmpl = expect.sliced(brc + 1).toString();
auto sub = expect.sliced(1, brc - 1);
const auto com = sub.indexOf(u',');
- bool ok{};
+ bool ok {};
if (com < 0) {
*require = *accept = sub.toInt(&ok);
return ok;
@@ -112,12 +108,12 @@ static bool isStashMessage(QStringView v)
return v.startsWith("Info: creating stash file "_L1);
}
-void tst_lupdate::doCompare(QList<QStringView> actual, const QString &expectedFn, bool err)
+void tst_lupdate::doCompare(QList<QStringView> actual, const QString& expectedFn, bool err)
{
QFile file(expectedFn);
QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text), qPrintable(expectedFn));
const QString expectedS = QString::fromUtf8(file.readAll());
- auto expected = QStringView{expectedS}.split(u'\n');
+ auto expected = QStringView { expectedS }.split(u'\n');
actual.erase(std::remove_if(actual.begin(), actual.end(), isStashMessage), actual.end());
@@ -125,7 +121,8 @@ void tst_lupdate::doCompare(QList<QStringView> actual, const QString &expectedFn
qsizetype oei = 0, oai = 0, oem = em, oam = am;
qsizetype require = 0, accept = 0;
QString tmpl;
- forever {
+ forever
+ {
if (!accept) {
oei = ei, oai = ai;
if (ei == em) {
@@ -135,7 +132,9 @@ void tst_lupdate::doCompare(QList<QStringView> actual, const QString &expectedFn
}
if (!prepareMatch(expected.at(ei++), &tmpl, &require, &accept))
QFAIL(qPrintable(QString("Malformed expected %1 at %3:%2"_L1)
- .arg(err ? "output"_L1 : "result"_L1).arg(ei).arg(expectedFn)));
+ .arg(err ? "output"_L1 : "result"_L1)
+ .arg(ei)
+ .arg(expectedFn)));
}
if (ai == am) {
if (require <= 0) {
@@ -145,27 +144,27 @@ void tst_lupdate::doCompare(QList<QStringView> actual, const QString &expectedFn
break;
}
if (err
- ? !QRegularExpression(QRegularExpression::anchoredPattern(tmpl)).matchView(actual.at(ai)).hasMatch()
- : (actual.at(ai) != tmpl)) {
+ ? !QRegularExpression(QRegularExpression::anchoredPattern(tmpl)).matchView(actual.at(ai)).hasMatch()
+ : (actual.at(ai) != tmpl)) {
if (require <= 0) {
accept = 0;
continue;
}
ei--;
require = accept = 0;
- forever {
+ forever
+ {
if (!accept) {
oem = em, oam = am;
if (ei == em)
break;
if (!prepareMatch(expected.at(--em), &tmpl, &require, &accept))
QFAIL(qPrintable(QString("Malformed expected %1 at %3:%2"_L1)
- .arg(err ? "output"_L1 : "result"_L1)
- .arg(em + 1).arg(expectedFn)));
+ .arg(err ? "output"_L1 : "result"_L1)
+ .arg(em + 1)
+ .arg(expectedFn)));
}
- if (ai == am || (err
- ? !QRegularExpression(QRegularExpression::anchoredPattern(tmpl)).matchView(actual.at(am - 1)).hasMatch()
- : (actual.at(am - 1) != tmpl))) {
+ if (ai == am || (err ? !QRegularExpression(QRegularExpression::anchoredPattern(tmpl)).matchView(actual.at(am - 1)).hasMatch() : (actual.at(am - 1) != tmpl))) {
if (require <= 0) {
accept = 0;
continue;
@@ -211,22 +210,21 @@ void tst_lupdate::doCompare(QList<QStringView> actual, const QString &expectedFn
diff += u'\n';
}
QFAIL(qPrintable((err ? "Output for "_L1 : "Result for "_L1)
- + expectedFn + " does not meet expectations:\n"_L1 + diff));
- }
+ + expectedFn + " does not meet expectations:\n"_L1 + diff));
+}
-void tst_lupdate::doCompare(const QString &actualFn, const QString &expectedFn, bool err)
+void tst_lupdate::doCompare(const QString& actualFn, const QString& expectedFn, bool err)
{
QFile afile(actualFn);
QVERIFY2(afile.open(QIODevice::ReadOnly | QIODevice::Text), qPrintable(actualFn));
const QString actual = QString::fromUtf8(afile.readAll());
- doCompare(QStringView{actual}.split(u'\n'), expectedFn, err);
+ doCompare(QStringView { actual }.split(u'\n'), expectedFn, err);
}
void tst_lupdate::good_data()
{
QTest::addColumn<QString>("directory");
- QTest::addColumn<bool>("useClangCpp");
QDir parsingDir(m_basePath + "good"_L1);
QStringList dirs = parsingDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
@@ -237,87 +235,43 @@ void tst_lupdate::good_data()
#ifndef Q_OS_MACOS
dirs.removeAll("parseobjc"_L1);
#endif
- QSet<QString> ignoredTests = {
- "lacksqobject_clang_parser"_L1, "parsecontexts_clang_parser"_L1, "parsecpp2_clang_parser"_L1,
- "parsecpp_clang_parser"_L1, "prefix_clang_parser"_L1, "preprocess_clang_parser"_L1,
- "parsecpp_clang_only"_L1};
-
- // Add test rows for the "classic" lupdate
- for (const QString &dir : dirs) {
- if (ignoredTests.contains(dir))
- continue;
- QTest::newRow(dir.toLocal8Bit()) << dir << false;
+ for (const QString& dir : dirs) {
+ QTest::newRow(dir.toLocal8Bit()) << dir;
}
-
-#if QT_CONFIG(clangcpp) && QT_CONFIG(widgets)
- if (QSysInfo::currentCpuArchitecture() == "arm64"_L1
- && QSysInfo::kernelType() == "linux"_L1 ) {
- qDebug("clangcpp tests are skipped on linux arm64, see also QTBUG-127751");
- return;
- }
- if (QSysInfo::kernelType() == "darwin"_L1) {
- qDebug("clangcpp tests are skipped on macOS, see also QTBUG-130006 and QTBUG-130096");
- return;
- }
-
- // Add test rows for the clang-based lupdate
- ignoredTests = {
- "lacksqobject"_L1,
- "parsecontexts"_L1,
- "parsecpp"_L1,
- "parsecpp2",
- "parsecpp_template"_L1,
- "parseqrc_json"_L1,
- "prefix"_L1,
- "preprocess"_L1,
- "using_namespaces"_L1,
- "proparsing2"_L1, // llvm8 cannot handle file name without extension
- "respfile"_L1, //@lst not supported with the new parser yet (include not properly set in the compile_command.json)
- "cmdline_deeppath"_L1, //no project file, new parser does not support (yet) this way of launching lupdate
- "cmdline_order"_L1, // no project, new parser do not pickup on macro defined but not used. Test not needed for new parser.
- "cmdline_recurse"_L1 // recursive scan without project file not supported (yet) with the new parser
- };
- for (const QString &dir : dirs) {
- if (ignoredTests.contains(dir))
- continue;
- QTest::newRow(("clang-"_ba + dir.toLocal8Bit()).constData()) << dir << true;
- }
-#endif
}
-static QByteArray msgStartFailed(const QProcess &process)
+static QByteArray msgStartFailed(const QProcess& process)
{
const QString result = u'"' + process.program() + u' ' + process.arguments().join(u' ')
- + "\": "_L1 + process.errorString();
+ + "\": "_L1 + process.errorString();
return result.toLocal8Bit();
}
-static QByteArray msgTimeout(const QProcess &process)
+static QByteArray msgTimeout(const QProcess& process)
{
const QString result = u'"' + process.program() + u' ' + process.arguments().join(u' ')
- + "\" timed out: "_L1 + process.errorString();
+ + "\" timed out: "_L1 + process.errorString();
return result.toLocal8Bit();
}
-static QByteArray msgCrashed(const QProcess &process, const QByteArray &output)
+static QByteArray msgCrashed(const QProcess& process, const QByteArray& output)
{
const QString result = u'"' + process.program() + u' ' + process.arguments().join(u' ')
- + "\" crashed\n"_L1;
+ + "\" crashed\n"_L1;
return result.toLocal8Bit() + output;
}
-static QByteArray msgExitCode(const QProcess &process, const QByteArray &output)
+static QByteArray msgExitCode(const QProcess& process, const QByteArray& output)
{
const QString result = u'"' + process.program() + u' ' + process.arguments().join(u' ')
- + "\" exited with code "_L1 + QString::number(process.exitCode())
- + u'\n';
+ + "\" exited with code "_L1 + QString::number(process.exitCode())
+ + u'\n';
return result.toLocal8Bit() + output;
}
void tst_lupdate::good()
{
QFETCH(QString, directory);
- QFETCH(bool, useClangCpp);
QString dir = m_basePath + "good/"_L1 + directory;
QString workDir = dir;
@@ -340,7 +294,7 @@ void tst_lupdate::good()
cmdstring.remove(0, 12);
generatedtsfiles.clear();
const auto parts = cmdstring.split(u' ');
- for (const QByteArray &s : parts)
+ for (const QByteArray& s : parts)
if (!s.isEmpty())
generatedtsfiles << QLatin1StringView(s);
} else if (cmdstring.startsWith("cd "_L1)) {
@@ -351,7 +305,7 @@ void tst_lupdate::good()
file.close();
}
- for (const QString &ts : std::as_const(generatedtsfiles)) {
+ for (const QString& ts : std::as_const(generatedtsfiles)) {
QString genTs = workDir + u'/' + ts;
QFile::remove(genTs);
QString beforetsfile = dir + u'/' + ts + ".before"_L1;
@@ -373,8 +327,6 @@ void tst_lupdate::good()
}
lupdateArguments.prepend("-silent"_L1);
- if (useClangCpp)
- lupdateArguments.append("-clang-parser"_L1);
QProcess proc;
proc.setWorkingDirectory(workDir);
@@ -403,19 +355,14 @@ void tst_lupdate::good()
QFile outfile(dir + "/expectedoutput.txt"_L1);
if (outfile.exists()) {
const QString errslist = QString::fromLocal8Bit(output);
- doCompare(QStringView{errslist}.split(u'\n'), outfile.fileName(), true);
+ doCompare(QStringView { errslist }.split(u'\n'), outfile.fileName(), true);
if (QTest::currentTestFailed())
return;
}
- for (const QString &ts : std::as_const(generatedtsfiles)) {
- if (dir.endsWith("preprocess_clang_parser"_L1)) {
- doCompare(workDir + u'/' + ts,
- dir + u'/' + ts + ".result"_L1, true);
- } else {
+ for (const QString& ts : std::as_const(generatedtsfiles)) {
doCompare(workDir + u'/' + ts,
- dir + u'/' + ts + ".result"_L1, false);
- }
+ dir + u'/' + ts + ".result"_L1, false);
}
}
@@ -430,7 +377,6 @@ void tst_lupdate::simtexth()
QCOMPARE(measured, expected);
}
-
void tst_lupdate::simtexth_data()
{
using namespace QTest;
--
2.51.0