Mercurial > projects > qtd
annotate generator/containergenerator.cpp @ 372:a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 08 Jul 2010 17:19:05 +0300 |
parents | 9784459f0750 |
children | d2f48c4cb3e3 |
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 |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
223 << "#include \"ArrayOpsPrimitive.h\"" << endl << endl; |
1 | 224 |
225 foreach (const TypeEntry *te, containerTypes) { | |
226 if (te->javaPackage() == cls->package()) { | |
227 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); | |
228 QString cls_name = centry->name(); | |
229 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
230 QString module = packageToQtModule(cls->package()); |
1 | 231 setFuncNames(cls_name); |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
232 s << "QTD_EXPORT(" << module << ", " << all_name << ")" << endl |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
233 << "QTD_EXPORT(" << module << ", " << ass_name << ")" << endl |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
234 << "QTD_EXPORT(" << module << ", " << get_name << ")" << endl << endl; |
1 | 235 } |
236 } | |
237 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
238 /* |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
239 QMap<const TypeEntry*, AbstractMetaType*> typeList = signalEntries[cls->package()]; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
240 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
241 QMapIterator<const TypeEntry*, AbstractMetaType*> i(typeList); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
242 while (i.hasNext()) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
243 i.next(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
244 s << "// " << i.key()->targetLangName() << endl |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
245 << "QTD_EXTERN QTD_DLL_PUBLIC void qtd_" << package << "_" << i.key()->targetLangName() << "_to_d_array(void *cpp_ptr, DArray* __d_container) {" << endl; |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
246 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
247 AbstractMetaType *arg_type = i.value(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
248 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
249 s << "container = (*reinterpret_cast< "; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
250 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
251 s << "(*)>(cpp_ptr));" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
252 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
253 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
|
254 s << "}" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
255 }*/ |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
256 |
270 | 257 s << "// signal conversion functions" << endl; |
258 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
259 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
260 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
261 s << "// " << te->targetLangName() << endl |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
262 << "QTD_EXTERN QTD_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
|
263 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
264 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
265 s << "container = (*reinterpret_cast< "; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
266 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
267 s << "(*)>(cpp_ptr));" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
268 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
269 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
|
270 s << "}" << endl; |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
271 } |
1 | 272 } |
273 | |
274 void ContainerGenerator::writeHeaderContent(QTextStream &s, AbstractMetaClass *cls) | |
275 { | |
35 | 276 QString file_upper = "ArrayOps_" + QString(cls->package()).replace(".", "_") + "_h"; |
277 file_upper = file_upper.toUpper(); | |
278 s << "#ifndef " << file_upper << endl | |
279 << "#define " << file_upper << endl << endl | |
280 << "#include <cstring>" << endl | |
1 | 281 << "#include \"qtd_core.h\"" << endl << endl; |
282 | |
283 foreach (const TypeEntry *te, containerTypes) { | |
284 if (te->javaPackage() == cls->package()) { | |
285 const ComplexTypeEntry *typeEntry = static_cast<const ComplexTypeEntry *>(te); | |
286 s << "// " << typeEntry->name() << endl; // " in " << it.second->name() << endl; | |
287 | |
288 Indentation indent(INDENT); | |
289 writeHeaderArrayFunctions(s, typeEntry); | |
290 } | |
291 } | |
35 | 292 |
293 s << "#endif // " << file_upper << endl; | |
1 | 294 } |
295 | |
296 void ContainerGenerator::setFuncNames(const QString& cls_name) | |
297 { | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
298 all_name = QString("allocate_%1_array").arg(cls_name); |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
299 ass_name = QString("assign_%1_array_element").arg(cls_name); |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
300 get_name = QString("get_%1_from_array").arg(cls_name); |
1 | 301 } |
302 | |
303 void ContainerGenerator::writeHeaderArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) | |
304 { | |
305 QString cls_name = centry->name(); | |
306 bool d_export = true; | |
307 QString d_type, cpp_type, cpp_type_assign; | |
308 | |
309 if (centry->name() == "QModelIndex") { | |
310 cpp_type = "QModelIndexAccessor*"; | |
311 } else if (centry->isStructInD()) { | |
312 cpp_type = centry->qualifiedCppName() + "*"; | |
313 } else if (centry->isObject() || centry->isQObject() || centry->isValue() || centry->isInterface() || centry->isVariant()) { | |
314 cpp_type = "void*"; | |
315 } | |
316 | |
317 setFuncNames(cls_name); | |
318 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
319 QString module = packageToQtModule(centry->javaPackage()); |
1 | 320 |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
321 s << "QTD_EXPORT_DECL(" << module << ", void, " << all_name << ", (void* arr, size_t len))" << endl |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
322 << "QTD_EXPORT_DECL(" << module << ", void, " << ass_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
323 << "QTD_EXPORT_DECL(" << module << ", void, " << get_name << ", (void* arr, size_t pos, " << cpp_type << " elem))" << endl; |
1 | 324 |
325 s << endl; | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
326 |
1 | 327 } |
328 | |
329 void ContainerGenerator::writeDContent(QTextStream &s, AbstractMetaClass *cls) | |
330 { | |
331 s << "module " << cls->package() << ".ArrayOps;" << endl << endl; | |
332 | |
333 int num_funcs = 0; | |
334 foreach (const TypeEntry *te, containerTypes) { | |
335 if (te->javaPackage() == cls->package()) { | |
336 const ComplexTypeEntry *typeEntry = static_cast<const ComplexTypeEntry *>(te); | |
337 s << "// " << typeEntry->name() << endl; | |
338 writeImportString(s, typeEntry); | |
339 s << endl; | |
340 | |
341 Indentation indent(INDENT); | |
342 | |
343 writeArrayFunctions(s, typeEntry); | |
344 s << endl; | |
345 num_funcs += NUM_ARRAY_FUNCS; | |
346 } | |
347 } | |
348 if (num_funcs == 0) | |
349 return; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
350 } |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
351 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
352 void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
353 { |
179 | 354 s << "module " << cls->package() << ".ArrayOps2;" << endl << endl |
355 << "import qt.QGlobal;" << endl << endl; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
356 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
357 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) { |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
358 const TypeEntry *te = arg_type->instantiations().first()->typeEntry(); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
359 if(!te->isPrimitive() && !te->isString()) |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
125
diff
changeset
|
360 writeImportString(s, te); |
270 | 361 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
|
362 } |
1 | 363 } |
364 | |
365 void ContainerGenerator::writeNotice(QTextStream &s) | |
366 { | |
367 s << "/****************************************************************************" << endl | |
368 << "**" << endl | |
369 << "** This is a generated file, please don't touch." << endl | |
370 << "**" << endl | |
371 << "****************************************************************************/" << endl << endl; | |
372 } | |
373 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
374 |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
375 // TODO: rewrite |
1 | 376 void ContainerGenerator::writeArrayFunctions(QTextStream &s, const ComplexTypeEntry *centry) |
377 { | |
378 QString cls_name = centry->name(); | |
379 QString type_name = cls_name; | |
380 | |
381 bool d_export = true; | |
382 QString d_type, cpp_type, cpp_assign_type, convert, nativeId; | |
383 | |
384 convert = "qtd_" + cls_name + "_cpp_to_d(elem)"; | |
385 nativeId = ""; | |
386 | |
387 if (centry->name() == "QModelIndex") { | |
388 cpp_type = "QModelIndexAccessor*"; | |
389 cpp_assign_type = cpp_type; | |
390 d_type = cpp_type; | |
391 convert = "*elem"; | |
392 } else if (centry->isStructInD()) { | |
393 cpp_type = centry->qualifiedCppName() + "*"; | |
394 cpp_assign_type = cpp_type; | |
395 d_type = cpp_type; | |
396 convert = "*elem"; | |
397 } else if (centry->isObject() || centry->isQObject() || centry->isValue() || centry->isInterface() || centry->isVariant()) { | |
398 cpp_type = "void*"; | |
399 cpp_assign_type = cpp_type + "*"; | |
400 d_type = cls_name; | |
110 | 401 if (centry->designatedInterface()) |
402 d_type = centry->designatedInterface()->name(); | |
372
a032df77b6ab
Simple debug helper. Unittests. Meta-object for polymorphic non-QObjects
Max Samukha <maxter@spambox.com>
parents:
357
diff
changeset
|
403 nativeId = ".qtdNativeId"; |
1 | 404 } |
405 | |
406 if (centry->designatedInterface()) { | |
407 type_name = centry->designatedInterface()->name(); | |
408 nativeId = ".__ptr_" + type_name; | |
409 } | |
410 | |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
411 DGenerator::writeDExport(s, "void", QString("allocate_%1_array").arg(cls_name), QString("%1[]* arr, size_t len").arg(type_name), |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
412 QString(" *arr = new %1[len]; ").arg(type_name)); |
1 | 413 |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
414 DGenerator::writeDExport(s, "void", QString("assign_%1_array_element").arg(cls_name), QString("%1[]* arr, size_t pos, %2 elem").arg(type_name, cpp_type), |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
415 QString(" (*arr)[pos] = %1; ").arg(convert)); |
1 | 416 |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
417 DGenerator::writeDExport(s, "void", QString("get_%1_from_array").arg(cls_name), QString("%1* arr, size_t pos, %2 elem").arg(type_name, cpp_assign_type), |
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
418 QString(" *elem = arr[pos]%1; ").arg(nativeId)); |
1 | 419 |
357
9784459f0750
An attempt (failed due to optlink) to improve locality of declarations exported from QtD executables
Max Samukha <maxter@spambox.com>
parents:
355
diff
changeset
|
420 s << "package " << d_type << " qtd_" << cls_name << "_cpp_to_d(" << cpp_type << " ret)" << endl |
1 | 421 << "{" << endl; |
422 | |
355
08c1ca7975ab
obviated redundant virtual dispatch callbacks
Max Samukha <maxter@spambox.com>
parents:
270
diff
changeset
|
423 marshalFromCppToD(s, centry); |
1 | 424 |
425 s << "}" << endl; | |
426 } |