diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-11-01 13:05:34 +0100 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-11-05 15:51:28 +0000 |
commit | 06162c1aa53ee9440f8b377db2ec86a9e7fd949c (patch) | |
tree | 4b286b6901e1399c794d841cc781e68c60c9af43 /src/plugins/compilationdatabaseprojectmanager | |
parent | 7f67e987ead9677f8ca95414994ea3e0ae1ef92d (diff) |
CompilationDatabase: Use QJsonDocument for separate objects
It is pretty easy to split objects without QJsonDocument help.
Due to the QJsonObject data size restriction use it
only for the already split objects inside the database.
Change-Id: Ice7c7407ad00aaac151a767f4d943fdcecf6a6b8
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/compilationdatabaseprojectmanager')
-rw-r--r-- | src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp index 9e724cb8252..155ed5185aa 100644 --- a/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp +++ b/src/plugins/compilationdatabaseprojectmanager/compilationdatabaseproject.cpp @@ -302,26 +302,51 @@ void createFolders(FolderNode *root, const Utils::FileName &rootPath) } } +std::vector<QJsonObject> readJsonObjects(const QString &filePath) +{ + std::vector<QJsonObject> result; + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) + return result; + + const QByteArray contents = file.readAll(); + int objectStart = contents.indexOf('{'); + int objectEnd = contents.indexOf('}', objectStart + 1); + + while (objectStart >= 0 && objectEnd >= 0) { + const QJsonDocument document = QJsonDocument::fromJson( + contents.mid(objectStart, objectEnd - objectStart + 1)); + if (document.isNull()) { + // The end was found incorrectly, search for the next one. + objectEnd = contents.indexOf('}', objectEnd + 1); + continue; + } + + result.push_back(document.object()); + objectStart = contents.indexOf('{', objectEnd + 1); + objectEnd = contents.indexOf('}', objectStart + 1); + } + + return result; +} + } // anonymous namespace void CompilationDatabaseProject::buildTreeAndProjectParts(const Utils::FileName &projectFile) { - QFile file(projectFilePath().toString()); - if (!file.open(QIODevice::ReadOnly)) { + std::vector<QJsonObject> array = readJsonObjects(projectFilePath().toString()); + if (array.empty()) { emitParsingFinished(false); return; } - const QJsonArray array = QJsonDocument::fromJson(file.readAll()).array(); - auto root = std::make_unique<DBProjectNode>(projectDirectory()); CppTools::RawProjectParts rpps; Utils::FileName commonPath; ToolChain *cToolchain = nullptr; ToolChain *cxxToolchain = nullptr; - for (const QJsonValue &element : array) { - const QJsonObject object = element.toObject(); + for (const QJsonObject &object : array) { Utils::FileName fileName = jsonObjectFilename(object); const QStringList flags = jsonObjectFlags(object); |