comparison generator/containergenerator.cpp @ 167:ae06da58ec25

fixed hacky conversion of arguments when emmitting a signal
author eldar
date Sat, 20 Jun 2009 19:14:29 +0000
parents 76e5e8597a83
children d69b58c01131
comparison
equal deleted inserted replaced
166:52da31f967f0 167:ae06da58ec25
43 #include "cppimplgenerator.h" 43 #include "cppimplgenerator.h"
44 #include "fileout.h" 44 #include "fileout.h"
45 45
46 static Indentor INDENT; 46 static Indentor INDENT;
47 47
48 ContainerGenerator::ContainerGenerator(): 48 ContainerGenerator::ContainerGenerator(CppImplGenerator *cpp_impl_generator):
49 DGenerator() 49 DGenerator(), m_cpp_impl_generator(cpp_impl_generator)
50 50
51 { 51 {
52 setFilenameStub("ArrayOps"); 52 setFilenameStub("ArrayOps");
53 excludedTypes.clear(); 53 excludedTypes.clear();
54 54
131 continue; 131 continue;
132 } 132 }
133 133
134 processFunction(function); 134 processFunction(function);
135 } 135 }
136
136 AbstractMetaFieldList fields = d_class->fields(); 137 AbstractMetaFieldList fields = d_class->fields();
137 foreach (const AbstractMetaField *field, fields) { 138 foreach (const AbstractMetaField *field, fields) {
138 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) { 139 if (field->wasPublic() || (field->wasProtected() && !d_class->isFinal())) {
139 processFunction(field->setter()); 140 processFunction(field->setter());
140 processFunction(field->getter()); 141 processFunction(field->getter());
141 } 142 }
142 } 143 }
143 144
145 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class);
146 for(int i = 0; i < signal_funcs.size(); i++) {
147 AbstractMetaFunction *signal = signal_funcs.at(i);
148
149 AbstractMetaArgumentList arguments = signal->arguments();
150 foreach (AbstractMetaArgument *argument, arguments) {
151 if(argument->type()->isContainer()) {
152 bool inList = false;
153 foreach(AbstractMetaType* type, signalEntries[d_class->package()]) {
154 const TypeEntry *teInList = type->instantiations().first()->typeEntry();
155 const TypeEntry *te = argument->type()->instantiations().first()->typeEntry();
156
157 if ((te == teInList) && (argument->type()->typeEntry() == type->typeEntry()))
158 inList = true;
159 }
160 if (!inList)
161 (signalEntries[d_class->package()]) << argument->type();
162 // (signalEntries[d_class->package()])[argument->type()->instantiations().first()->typeEntry()] = argument->type();
163 }
164 }
165 }
144 } 166 }
145 } 167 }
146 168
147 void ContainerGenerator::generate() 169 void ContainerGenerator::generate()
148 { 170 {
149 buildTypeList(); 171 buildTypeList();
150 172
151 writeFile(cppFilename(), CppDirectory, &ContainerGenerator::writeCppContent); // cpp file 173 writeFile(cppFilename(), CppDirectory, &ContainerGenerator::writeCppContent); // cpp file
152 writeFile("ArrayOps_%1.h", HDirectory, &ContainerGenerator::writeHeaderContent); // header file 174 writeFile("ArrayOps_%1.h", HDirectory, &ContainerGenerator::writeHeaderContent); // header file
153 writeFile(dFilename(), DDirectory, &ContainerGenerator::writeDContent); // d file 175 writeFile(dFilename(), DDirectory, &ContainerGenerator::writeDContent); // d file
176 writeFile("ArrayOps2.d", DDirectory, &ContainerGenerator::writeDContent2); // d file
154 } 177 }
155 178
156 void ContainerGenerator::writeFile(const QString& fileName, OutputDirectoryType dirType, WriteOut writeOut) 179 void ContainerGenerator::writeFile(const QString& fileName, OutputDirectoryType dirType, WriteOut writeOut)
157 { 180 {
158 AbstractMetaClassList classList = classes(); 181 AbstractMetaClassList classList = classes();
191 void ContainerGenerator::writeCppContent(QTextStream &s, AbstractMetaClass *cls) 214 void ContainerGenerator::writeCppContent(QTextStream &s, AbstractMetaClass *cls)
192 { 215 {
193 QString package = cls->package().replace(".", "_"); 216 QString package = cls->package().replace(".", "_");
194 217
195 s << "// stuff for passing D function pointers" << endl << endl 218 s << "// stuff for passing D function pointers" << endl << endl
196 << "#ifdef CPP_SHARED" << endl << endl 219 << "#include \"qtd_masterinclude.h\"" << endl << endl
197 << "#include \"ArrayOps_" << package << ".h\"" << endl << endl; 220 << "#include \"qtd_core.h\"" << endl
221 << "#include \"ArrayOps_" << package << ".h\"" << endl
222 << "#include \"ArrayOps_qt_core.h\"" << endl
223 << "#include \"ArrayOpsPrimitive.h\"" << endl << endl
224 << "#ifdef CPP_SHARED" << endl << endl;
225
198 226
199 foreach (const TypeEntry *te, containerTypes) { 227 foreach (const TypeEntry *te, containerTypes) {
200 if (te->javaPackage() == cls->package()) { 228 if (te->javaPackage() == cls->package()) {
201 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te); 229 const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(te);
202 QString cls_name = centry->name(); 230 QString cls_name = centry->name();
226 num_funcs += NUM_ARRAY_FUNCS; 254 num_funcs += NUM_ARRAY_FUNCS;
227 } 255 }
228 } 256 }
229 s << "}" << endl 257 s << "}" << endl
230 << "#endif" << endl; 258 << "#endif" << endl;
259 /*
260 QMap<const TypeEntry*, AbstractMetaType*> typeList = signalEntries[cls->package()];
261
262 QMapIterator<const TypeEntry*, AbstractMetaType*> i(typeList);
263 while (i.hasNext()) {
264 i.next();
265 s << "// " << i.key()->targetLangName() << endl
266 << "extern \"C\" DLL_PUBLIC void qtd_" << package << "_" << i.key()->targetLangName() << "_to_d_array(void *cpp_ptr, DArray* __d_container) {" << endl;
267
268 AbstractMetaType *arg_type = i.value();
269 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption);
270 s << "container = (*reinterpret_cast< ";
271 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference);
272 s << "(*)>(cpp_ptr));" << endl;
273
274 m_cpp_impl_generator->writeQtToJavaContainer(s, arg_type, "container", "__d_container", 0, -1);
275 s << "}" << endl;
276 }*/
277
278 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) {
279 const TypeEntry *te = arg_type->instantiations().first()->typeEntry();
280 s << "// " << te->targetLangName() << endl
281 << "extern \"C\" DLL_PUBLIC void " << fromCppContainerName(cls, arg_type) << "(void *cpp_ptr, DArray* __d_container) {" << endl;
282
283 m_cpp_impl_generator->writeTypeInfo(s, arg_type, NoOption);
284 s << "container = (*reinterpret_cast< ";
285 m_cpp_impl_generator->writeTypeInfo(s, arg_type, ExcludeReference);
286 s << "(*)>(cpp_ptr));" << endl;
287
288 m_cpp_impl_generator->writeQtToJavaContainer(s, arg_type, "container", "__d_container", 0, -1);
289 s << "}" << endl;
290 }
231 } 291 }
232 292
233 void ContainerGenerator::writeHeaderContent(QTextStream &s, AbstractMetaClass *cls) 293 void ContainerGenerator::writeHeaderContent(QTextStream &s, AbstractMetaClass *cls)
234 { 294 {
235 QString file_upper = "ArrayOps_" + QString(cls->package()).replace(".", "_") + "_h"; 295 QString file_upper = "ArrayOps_" + QString(cls->package()).replace(".", "_") + "_h";
332 } 392 }
333 } 393 }
334 s << " qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(callbacks.ptr);" << endl 394 s << " qtd_" << cls->package().replace(".", "_") << "_ArrayOps_initCallBacks(callbacks.ptr);" << endl
335 << " }" << endl 395 << " }" << endl
336 << "}" << endl; 396 << "}" << endl;
397
398
399 }
400
401 void ContainerGenerator::writeDContent2(QTextStream &s, AbstractMetaClass *cls)
402 {
403 s << "module " << cls->package() << ".ArrayOps2;" << endl << endl;
404
405 foreach(AbstractMetaType* arg_type, signalEntries[cls->package()]) {
406 const TypeEntry *te = arg_type->instantiations().first()->typeEntry();
407 if(!te->isPrimitive() && !te->isString())
408 writeImportString(s, te);
409 s << "extern (C) void " << fromCppContainerName(cls, arg_type) << "(void *cpp_ptr, " << te->targetLangName() << "[]* __d_container);" << endl;
410 }
337 } 411 }
338 412
339 void ContainerGenerator::writeNotice(QTextStream &s) 413 void ContainerGenerator::writeNotice(QTextStream &s)
340 { 414 {
341 s << "/****************************************************************************" << endl 415 s << "/****************************************************************************" << endl