Mercurial > projects > qtd
annotate generator/containergenerator.cpp @ 222:c9670583880e
build.bat updates
author | eldar |
---|---|
date | Tue, 14 Jul 2009 22:14:00 +0000 |
parents | d69b58c01131 |
children | 7664de4a55e5 |
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 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
278 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
279 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
280 s << "// " << te->targetLangName() << endl |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
281 << "extern \"C\" DLL_PUBLIC void " << fromCppContainerName(cls, arg_type) << "(void *cpp_ptr, DArray* __d_container) {" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
282 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
283 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
284 s << "container = (*reinterpret_cast< "; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
285 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
286 s << "(*)>(cpp_ptr));" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
287 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
288 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
|
289 s << "}" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
290 } |
1 | 291 } |
292 | |
293 void ContainerGenerator::writeHeaderContent(QTextStream &s, AbstractMetaClass *cls) | |
294 { | |
35 | 295 QString file_upper = "ArrayOps_" + QString(cls->package()).replace(".", "_") + "_h"; |
296 file_upper = file_upper.toUpper(); | |
297 s << "#ifndef " << file_upper << endl | |
298 << "#define " << file_upper << endl << endl | |
299 << "#include <cstring>" << endl | |
1 | 300 << "#include \"qtd_core.h\"" << endl << endl; |
301 | |
302 foreach (const TypeEntry *te, containerTypes) { | |
303 if (te->javaPackage() == cls->package()) { | |
304 const ComplexTypeEntry *typeEntry = static_cast<const ComplexTypeEntry *>(te); | |
305 s << "// " << typeEntry->name() << endl; // " in " << it.second->name() << endl; | |
306 | |
307 Indentation indent(INDENT); | |
308 writeHeaderArrayFunctions(s, typeEntry); | |
309 } | |
310 } | |
35 | 311 |
312 s << "#endif // " << file_upper << endl; | |
1 | 313 } |
314 | |
315 void ContainerGenerator::setFuncNames(const QString& cls_name) | |
316 { | |
317 all_name = QString("qtd_allocate_%1_array").arg(cls_name); | |
318 ass_name = QString("qtd_assign_%1_array_element").arg(cls_name); | |
319 get_name = QString("qtd_get_%1_from_array").arg(cls_name); | |
320 } | |
321 | |
322 void ContainerGenerator::writeHeaderArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | |
323 { | |
324 QString cls_name = centry->name(); | |
325 bool d_export = true; | |
326 QString d_type, cpp_type, cpp_type_assign; | |
327 | |
328 if (centry->name() == "QModelIndex") { | |
329 cpp_type = "QModelIndexAccessor*"; | |
330 } else if (centry->isStructInD()) { | |
331 cpp_type = centry->qualifiedCppName() + "*"; | |
332 } else if (centry->isObject() || centry->isQObject() || centry->isValue() || centry->isInterface() || centry->isVariant()) { | |
333 cpp_type = "void*"; | |
334 } | |
335 | |
336 setFuncNames(cls_name); | |
337 | |
338 s << "QTD_EXPORT(void, " << all_name << ", (void* arr, size_t len))" << endl | |
339 << "QTD_EXPORT(void, " << ass_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl | |
340 << "QTD_EXPORT(void, " << get_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl; | |
341 | |
342 s << "#ifdef CPP_SHARED" << endl | |
343 << "#define " << all_name << " qtd_get_" << all_name << "()" << endl | |
344 << "#define " << ass_name << " qtd_get_" << ass_name << "()" << endl | |
345 << "#define " << get_name << " qtd_get_" << get_name << "()" << endl | |
346 << "#endif" << endl; | |
347 | |
348 s << endl; | |
349 } | |
350 | |
351 void ContainerGenerator::writeDContent(QTextStream &s, AbstractMetaClass *cls) | |
352 { | |
353 s << "module " << cls->package() << ".ArrayOps;" << endl << endl; | |
354 | |
355 int num_funcs = 0; | |
356 foreach (const TypeEntry *te, containerTypes) { | |
357 if (te->javaPackage() == cls->package()) { | |
358 const ComplexTypeEntry *typeEntry = static_cast<const ComplexTypeEntry *>(te); | |
359 s << "// " << typeEntry->name() << endl; | |
360 writeImportString(s, typeEntry); | |
361 s << endl; | |
362 | |
363 Indentation indent(INDENT); | |
364 | |
365 writeArrayFunctions(s, typeEntry); | |
366 s << endl; | |
367 num_funcs += NUM_ARRAY_FUNCS; | |
368 } | |
369 } | |
370 if (num_funcs == 0) | |
371 return; | |
372 | |
125 | 373 s << "version (cpp_shared) {" << endl |
1 | 374 << " private extern (C) void qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(void* callbacks);" << endl << endl |
375 << " static this() {" << endl | |
376 << " void*[" << num_funcs << "] callbacks; " << endl << endl; | |
377 | |
378 num_funcs = 0; | |
379 foreach (const TypeEntry *te, containerTypes) { | |
380 if (te->javaPackage() == cls->package()) { | |
381 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
382 | |
383 QString cls_name = centry->name(); | |
384 setFuncNames(cls_name); | |
385 | |
386 s << " callbacks[" << num_funcs + 0 << "] = &" << all_name << ";" << endl | |
387 << " callbacks[" << num_funcs + 1 << "] = &" << ass_name << ";" << endl | |
388 << " callbacks[" << num_funcs + 2 << "] = &" << get_name << ";" << endl; | |
389 | |
390 s << endl; | |
391 num_funcs += NUM_ARRAY_FUNCS; | |
392 } | |
393 } | |
394 s << " qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(callbacks.ptr);" << endl | |
395 << " }" << endl | |
396 << "}" << endl; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
397 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
398 |
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 void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
402 { |
179 | 403 s << "module " << cls->package() << ".ArrayOps2;" << endl << endl |
404 << "import qt.QGlobal;" << endl << endl; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
405 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
406 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
407 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
408 if(!te->isPrimitive() && !te->isString()) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
409 writeImportString(s, te); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
410 s << "extern (C) void " << fromCppContainerName(cls, arg_type) << "(void *cpp_ptr, " << te->targetLangName() << "[]* __d_container);" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
411 } |
1 | 412 } |
413 | |
414 void ContainerGenerator::writeNotice(QTextStream &s) | |
415 { | |
416 s << "/****************************************************************************" << endl | |
417 << "**" << endl | |
418 << "** This is a generated file, please don't touch." << endl | |
419 << "**" << endl | |
420 << "****************************************************************************/" << endl << endl; | |
421 } | |
422 | |
423 void ContainerGenerator::writeArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | |
424 { | |
425 QString cls_name = centry->name(); | |
426 QString type_name = cls_name; | |
427 | |
428 bool d_export = true; | |
429 QString d_type, cpp_type, cpp_assign_type, convert, nativeId; | |
430 | |
431 convert = "qtd_" + cls_name + "_cpp_to_d(elem)"; | |
432 nativeId = ""; | |
433 | |
434 if (centry->name() == "QModelIndex") { | |
435 cpp_type = "QModelIndexAccessor*"; | |
436 cpp_assign_type = cpp_type; | |
437 d_type = cpp_type; | |
438 convert = "*elem"; | |
439 } else if (centry->isStructInD()) { | |
440 cpp_type = centry->qualifiedCppName() + "*"; | |
441 cpp_assign_type = cpp_type; | |
442 d_type = cpp_type; | |
443 convert = "*elem"; | |
444 } else if (centry->isObject() || centry->isQObject() || centry->isValue() || centry->isInterface() || centry->isVariant()) { | |
445 cpp_type = "void*"; | |
446 cpp_assign_type = cpp_type + "*"; | |
447 d_type = cls_name; | |
110 | 448 if (centry->designatedInterface()) |
449 d_type = centry->designatedInterface()->name(); | |
1 | 450 nativeId = ".nativeId"; |
451 } | |
452 | |
453 if (centry->designatedInterface()) { | |
454 type_name = centry->designatedInterface()->name(); | |
455 nativeId = ".__ptr_" + type_name; | |
456 } | |
457 | |
458 s << "private extern(C) void qtd_allocate_" << cls_name << "_array(" << type_name << "[]* arr, size_t len)" << endl | |
459 << "{" << endl | |
460 << INDENT << "*arr = new " << type_name << "[len];" << endl | |
461 << "}" << endl << endl; | |
462 | |
463 s << "private extern(C) void qtd_assign_" << cls_name << "_array_element(" << type_name << "[]* arr, size_t pos, " << cpp_type << " elem)" << endl | |
464 << "{" << endl | |
465 << INDENT << "(*arr)[pos] = " << convert << ";" << endl | |
466 << "}" << endl << endl | |
467 | |
468 << "private extern(C) void qtd_get_" << cls_name << "_from_array(" << type_name << "* arr, size_t pos, " << cpp_assign_type << " elem)" << endl | |
469 << "{" << endl | |
470 << INDENT << "*elem = arr[pos]" << nativeId << ";" << endl | |
471 << "}" << endl << endl | |
472 | |
473 << "package " << d_type << " qtd_" << cls_name << "_cpp_to_d(" << cpp_type << " __qt_return_value)" << endl | |
474 << "{" << endl; | |
475 | |
476 marshallFromCppToD(s, centry); | |
477 | |
478 s << "}" << endl; | |
479 } |