comparison generator/dgenerator.cpp @ 188:7dd099050621

initial commit for D2 support
author eldar
date Sun, 12 Jul 2009 18:58:03 +0000
parents 34fe79a9915b
children 438877e90dbe
comparison
equal deleted inserted replaced
187:34fe79a9915b 188:7dd099050621
121 QString s; 121 QString s;
122 122
123 if (context != 0 && d_type != 0 && context->typeEntry()->isGenericClass() && d_type->originalTemplateType() != 0) 123 if (context != 0 && d_type != 0 && context->typeEntry()->isGenericClass() && d_type->originalTemplateType() != 0)
124 d_type = d_type->originalTemplateType(); 124 d_type = d_type->originalTemplateType();
125 125
126 QString constPrefix, constPostfix;
127 if (d_type && d_type->isConstant() && dVersion == 2) {
128 constPrefix = "const(";
129 constPostfix = ") ";
130 }
131
126 if (!d_type) { 132 if (!d_type) {
127 s = "void"; 133 s = "void";
128 } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") { 134 } else if (d_type->typeEntry()->qualifiedCppName() == "QChar") {
129 s = "wchar" + QString(d_type->actualIndirections(), '*'); 135 s = "wchar" + QString(d_type->actualIndirections(), '*');
130 } else if (d_type->typeEntry() && d_type->typeEntry()->qualifiedCppName() == "QString") { 136 } else if (d_type->typeEntry() && d_type->typeEntry()->qualifiedCppName() == "QString") {
161 if (d_type->typeEntry()->isValue() && !d_type->typeEntry()->isStructInD()) 167 if (d_type->typeEntry()->isValue() && !d_type->typeEntry()->isStructInD())
162 s = d_type->typeEntry()->lookupName(); 168 s = d_type->typeEntry()->lookupName();
163 else if (d_type->typeEntry()->isEnum()) 169 else if (d_type->typeEntry()->isEnum())
164 s = "int" + QString(d_type->actualIndirections(), '*'); 170 s = "int" + QString(d_type->actualIndirections(), '*');
165 else 171 else
166 s = d_type->typeEntry()->lookupName() + QString(d_type->actualIndirections(), '*'); 172 s = constPrefix + d_type->typeEntry()->lookupName() + QString(d_type->actualIndirections(), '*') + constPostfix;
167 } else if (d_type->isContainer()) { 173 } else if (d_type->isContainer()) {
168 const ContainerTypeEntry* c_entry = static_cast<const ContainerTypeEntry*>(d_type->typeEntry()); 174 const ContainerTypeEntry* c_entry = static_cast<const ContainerTypeEntry*>(d_type->typeEntry());
169 Q_ASSERT(c_entry); 175 Q_ASSERT(c_entry);
170 176
171 if ((option & SkipTemplateParameters) == 0) { 177 if ((option & SkipTemplateParameters) == 0) {
201 const TypeEntry *type = d_type->typeEntry(); 207 const TypeEntry *type = d_type->typeEntry();
202 if (type->designatedInterface()) 208 if (type->designatedInterface())
203 type = type->designatedInterface(); 209 type = type->designatedInterface();
204 if (type->isString()) 210 if (type->isString())
205 s = "string"; 211 s = "string";
206 else if (type->isObject()){ 212 else if (type->isObject()) {
207 s = type->name(); 213 s = type->name();
214 } else if (type->isValue()){
215 s = constPrefix + type->lookupName() + constPostfix;
208 } else { 216 } else {
209 s = type->lookupName(); 217 s = type->lookupName();
210 } 218 }
211 } 219 }
212 } 220 }
753 s << "super."; 761 s << "super.";
754 }*/ 762 }*/
755 s << d_function->marshalledName() << "("; 763 s << d_function->marshalledName() << "(";
756 } 764 }
757 765
758 if (!d_function->isConstructor() && !d_function->isStatic()) 766 if (!d_function->isConstructor() && !d_function->isStatic()) {
759 s << "nativeId"; 767 if(dVersion == 2 && d_function->isConstant())
768 s << "(cast(" << d_function->ownerClass()->name() << ")this).nativeId";
769 else
770 s << "nativeId";
771 }
760 772
761 if (d_function->isConstructor() && 773 if (d_function->isConstructor() &&
762 ( d_function->implementingClass()->hasVirtualFunctions() 774 ( d_function->implementingClass()->hasVirtualFunctions()
763 || d_function->implementingClass()->typeEntry()->isObject() ) ) { // qtd 775 || d_function->implementingClass()->typeEntry()->isObject() ) ) { // qtd
764 s << "cast(void*) this"; 776 s << "cast(void*) this";
816 bool force_abstract = te->isComplex() && (((static_cast<const ComplexTypeEntry *>(te))->typeFlags() & ComplexTypeEntry::ForceAbstract) != 0); 828 bool force_abstract = te->isComplex() && (((static_cast<const ComplexTypeEntry *>(te))->typeFlags() & ComplexTypeEntry::ForceAbstract) != 0);
817 if (!force_abstract) { 829 if (!force_abstract) {
818 s << arg_name << " is null ? null : "; 830 s << arg_name << " is null ? null : ";
819 } // else if (value type is abstract) then we will get a null pointer exception, which is all right 831 } // else if (value type is abstract) then we will get a null pointer exception, which is all right
820 832
821 s << arg_name << ".nativeId"; 833 if(dVersion == 2 && type->isConstant())
834 s << "(cast(" << type->name() << ")" << arg_name << ").nativeId";
835 else
836 s << arg_name << ".nativeId";
822 } 837 }
823 } 838 }
824 } 839 }
825 840
826 if (useJumpTable) { 841 if (useJumpTable) {
1934 1949
1935 if (m_doc_parser) { 1950 if (m_doc_parser) {
1936 s << m_doc_parser->documentation(d_class) << endl << endl; 1951 s << m_doc_parser->documentation(d_class) << endl << endl;
1937 } 1952 }
1938 1953
1939 /* qtd s << "@QtJambiGeneratedClass" << endl;
1940
1941 if ((d_class->typeEntry()->typeFlags() & ComplexTypeEntry::Deprecated) != 0) {
1942 s << "@Deprecated" << endl;
1943 }
1944 */
1945
1946 // Enums aliases outside of the class - hack 1954 // Enums aliases outside of the class - hack
1947 if (!d_class->enums().isEmpty()) { 1955 if (!d_class->enums().isEmpty()) {
1948 QString fileName = QString("%1_enum.d").arg(d_class->name()); 1956 QString fileName = QString("%1_enum.d").arg(d_class->name());
1949 FileOut fileOut(outputDirectory() + "/" + subDirectoryForClass(d_class) + "/" + fileName); 1957 FileOut fileOut(outputDirectory() + "/" + subDirectoryForClass(d_class) + "/" + fileName);
1950 1958
1953 writeEnum(fileOut.stream, d_enum); 1961 writeEnum(fileOut.stream, d_enum);
1954 } 1962 }
1955 1963
1956 1964
1957 s << endl; 1965 s << endl;
1966
1967 /* qtd s << "@QtJambiGeneratedClass" << endl;
1968
1969 if ((d_class->typeEntry()->typeFlags() & ComplexTypeEntry::Deprecated) != 0) {
1970 s << "@Deprecated" << endl;
1971 }
1972 */
1973
1958 1974
1959 if (d_class->isInterface()) { 1975 if (d_class->isInterface()) {
1960 s << "public interface "; 1976 s << "public interface ";
1961 } else { 1977 } else {
1962 if (d_class->isPublic()) 1978 if (d_class->isPublic())
2826 << type->typeEntry()->qualifiedTargetLangName() << ") " << arg_name << ";"; 2842 << type->typeEntry()->qualifiedTargetLangName() << ") " << arg_name << ";";
2827 else if (type->typeEntry()->qualifiedCppName() == "QChar") 2843 else if (type->typeEntry()->qualifiedCppName() == "QChar")
2828 s << INDENT << "auto " << arg_name << "_d_ref = cast(wchar" << QString(type->actualIndirections(), '*') 2844 s << INDENT << "auto " << arg_name << "_d_ref = cast(wchar" << QString(type->actualIndirections(), '*')
2829 << ") " << arg_name << ";"; 2845 << ") " << arg_name << ";";
2830 else if (type->isTargetLangString()) 2846 else if (type->isTargetLangString())
2831 s << INDENT << "string " << arg_name << "_d_ref = toString(" 2847 s << INDENT << "string " << arg_name << "_d_ref = toUTF8("
2832 << arg_name << "[0.." << arg_name << "_size]);"; 2848 << arg_name << "[0.." << arg_name << "_size]);";
2833 else if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") { 2849 else if (type->typeEntry()->isValue() && type->isNativePointer() && type->typeEntry()->name() == "QString") {
2834 s << INDENT << "auto " << arg_name << "_d_qstr = QString(" << arg_name << ", true);" << endl 2850 s << INDENT << "auto " << arg_name << "_d_qstr = QString(" << arg_name << ", true);" << endl
2835 << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();"; 2851 << INDENT << "string " << arg_name << "_d_ref = " << arg_name << "_d_qstr.toNativeString();";
2836 } else if(type->isVariant()) 2852 } else if(type->isVariant())