forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
} // anonymous namespace
|
||||||
|
|
||||||
void CompilationDatabaseProject::buildTreeAndProjectParts(const Utils::FileName &projectFile)
|
void CompilationDatabaseProject::buildTreeAndProjectParts(const Utils::FileName &projectFile)
|
||||||
{
|
{
|
||||||
QFile file(projectFilePath().toString());
|
std::vector<QJsonObject> array = readJsonObjects(projectFilePath().toString());
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (array.empty()) {
|
||||||
emitParsingFinished(false);
|
emitParsingFinished(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QJsonArray array = QJsonDocument::fromJson(file.readAll()).array();
|
|
||||||
|
|
||||||
auto root = std::make_unique<DBProjectNode>(projectDirectory());
|
auto root = std::make_unique<DBProjectNode>(projectDirectory());
|
||||||
|
|
||||||
CppTools::RawProjectParts rpps;
|
CppTools::RawProjectParts rpps;
|
||||||
Utils::FileName commonPath;
|
Utils::FileName commonPath;
|
||||||
ToolChain *cToolchain = nullptr;
|
ToolChain *cToolchain = nullptr;
|
||||||
ToolChain *cxxToolchain = nullptr;
|
ToolChain *cxxToolchain = nullptr;
|
||||||
for (const QJsonValue &element : array) {
|
for (const QJsonObject &object : array) {
|
||||||
const QJsonObject object = element.toObject();
|
|
||||||
Utils::FileName fileName = jsonObjectFilename(object);
|
Utils::FileName fileName = jsonObjectFilename(object);
|
||||||
const QStringList flags = jsonObjectFlags(object);
|
const QStringList flags = jsonObjectFlags(object);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user