Mercurial > projects > qtd
annotate generator/containergenerator.cpp @ 299:87db643519a4 signals
missing bits prior to getting it compiled on windows
author | eldar |
---|---|
date | Sun, 06 Dec 2009 22:20:23 +0000 |
parents | 49bfc86ff583 |
children | 08c1ca7975ab |
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 "containergenerator.h" | |
43 #include "cppimplgenerator.h" | |
44 #include "fileout.h" | |
45 | |
46 static Indentor INDENT; | |
47 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
48 ContainerGenerator::ContainerGenerator(CppImplGenerator *cpp_impl_generator): |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
49 DGenerator(), m_cpp_impl_generator(cpp_impl_generator) |
1 | 50 |
51 { | |
52 setFilenameStub("ArrayOps"); | |
53 excludedTypes.clear(); | |
54 | |
55 // qtd2 | |
56 excludedTypes << "QFuture"; | |
57 } | |
58 | |
59 QString ContainerGenerator::subDirectoryForPackage(const QString &package, OutputDirectoryType type) const | |
60 { | |
61 switch (type) { | |
62 case CppDirectory: | |
63 return "cpp/" + QString(package).replace(".", "_") + "/"; | |
64 case DDirectory: | |
65 return QString(package).replace(".", "/"); | |
66 case HDirectory: | |
67 return "include/"; | |
68 default: | |
69 return QString(); // kill nonsense warnings | |
70 } | |
71 } | |
72 | |
73 void ContainerGenerator::write(QTextStream &, const AbstractMetaClass *) | |
74 { | |
75 // not used | |
76 } | |
77 | |
78 void ContainerGenerator::addTypeEntry(const TypeEntry* te) | |
79 { | |
80 if (!excludedTypes.contains(te->name())) | |
81 containerTypes << te; | |
82 } | |
83 | |
84 void ContainerGenerator::processType(AbstractMetaType *d_type) | |
85 { | |
86 if (d_type->isContainer()) { | |
87 QList<AbstractMetaType *> args = d_type->instantiations(); | |
88 | |
89 if (args.size() == 1) // QVector or QList | |
90 if (args.at(0)->typeEntry()->isComplex() | |
91 && !args.at(0)->isContainer() | |
92 && !args.at(0)->isTargetLangString()) | |
93 addTypeEntry(args.at(0)->typeEntry()); // qMakePair(args.at(0)->typeEntry(), m_class); | |
94 } | |
95 } | |
96 | |
97 void ContainerGenerator::processFunction(const AbstractMetaFunction *d_function) | |
98 { | |
99 if (notWrappedYet(d_function)) // qtd2 | |
100 return; | |
101 | |
102 if (d_function->type()) { | |
103 AbstractMetaType *d_type = d_function->type(); | |
104 if (d_type->isContainer()) { | |
105 processType(d_type); | |
106 } | |
107 } | |
108 | |
109 AbstractMetaArgumentList arguments = d_function->arguments(); | |
110 for (int i=0; i<arguments.count(); ++i) { | |
111 const AbstractMetaArgument *arg = arguments.at(i); | |
112 processType(arg->type()); | |
113 } | |
114 } | |
115 | |
116 void ContainerGenerator::buildTypeList() | |
117 { | |
118 foreach (AbstractMetaClass *d_class, classes()) { | |
119 m_class = d_class; | |
120 AbstractMetaFunctionList d_funcs = d_class->functionsInTargetLang(); | |
121 for (int i=0; i<d_funcs.size(); ++i) { | |
122 AbstractMetaFunction *function = d_funcs.at(i); | |
123 | |
124 // If a method in an interface class is modified to be private, this should | |
125 // not be present in the interface at all, only in the implementation. | |
126 if (d_class->isInterface()) { | |
127 uint includedAttributes = 0; | |
128 uint excludedAttributes = 0; | |
129 retrieveModifications(function, d_class, &excludedAttributes, &includedAttributes); | |
130 if (includedAttributes & AbstractMetaAttributes::Private) | |
131 continue; | |
132 } | |
133 | |
134 processFunction(function); | |
135 } | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
136 |
1 | 137 AbstractMetaFieldList fields = d_class->fields(); |
138 foreach (const AbstractMetaField *field, fields) { | |
139 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) { | |
140 processFunction(field->setter()); | |
141 processFunction(field->getter()); | |
142 } | |
143 } | |
144 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
145 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
146 for(int i = 0; i < signal_funcs.size(); i++) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
147 AbstractMetaFunction *signal = signal_funcs.at(i); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
148 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
149 AbstractMetaArgumentList arguments = signal->arguments(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
150 foreach (AbstractMetaArgument *argument, arguments) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
151 if(argument->type()->isContainer()) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
152 bool inList = false; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
153 foreach(AbstractMetaType* type, signalEntries[d_class->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
154 const TypeEntry *teInList = type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
155 const TypeEntry *te = argument->type()->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
156 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
157 if ((te == teInList) && (argument->type()->typeEntry() == type->typeEntry())) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
158 inList = true; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
159 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
160 if (!inList) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
161 (signalEntries[d_class->package()]) << argument->type(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
162 // (signalEntries[d_class->package()])[argument->type()->instantiations().first()->typeEntry()] = argument->type(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
163 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
164 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
165 } |
1 | 166 } |
167 } | |
168 | |
169 void ContainerGenerator::generate() | |
170 { | |
171 buildTypeList(); | |
172 | |
173 writeFile(cppFilename(), CppDirectory, &ContainerGenerator::writeCppContent); // cpp file | |
174 writeFile("ArrayOps_%1.h", HDirectory, &ContainerGenerator::writeHeaderContent); // header file | |
175 writeFile(dFilename(), DDirectory, &ContainerGenerator::writeDContent); // d file | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
176 writeFile("ArrayOps2.d", DDirectory, &ContainerGenerator::writeDContent2); // d file |
1 | 177 } |
178 | |
179 void ContainerGenerator::writeFile(const QString& fileName, OutputDirectoryType dirType, WriteOut writeOut) | |
180 { | |
181 AbstractMetaClassList classList = classes(); | |
182 QHash<QString, FileOut *> fileHash; | |
183 | |
184 // Seems continue is not supported by our foreach loop, so | |
185 foreach (AbstractMetaClass *cls, classList) { | |
186 | |
187 FileOut *f = fileHash.value(cls->package(), 0); | |
188 if (f == 0) { | |
189 f = new FileOut(outputDirectory() + "/" + subDirectoryForPackage(cls->package(), dirType) + "/" + | |
190 fileName.arg(cls->package().replace(".", "_"))); | |
191 writeNotice(f->stream); | |
192 | |
193 (this->*writeOut)(f->stream, cls); | |
194 | |
195 fileHash.insert(cls->package(), f); | |
196 | |
197 // QString pro_file_name = cls->package().replace(".", "_") + "/" + cls->package().replace(".", "_") + ".pri"; | |
198 // priGenerator->addSource(pro_file_name, cppFilename()); | |
199 } | |
200 } | |
201 | |
202 foreach (QString package, fileHash.keys()) { | |
203 FileOut *f = fileHash.value(package, 0); | |
204 if (f != 0) { | |
205 if( f->done() ) | |
206 ++m_num_generated_written; | |
207 ++m_num_generated; | |
208 | |
209 delete f; | |
210 } | |
211 } | |
212 } | |
213 | |
214 void ContainerGenerator::writeCppContent(QTextStream &s, AbstractMetaClass *cls) | |
215 { | |
216 QString package = cls->package().replace(".", "_"); | |
217 | |
218 s << "// stuff for passing D function pointers" << endl << endl | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
219 << "#include \"qtd_masterinclude.h\"" << endl << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
220 << "#include \"qtd_core.h\"" << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
221 << "#include \"ArrayOps_" << package << ".h\"" << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
222 << "#include \"ArrayOps_qt_core.h\"" << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
223 << "#include \"ArrayOpsPrimitive.h\"" << endl << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
224 << "#ifdef CPP_SHARED" << endl << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
225 |
1 | 226 |
227 foreach (const TypeEntry *te, containerTypes) { | |
228 if (te->javaPackage() == cls->package()) { | |
229 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
230 QString cls_name = centry->name(); | |
231 | |
232 setFuncNames(cls_name); | |
233 s << "QTD_EXPORT_VAR(" << all_name << ")" << endl | |
234 << "QTD_EXPORT_VAR(" << ass_name << ")" << endl | |
235 << "QTD_EXPORT_VAR(" << get_name << ")" << endl << endl; | |
236 } | |
237 } | |
238 | |
239 s << endl | |
240 << "extern \"C\" DLL_PUBLIC void qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(pfunc_abstr *callbacks)" << endl | |
241 << "{" << endl; | |
242 | |
243 int num_funcs = 0; | |
244 foreach (const TypeEntry *te, containerTypes) { | |
245 if (te->javaPackage() == cls->package()) { | |
246 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
247 QString cls_name = centry->name(); | |
248 | |
249 setFuncNames(cls_name); | |
250 s << " QTD_EXPORT_VAR_SET(" << all_name << ", callbacks[" << num_funcs + 0 << "]);" << endl | |
251 << " QTD_EXPORT_VAR_SET(" << ass_name << ", callbacks[" << num_funcs + 1 << "]);" << endl | |
252 << " QTD_EXPORT_VAR_SET(" << get_name << ", callbacks[" << num_funcs + 2 << "]);" << endl << endl; | |
253 | |
254 num_funcs += NUM_ARRAY_FUNCS; | |
255 } | |
256 } | |
257 s << "}" << endl | |
258 << "#endif" << endl; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
259 /* |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
260 QMap<const TypeEntry*, AbstractMetaType*> typeList = signalEntries[cls->package()]; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
261 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
262 QMapIterator<const TypeEntry*, AbstractMetaType*> i(typeList); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
263 while (i.hasNext()) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
264 i.next(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
265 s << "// " << i.key()->targetLangName() << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
266 << "extern \"C\" DLL_PUBLIC void qtd_" << package << "_" << i.key()->targetLangName() << "_to_d_array(void *cpp_ptr, DArray* __d_container) {" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
267 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
268 AbstractMetaType *arg_type = i.value(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
269 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
270 s << "container = (*reinterpret_cast< "; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
271 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
272 s << "(*)>(cpp_ptr));" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
273 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
274 m_cpp_impl_generator->writeQtToJavaContainer(s, arg_type, "container", "__d_container", 0, -1); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
275 s << "}" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
276 }*/ |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
277 |
270 | 278 s << "// signal conversion functions" << endl; |
279 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
280 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
281 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
282 s << "// " << te->targetLangName() << endl |
270 | 283 << "extern \"C\" DLL_PUBLIC void " << cppContainerConversionName(cls, arg_type, FromCpp) << "(void *cpp_ptr, DArray* __d_container) {" << endl; |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
284 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
285 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
286 s << "container = (*reinterpret_cast< "; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
287 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
288 s << "(*)>(cpp_ptr));" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
289 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
290 m_cpp_impl_generator->writeQtToJavaContainer(s, arg_type, "container", "__d_container", 0, -1); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
291 s << "}" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
292 } |
1 | 293 } |
294 | |
295 void ContainerGenerator::writeHeaderContent(QTextStream &s, AbstractMetaClass *cls) | |
296 { | |
35 | 297 QString file_upper = "ArrayOps_" + QString(cls->package()).replace(".", "_") + "_h"; |
298 file_upper = file_upper.toUpper(); | |
299 s << "#ifndef " << file_upper << endl | |
300 << "#define " << file_upper << endl << endl | |
301 << "#include <cstring>" << endl | |
1 | 302 << "#include \"qtd_core.h\"" << endl << endl; |
303 | |
304 foreach (const TypeEntry *te, containerTypes) { | |
305 if (te->javaPackage() == cls->package()) { | |
306 const ComplexTypeEntry *typeEntry = static_cast<const ComplexTypeEntry *>(te); | |
307 s << "// " << typeEntry->name() << endl; // " in " << it.second->name() << endl; | |
308 | |
309 Indentation indent(INDENT); | |
310 writeHeaderArrayFunctions(s, typeEntry); | |
311 } | |
312 } | |
35 | 313 |
314 s << "#endif // " << file_upper << endl; | |
1 | 315 } |
316 | |
317 void ContainerGenerator::setFuncNames(const QString& cls_name) | |
318 { | |
319 all_name = QString("qtd_allocate_%1_array").arg(cls_name); | |
320 ass_name = QString("qtd_assign_%1_array_element").arg(cls_name); | |
321 get_name = QString("qtd_get_%1_from_array").arg(cls_name); | |
322 } | |
323 | |
324 void ContainerGenerator::writeHeaderArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | |
325 { | |
326 QString cls_name = centry->name(); | |
327 bool d_export = true; | |
328 QString d_type, cpp_type, cpp_type_assign; | |
329 | |
330 if (centry->name() == "QModelIndex") { | |
331 cpp_type = "QModelIndexAccessor*"; | |
332 } else if (centry->isStructInD()) { | |
333 cpp_type = centry->qualifiedCppName() + "*"; | |
334 } else if (centry->isObject() || centry->isQObject() || centry->isValue() || centry->isInterface() || centry->isVariant()) { | |
335 cpp_type = "void*"; | |
336 } | |
337 | |
338 setFuncNames(cls_name); | |
339 | |
340 s << "QTD_EXPORT(void, " << all_name << ", (void* arr, size_t len))" << endl | |
341 << "QTD_EXPORT(void, " << ass_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl | |
342 << "QTD_EXPORT(void, " << get_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl; | |
343 | |
344 s << "#ifdef CPP_SHARED" << endl | |
345 << "#define " << all_name << " qtd_get_" << all_name << "()" << endl | |
346 << "#define " << ass_name << " qtd_get_" << ass_name << "()" << endl | |
347 << "#define " << get_name << " qtd_get_" << get_name << "()" << endl | |
348 << "#endif" << endl; | |
349 | |
350 s << endl; | |
351 } | |
352 | |
353 void ContainerGenerator::writeDContent(QTextStream &s, AbstractMetaClass *cls) | |
354 { | |
355 s << "module " << cls->package() << ".ArrayOps;" << endl << endl; | |
356 | |
357 int num_funcs = 0; | |
358 foreach (const TypeEntry *te, containerTypes) { | |
359 if (te->javaPackage() == cls->package()) { | |
360 const ComplexTypeEntry *typeEntry = static_cast<const ComplexTypeEntry *>(te); | |
361 s << "// " << typeEntry->name() << endl; | |
362 writeImportString(s, typeEntry); | |
363 s << endl; | |
364 | |
365 Indentation indent(INDENT); | |
366 | |
367 writeArrayFunctions(s, typeEntry); | |
368 s << endl; | |
369 num_funcs += NUM_ARRAY_FUNCS; | |
370 } | |
371 } | |
372 if (num_funcs == 0) | |
373 return; | |
374 | |
125 | 375 s << "version (cpp_shared) {" << endl |
1 | 376 << " private extern (C) void qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(void* callbacks);" << endl << endl |
377 << " static this() {" << endl | |
378 << " void*[" << num_funcs << "] callbacks; " << endl << endl; | |
379 | |
380 num_funcs = 0; | |
381 foreach (const TypeEntry *te, containerTypes) { | |
382 if (te->javaPackage() == cls->package()) { | |
383 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
384 | |
385 QString cls_name = centry->name(); | |
386 setFuncNames(cls_name); | |
387 | |
388 s << " callbacks[" << num_funcs + 0 << "] = &" << all_name << ";" << endl | |
389 << " callbacks[" << num_funcs + 1 << "] = &" << ass_name << ";" << endl | |
390 << " callbacks[" << num_funcs + 2 << "] = &" << get_name << ";" << endl; | |
391 | |
392 s << endl; | |
393 num_funcs += NUM_ARRAY_FUNCS; | |
394 } | |
395 } | |
396 s << " qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(callbacks.ptr);" << endl | |
397 << " }" << endl | |
398 << "}" << endl; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
399 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
400 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
401 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
402 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
403 void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
404 { |
179 | 405 s << "module " << cls->package() << ".ArrayOps2;" << endl << endl |
406 << "import qt.QGlobal;" << endl << endl; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
407 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
408 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
409 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
410 if(!te->isPrimitive() && !te->isString()) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
411 writeImportString(s, te); |
270 | 412 s << "extern (C) void " << cppContainerConversionName(cls, arg_type, FromCpp) << "(void *cpp_ptr, " << te->targetLangName() << "[]* __d_container);" << endl; |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
413 } |
1 | 414 } |
415 | |
416 void ContainerGenerator::writeNotice(QTextStream &s) | |
417 { | |
418 s << "/****************************************************************************" << endl | |
419 << "**" << endl | |
420 << "** This is a generated file, please don't touch." << endl | |
421 << "**" << endl | |
422 << "****************************************************************************/" << endl << endl; | |
423 } | |
424 | |
425 void ContainerGenerator::writeArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | |
426 { | |
427 QString cls_name = centry->name(); | |
428 QString type_name = cls_name; | |
429 | |
430 bool d_export = true; | |
431 QString d_type, cpp_type, cpp_assign_type, convert, nativeId; | |
432 | |
433 convert = "qtd_" + cls_name + "_cpp_to_d(elem)"; | |
434 nativeId = ""; | |
435 | |
436 if (centry->name() == "QModelIndex") { | |
437 cpp_type = "QModelIndexAccessor*"; | |
438 cpp_assign_type = cpp_type; | |
439 d_type = cpp_type; | |
440 convert = "*elem"; | |
441 } else if (centry->isStructInD()) { | |
442 cpp_type = centry->qualifiedCppName() + "*"; | |
443 cpp_assign_type = cpp_type; | |
444 d_type = cpp_type; | |
445 convert = "*elem"; | |
446 } else if (centry->isObject() || centry->isQObject() || centry->isValue() || centry->isInterface() || centry->isVariant()) { | |
447 cpp_type = "void*"; | |
448 cpp_assign_type = cpp_type + "*"; | |
449 d_type = cls_name; | |
110 | 450 if (centry->designatedInterface()) |
451 d_type = centry->designatedInterface()->name(); | |
254 | 452 nativeId = ".__nativeId"; |
1 | 453 } |
454 | |
455 if (centry->designatedInterface()) { | |
456 type_name = centry->designatedInterface()->name(); | |
457 nativeId = ".__ptr_" + type_name; | |
458 } | |
459 | |
460 s << "private extern(C) void qtd_allocate_" << cls_name << "_array(" << type_name << "[]* arr, size_t len)" << endl | |
461 << "{" << endl | |
462 << INDENT << "*arr = new " << type_name << "[len];" << endl | |
463 << "}" << endl << endl; | |
464 | |
465 s << "private extern(C) void qtd_assign_" << cls_name << "_array_element(" << type_name << "[]* arr, size_t pos, " << cpp_type << " elem)" << endl | |
466 << "{" << endl | |
467 << INDENT << "(*arr)[pos] = " << convert << ";" << endl | |
468 << "}" << endl << endl | |
469 | |
470 << "private extern(C) void qtd_get_" << cls_name << "_from_array(" << type_name << "* arr, size_t pos, " << cpp_assign_type << " elem)" << endl | |
471 << "{" << endl | |
472 << INDENT << "*elem = arr[pos]" << nativeId << ";" << endl | |
473 << "}" << endl << endl | |
474 | |
254 | 475 << "package " << d_type << " qtd_" << cls_name << "_cpp_to_d(" << cpp_type << " ret)" << endl |
1 | 476 << "{" << endl; |
477 | |
478 marshallFromCppToD(s, centry); | |
479 | |
480 s << "}" << endl; | |
481 } |