diff --git a/src/linguist/lupdate/cpp_clang.cpp b/src/linguist/lupdate/cpp_clang.cpp new file mode 100644 index 0000000000000000000000000000000000000000..198724f50197b5408ed07f2d0d2e8e94219cdf22 --- /dev/null +++ b/src/linguist/lupdate/cpp_clang.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Linguist of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "cpp_clang.h" + +#include <translator.h> + +QT_BEGIN_NAMESPACE + +void ClangCppParser::loadCPP(Translator &translator, const QStringList &filenames, + ConversionData &cd) +{ + // Going through the files to be parsed + std::vector<std::string> sources; + for (const QString &filename: filenames) + sources.push_back(filename.toStdString()); + + // The ClangTool is to be created and run from this function. + + // First we'll need an OptionParser + // Then we'll create a ClangTool taking the OptionParser and the sources as argument + + // The translator to store the information from the parsing of the files. + Translator *tor = new Translator(); + + // TODO: set up clang tool for parsing + qWarning("lupdate: Clang based C++ parser not implemented!"); + + // TODO: remove this printing at a later point + // Printing the translator (storage and manipulation of translation info from linguist module) + if (qEnvironmentVariableIsSet("QT_LUPDATE_CLANG_DEBUG")) + tor->dump(); + + for (const TranslatorMessage &msg: tor->messages()) + translator.extend(msg, cd); + +} +QT_END_NAMESPACE diff --git a/src/linguist/lupdate/cpp_clang.h b/src/linguist/lupdate/cpp_clang.h new file mode 100644 index 0000000000000000000000000000000000000000..d4357f129d920d1932b9d382b0d88482077c147f --- /dev/null +++ b/src/linguist/lupdate/cpp_clang.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Linguist of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CLANG_CPP_H +#define CLANG_CPP_H + +#include "lupdate.h" + + +QT_BEGIN_NAMESPACE + +namespace ClangCppParser { + void loadCPP(Translator &translator, const QStringList &filenames, + ConversionData &cd); +} + +QT_END_NAMESPACE + + +#endif diff --git a/src/linguist/lupdate/lupdate.pro b/src/linguist/lupdate/lupdate.pro index e69703da2360c77838f337003c28597350e4af32..615b41802f5d519d550a95410ac47c8ced86ac6a 100644 --- a/src/linguist/lupdate/lupdate.pro +++ b/src/linguist/lupdate/lupdate.pro @@ -21,13 +21,15 @@ SOURCES += \ \ cpp.cpp \ java.cpp \ - ui.cpp + ui.cpp \ + cpp_clang.cpp qtHaveModule(qmldevtools-private): SOURCES += qdeclarative.cpp HEADERS += \ lupdate.h \ cpp.h \ + cpp_clang.h \ ../shared/projectdescriptionreader.h \ ../shared/qrcreader.h \ ../shared/runqttool.h \ diff --git a/src/linguist/lupdate/main.cpp b/src/linguist/lupdate/main.cpp index 712b955509d67921153a2f042d7c6b7b7acfc569..5ab3f59b9604269f459208e62c0d4404dba3e039 100644 --- a/src/linguist/lupdate/main.cpp +++ b/src/linguist/lupdate/main.cpp @@ -28,6 +28,7 @@ ****************************************************************************/ #include "lupdate.h" +#include "cpp_clang.h" #include <profileutils.h> #include <projectdescriptionreader.h> @@ -47,6 +48,8 @@ #include <iostream> +bool useClangToParseCpp = false; + // Can't have an array of QStaticStringData<N> for different N, so // use QString, which requires constructor calls. Doesn't matter // much, since this is in an app, not a lib: @@ -275,6 +278,9 @@ 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 \n" + " Use clang to parse cpp files. Otherwise a custom parser is used.\n" + " Need a compile_commands.json for the files that needs to be parsed.\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" @@ -513,7 +519,11 @@ static void processSources(Translator &fetchedTor, printErr(LU::tr("lupdate warning: Some files have been ignored due to missing qml/javascript support\n")); #endif - loadCPP(fetchedTor, sourceFilesCpp, cd); + if (useClangToParseCpp) + ClangCppParser::loadCPP(fetchedTor, sourceFilesCpp, cd); + else + loadCPP(fetchedTor, sourceFilesCpp, cd); + if (!cd.error().isEmpty()) printErr(cd.error()); } @@ -833,6 +843,9 @@ int main(int argc, char **argv) includePath += args[i].mid(2); } continue; + } else if (arg == QLatin1String("-clang-parser")) { + useClangToParseCpp = true; + continue; } else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) { printErr(LU::tr("Unrecognized option '%1'.\n").arg(arg)); return 1;