summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-01-16 11:33:41 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-02-07 21:23:55 +0100
commitf64694647a9a3d54fa5ecdaf2570e8c7404271a6 (patch)
tree18a98362d72b210c7672084687b052888faeb053 /src/tools
parent0eb922a4e99da83f5600d36510668dfa002a17aa (diff)
moc: Extend revision markers to allow for major and minor version
As we want Qt's own revisions to follow the Qt versioning scheme, we need to allow for the minor version to reset to 0 now. In order to facilitate this, we interpret the argument passed the current Q_REVISION macro as major version and allow for an optional minor version. Both are encoded it into the resulting revision number. Change-Id: I3519fe20233d473f34a24ec9589d045cdd162a12 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/moc/moc.cpp88
-rw-r--r--src/tools/moc/moc.h2
2 files changed, 54 insertions, 36 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index 625725e5a1..5e2e492f94 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -376,17 +376,42 @@ bool Moc::skipCxxAttributes()
return false;
}
-bool Moc::testFunctionRevision(FunctionDef *def)
+QTypeRevision Moc::parseRevision()
{
- if (test(Q_REVISION_TOKEN)) {
- next(LPAREN);
- QByteArray revision = lexemUntil(RPAREN);
- revision.remove(0, 1);
- revision.chop(1);
+ next(LPAREN);
+ QByteArray revisionString = lexemUntil(RPAREN);
+ revisionString.remove(0, 1);
+ revisionString.chop(1);
+ const QList<QByteArray> majorMinor = revisionString.split(',');
+ switch (majorMinor.length()) {
+ case 1: {
bool ok = false;
- def->revision = revision.toInt(&ok);
- if (!ok || def->revision < 0)
+ const int revision = revisionString.toInt(&ok);
+ if (!ok || !QTypeRevision::isValidSegment(revision))
error("Invalid revision");
+ return QTypeRevision::fromMinorVersion(revision);
+ }
+ case 2: { // major.minor
+ bool ok = false;
+ const int major = majorMinor[0].toInt(&ok);
+ if (!ok || !QTypeRevision::isValidSegment(major))
+ error("Invalid major version");
+ const int minor = majorMinor[1].toInt(&ok);
+ if (!ok || !QTypeRevision::isValidSegment(minor))
+ error("Invalid minor version");
+ return QTypeRevision::fromVersion(major, minor);
+ }
+ default:
+ error("Invalid revision");
+ return QTypeRevision();
+ }
+}
+
+bool Moc::testFunctionRevision(FunctionDef *def)
+{
+
+ if (test(Q_REVISION_TOKEN)) {
+ def->revision = parseRevision().toEncodedVersion<int>();
return true;
}
@@ -1100,17 +1125,9 @@ void Moc::generate(FILE *out, FILE *jsonOutput)
void Moc::parseSlots(ClassDef *def, FunctionDef::Access access)
{
- int defaultRevision = -1;
- if (test(Q_REVISION_TOKEN)) {
- next(LPAREN);
- QByteArray revision = lexemUntil(RPAREN);
- revision.remove(0, 1);
- revision.chop(1);
- bool ok = false;
- defaultRevision = revision.toInt(&ok);
- if (!ok || defaultRevision < 0)
- error("Invalid revision");
- }
+ QTypeRevision defaultRevision;
+ if (test(Q_REVISION_TOKEN))
+ defaultRevision = parseRevision();
next(COLON);
while (inClass(def) && hasNext()) {
@@ -1139,8 +1156,8 @@ void Moc::parseSlots(ClassDef *def, FunctionDef::Access access)
continue;
if (funcDef.revision > 0) {
++def->revisionedMethods;
- } else if (defaultRevision != -1) {
- funcDef.revision = defaultRevision;
+ } else if (defaultRevision.isValid()) {
+ funcDef.revision = defaultRevision.toEncodedVersion<int>();
++def->revisionedMethods;
}
def->slotList += funcDef;
@@ -1154,17 +1171,9 @@ void Moc::parseSlots(ClassDef *def, FunctionDef::Access access)
void Moc::parseSignals(ClassDef *def)
{
- int defaultRevision = -1;
- if (test(Q_REVISION_TOKEN)) {
- next(LPAREN);
- QByteArray revision = lexemUntil(RPAREN);
- revision.remove(0, 1);
- revision.chop(1);
- bool ok = false;
- defaultRevision = revision.toInt(&ok);
- if (!ok || defaultRevision < 0)
- error("Invalid revision");
- }
+ QTypeRevision defaultRevision;
+ if (test(Q_REVISION_TOKEN))
+ defaultRevision = parseRevision();
next(COLON);
while (inClass(def) && hasNext()) {
@@ -1195,8 +1204,8 @@ void Moc::parseSignals(ClassDef *def)
error("Not a signal declaration");
if (funcDef.revision > 0) {
++def->revisionedMethods;
- } else if (defaultRevision != -1) {
- funcDef.revision = defaultRevision;
+ } else if (defaultRevision.isValid()) {
+ funcDef.revision = defaultRevision.toEncodedVersion<int>();
++def->revisionedMethods;
}
def->signalList += funcDef;
@@ -1257,6 +1266,10 @@ void Moc::createPropertyDef(PropertyDef &propDef)
} else if (l[0] == 'R' && l == "REQUIRED") {
propDef.required = true;
continue;
+ } else if (l[0] == 'R' && l == "REVISION" && test(LPAREN)) {
+ prev();
+ propDef.revision = parseRevision().toEncodedVersion<int>();
+ continue;
}
QByteArray v, v2;
@@ -1289,9 +1302,10 @@ void Moc::createPropertyDef(PropertyDef &propDef)
propDef.reset = v + v2;
else if (l == "REVISION") {
bool ok = false;
- propDef.revision = v.toInt(&ok);
- if (!ok || propDef.revision < 0)
+ const int minor = v.toInt(&ok);
+ if (!ok || !QTypeRevision::isValidSegment(minor))
error(1);
+ propDef.revision = QTypeRevision::fromMinorVersion(minor).toEncodedVersion<int>();
} else
error(2);
break;
@@ -1499,6 +1513,8 @@ void Moc::parseClassInfo(BaseDef *def)
next(COMMA);
if (test(STRING_LITERAL)) {
infoDef.value = symbol().unquotedLexem();
+ } else if (test(Q_REVISION_TOKEN)) {
+ infoDef.value = QByteArray::number(parseRevision().toEncodedVersion<quint16>());
} else {
// support Q_CLASSINFO("help", QT_TR_NOOP("blah"))
next(IDENTIFIER);
diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h
index 4d3d32a6ac..63caf36d61 100644
--- a/src/tools/moc/moc.h
+++ b/src/tools/moc/moc.h
@@ -36,6 +36,7 @@
#include <qjsondocument.h>
#include <qjsonarray.h>
#include <qjsonobject.h>
+#include <qversionnumber.h>
#include <stdio.h>
#include <ctype.h>
@@ -271,6 +272,7 @@ public:
bool testFunctionAttribute(FunctionDef *def);
bool testFunctionAttribute(Token tok, FunctionDef *def);
bool testFunctionRevision(FunctionDef *def);
+ QTypeRevision parseRevision();
bool skipCxxAttributes();