summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-01-29 12:51:41 +0100
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-02-05 14:44:16 +0000
commit06328591d418ba1d88e9ef93ac761229d826450c (patch)
tree82e4697663aaea19ef31eafc9710a3227287c0c8 /tools
parentd9fb4e37573e55d85b1cfbb24c94d48d93350a54 (diff)
Add a version check & edit disclaimer to generated files.
The version check is to make sure that the generated .cpp/.h files are compiled against the same version of the module as the generator. The disclaimer is to tell users that the .cpp/.h files are generated and not intented to be edited. Change-Id: I394311b7995ea6e502f1c65e0e11d130487bce0e Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qscxmlc/qscxmlc.cpp1
-rw-r--r--tools/qscxmlc/scxmlcppdumper.cpp30
-rw-r--r--tools/qscxmlc/scxmlcppdumper.h1
3 files changed, 32 insertions, 0 deletions
diff --git a/tools/qscxmlc/qscxmlc.cpp b/tools/qscxmlc/qscxmlc.cpp
index 169eaf2..3b3ab7b 100644
--- a/tools/qscxmlc/qscxmlc.cpp
+++ b/tools/qscxmlc/qscxmlc.cpp
@@ -165,6 +165,7 @@ int main(int argc, char *argv[])
docs.insert(mainDoc, mainClassname);
TranslationUnit tu = options;
+ tu.scxmlFileName = QFileInfo(file).fileName();
tu.mainDocument = mainDoc;
tu.outHFileName = outHFileName;
tu.outCppFileName = outCppFileName;
diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp
index 26d497b..257315d 100644
--- a/tools/qscxmlc/scxmlcppdumper.cpp
+++ b/tools/qscxmlc/scxmlcppdumper.cpp
@@ -37,6 +37,27 @@
#include "generator.h"
QT_BEGIN_NAMESPACE
+
+enum { qscxmlcOutputRevision = 1 };
+
+static const QString doNotEditComment = QString::fromLatin1(
+ "//\n"
+ "// Statemachine code from reading SCXML file '%1'\n"
+ "// Created by: The Qt SCXML Compiler version %2 (Qt %3)\n"
+ "// WARNING! All changes made in this file will be lost!\n"
+ "//\n"
+ );
+
+static const QString revisionCheck = QString::fromLatin1(
+ "#if !defined(Q_QSCXMLC_OUTPUT_REVISION)\n"
+ "#error \"The header file '%1' doesn't include <qscxmlqstates.h>.\"\n"
+ "#elif Q_QSCXMLC_OUTPUT_REVISION != %2\n"
+ "#error \"This file was generated using the qscxmlc from %3. It\"\n"
+ "#error \"cannot be used with the include files from this version of Qt.\"\n"
+ "#error \"(The qscxmlc has changed too much.)\"\n"
+ "#endif\n"
+ );
+
struct StringListDumper {
StringListDumper &operator <<(const QString &s) {
text.append(s);
@@ -1274,6 +1295,9 @@ QString CppDumper::mangleId(const QString &id) // TODO: remove
void CppDumper::writeHeaderStart(const QString &headerGuard, const QStringList &forwardDecls)
{
+ h << doNotEditComment.arg(m_translationUnit->scxmlFileName, QString::number(qscxmlcOutputRevision), QString::fromLatin1(QT_VERSION_STR))
+ << endl;
+
h << QStringLiteral("#ifndef ") << headerGuard << endl
<< QStringLiteral("#define ") << headerGuard << endl
<< endl;
@@ -1356,6 +1380,9 @@ void CppDumper::writeHeaderEnd(const QString &headerGuard, const QStringList &me
void CppDumper::writeImplStart(const QVector<ClassDump> &allClazzes)
{
+ cpp << doNotEditComment.arg(m_translationUnit->scxmlFileName, QString::number(qscxmlcOutputRevision), QString::fromLatin1(QT_VERSION_STR))
+ << endl;
+
StringListDumper includes;
foreach (const ClassDump &clazz, allClazzes) {
includes.text += clazz.implIncludes.text;
@@ -1371,6 +1398,9 @@ void CppDumper::writeImplStart(const QVector<ClassDump> &allClazzes)
includes.write(cpp, QStringLiteral("#include <"), QStringLiteral(">\n"));
cpp << endl;
}
+ cpp << endl
+ << revisionCheck.arg(m_translationUnit->scxmlFileName, QString::number(qscxmlcOutputRevision), QString::fromLatin1(QT_VERSION_STR))
+ << endl;
if (!m_translationUnit->namespaceName.isEmpty())
cpp << l("namespace ") << m_translationUnit->namespaceName << l(" {") << endl << endl;
}
diff --git a/tools/qscxmlc/scxmlcppdumper.h b/tools/qscxmlc/scxmlcppdumper.h
index 2465a22..be590c0 100644
--- a/tools/qscxmlc/scxmlcppdumper.h
+++ b/tools/qscxmlc/scxmlcppdumper.h
@@ -46,6 +46,7 @@ struct TranslationUnit
, mainDocument(Q_NULLPTR)
{}
+ QString scxmlFileName;
QString outHFileName, outCppFileName;
QString namespaceName;
bool useCxx11;