1 | // Copyright (C) 2018 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 LANGUAGE_H |
5 | #define LANGUAGE_H |
6 | |
7 | #include <QtCore/qstring.h> |
8 | #include <QtCore/qstringview.h> |
9 | #include <QtCore/qstring.h> |
10 | |
11 | QT_FORWARD_DECLARE_CLASS(QTextStream) |
12 | |
13 | enum class Language { Cpp, Python }; |
14 | |
15 | enum class ConnectionSyntax { StringBased, MemberFunctionPtr }; |
16 | |
17 | namespace language { |
18 | |
19 | Language language(); |
20 | void setLanguage(Language); |
21 | |
22 | ConnectionSyntax connectionSyntax(); |
23 | void setConnectionSyntax(ConnectionSyntax cs); |
24 | |
25 | extern QString derefPointer; |
26 | extern char listStart; |
27 | extern char listEnd; |
28 | extern QString nullPtr; |
29 | extern QString operatorNew; |
30 | extern QString qtQualifier; |
31 | extern QString qualifier; |
32 | extern QString self; |
33 | extern QString eol; |
34 | extern QString emptyString; |
35 | |
36 | extern QString cppQualifier; |
37 | extern QString cppTrue; |
38 | extern QString cppFalse; |
39 | |
40 | // Base class for streamable objects with one QStringView parameter |
41 | class StringViewStreamable |
42 | { |
43 | public: |
44 | StringViewStreamable(QStringView parameter) : m_parameter(parameter) {} |
45 | |
46 | QStringView parameter() const { return m_parameter; } |
47 | |
48 | private: |
49 | QStringView m_parameter; |
50 | }; |
51 | |
52 | class qtConfig : public StringViewStreamable |
53 | { |
54 | public: |
55 | qtConfig(QStringView name) : StringViewStreamable(name) {} |
56 | }; |
57 | |
58 | QTextStream &operator<<(QTextStream &str, const qtConfig &c); |
59 | |
60 | class openQtConfig : public StringViewStreamable |
61 | { |
62 | public: |
63 | openQtConfig(QStringView name) : StringViewStreamable(name) {} |
64 | }; |
65 | |
66 | QTextStream &operator<<(QTextStream &str, const openQtConfig &c); |
67 | |
68 | class closeQtConfig : public StringViewStreamable |
69 | { |
70 | public: |
71 | closeQtConfig(QStringView name) : StringViewStreamable(name) {} |
72 | }; |
73 | |
74 | QTextStream &operator<<(QTextStream &, const closeQtConfig &c); |
75 | |
76 | QString fixClassName(QString className); |
77 | |
78 | const char *toolbarArea(int v); |
79 | const char *sizePolicy(int v); |
80 | const char *dockWidgetArea(int v); |
81 | const char *paletteColorRole(int v); |
82 | |
83 | enum class Encoding { Utf8, Unicode }; |
84 | |
85 | void _formatString(QTextStream &str, const QString &value, const QString &indent, |
86 | bool qString); |
87 | |
88 | template <bool AsQString> |
89 | class _string |
90 | { |
91 | public: |
92 | explicit _string(const QString &value, const QString &indent = QString()) |
93 | : m_value(value), m_indent(indent) {} |
94 | |
95 | void format(QTextStream &str) const |
96 | { _formatString(str, value: m_value, indent: m_indent, qString: AsQString); } |
97 | |
98 | private: |
99 | const QString &m_value; |
100 | const QString &m_indent; |
101 | }; |
102 | |
103 | template <bool AsQString> |
104 | inline QTextStream &operator<<(QTextStream &str, const language::_string<AsQString> &s) |
105 | { |
106 | s.format(str); |
107 | return str; |
108 | } |
109 | |
110 | using charliteral = _string<false>; |
111 | using qstring = _string<true>; |
112 | |
113 | class repeat { |
114 | public: |
115 | explicit repeat(int count, char c) : m_count(count), m_char(c) {} |
116 | |
117 | friend QTextStream &operator<<(QTextStream &str, const repeat &r); |
118 | |
119 | private: |
120 | const int m_count; |
121 | const char m_char; |
122 | }; |
123 | |
124 | class startFunctionDefinition1 { |
125 | public: |
126 | explicit startFunctionDefinition1(const char *name, const QString ¶meterType, |
127 | const QString ¶meterName, |
128 | const QString &indent, |
129 | const char *returnType = nullptr); |
130 | |
131 | friend QTextStream &operator<<(QTextStream &str, const startFunctionDefinition1 &f); |
132 | private: |
133 | const char *m_name; |
134 | const QString &m_parameterType; |
135 | const QString &m_parameterName; |
136 | const QString &m_indent; |
137 | const char *m_return; |
138 | }; |
139 | |
140 | class endFunctionDefinition { |
141 | public: |
142 | explicit endFunctionDefinition(const char *name); |
143 | |
144 | friend QTextStream &operator<<(QTextStream &str, const endFunctionDefinition &f); |
145 | private: |
146 | const char *m_name; |
147 | }; |
148 | |
149 | void _formatStackVariable(QTextStream &str, const char *className, QStringView varName, bool withInitParameters); |
150 | |
151 | template <bool withInitParameters> |
152 | class _stackVariable { |
153 | public: |
154 | explicit _stackVariable(const char *className, QStringView varName) : |
155 | m_className(className), m_varName(varName) {} |
156 | |
157 | void format(QTextStream &str) const |
158 | { _formatStackVariable(str, className: m_className, varName: m_varName, withInitParameters); } |
159 | |
160 | private: |
161 | const char *m_className; |
162 | QStringView m_varName; |
163 | QStringView m_parameters; |
164 | }; |
165 | |
166 | template <bool withInitParameters> |
167 | inline QTextStream &operator<<(QTextStream &str, const _stackVariable<withInitParameters> &s) |
168 | { |
169 | s.format(str); |
170 | return str; |
171 | } |
172 | |
173 | using stackVariable = _stackVariable<false>; |
174 | using stackVariableWithInitParameters = _stackVariable<true>; |
175 | |
176 | enum class SignalSlotOption |
177 | { |
178 | Ambiguous = 0x1 |
179 | }; |
180 | |
181 | Q_DECLARE_FLAGS(SignalSlotOptions, SignalSlotOption) |
182 | |
183 | struct SignalSlot |
184 | { |
185 | QString name; |
186 | QString signature; |
187 | QString className; |
188 | SignalSlotOptions options; |
189 | }; |
190 | |
191 | void formatConnection(QTextStream &str, const SignalSlot &sender, const SignalSlot &receiver, |
192 | ConnectionSyntax connectionSyntax); |
193 | |
194 | QString boolValue(bool v); |
195 | |
196 | QString enumValue(const QString &value); |
197 | |
198 | } // namespace language |
199 | |
200 | #endif // LANGUAGE_H |
201 | |