1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtScxml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef SCXMLCPPDUMPER_H
30#define SCXMLCPPDUMPER_H
31
32#include "qscxmlglobals.h"
33
34#include <QtScxml/private/qscxmlcompiler_p.h>
35#include <QtScxml/private/qscxmltabledata_p.h>
36
37#include <QTextStream>
38
39QT_BEGIN_NAMESPACE
40
41struct TranslationUnit
42{
43 TranslationUnit()
44 : stateMethods(false)
45 , mainDocument(nullptr)
46 {}
47
48 QString scxmlFileName;
49 QString outHFileName, outCppFileName;
50 QString namespaceName;
51 bool stateMethods;
52 DocumentModel::ScxmlDocument *mainDocument;
53 QList<DocumentModel::ScxmlDocument *> allDocuments;
54 QHash<DocumentModel::ScxmlDocument *, QString> classnameForDocument;
55 QList<TranslationUnit *> dependencies;
56};
57
58class CppDumper
59{
60public:
61 CppDumper(QTextStream &headerStream, QTextStream &cppStream)
62 : h(headerStream)
63 , cpp(cppStream)
64 {}
65
66 void dump(TranslationUnit *unit);
67
68private:
69 void writeHeaderStart(const QString &headerGuard, const QStringList &forwardDecls);
70 void writeClass(const QString &className,
71 const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
72 void writeHeaderEnd(const QString &headerGuard, const QStringList &metatypeDecls);
73 void writeImplStart();
74 void writeImplBody(const QScxmlInternal::GeneratedTableData &table,
75 const QString &className,
76 DocumentModel::ScxmlDocument *doc,
77 const QStringList &factory,
78 const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
79 void writeImplEnd();
80 QString mangleIdentifier(const QString &str);
81
82private:
83 QString generatePropertyDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
84 QString generateAccessorDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
85 QString generateSignalDecls(const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
86 QString generateMetaObject(const QString &className,
87 const QScxmlInternal::GeneratedTableData::MetaDataInfo &info);
88
89 QTextStream &h;
90 QTextStream &cpp;
91
92 static QByteArray b(const char *str) { return QByteArray(str); }
93 static QLatin1String l (const char *str) { return QLatin1String(str); }
94
95 TranslationUnit *m_translationUnit;
96
97 mutable QHash<QString, QString> m_mangledToOriginal;
98};
99
100QT_END_NAMESPACE
101
102#endif // SCXMLCPPDUMPER_H
103

source code of qtscxml/tools/qscxmlc/scxmlcppdumper.h