Skip to content

Commit b190643

Browse files
author
florianlink
committed
changed generator to use int instead of protected enums in shell and wrapper class (clang would not compile the previous approach using friend)
git-svn-id: http://svn.code.sf.net/p/pythonqt/code/trunk@353 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent ebe6abd commit b190643

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

generator/generator.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ class Generator : public QObject
8383
NoBlockedSlot = 0x00100000,
8484

8585
SuperCall = 0x00200000,
86-
// These 2 are added for PythonQt
86+
// The following options have been added for PythonQt:
8787
FirstArgIsWrappedObject = 0x00400000,
8888
ConvertReferenceToPtr = 0x00800000,
8989
UseIndexedName = 0x01000000,
90-
91-
GlobalRefJObject = 0x00100000,
90+
ProtectedEnumAsInts = 0x02000000,
9291

9392
ForceValueType = ExcludeReference | ExcludeConst
9493
};

generator/shellgenerator.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type,
7979
} else if (te->isFlags()) {
8080
s << ((FlagsTypeEntry *) te)->originalName();
8181
} else {
82+
if (type->isEnum() && (options & ProtectedEnumAsInts)) {
83+
AbstractMetaEnum* enumType = m_classes.findEnum((EnumTypeEntry *)te);
84+
if (enumType && enumType->wasProtected()) {
85+
s << "int";
86+
} else {
87+
s << fixCppTypeName(te->qualifiedCppName());
88+
}
89+
} else {
8290
s << fixCppTypeName(te->qualifiedCppName());
91+
}
8392
}
8493

8594
if (type->instantiations().size() > 0

generator/shellgenerator.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ class ShellGenerator : public Generator
5858
return "generated_cpp/" + cls->package().replace(".", "_") + "/";
5959
}
6060

61-
static void writeTypeInfo(QTextStream &s, const AbstractMetaType *type, Option option = NoOption);
62-
static void writeFunctionSignature(QTextStream &s, const AbstractMetaFunction *meta_function,
61+
void writeTypeInfo(QTextStream &s, const AbstractMetaType *type, Option option = NoOption);
62+
void writeFunctionSignature(QTextStream &s, const AbstractMetaFunction *meta_function,
6363
const AbstractMetaClass *implementor = 0,
6464
const QString &name_prefix = QString(),
6565
Option option = NoOption,
6666
const QString &classname_prefix = QString(),
6767
const QStringList &extra_arguments = QStringList(),
6868
int numArguments = -1);
69-
static void writeFunctionArguments(QTextStream &s, const AbstractMetaClass* owner, const AbstractMetaArgumentList &arguments,
69+
void writeFunctionArguments(QTextStream &s, const AbstractMetaClass* owner, const AbstractMetaArgumentList &arguments,
7070
Option option = NoOption,
7171
int numArguments = -1);
7272

generator/shellheadergenerator.cpp

+28-6
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,44 @@ void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c
162162
s << "class " << promoterClassName(meta_class)
163163
<< " : public " << meta_class->qualifiedCppName() << endl << "{ public:" << endl;
164164

165-
s << "friend class " << wrapperClassName(meta_class) << ";" << endl;
166-
165+
AbstractMetaEnumList enums1 = meta_class->enums();
166+
qSort(enums1.begin(), enums1.end(), enum_lessThan);
167+
foreach(AbstractMetaEnum* enum1, enums1) {
168+
if (enum1->wasProtected()) {
169+
s << "enum " << enum1->name() << "{" << endl;
170+
bool first = true;
171+
QString scope = meta_class->qualifiedCppName();
172+
foreach(AbstractMetaEnumValue* value, enum1->values()) {
173+
if (first) { first = false; }
174+
else { s << ", "; }
175+
s << " " << value->name() << " = " << scope << "::" << value->name();
176+
}
177+
s << "};" << endl;
178+
}
179+
}
180+
167181
foreach(AbstractMetaFunction* fun, promoteFunctions) {
168182
s << "inline ";
169183
writeFunctionSignature(s, fun, 0, "promoted_",
170-
Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
184+
Option(IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces | ProtectedEnumAsInts));
171185
s << " { ";
172186
QString scriptFunctionName = fun->originalName();
173187
AbstractMetaArgumentList args = fun->arguments();
174-
if (fun->type())
188+
if (fun->type()) {
175189
s << "return ";
190+
}
176191
s << meta_class->qualifiedCppName() << "::";
177192
s << fun->originalName() << "(";
178193
for (int i = 0; i < args.size(); ++i) {
179-
if (i > 0)
194+
if (i > 0) {
180195
s << ", ";
196+
}
197+
if (args.at(i)->type()->isEnum()) {
198+
AbstractMetaEnum* enumType = m_classes.findEnum((EnumTypeEntry *)args.at(i)->type()->typeEntry());
199+
if (enumType && enumType->wasProtected()) {
200+
s << "(" << enumType->typeEntry()->qualifiedCppName() << ")";
201+
}
202+
}
181203
s << args.at(i)->argumentName();
182204
}
183205
s << "); }" << endl;
@@ -291,7 +313,7 @@ void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c
291313
if (!function->isSlot() || function->isVirtual()) {
292314
s << " ";
293315
writeFunctionSignature(s, function, 0, QString(),
294-
Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces));
316+
Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces | ProtectedEnumAsInts));
295317
s << ";" << endl;
296318
}
297319
}

generator/shellimplgenerator.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
200200
s << meta_class->qualifiedCppName() << "::";
201201
s << fun->originalName() << "(";
202202
for (int i = 0; i < args.size(); ++i) {
203-
if (i > 0)
203+
if (i > 0) {
204204
s << ", ";
205+
}
205206
s << args.at(i)->indexedName();
206207
}
207208
s << ");";
@@ -242,7 +243,7 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla
242243
continue;
243244
}
244245
writeFunctionSignature(s, fun, meta_class, QString(),
245-
Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces),
246+
Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces | ProtectedEnumAsInts),
246247
"PythonQtWrapper_");
247248
s << endl << "{" << endl;
248249
s << " ";

0 commit comments

Comments
 (0)