Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmltcoutputprimitives_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant
4
5
#
ifndef
QQMLTCOUTPUTPRIMITIVES_P_H
6
#
define
QQMLTCOUTPUTPRIMITIVES_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
<
QtCore
/
qstack
.
h
>
20
#
include
<
QtCore
/
qstring
.
h
>
21
#
include
<
QtCore
/
qstringbuilder
.
h
>
22
23
QT_BEGIN_NAMESPACE
24
25
namespace
QQmltc
{
26
27
struct
Output
28
{
29
QString
header
;
30
QString
cpp
;
31
};
32
33
class
OutputWrapper
34
{
35
Output
&m_code;
36
37
template
<
typename
String>
38
static
void
rawAppend(QString &out,
const
String &what,
int
extraIndent = 0)
39
{
40
constexpr
char16_t
newLine[] = u"\n";
41
out += QString(extraIndent * 4, u' ') + what + newLine;
42
}
43
44
public
:
45
OutputWrapper
(
Output
&code) : m_code(code) { }
46
const
Output
&
code
()
const
{
return
m_code; }
47
48
QStack
<
QString
>
memberScopes
;
// member name scopes e.g. MyClass::MySubclass::
49
int
headerIndent
= 0;
// header indentation level
50
int
cppIndent
= 0;
// cpp indentation level
51
52
// manages current scope of the generated code, which is necessary for
53
// cpp file generation. Example:
54
// class MyClass { MyClass(); }; - in header
55
// MyClass::MyClass() {} - in cpp
56
// MemberNameScope makes sure "MyClass::" is recorded
57
struct
MemberNameScope
58
{
59
OutputWrapper
*
m_code
;
60
MemberNameScope
(
OutputWrapper
*code,
const
QString &str) :
m_code
(code)
61
{
62
m_code
->memberScopes.push(str);
63
}
64
~
MemberNameScope
() {
m_code
->memberScopes.pop(); }
65
Q_DISABLE_COPY_MOVE
(
MemberNameScope
)
66
};
67
68
struct
HeaderIndentationScope
69
{
70
OutputWrapper
*
m_code
;
71
HeaderIndentationScope
(
OutputWrapper
*code) :
m_code
(code) { ++
m_code
->
headerIndent
; }
72
~
HeaderIndentationScope
() { --
m_code
->
headerIndent
; }
73
Q_DISABLE_COPY_MOVE
(
HeaderIndentationScope
)
74
};
75
76
struct
CppIndentationScope
77
{
78
OutputWrapper
*
m_code
;
79
CppIndentationScope
(
OutputWrapper
*code) :
m_code
(code) { ++
m_code
->
cppIndent
; }
80
~
CppIndentationScope
() { --
m_code
->
cppIndent
; }
81
Q_DISABLE_COPY_MOVE
(
CppIndentationScope
)
82
};
83
84
// appends string \a what with extra indentation \a extraIndent to current
85
// header string
86
template
<
typename
String>
87
void
rawAppendToHeader
(
const
String &what,
int
extraIndent = 0)
88
{
89
rawAppend(m_code.header, what,
headerIndent
+ extraIndent);
90
}
91
92
// appends string \a what with extra indentation \a extraIndent to current
93
// cpp string
94
template
<
typename
String>
95
void
rawAppendToCpp
(
const
String &what,
int
extraIndent = 0)
96
{
97
rawAppend(m_code.cpp, what,
cppIndent
+ extraIndent);
98
}
99
100
// special case of rawAppendToCpp that makes sure that string "foo()"
101
// becomes "MyClass::foo()"
102
template
<
typename
String>
103
void
rawAppendSignatureToCpp
(
const
String &what,
int
extraIndent = 0)
104
{
105
QString signatureScope;
106
for
(
const
auto
&scope : std::as_const(memberScopes))
107
signatureScope += scope + u"::";
108
rawAppendToCpp(signatureScope + what, extraIndent);
109
}
110
};
111
112
}
// namespace QQmltc
113
114
QT_END_NAMESPACE
115
116
#
endif
// QQMLTCOUTPUTPRIMITIVES_P_H
QQmltc::OutputWrapper
Definition
qqmltcoutputprimitives_p.h:34
QQmltc::OutputWrapper::rawAppendToHeader
void rawAppendToHeader(const String &what, int extraIndent=0)
Definition
qqmltcoutputprimitives_p.h:87
QQmltc::OutputWrapper::rawAppendSignatureToCpp
void rawAppendSignatureToCpp(const String &what, int extraIndent=0)
Definition
qqmltcoutputprimitives_p.h:103
QQmltc::OutputWrapper::rawAppendToCpp
void rawAppendToCpp(const String &what, int extraIndent=0)
Definition
qqmltcoutputprimitives_p.h:95
QQmltc::OutputWrapper::memberScopes
QStack< QString > memberScopes
Definition
qqmltcoutputprimitives_p.h:48
QQmltc::OutputWrapper::code
const Output & code() const
Definition
qqmltcoutputprimitives_p.h:46
QQmltc::OutputWrapper::cppIndent
int cppIndent
Definition
qqmltcoutputprimitives_p.h:50
QQmltc::OutputWrapper::OutputWrapper
OutputWrapper(Output &code)
Definition
qqmltcoutputprimitives_p.h:45
QQmltc::OutputWrapper::headerIndent
int headerIndent
Definition
qqmltcoutputprimitives_p.h:49
QQmltc
Definition
qqmltccodewriter.cpp:19
QQmltc::OutputWrapper::CppIndentationScope
Definition
qqmltcoutputprimitives_p.h:77
QQmltc::OutputWrapper::CppIndentationScope::CppIndentationScope
CppIndentationScope(OutputWrapper *code)
Definition
qqmltcoutputprimitives_p.h:79
QQmltc::OutputWrapper::CppIndentationScope::m_code
OutputWrapper * m_code
Definition
qqmltcoutputprimitives_p.h:78
QQmltc::OutputWrapper::CppIndentationScope::~CppIndentationScope
~CppIndentationScope()
Definition
qqmltcoutputprimitives_p.h:80
QQmltc::OutputWrapper::HeaderIndentationScope
Definition
qqmltcoutputprimitives_p.h:69
QQmltc::OutputWrapper::HeaderIndentationScope::HeaderIndentationScope
HeaderIndentationScope(OutputWrapper *code)
Definition
qqmltcoutputprimitives_p.h:71
QQmltc::OutputWrapper::HeaderIndentationScope::m_code
OutputWrapper * m_code
Definition
qqmltcoutputprimitives_p.h:70
QQmltc::OutputWrapper::HeaderIndentationScope::~HeaderIndentationScope
~HeaderIndentationScope()
Definition
qqmltcoutputprimitives_p.h:72
QQmltc::OutputWrapper::MemberNameScope
Definition
qqmltcoutputprimitives_p.h:58
QQmltc::OutputWrapper::MemberNameScope::MemberNameScope
MemberNameScope(OutputWrapper *code, const QString &str)
Definition
qqmltcoutputprimitives_p.h:60
QQmltc::OutputWrapper::MemberNameScope::m_code
OutputWrapper * m_code
Definition
qqmltcoutputprimitives_p.h:59
QQmltc::OutputWrapper::MemberNameScope::~MemberNameScope
~MemberNameScope()
Definition
qqmltcoutputprimitives_p.h:64
QQmltc::Output
Definition
qqmltcoutputprimitives_p.h:28
QQmltc::Output::cpp
QString cpp
Definition
qqmltcoutputprimitives_p.h:30
QQmltc::Output::header
QString header
Definition
qqmltcoutputprimitives_p.h:29
qtdeclarative
src
qmltc
qqmltcoutputprimitives_p.h
Generated on
for Qt by
1.18.0