comparison generator/dgenerator.cpp @ 295:463563fc9e17 signals

more of QList. const functions in C++ are now const in D too. Drop of the store result feature, which was incompatible with const functions and introduced too much of the bloat in the generator.
author eldar
date Sun, 22 Nov 2009 11:01:19 +0000
parents bb37b0ed94c9
children bc783e20da2b
comparison
equal deleted inserted replaced
294:bb37b0ed94c9 295:463563fc9e17
880 s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl; 880 s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl;
881 } 881 }
882 882
883 // return value marschalling 883 // return value marschalling
884 if(return_type) { 884 if(return_type) {
885 if (!returnImmediately && !d_function->storeResult()) { 885 if (!returnImmediately) {
886 s << INDENT; 886 s << INDENT;
887 QString modified_type = d_function->typeReplaced(0); 887 QString modified_type = d_function->typeReplaced(0);
888 if (modified_type.isEmpty()) 888 if (modified_type.isEmpty())
889 s << translateType(d_function->type(), d_function->implementingClass()); 889 s << translateType(d_function->type(), d_function->implementingClass());
890 else 890 else
906 906
907 if (return_type->isNativePointer() && return_type->typeEntry()->isValue()) 907 if (return_type->isNativePointer() && return_type->typeEntry()->isValue())
908 s << "new " << return_type->name() << "(ret, QtdObjectFlags.nativeOwnership);" << endl; 908 s << "new " << return_type->name() << "(ret, QtdObjectFlags.nativeOwnership);" << endl;
909 909
910 if (return_type->isObject()) { 910 if (return_type->isObject()) {
911 if(d_function->storeResult()) 911 s << "qtd_" << return_type->name() << "_from_ptr(ret);" << endl << endl;
912 s << INDENT << QString("__m_%1.__nativeId = ret;").arg(d_function->name()) << endl
913 << INDENT << QString("return __m_%1;").arg(d_function->name()) << endl;
914 else
915 s << "qtd_" << return_type->name() << "_from_ptr(ret);" << endl;
916 s << endl;
917 } 912 }
918 913
919 if (return_type->isArray()) { 914 if (return_type->isArray()) {
920 s << "ret[0 .. " << return_type->arrayElementCount() << "];" << endl; 915 s << "ret[0 .. " << return_type->arrayElementCount() << "];" << endl;
921 } 916 }
922 917
923 foreach (ReferenceCount referenceCount, referenceCounts) { 918 foreach (ReferenceCount referenceCount, referenceCounts) {
924 writeReferenceCount(s, referenceCount, "__d_return_value"); 919 writeReferenceCount(s, referenceCount, "__d_return_value");
925 } 920 }
926 921
927 if (!returnImmediately && !d_function->storeResult()) 922 if (!returnImmediately)
928 s << INDENT << "return __d_return_value;" << endl; 923 s << INDENT << "return __d_return_value;" << endl;
929 } 924 }
930 writeInjectedCode(s, d_function, CodeSnip::End); 925 writeInjectedCode(s, d_function, CodeSnip::End);
931 926
932 if(return_in_arg) // qtd 927 if(return_in_arg) // qtd
985 writeFunctionAttributes(s, d_function, included_attributes, excluded_attributes, option); 980 writeFunctionAttributes(s, d_function, included_attributes, excluded_attributes, option);
986 981
987 s << functionName << "("; 982 s << functionName << "(";
988 writeFunctionArguments(s, d_function, argument_count, option); 983 writeFunctionArguments(s, d_function, argument_count, option);
989 s << ")"; 984 s << ")";
985
986 if(d_function->isConstant())
987 s << " const";
990 988
991 return result; 989 return result;
992 } 990 }
993 991
994 void DGenerator::setupForFunction(const AbstractMetaFunction *d_function, 992 void DGenerator::setupForFunction(const AbstractMetaFunction *d_function,
2305 s << INDENT << "if (!static_inited)" << endl 2303 s << INDENT << "if (!static_inited)" << endl
2306 << INDENT << " static_init_" << d_class->name() << "();" << endl << endl; 2304 << INDENT << " static_init_" << d_class->name() << "();" << endl << endl;
2307 } 2305 }
2308 */ 2306 */
2309 2307
2310 // customized store-result instances
2311 d_funcs = d_class->functionsInTargetLang();
2312 for (int i=0; i<d_funcs.size(); ++i) {
2313 AbstractMetaFunction *d_function = d_funcs.at(i);
2314 uint included_attributes = 0;
2315 uint excluded_attributes = 0;
2316 setupForFunction(d_function, &included_attributes, &excluded_attributes);
2317 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes;
2318 bool isStatic = (attr & AbstractMetaAttributes::Static);
2319
2320 if (!isStatic && (attr & AbstractMetaAttributes::Abstract))
2321 continue;
2322
2323 if(d_function->storeResult()) {
2324 QString type_name = d_function->type()->name();
2325 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry());
2326 if(ctype->isAbstract())
2327 type_name = type_name + "_ConcreteWrapper";
2328
2329 s << INDENT << " __m_" << d_function->name() << " = new "
2330 << type_name << "(cast(void*)null);" << endl;
2331 if (d_function->type()->isQObject())
2332 s << INDENT << " __m_" << d_function->name() << ".__setFlags(QtdObjectFlags.nativeOwnership, true);" << endl;
2333 }
2334 }
2335 2308
2336 // pointers to native interface objects for classes that implement interfaces 2309 // pointers to native interface objects for classes that implement interfaces
2337 // initializing 2310 // initializing
2338 interfaces = d_class->interfaces(); 2311 interfaces = d_class->interfaces();
2339 if (!interfaces.isEmpty()) { 2312 if (!interfaces.isEmpty()) {
2345 } 2318 }
2346 } 2319 }
2347 2320
2348 2321
2349 s << INDENT << "}" << endl << endl; 2322 s << INDENT << "}" << endl << endl;
2350
2351 /******************!!!DUPLICATE OF ABOVE!!!*********************/
2352 for (int i=0; i<d_funcs.size(); ++i) {
2353 AbstractMetaFunction *d_function = d_funcs.at(i);
2354 uint included_attributes = 0;
2355 uint excluded_attributes = 0;
2356 setupForFunction(d_function, &included_attributes, &excluded_attributes);
2357 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes;
2358 bool isStatic = (attr & AbstractMetaAttributes::Static);
2359
2360 if (!isStatic && (attr & AbstractMetaAttributes::Abstract))
2361 continue;
2362
2363 if(d_function->storeResult()) {
2364 QString type_name = d_function->type()->name();
2365 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry());
2366 if(ctype->isAbstract())
2367 type_name = type_name + "_ConcreteWrapper";
2368
2369 s << INDENT << type_name << " __m_" << d_function->name() << ";" << endl;
2370 }
2371 }
2372 /***************************************************************/
2373 2323
2374 // pointers to native interface objects for classes that implement interfaces 2324 // pointers to native interface objects for classes that implement interfaces
2375 // initializing 2325 // initializing
2376 interfaces = d_class->interfaces(); 2326 interfaces = d_class->interfaces();
2377 if (!interfaces.isEmpty()) { 2327 if (!interfaces.isEmpty()) {
2457 Indentation indent(INDENT); 2407 Indentation indent(INDENT);
2458 QString hasShellFlag = d_class->generateShellClass() ? " | QtdObjectFlags.hasShell" : ""; 2408 QString hasShellFlag = d_class->generateShellClass() ? " | QtdObjectFlags.hasShell" : "";
2459 s << INDENT << "public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.nativeOwnership) {" << endl 2409 s << INDENT << "public this(void* native_id, QtdObjectFlags flags = QtdObjectFlags.nativeOwnership) {" << endl
2460 << INDENT << " super(native_id, flags);" << endl << endl; 2410 << INDENT << " super(native_id, flags);" << endl << endl;
2461 2411
2462 /******************!!!DUPLICATE!!!*********************/
2463 d_funcs = d_class->functionsInTargetLang();
2464 for (int i=0; i<d_funcs.size(); ++i) {
2465 AbstractMetaFunction *d_function = d_funcs.at(i);
2466 uint included_attributes = 0;
2467 uint excluded_attributes = 0;
2468 setupForFunction(d_function, &included_attributes, &excluded_attributes);
2469 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes;
2470 // qtd bool isStatic = (attr & AbstractMetaAttributes::Static);
2471
2472 if(d_function->storeResult()) {
2473 QString type_name = d_function->type()->name();
2474 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry());
2475 if(ctype->isAbstract())
2476 type_name = type_name + "_ConcreteWrapper";
2477 s << INDENT << " __m_" << d_function->name() << " = new "
2478 << type_name << "(cast(void*)null);" << endl;
2479 if (d_function->type()->isQObject())
2480 s << INDENT << " __m_" << d_function->name() << ".__setFlags(QtdObjectFlags.nativeOwnership, true);" << endl;
2481 }
2482 }
2483
2484 s << INDENT << "}" << endl << endl; 2412 s << INDENT << "}" << endl << endl;
2485
2486 for (int i=0; i<d_funcs.size(); ++i) {
2487 AbstractMetaFunction *d_function = d_funcs.at(i);
2488 uint included_attributes = 0;
2489 uint excluded_attributes = 0;
2490 setupForFunction(d_function, &included_attributes, &excluded_attributes);
2491 uint attr = d_function->attributes() & (~excluded_attributes) | included_attributes;
2492 // qtd bool isStatic = (attr & AbstractMetaAttributes::Static);
2493
2494 if(d_function->storeResult()) {
2495 QString type_name = d_function->type()->name();
2496 const ComplexTypeEntry *ctype = static_cast<const ComplexTypeEntry *>(d_function->type()->typeEntry());
2497 if(ctype->isAbstract())
2498 type_name = type_name + "_ConcreteWrapper";
2499
2500 s << INDENT << d_function->type()->name() << " __m_" << d_function->name() << ";" << endl;
2501 }
2502 }
2503 /***************************************************************/
2504
2505
2506
2507
2508
2509 2413
2510 uint exclude_attributes = AbstractMetaAttributes::Native | AbstractMetaAttributes::Abstract; 2414 uint exclude_attributes = AbstractMetaAttributes::Native | AbstractMetaAttributes::Abstract;
2511 uint include_attributes = 0; 2415 uint include_attributes = 0;
2512 AbstractMetaFunctionList functions = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NonEmptyFunctions | AbstractMetaClass::NotRemovedFromTargetLang); 2416 AbstractMetaFunctionList functions = d_class->queryFunctions(AbstractMetaClass::NormalFunctions | AbstractMetaClass::AbstractFunctions | AbstractMetaClass::NonEmptyFunctions | AbstractMetaClass::NotRemovedFromTargetLang);
2513 foreach (const AbstractMetaFunction *d_function, functions) { 2417 foreach (const AbstractMetaFunction *d_function, functions) {
2514 retrieveModifications(d_function, d_class, &exclude_attributes, &include_attributes); 2418 retrieveModifications(d_function, d_class, &exclude_attributes, &include_attributes);
2515 if (notWrappedYet(d_function)) 2419 if (notWrappedYet(d_function))
2516 continue; 2420 continue;
2517 /* qtd s << endl 2421 s << endl
2518 << INDENT << "@Override" << endl; */ 2422 << INDENT << "override ";
2519 writeFunctionAttributes(s, d_function, include_attributes, exclude_attributes, 2423 writeFunctionAttributes(s, d_function, include_attributes, exclude_attributes,
2520 d_function->isNormal() || d_function->isSignal() ? 0 : SkipReturnType); 2424 d_function->isNormal() || d_function->isSignal() ? 0 : SkipReturnType);
2521 2425
2522 s << d_function->name() << "("; 2426 s << d_function->name() << "(";
2523 writeFunctionArguments(s, d_function, d_function->arguments().count()); 2427 writeFunctionArguments(s, d_function, d_function->arguments().count());
2524 s << ") {" << endl; 2428 s << ")";
2429
2430 if(d_function->isConstant())
2431 s << " const";
2432
2433 s << " {" << endl;
2525 { 2434 {
2526 Indentation indent(INDENT); 2435 Indentation indent(INDENT);
2527 writeJavaCallThroughContents(s, d_function, SuperCall); 2436 writeJavaCallThroughContents(s, d_function, SuperCall);
2528 } 2437 }
2529 s << INDENT << "}" << endl; 2438 s << INDENT << "}" << endl;
3196 foreach(QString child, ctype->includedClasses) { 3105 foreach(QString child, ctype->includedClasses) {
3197 ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child); 3106 ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child);
3198 ctype_child->addedTo = cls->name(); 3107 ctype_child->addedTo = cls->name();
3199 } 3108 }
3200 3109
3201 foreach (AbstractMetaFunction *function, cls->functions())
3202 function->checkStoreResult();
3203 /* we don't need this anymore 3110 /* we don't need this anymore
3204 // generate QObject conversion functions only those that are required 3111 // generate QObject conversion functions only those that are required
3205 AbstractMetaFunctionList d_funcs = cls->functionsInTargetLang(); 3112 AbstractMetaFunctionList d_funcs = cls->functionsInTargetLang();
3206 for (int i=0; i<d_funcs.size(); ++i) { 3113 for (int i=0; i<d_funcs.size(); ++i) {
3207 AbstractMetaType *f_type = d_funcs.at(i)->type(); 3114 AbstractMetaType *f_type = d_funcs.at(i)->type();