summaryrefslogtreecommitdiffstats
path: root/src/linguist
diff options
context:
space:
mode:
authorLucie Gérard <lucie.gerard@qt.io>2019-08-06 13:11:06 +0200
committerLucie Gérard <lucie.gerard@qt.io>2019-08-08 08:46:03 +0200
commita79eaba195f3b235b4c8db79caa75e42b38664a8 (patch)
tree95075f6d31f55c20aa1df4a2148e597a8ec96048 /src/linguist
parent4e2d9619fe228e11ac01e7faa35e7f23b737ad18 (diff)
Add empty clangcpp parser functionality
The new parser is advertised in the help An option is added to the command line argument A new loadcpp function is added to parse with clang No code needing clang library is added yet. Change-Id: Iee07fce319e6be13d3689077ab61c1e4e44b5fc2 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/linguist')
-rw-r--r--src/linguist/lupdate/cpp_clang.cpp62
-rw-r--r--src/linguist/lupdate/cpp_clang.h45
-rw-r--r--src/linguist/lupdate/lupdate.pro4
-rw-r--r--src/linguist/lupdate/main.cpp15
4 files changed, 124 insertions, 2 deletions
diff --git a/src/linguist/lupdate/cpp_clang.cpp b/src/linguist/lupdate/cpp_clang.cpp
new file mode 100644
index 000000000..198724f50
--- /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 000000000..d4357f129
--- /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 e69703da2..615b41802 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 712b95550..5ab3f59b9 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;