1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef SCXMLCPPDUMPER_H |
5 | #define SCXMLCPPDUMPER_H |
6 | |
7 | #include <QtScxml/qscxmlglobals.h> |
8 | #include <QtScxml/private/qscxmlcompiler_p.h> |
9 | #include <QtScxml/private/qscxmltabledata_p.h> |
10 | |
11 | #include <QTextStream> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | struct TranslationUnit |
16 | { |
17 | TranslationUnit() |
18 | : stateMethods(false) |
19 | , mainDocument(nullptr) |
20 | {} |
21 | |
22 | QString scxmlFileName; |
23 | QString outHFileName, outCppFileName; |
24 | QString namespaceName; |
25 | bool stateMethods; |
26 | DocumentModel::ScxmlDocument *mainDocument; |
27 | QList<DocumentModel::ScxmlDocument *> allDocuments; |
28 | QHash<DocumentModel::ScxmlDocument *, QString> classnameForDocument; |
29 | QList<TranslationUnit *> dependencies; |
30 | }; |
31 | |
32 | class CppDumper |
33 | { |
34 | public: |
35 | CppDumper(QTextStream &, QTextStream &cppStream) |
36 | : h(headerStream) |
37 | , cpp(cppStream) |
38 | {} |
39 | |
40 | void dump(TranslationUnit *unit); |
41 | |
42 | private: |
43 | void (const QString &, const QStringList &forwardDecls); |
44 | void writeClass(const QString &className, |
45 | const QScxmlInternal::GeneratedTableData::MetaDataInfo &info); |
46 | void (const QString &, const QStringList &metatypeDecls); |
47 | void writeImplStart(); |
48 | void writeImplBody(const QScxmlInternal::GeneratedTableData &table, |
49 | const QString &className, |
50 | DocumentModel::ScxmlDocument *doc, |
51 | const QStringList &factory, |
52 | const QScxmlInternal::GeneratedTableData::MetaDataInfo &info); |
53 | void writeImplEnd(); |
54 | QString mangleIdentifier(const QString &str); |
55 | |
56 | private: |
57 | QString generatePropertyDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info); |
58 | QString generateAccessorDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info); |
59 | QString generateSignalDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info); |
60 | QString generateMetaObject(const QString &className, |
61 | const QScxmlInternal::GeneratedTableData::MetaDataInfo &info); |
62 | |
63 | QTextStream &h; |
64 | QTextStream &cpp; |
65 | |
66 | static QByteArray b(const char *str) { return QByteArray(str); } |
67 | static QLatin1String l (const char *str) { return QLatin1String(str); } |
68 | |
69 | TranslationUnit *m_translationUnit; |
70 | |
71 | mutable QHash<QString, QString> m_mangledToOriginal; |
72 | }; |
73 | |
74 | QT_END_NAMESPACE |
75 | |
76 | #endif // SCXMLCPPDUMPER_H |
77 | |