Mercurial > projects > qtd
comparison generator/dgenerator.cpp @ 341:4920ef9206fe
moved enums into interfaces
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Thu, 13 May 2010 16:39:41 +0300 |
parents | 5896535a03cd |
children | c887282e1590 |
comparison
equal
deleted
inserted
replaced
340:9fc85d7280ba | 341:4920ef9206fe |
---|---|
284 } | 284 } |
285 | 285 |
286 s << " } // end of enum " << d_enum->name() << endl << endl; | 286 s << " } // end of enum " << d_enum->name() << endl << endl; |
287 } | 287 } |
288 | 288 |
289 void DGenerator::writeEnumAlias(QTextStream &s, const AbstractMetaEnum *d_enum) | 289 void DGenerator::writeEnumAliases(QTextStream &s, const AbstractMetaEnum *d_enum) |
290 { | 290 { |
291 // aliases for enums to be used in easier way like QFont.Bold instead of QFont.Weight.Bold | 291 FlagsTypeEntry *flags = d_enum->typeEntry()->flags(); |
292 //s << QString(" alias %1 %2;").arg(d_enum->typeEntry()->qualifiedTargetLangName()).arg(d_enum->name()) << endl << endl; | 292 if (flags) |
293 s << INDENT << "alias " << d_enum->name() << " " << flags->targetLangName() << ";" << endl << endl; | |
294 | |
293 const AbstractMetaEnumValueList &values = d_enum->values(); | 295 const AbstractMetaEnumValueList &values = d_enum->values(); |
294 for (int i=0; i<values.size(); ++i) { | 296 for (int i=0; i<values.size(); ++i) { |
295 AbstractMetaEnumValue *enum_value = values.at(i); | 297 AbstractMetaEnumValue *enum_value = values.at(i); |
296 | 298 |
297 if (d_enum->typeEntry()->isEnumValueRejected(enum_value->name())) | 299 if (!d_enum->typeEntry()->isEnumValueRejected(enum_value->name())) |
298 continue; | 300 s << INDENT << QString("alias %1.%2 %2;").arg(d_enum->name()).arg(enum_value->name()) << endl; |
299 | |
300 s << QString(" alias %1.%2 %2;").arg(d_enum->name()).arg(enum_value->name()) << endl; | |
301 } | 301 } |
302 s << endl; | 302 s << endl; |
303 } | 303 } |
304 | 304 |
305 void DGenerator::writeEnum(QTextStream &s, const AbstractMetaEnum *d_enum) | 305 void DGenerator::writeEnum(QTextStream &s, const AbstractMetaEnum *d_enum, bool withAliases) |
306 { | 306 { |
307 if (m_doc_parser) { | 307 if (m_doc_parser) { |
308 s << m_doc_parser->documentation(d_enum); | 308 s << m_doc_parser->documentation(d_enum); |
309 } | 309 } |
310 | 310 |
320 && !d_enum->hasQEnumsDeclaration()) { | 320 && !d_enum->hasQEnumsDeclaration()) { |
321 s << " @QtBlockedEnum" << endl; | 321 s << " @QtBlockedEnum" << endl; |
322 } | 322 } |
323 */ | 323 */ |
324 // Generates Java 1.5 type enums | 324 // Generates Java 1.5 type enums |
325 s << "public enum " << d_enum->name() << " {" << endl; | 325 s << INDENT << "public enum " << d_enum->name() << " {" << endl; |
326 const AbstractMetaEnumValueList &values = d_enum->values(); | 326 const AbstractMetaEnumValueList &values = d_enum->values(); |
327 EnumTypeEntry *entry = d_enum->typeEntry(); | 327 EnumTypeEntry *entry = d_enum->typeEntry(); |
328 | 328 |
329 | |
329 for (int i=0; i<values.size(); ++i) { | 330 for (int i=0; i<values.size(); ++i) { |
331 Indentation indent(INDENT); | |
330 AbstractMetaEnumValue *enum_value = values.at(i); | 332 AbstractMetaEnumValue *enum_value = values.at(i); |
331 | 333 |
332 if (d_enum->typeEntry()->isEnumValueRejected(enum_value->name())) | 334 if (d_enum->typeEntry()->isEnumValueRejected(enum_value->name())) |
333 continue; | 335 continue; |
334 | 336 |
335 if (m_doc_parser) | 337 if (m_doc_parser) |
336 s << m_doc_parser->documentation(enum_value); | 338 s << m_doc_parser->documentation(enum_value); |
337 | 339 |
338 s << " " << enum_value->name() << " = " << enum_value->value(); | 340 s << INDENT << enum_value->name() << " = " << enum_value->value(); |
339 | 341 |
340 if (i != values.size() - 1) { | 342 if (i != values.size() - 1) { |
341 AbstractMetaEnumValue *next_value = values.at(i+1); // qtd | 343 AbstractMetaEnumValue *next_value = values.at(i+1); // qtd |
342 if (!(d_enum->typeEntry()->isEnumValueRejected(next_value->name()) && i == values.size() - 2)) // qtd | 344 if (!(d_enum->typeEntry()->isEnumValueRejected(next_value->name()) && i == values.size() - 2)) // qtd |
343 s << "," << endl; | 345 s << "," << endl; |
416 /* FlagsTypeEntry *flags_entry = entry->flags(); | 418 /* FlagsTypeEntry *flags_entry = entry->flags(); |
417 if (flags_entry) { | 419 if (flags_entry) { |
418 QString flagsName = flags_entry->targetLangName(); | 420 QString flagsName = flags_entry->targetLangName(); |
419 s << INDENT << "alias QFlags!(" << d_enum->name() << ") " << flagsName << ";" << endl << endl; | 421 s << INDENT << "alias QFlags!(" << d_enum->name() << ") " << flagsName << ";" << endl << endl; |
420 }*/ | 422 }*/ |
423 | |
424 if (withAliases) | |
425 writeEnumAliases(s, d_enum); | |
421 } | 426 } |
422 | 427 |
423 void DGenerator::writePrivateNativeFunction(QTextStream &s, const AbstractMetaFunction *d_function) | 428 void DGenerator::writePrivateNativeFunction(QTextStream &s, const AbstractMetaFunction *d_function) |
424 { | 429 { |
425 int exclude_attributes = AbstractMetaAttributes::Public | AbstractMetaAttributes::Protected; | 430 int exclude_attributes = AbstractMetaAttributes::Public | AbstractMetaAttributes::Protected; |
892 TypeSystem::Ownership owner = d_function->ownership(d_function->implementingClass(), TypeSystem::TargetLangCode, -1); | 897 TypeSystem::Ownership owner = d_function->ownership(d_function->implementingClass(), TypeSystem::TargetLangCode, -1); |
893 if (owner != TypeSystem::InvalidOwnership && d_function->isConstructor()) | 898 if (owner != TypeSystem::InvalidOwnership && d_function->isConstructor()) |
894 s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl; | 899 s << INDENT << "this." << function_call_for_ownership(owner) << ";" << endl; |
895 } | 900 } |
896 | 901 |
897 // return value marschalling | 902 // return value marshalling |
898 if(return_type) { | 903 if(return_type) { |
899 if (!returnImmediately) { | 904 if (!returnImmediately) { |
900 s << INDENT; | 905 s << INDENT; |
901 QString modified_type = d_function->typeReplaced(0); | 906 QString modified_type = d_function->typeReplaced(0); |
902 if (modified_type.isEmpty()) | 907 if (modified_type.isEmpty()) |
1783 } else if (type->isTargetLangString()) { | 1788 } else if (type->isTargetLangString()) { |
1784 s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl | 1789 s << INDENT << "auto " << arg_name << "_ptr = " << arg_ptr << ";" << endl |
1785 << INDENT << "string " << arg_name << " = QStringUtil.toNativeString(" << arg_name << "_ptr);"; | 1790 << INDENT << "string " << arg_name << " = QStringUtil.toNativeString(" << arg_name << "_ptr);"; |
1786 } else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) { | 1791 } else if(type->isPrimitive() || type->isEnum() || type->isFlags() || type->typeEntry()->isStructInD()) { |
1787 QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName(); | 1792 QString type_name = argument->type()->typeEntry()->qualifiedTargetLangName(); |
1788 if (type->isFlags()) | |
1789 type_name = "int"; | |
1790 s << INDENT << "auto " << arg_name << " = *(cast(" << type_name << "*)" << arg_ptr << ");"; | 1793 s << INDENT << "auto " << arg_name << " = *(cast(" << type_name << "*)" << arg_ptr << ");"; |
1791 } else if(type->isObject() || type->isQObject() | 1794 } else if(type->isObject() || type->isQObject() |
1792 || (type->typeEntry()->isValue() && type->isNativePointer()) | 1795 || (type->typeEntry()->isValue() && type->isNativePointer()) |
1793 || type->isValue()) { | 1796 || type->isValue()) { |
1794 QString type_name = type->name(); | 1797 QString type_name = type->name(); |
2105 s << endl << "{" << endl; | 2108 s << endl << "{" << endl; |
2106 | 2109 |
2107 Indentation indent(INDENT); | 2110 Indentation indent(INDENT); |
2108 | 2111 |
2109 // Enums | 2112 // Enums |
2110 if (!d_class->enums().isEmpty()) { | 2113 if (!d_class->typeEntry()->designatedInterface() && !d_class->enums().isEmpty()) { |
2111 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | 2114 foreach (AbstractMetaEnum *d_enum, d_class->enums()) |
2112 writeEnum(s, d_enum); | 2115 writeEnum(s, d_enum, true); |
2116 } | |
2117 | |
2118 // Enums in designated interfaces | |
2119 if (d_class->isInterface() && d_class->primaryInterfaceImplementor()) { | |
2120 foreach (AbstractMetaEnum *d_enum, d_class->primaryInterfaceImplementor()->enums()) | |
2121 writeEnum(s, d_enum, true); | |
2113 } | 2122 } |
2114 | 2123 |
2115 // Define variables for reference count mechanism | 2124 // Define variables for reference count mechanism |
2116 if (!d_class->isInterface() && !d_class->isNamespace()) { | 2125 if (!d_class->isInterface() && !d_class->isNamespace()) { |
2117 QHash<QString, int> variables; | 2126 QHash<QString, int> variables; |
2195 | 2204 |
2196 s << INDENT << " " << d_class->package() << ".QtJambi_LibraryInitializer.init();" << endl | 2205 s << INDENT << " " << d_class->package() << ".QtJambi_LibraryInitializer.init();" << endl |
2197 << INDENT << "}" << endl; | 2206 << INDENT << "}" << endl; |
2198 } | 2207 } |
2199 */ | 2208 */ |
2200 | |
2201 // Enums aliases | |
2202 foreach (AbstractMetaEnum *d_enum, d_class->enums()) | |
2203 writeEnumAlias(s, d_enum); | |
2204 | 2209 |
2205 // Signals | 2210 // Signals |
2206 if (d_class->isQObject()) | 2211 if (d_class->isQObject()) |
2207 { | 2212 { |
2208 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); | 2213 AbstractMetaFunctionList signal_funcs = signalFunctions(d_class, false); |
2600 foreach (AbstractMetaClass *cls, includedClassesList) { | 2605 foreach (AbstractMetaClass *cls, includedClassesList) { |
2601 m_isRecursive = true; | 2606 m_isRecursive = true; |
2602 write(s, cls); | 2607 write(s, cls); |
2603 m_isRecursive = false; | 2608 m_isRecursive = false; |
2604 } | 2609 } |
2605 | |
2606 | 2610 |
2607 if (d_class->isQObject()) | 2611 if (d_class->isQObject()) |
2608 writeQObjectFreeFunctions(s, d_class); | 2612 writeQObjectFreeFunctions(s, d_class); |
2609 | 2613 |
2610 if (d_class->typeEntry()->isValue()) | 2614 if (d_class->typeEntry()->isValue()) |