diff options
author | Brett Stottlemyer <bstottle@ford.com> | 2021-03-07 10:51:50 -0500 |
---|---|---|
committer | Brett Stottlemyer <bstottle@ford.com> | 2021-07-15 14:44:24 -0400 |
commit | 0ab10b008f4b713b7a58206b796668e05e80c2c6 (patch) | |
tree | 6795aadfd8e9d74d962ccd8709342dc414fd6065 /tools/repc/utils.cpp | |
parent | d8b6dce0d2cf91e20905856aef06c77c8659da98 (diff) |
Add example of reading CBOR data from pythonwip/serialization
This is currently a test harness that will expand as the CBOR
functionality is prototyped.
A start at changes to repc to autogenerate python code for Replica types
is also included.
Change-Id: I97c3ad4c62c7d747c1918f88be41fb7643bbb46d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tools/repc/utils.cpp')
-rw-r--r-- | tools/repc/utils.cpp | 141 |
1 files changed, 137 insertions, 4 deletions
diff --git a/tools/repc/utils.cpp b/tools/repc/utils.cpp index b6260a3..946f394 100644 --- a/tools/repc/utils.cpp +++ b/tools/repc/utils.cpp @@ -26,12 +26,13 @@ ** ****************************************************************************/ -#include <qjsonvalue.h> -#include <qjsonarray.h> -#include <qjsonobject.h> +#include <QCryptographicHash> +#include <QJsonArray> +#include <QJsonObject> +#include <QJsonValue> -#include "utils.h" #include "repparser.h" +#include "utils.h" #define _(X) QLatin1String(X) @@ -286,4 +287,136 @@ AST classList2AST(const QJsonArray &classes) return ret; } +static QByteArray typeData(const QString &type, const QHash<QString, QByteArray> &specialTypes) +{ + QHash<QString, QByteArray>::const_iterator it = specialTypes.find(type); + if (it != specialTypes.end()) + return it.value(); + const auto pos = type.lastIndexOf(QLatin1String("::")); + if (pos > 0) + return typeData(type.mid(pos + 2), specialTypes); + return type.toLatin1(); +} + +static QByteArray functionsData(const QList<ASTFunction> &functions, const QHash<QString, QByteArray> &specialTypes) +{ + QByteArray ret; + for (const ASTFunction &func : functions) { + ret += func.name.toLatin1(); + for (const ASTDeclaration ¶m : func.params) { + ret += param.name.toLatin1(); + ret += typeData(param.type, specialTypes); + ret += QByteArray(reinterpret_cast<const char *>(¶m.variableType), sizeof(param.variableType)); + } + ret += typeData(func.returnType, specialTypes); + } + return ret; +} + +GeneratorBase::GeneratorBase() +{ +} + +GeneratorBase::~GeneratorBase() +{ + +} + +QByteArray GeneratorBase::enumSignature(const ASTEnum &e) +{ + QByteArray ret; + ret += e.name.toLatin1(); + for (const ASTEnumParam ¶m : e.params) + ret += param.name.toLatin1() + QByteArray::number(param.value); + return ret; +} + +QByteArray GeneratorBase::classSignature(const ASTClass &ac) +{ + QCryptographicHash checksum(QCryptographicHash::Sha1); + auto specialTypes = m_globalEnumsPODs; + for (const ASTEnum &e : ac.enums) // add local enums + specialTypes[e.name] = enumSignature(e); + + checksum.addData(ac.name.toLatin1()); + + // Checksum properties + for (const ASTProperty &p : ac.properties) { + checksum.addData(p.name.toLatin1()); + checksum.addData(typeData(p.type, specialTypes)); + checksum.addData(reinterpret_cast<const char *>(&p.modifier), sizeof(p.modifier)); + } + + // Checksum signals + checksum.addData(functionsData(ac.signalsList, specialTypes)); + + // Checksum slots + checksum.addData(functionsData(ac.slotsList, specialTypes)); + + return checksum.result().toHex(); +} + +QByteArray GeneratorBase::podSignature(const POD &pod) +{ + QByteArray podData = pod.name.toLatin1(); + for (const PODAttribute &attr : pod.attributes) + podData += attr.name.toLatin1() + typeData(attr.type, m_globalEnumsPODs); + + return podData; +} + +GeneratorImplBase::GeneratorImplBase(QTextStream &_stream) : stream(_stream) +{ +} + +bool GeneratorImplBase::hasNotify(const ASTProperty &property, Mode mode) +{ + switch (property.modifier) { + case ASTProperty::Constant: + if (mode == Mode::Replica) // We still need to notify when we get the initial value + return true; + else + return false; + case ASTProperty::ReadOnly: + case ASTProperty::ReadWrite: + case ASTProperty::ReadPush: + case ASTProperty::SourceOnlySetter: + return true; + } + Q_UNREACHABLE(); +} + +bool GeneratorImplBase::hasPush(const ASTProperty &property, Mode mode) +{ + Q_UNUSED(mode) + switch (property.modifier) { + case ASTProperty::ReadPush: + return true; + case ASTProperty::Constant: + case ASTProperty::ReadOnly: + case ASTProperty::ReadWrite: + case ASTProperty::SourceOnlySetter: + return false; + } + Q_UNREACHABLE(); +} + +bool GeneratorImplBase::hasSetter(const ASTProperty &property, Mode mode) +{ + switch (property.modifier) { + case ASTProperty::Constant: + case ASTProperty::ReadOnly: + return false; + case ASTProperty::ReadWrite: + return true; + case ASTProperty::ReadPush: + case ASTProperty::SourceOnlySetter: + if (mode == Mode::Replica) // The setter slot isn't known to the PROP + return false; + else // The Source can use the setter, since non-asynchronous + return true; + } + Q_UNREACHABLE(); +} + QT_END_NAMESPACE |