[Kde-bindings] KDE/kdebindings/generator
Arno Rehn
kde at arnorehn.de
Thu Apr 22 18:34:31 UTC 2010
SVN commit 1117675 by arnorehn:
* Disable resolving typedefs in signals and slots. They're only resolved
'in memory' to generate the proper type flags and smoke code.
* Remove the now obsolete flagTypes hash.
CCMAIL: kde-bindings at kde.org
M +2 -0 generators/smoke/globals.h
M +43 -27 generators/smoke/helpers.cpp
M +66 -58 generators/smoke/writeSmokeDataFile.cpp
M +6 -8 generatorvisitor.cpp
M +0 -2 options.cpp
M +0 -2 options.h
--- trunk/KDE/kdebindings/generator/generators/smoke/globals.h #1117674:1117675
@@ -68,6 +68,7 @@
void write();
bool isClassUsed(const Class* klass);
+ QString getTypeFlags(const Type *type, int *classIdx);
QMap<QString, int> classIndex;
QHash<const Member*, int> methodIdx;
@@ -123,6 +124,7 @@
static void addOverloads(const Method& meth);
static void addAccessorMethods(const Field& field, QSet<Type*> *usedTypes);
+ static QChar munge(const Type *type);
static QString mungedName(const Method&);
static QString stackItemField(const Type* type);
--- trunk/KDE/kdebindings/generator/generators/smoke/helpers.cpp #1117674:1117675
@@ -452,41 +452,53 @@
klass->appendMethod(meth);
}
+QChar Util::munge(const Type *type) {
+ if (type->getTypedef()) {
+ Type resolved = type->getTypedef()->resolve();
+ return munge(&resolved);
+ }
+
+ if (type->pointerDepth() > 1 || (type->getClass() && type->getClass()->isTemplate() && (!Options::qtMode || (Options::qtMode && type->getClass()->name() != "QFlags"))) ||
+ (Options::voidpTypes.contains(type->name()) && !Options::scalarTypes.contains(type->name())) )
+ {
+ // QString and QStringList are both mapped to Smoke::t_voidp, but QString is a scalar as well
+ // TODO: fix this - neither QStringList nor QString should be mapped to Smoke::t_voidp or munged as ? or $
+
+ // reference to array or hash or unknown
+ return '?';
+ } else if (type->isIntegral() || type->getEnum() || Options::scalarTypes.contains(type->name()) ||
+ (Options::qtMode && !type->isRef() && type->pointerDepth() == 0 &&
+ (type->getClass() && type->getClass()->isTemplate() && type->getClass()->name() == "QFlags")))
+ {
+ // plain scalar
+ return '$';
+ } else if (type->getClass()) {
+ // object
+ return '#';
+ } else {
+ // unknown
+ return '?';
+ }
+}
+
QString Util::mungedName(const Method& meth) {
QString ret = meth.name();
foreach (const Parameter& param, meth.parameters()) {
const Type* type = param.type();
- if (type->pointerDepth() > 1 || (type->getClass() && type->getClass()->isTemplate() && (!Options::qtMode || (Options::qtMode && type->getClass()->name() != "QFlags"))) ||
- (Options::voidpTypes.contains(type->name()) && !Options::scalarTypes.contains(type->name())) )
- {
- // QString and QStringList are both mapped to Smoke::t_voidp, but QString is a scalar as well
- // TODO: fix this - neither QStringList nor QString should be mapped to Smoke::t_voidp or munged as ? or $
-
- // reference to array or hash or unknown
- ret += "?";
- } else if (type->isIntegral() || type->getEnum() || Options::scalarTypes.contains(type->name()) ||
- (Options::qtMode && !type->isRef() && type->pointerDepth() == 0 &&
- (type->getTypedef() && flagTypes.contains(type->getTypedef())) ||
- (type->getClass() && type->getClass()->isTemplate() && type->getClass()->name() == "QFlags")))
- {
- // plain scalar
- ret += "$";
- } else if (type->getClass()) {
- // object
- ret += "#";
- } else {
- // unknown
- ret += "?";
- }
- }
+ ret += munge(type);
+ }
return ret;
}
QString Util::stackItemField(const Type* type)
{
+ if (type->getTypedef()) {
+ Type resolved = type->getTypedef()->resolve();
+ return stackItemField(&resolved);
+ }
+
if (Options::qtMode && !type->isRef() && type->pointerDepth() == 0 &&
- ((type->getTypedef() && flagTypes.contains(type->getTypedef()))
- || (type->getClass() && type->getClass()->isTemplate() && type->getClass()->name() == "QFlags")))
+ type->getClass() && type->getClass()->isTemplate() && type->getClass()->name() == "QFlags")
{
return "s_uint";
}
@@ -517,6 +529,11 @@
QString Util::assignmentString(const Type* type, const QString& var)
{
+ if (type->getTypedef()) {
+ Type resolved = type->getTypedef()->resolve();
+ return assignmentString(&resolved, var);
+ }
+
if (type->pointerDepth() > 0 || type->isFunctionPointer()) {
return "(void*)" + var;
} else if (type->isRef()) {
@@ -525,8 +542,7 @@
return var;
} else if (type->getEnum()) {
return var;
- } else if (Options::qtMode && ( (type->getTypedef() && flagTypes.contains(type->getTypedef()))
- || (type->getClass() && type->getClass()->isTemplate() && type->getClass()->name() == "QFlags")))
+ } else if (Options::qtMode && type->getClass() && type->getClass()->isTemplate() && type->getClass()->name() == "QFlags")
{
return "(uint)" + var;
} else {
--- trunk/KDE/kdebindings/generator/generators/smoke/writeSmokeDataFile.cpp #1117674:1117675
@@ -102,6 +102,71 @@
return false;
}
+QString SmokeDataFile::getTypeFlags(const Type *t, int *classIdx)
+{
+ if (t->getTypedef()) {
+ Type resolved = t->getTypedef()->resolve();
+ return getTypeFlags(&resolved, classIdx);
+ }
+
+ QString flags = "0";
+ if (Options::voidpTypes.contains(t->name())) {
+ // support some of the weird quirks the kalyptus code has
+ flags += "|Smoke::t_voidp";
+ } else if (t->getClass()) {
+ if (t->getClass()->isTemplate()) {
+ if (Options::qtMode && t->getClass()->name() == "QFlags") {
+ flags += "|Smoke::t_uint";
+ } else {
+ flags += "|Smoke::t_voidp";
+ }
+ } else {
+ flags += "|Smoke::t_class";
+ *classIdx = classIndex.value(t->getClass()->toString(), 0);
+ }
+ } else if (t->isIntegral() && t->name() != "void" && t->pointerDepth() == 0 && !t->isRef()) {
+ flags += "|Smoke::t_";
+ QString typeName = t->name();
+
+ // replace the unsigned stuff, look the type up in Util::typeMap and if
+ // necessary, add a 'u' for unsigned types at the beginning again
+ bool _unsigned = false;
+ if (typeName.startsWith("unsigned ")) {
+ typeName.replace("unsigned ", "");
+ _unsigned = true;
+ }
+ typeName.replace("signed ", "");
+ typeName = Util::typeMap.value(typeName, typeName);
+ if (_unsigned)
+ typeName.prepend('u');
+
+ flags += typeName;
+ } else if (t->getEnum()) {
+ flags += "|Smoke::t_enum";
+ if (t->getEnum()->parent()) {
+ *classIdx = classIndex.value(t->getEnum()->parent()->toString(), 0);
+ } else if (!t->getEnum()->nameSpace().isEmpty()) {
+ *classIdx = classIndex.value(t->getEnum()->nameSpace(), 0);
+ } else {
+ *classIdx = classIndex.value("QGlobalSpace", 0);
+ }
+ } else {
+ flags += "|Smoke::t_voidp";
+ }
+
+ if (t->isRef())
+ flags += "|Smoke::tf_ref";
+ if (t->pointerDepth() > 0)
+ flags += "|Smoke::tf_ptr";
+ if (!t->isRef() && t->pointerDepth() == 0)
+ flags += "|Smoke::tf_stack";
+ if (t->isConst())
+ flags += "|Smoke::tf_const";
+ flags.replace("0|", "");
+
+ return flags;
+}
+
void SmokeDataFile::write()
{
qDebug("writing out smokedata.cpp [%s]", qPrintable(Options::module));
@@ -310,64 +375,7 @@
if (t == Type::Void)
continue;
int classIdx = 0;
- QString flags = "0";
- if (Options::voidpTypes.contains(t->name())) {
- // support some of the weird quirks the kalyptus code has
- flags += "|Smoke::t_voidp";
- } else if (t->getClass()) {
- if (t->getClass()->isTemplate()) {
- if (Options::qtMode && t->getClass()->name() == "QFlags") {
- flags += "|Smoke::t_uint";
- } else {
- flags += "|Smoke::t_voidp";
- }
- } else {
- flags += "|Smoke::t_class";
- classIdx = classIndex.value(t->getClass()->toString(), 0);
- }
- } else if (t->isIntegral() && t->name() != "void" && t->pointerDepth() == 0 && !t->isRef()) {
- flags += "|Smoke::t_";
- QString typeName = t->name();
-
- // replace the unsigned stuff, look the type up in Util::typeMap and if
- // necessary, add a 'u' for unsigned types at the beginning again
- bool _unsigned = false;
- if (typeName.startsWith("unsigned ")) {
- typeName.replace("unsigned ", "");
- _unsigned = true;
- }
- typeName.replace("signed ", "");
- typeName = Util::typeMap.value(typeName, typeName);
- if (_unsigned)
- typeName.prepend('u');
-
- flags += typeName;
- } else if (t->getEnum()) {
- flags += "|Smoke::t_enum";
- if (t->getEnum()->parent()) {
- classIdx = classIndex.value(t->getEnum()->parent()->toString(), 0);
- } else if (!t->getEnum()->nameSpace().isEmpty()) {
- classIdx = classIndex.value(t->getEnum()->nameSpace(), 0);
- } else {
- classIdx = classIndex.value("QGlobalSpace", 0);
- }
- } else if (Options::qtMode && !t->isRef() && t->pointerDepth() == 0 && t->getTypedef() &&
- flagTypes.contains(t->getTypedef()))
- {
- flags += "|Smoke::t_uint";
- } else {
- flags += "|Smoke::t_voidp";
- }
-
- if (t->isRef())
- flags += "|Smoke::tf_ref";
- if (t->pointerDepth() > 0)
- flags += "|Smoke::tf_ptr";
- if (!t->isRef() && t->pointerDepth() == 0)
- flags += "|Smoke::tf_stack";
- if (t->isConst())
- flags += "|Smoke::tf_const";
- flags.replace("0|", "");
+ QString flags = getTypeFlags(t, &classIdx);
typeIndex[t] = i;
out << " { \"" << it.key() << "\", " << classIdx << ", " << flags << " },\t//" << i++ << "\n";
}
--- trunk/KDE/kdebindings/generator/generatorvisitor.cpp #1117674:1117675
@@ -293,6 +293,8 @@
void GeneratorVisitor::visitAccessSpecifier(AccessSpecifierAST* node)
{
+ static bool oldResolveTypedefs = ParserOptions::resolveTypedefs;
+
if (!inClass) {
DefaultVisitor::visitAccessSpecifier(node);
return;
@@ -300,6 +302,7 @@
inSignals.top() = false;
inSlots.top() = false;
+ ParserOptions::resolveTypedefs = oldResolveTypedefs;
const ListNode<std::size_t> *it = node->specs->toFront(), *end = it;
do {
@@ -312,12 +315,14 @@
else if (t.kind == Token_private)
access.top() = Access_private;
- // signal/slot handling
+ // signal/slot handling; don't resolve typedefs in signals and slots
if (t.kind == Token_signals) {
access.top() = Access_protected;
inSignals.top() = true;
+ ParserOptions::resolveTypedefs = false;
} else if (t.kind == Token_slots) {
inSlots.top() = true;
+ ParserOptions::resolveTypedefs = false;
}
}
it = it->next;
@@ -418,13 +423,6 @@
QHash<QString, Typedef>::iterator it = typedefs.insert(name, tdef);
if (parent)
parent->appendChild(&it.value());
-
- if (ParserOptions::qtMode && currentTypeRef->name() == "QFlags" &&
- !currentTypeRef->templateArguments().isEmpty())
- {
- // in Qt-mode, store that this is a QFlags-typedef
- flagTypes.insert(&it.value());
- }
}
createTypedef = false;
return;
--- trunk/KDE/kdebindings/generator/options.cpp #1117674:1117675
@@ -30,5 +30,3 @@
bool ParserOptions::resolveTypedefs = false;
bool ParserOptions::qtMode = false;
QStringList ParserOptions::dropMacros;
-
-QSet<const Typedef*> flagTypes;
--- trunk/KDE/kdebindings/generator/options.h #1117674:1117675
@@ -42,6 +42,4 @@
static QStringList dropMacros;
};
-extern GENERATOR_EXPORT QSet<const Typedef*> flagTypes;
-
#endif
More information about the Kde-bindings
mailing list