// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#include "codegen/lang/subsets.h"
#include "codegen/common/logging.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace codegen {
namespace lang {
namespace {
constexpr int kErrorCantReadKeys = 831;
constexpr int kErrorCantReadSource = 832;
constexpr int kErrorCantWriteSubset = 833;
constexpr auto kCacheVersion = quint32(1);
const auto kKeysFile = QString("lang_auto_keys.h");
const auto kSubsetsFolder = QString("lang_subsets");
const auto kCacheFile = QString("lang_subsets/.cache");
const auto kDeclarationStart = QByteArray("inline constexpr phrase ", kDeclarationStart.size() - 1);
const auto brace = (after < 0) ? -1 : line.indexOf('{', after + 2);
if (after < 0 || brace < 0) {
common::logError(kErrorCantReadKeys, path)
0 && data[lineStart - 1] != '\n') {
--lineStart;
}
auto clean = true;
for (auto i = lineStart; i != found; ++i) {
if (data[i] != ' ' && data[i] != '\t') {
clean = false;
break;
}
}
if (!clean) {
continue;
}
auto quote = from;
while (quote != size && (data[quote] == ' ' || data[quote] == '\t')) {
++quote;
}
if (quote == size || data[quote] != '"') {
continue;
}
const auto till = content.indexOf('"', quote + 1);
if (till < 0) {
break;
}
result.includes.push_back(content.mid(quote + 1, till - quote - 1));
from = till + 1;
}
}
[[nodiscard]] Cache ReadCache(const QString &path) {
auto result = Cache();
auto file = QFile(path);
if (!file.open(QIODevice::ReadOnly)) {
return result;
}
auto stream = QDataStream(&file);
auto version = quint32(0);
stream >> version;
if (version != kCacheVersion) {
return Cache();
}
stream >> result.keysModified >> result.keysSize;
stream >> result.scanned >> result.subsets;
return (stream.status() == QDataStream::Ok) ? result : Cache();
}
void WriteCache(const QString &path, const Cache &cache) {
auto file = QFile(path);
if (!file.open(QIODevice::WriteOnly)) {
return;
}
auto stream = QDataStream(&file);
stream