Mercurial > projects > qtd
annotate generator/cppheadergenerator.cpp @ 297:bc783e20da2b signals
share strange dmd
author | eldar |
---|---|
date | Sun, 22 Nov 2009 22:18:06 +0000 |
parents | f9559a957be9 |
children | 98b211f3ee34 |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** | |
5 ** This file is part of Qt Jambi. | |
6 ** | |
7 ** * Commercial Usage | |
8 * Licensees holding valid Qt Commercial licenses may use this file in | |
9 * accordance with the Qt Commercial License Agreement provided with the | |
10 * Software or, alternatively, in accordance with the terms contained in | |
11 * a written agreement between you and Nokia. | |
12 * | |
13 * | |
14 * GNU General Public License Usage | |
15 * Alternatively, this file may be used under the terms of the GNU | |
16 * General Public License versions 2.0 or 3.0 as published by the Free | |
17 * Software Foundation and appearing in the file LICENSE.GPL included in | |
18 * the packaging of this file. Please review the following information | |
19 * to ensure GNU General Public Licensing requirements will be met: | |
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
22 * exception, Nokia gives you certain additional rights. These rights | |
23 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
24 * the file GPL_EXCEPTION.txt in this package. | |
25 * | |
26 * Qt for Windows(R) Licensees | |
27 * As a special exception, Nokia, as the sole copyright holder for Qt | |
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
29 * right for the Qt/Eclipse Integration to link to functionality | |
30 * provided by Qt Designer and its related libraries. | |
31 * | |
32 * | |
33 * If you are unsure which license is appropriate for your use, please | |
34 * contact the sales department at qt-sales@nokia.com. | |
35 | |
36 ** | |
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
39 ** | |
40 ****************************************************************************/ | |
41 | |
42 #include "cppheadergenerator.h" | |
43 | |
44 #include <QtCore/QDir> | |
45 | |
46 #include <qdebug.h> | |
47 | |
48 QString CppHeaderGenerator::fileNameForClass(const AbstractMetaClass *java_class) const | |
49 { | |
50 return QString("%1_shell.h").arg(java_class->name()); | |
51 } | |
52 | |
53 void CppHeaderGenerator::writeFieldAccessors(QTextStream &s, const AbstractMetaField *java_field) | |
54 { | |
55 Q_ASSERT(java_field->isProtected()); | |
56 | |
57 const AbstractMetaFunction *setter = java_field->setter(); | |
58 const AbstractMetaFunction *getter = java_field->getter(); | |
59 | |
60 // qtd2 | |
61 if(notWrappedYet(getter)) | |
62 return; | |
63 | |
64 if (getter->isModifiedRemoved(TypeSystem::ShellCode)) | |
65 return; | |
66 | |
67 s << " "; | |
68 writeFunctionSignature(s, getter, 0, QString(), Option(ShowStatic)); | |
69 s << ";" << endl; | |
70 | |
71 // qtd2 | |
72 if(notWrappedYet(setter)) | |
73 return; | |
74 | |
75 if (!java_field->type()->isConstant()) { | |
76 if (setter->isModifiedRemoved(TypeSystem::ShellCode)) | |
77 return; | |
78 | |
79 s << " "; | |
80 writeFunctionSignature(s, setter, 0, QString(), Option(ShowStatic)); | |
81 s << ";" << endl; | |
82 } | |
83 } | |
84 | |
85 void CppHeaderGenerator::writeSignalWrapper(QTextStream &s, const AbstractMetaFunction *signal) | |
86 { | |
87 s << " "; | |
88 writeFunctionSignature(s, signal, 0, signalWrapperPrefix(), | |
89 Option(NormalizeAndFixTypeSignature | OriginalName | OriginalTypeDescription | IncludeDefaultExpression)); | |
90 s << ";" << endl; | |
91 } | |
92 | |
93 void CppHeaderGenerator::writeSignalWrappers(QTextStream &s, const AbstractMetaClass *java_class) | |
94 { | |
95 AbstractMetaFunctionList signal_funcs = signalFunctions(java_class); | |
96 if (signal_funcs.size() > 0) { | |
97 s << endl << "public slots:" << endl; | |
98 foreach (const AbstractMetaFunction *signal, signal_funcs) { | |
99 writeSignalWrapper(s, signal); | |
100 } | |
101 } | |
102 } | |
103 | |
104 void CppHeaderGenerator::writeWrapperClass(QTextStream &s, const AbstractMetaClass *java_class) | |
105 { | |
106 AbstractMetaFunctionList signal_functions = | |
107 java_class->queryFunctions(AbstractMetaClass::Signals | AbstractMetaClass::Visible | AbstractMetaClass::NotRemovedFromTargetLang); | |
108 if (signal_functions.size() == 0) | |
109 return ; | |
110 | |
111 s << "class QtJambi_SignalWrapper_" << java_class->name() << ": public QObject" << endl | |
112 << "{" << endl | |
113 << " Q_OBJECT" << endl; | |
114 writeSignalWrappers(s, java_class); | |
115 s << endl << "public:" << endl | |
116 << " QtJambiSignalInfo m_signals[" << signal_functions.size() << "];" << endl | |
117 << " QtJambiLink *link;" << endl | |
118 << "};" << endl << endl; | |
119 } | |
120 | |
121 void CppHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *java_class) | |
122 { | |
123 QString include_block = java_class->name().toUpper() + "_SHELL_H"; | |
124 | |
125 s << "#ifndef " << include_block << endl | |
126 << "#define " << include_block << endl << endl | |
127 // << "#include <qtjambi_core.h>" << endl | |
128 << "#include <QtCore/QHash>" << endl | |
129 << "#include <QObjectEntity.h>" << endl; | |
130 | |
131 Include inc = java_class->typeEntry()->include(); | |
132 s << "#include "; | |
133 if (inc.type == Include::IncludePath) | |
134 s << "<"; | |
135 else | |
136 s << "\""; | |
137 s << inc.name; | |
138 if (inc.type == Include::IncludePath) | |
139 s << ">"; | |
140 else | |
141 s << "\""; | |
142 s << endl << endl; | |
143 | |
144 IncludeList list = java_class->typeEntry()->extraIncludes(); | |
145 qSort(list.begin(), list.end()); | |
146 foreach (const Include &inc, list) { | |
147 if (inc.type == Include::TargetLangImport) | |
148 continue; | |
149 | |
150 s << "#include "; | |
151 if (inc.type == Include::LocalPath) | |
152 s << "\""; | |
153 else | |
154 s << "<"; | |
155 | |
156 s << inc.name; | |
157 | |
158 if (inc.type == Include::LocalPath) | |
159 s << "\""; | |
160 else | |
161 s << ">"; | |
162 | |
163 s << endl; | |
164 } | |
165 | |
166 /* qtd writeForwardDeclareSection(s, java_class); | |
167 | |
168 writeWrapperClass(s, java_class); | |
169 */ | |
170 s << endl; | |
238 | 171 |
1 | 172 |
173 if (!java_class->generateShellClass()) { | |
174 s << "#endif" << endl << endl; | |
238 | 175 priGenerator->addHeader(java_class->package(), fileNameForClass(java_class)); |
1 | 176 return ; |
177 } | |
178 | |
179 s << "class " << shellClassName(java_class) | |
180 << " : public " << java_class->qualifiedCppName(); | |
254 | 181 if (java_class->isQObject()) |
182 s << ", public QtD_QObjectEntity"; | |
183 else if(java_class->hasVirtualFunctions()) | |
184 s << ", public QtD_Entity"; | |
1 | 185 s << endl << "{" << endl; |
186 | |
187 if (java_class->isQObject()) { | |
188 s << "public:" << endl | |
254 | 189 << " Q_OBJECT_CHECK" << endl |
1 | 190 // << " mutable const QMetaObject *m_meta_object;" << endl; |
191 | |
192 /* if (java_class->hasVirtualSlots()) { | |
193 s << " mutable QHash<int,int> m_map;" << endl; | |
194 } | |
195 */ | |
105
3aa118a9ae71
each QObject now has associated child QObject for handling signals. fixes #15
eldar
parents:
21
diff
changeset
|
196 // s << " const QMetaObject *metaObject() const;" << endl |
1 | 197 // << " void *qt_metacast(const char *);" << endl |
254 | 198 // << " QT_TR_FUNCTIONS" << end |
199 << " virtual int qt_metacall(QMetaObject::Call, int, void **);" << endl | |
288 | 200 << " int __override_qt_metacall(QMetaObject::Call _c, int _id, void **_a);" << endl |
201 | |
254 | 202 << "private:" << endl; |
1 | 203 } |
204 | |
205 | |
206 s << "public:" << endl; | |
207 // constructor | |
208 foreach (const AbstractMetaFunction *function, java_class->functions()) { | |
209 if (function->isConstructor() && !function->isPrivate()) | |
210 writeFunction(s, function); | |
211 } | |
212 | |
213 s << " ~" << shellClassName(java_class) << "();" << endl; | |
214 s << endl; | |
215 | |
216 // All functions in original class that should be reimplemented in shell class | |
217 AbstractMetaFunctionList shell_functions = java_class->functionsInShellClass(); | |
218 foreach (const AbstractMetaFunction *function, shell_functions) { | |
219 if(notWrappedYet(function)) | |
220 continue; | |
221 writeFunction(s, function); | |
222 } | |
223 | |
224 // Public call throughs for protected functions | |
225 AbstractMetaFunctionList public_overrides = java_class->publicOverrideFunctions(); | |
226 foreach (const AbstractMetaFunction *function, public_overrides) { | |
227 if(notWrappedYet(function)) | |
228 continue; | |
229 writePublicFunctionOverride(s, function); | |
230 } | |
231 | |
232 // Override all virtual functions to get the decision on static/virtual call | |
233 AbstractMetaFunctionList virtual_functions = java_class->virtualOverrideFunctions(); | |
234 foreach (const AbstractMetaFunction *function, virtual_functions) { | |
235 if(notWrappedYet(function)) | |
236 continue; | |
237 | |
238 writeVirtualFunctionOverride(s, function); | |
239 } | |
240 | |
241 // Field accessors | |
242 foreach (const AbstractMetaField *field, java_class->fields()) { | |
243 if (field->isProtected()) | |
244 writeFieldAccessors(s, field); | |
245 } | |
246 /* qtd | |
247 writeVariablesSection(s, java_class); | |
248 */ | |
249 writeInjectedCode(s, java_class); | |
250 | |
251 s << "};" << endl << endl | |
252 << "#endif // " << include_block << endl; | |
253 | |
238 | 254 priGenerator->addHeader(java_class->package(), fileNameForClass(java_class)); |
255 priGenerator->addClass(java_class->package(), java_class->name()); | |
1 | 256 } |
257 | |
258 | |
259 /*! | |
260 Writes out declarations of virtual C++ functions so that they | |
261 can be reimplemented from the java side. | |
262 */ | |
263 void CppHeaderGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction *java_function) | |
264 { | |
265 if (java_function->isModifiedRemoved(TypeSystem::ShellCode)) | |
266 return; | |
267 | |
268 s << " "; | |
269 writeFunctionSignature(s, java_function, 0, QString(), Option(OriginalName | ShowStatic)); | |
270 s << ";" << endl; | |
271 } | |
272 | |
273 void CppHeaderGenerator::writePublicFunctionOverride(QTextStream &s, | |
274 const AbstractMetaFunction *java_function) | |
275 { | |
276 s << " "; | |
277 writeFunctionSignature(s, java_function, 0, "__public_", Option(EnumAsInts | ShowStatic | UnderscoreSpaces)); | |
278 s << ";" << endl; | |
279 } | |
280 | |
281 | |
282 void CppHeaderGenerator::writeVirtualFunctionOverride(QTextStream &s, | |
283 const AbstractMetaFunction *java_function) | |
284 { | |
285 if (java_function->isModifiedRemoved(TypeSystem::NativeCode)) | |
286 return; | |
287 | |
288 s << " "; | |
21 | 289 writeFunctionSignature(s, java_function, 0, "__override_", Option(EnumAsInts | ShowStatic | UnderscoreSpaces), QString(), QStringList() << "bool static_call"); |
1 | 290 s << ";" << endl; |
291 } | |
292 | |
293 | |
294 void CppHeaderGenerator::writeForwardDeclareSection(QTextStream &s, const AbstractMetaClass *) | |
295 { | |
296 s << endl | |
297 << "class QtJambiFunctionTable;" << endl | |
298 << "class QtJambiLink;" << endl; | |
299 } | |
300 | |
301 | |
302 void CppHeaderGenerator::writeVariablesSection(QTextStream &s, const AbstractMetaClass *) | |
303 { | |
304 s << endl | |
305 << " QtJambiFunctionTable *m_vtable;" << endl | |
306 << " QtJambiLink *m_link;" << endl; | |
307 } | |
308 | |
309 void CppHeaderGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *java_class) | |
310 { | |
311 CodeSnipList code_snips = java_class->typeEntry()->codeSnips(); | |
312 foreach (const CodeSnip &cs, code_snips) { | |
313 if (cs.language == TypeSystem::ShellDeclaration) { | |
314 s << cs.code() << endl; | |
315 } | |
316 } | |
317 } |