summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp15
-rw-r--r--src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.cpp20
-rw-r--r--src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.h2
3 files changed, 24 insertions, 13 deletions
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
index 351917f019..650b3ad7ef 100644
--- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
+++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp
@@ -64,16 +64,18 @@ namespace Internal {
namespace {
-QStringList jsonObjectFlags(const QJsonObject &object)
+QStringList jsonObjectFlags(const QJsonObject &object, QSet<QString> &flagsCache)
{
QStringList flags;
const QJsonArray arguments = object["arguments"].toArray();
if (arguments.isEmpty()) {
- flags = splitCommandLine(object["command"].toString());
+ flags = splitCommandLine(object["command"].toString(), flagsCache);
} else {
flags.reserve(arguments.size());
- for (const QJsonValue &arg : arguments)
- flags.append(arg.toString());
+ for (const QJsonValue &arg : arguments) {
+ auto flagIt = flagsCache.insert(arg.toString());
+ flags.append(*flagIt);
+ }
}
return flags;
@@ -339,6 +341,7 @@ std::vector<Entry> readJsonObjects(const QString &filePath)
int objectStart = contents.indexOf('{');
int objectEnd = contents.indexOf('}', objectStart + 1);
+ QSet<QString> flagsCache;
while (objectStart >= 0 && objectEnd >= 0) {
const QJsonDocument document = QJsonDocument::fromJson(
contents.mid(objectStart, objectEnd - objectStart + 1));
@@ -350,8 +353,8 @@ std::vector<Entry> readJsonObjects(const QString &filePath)
const QJsonObject object = document.object();
const Utils::FileName fileName = jsonObjectFilename(object);
- const QStringList flags
- = filterFromFileName(jsonObjectFlags(object), fileName.toFileInfo().baseName());
+ const QStringList flags = filterFromFileName(jsonObjectFlags(object, flagsCache),
+ fileName.toFileInfo().baseName());
result.push_back({flags, fileName, object["directory"].toString()});
objectStart = contents.indexOf('{', objectEnd + 1);
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.cpp
index 1884aa1c6d..8f4f2212b6 100644
--- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.cpp
+++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.cpp
@@ -33,6 +33,7 @@
#include <QDir>
#include <QRegularExpression>
+#include <QSet>
using namespace ProjectExplorer;
@@ -205,7 +206,7 @@ void filteredFlags(const QString &fileName,
flags = filtered;
}
-QStringList splitCommandLine(QString commandLine)
+QStringList splitCommandLine(QString commandLine, QSet<QString> &flagsCache)
{
QStringList result;
bool insideQuotes = false;
@@ -215,12 +216,19 @@ QStringList splitCommandLine(QString commandLine)
for (const QString &part : commandLine.split(QRegularExpression("\""))) {
if (insideQuotes) {
const QString quotedPart = "\"" + part + "\"";
- if (result.last().endsWith("="))
- result.last().append(quotedPart);
- else
- result.append(quotedPart);
+ if (result.last().endsWith("=")) {
+ auto flagIt = flagsCache.insert(result.last() + quotedPart);
+ result.last() = *flagIt;
+ } else {
+ auto flagIt = flagsCache.insert(quotedPart);
+ result.append(*flagIt);
+ }
} else { // If 's' is outside quotes ...
- result.append(part.split(QRegularExpression("\\s+"), QString::SkipEmptyParts));
+ for (const QString &flag :
+ part.split(QRegularExpression("\\s+"), QString::SkipEmptyParts)) {
+ auto flagIt = flagsCache.insert(flag);
+ result.append(*flagIt);
+ }
}
insideQuotes = !insideQuotes;
}
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.h b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.h
index e465b6ba23..52b251723a 100644
--- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.h
+++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseutils.h
@@ -47,6 +47,6 @@ void filteredFlags(const QString &fileName,
QVector<ProjectExplorer::Macro> &macros,
CppTools::ProjectFile::Kind &fileKind);
-QStringList splitCommandLine(QString commandLine);
+QStringList splitCommandLine(QString commandLine, QSet<QString> &flagsCache);
} // namespace CompilationDatabaseProjectManager