diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-07-09 09:56:51 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-13 01:51:42 +0200 |
commit | 0efa445141ce3d7243f28e7b6da730d8dec17e23 (patch) | |
tree | dea4b906324ec959ca73071726390a084f871bfb /src/tools | |
parent | a2b0ab4f579151bd2a6145dd18ce684fadedfe23 (diff) |
Create a way to inform moc about private signals.
Moc checks for the use of the QPrivateSignal struct, which is part of
the Q_OBJECT macro and is private to each class that uses it. Moc then
generates a name of the signal which does not include the private
struct, and generates code to invoke such signals with an instance of
the private struct.
This way we can mark private signals as such and prevent them from
being emitted from subclasses or from outside of the class entirely.
The drawback to this is that it only works if the private
signal has no default arguments. However, at least in Qt, there are
no such signals.
Change-Id: Id16eadaa8d3c36a2c3b265077877f3e1d8304c84
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/moc/generator.cpp | 37 | ||||
-rw-r--r-- | src/tools/moc/moc.cpp | 4 | ||||
-rw-r--r-- | src/tools/moc/moc.h | 3 |
3 files changed, 36 insertions, 8 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index bcf70cbe91..09a4603753 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -540,7 +540,8 @@ void Generator::registerFunctionStrings(const QList<FunctionDef>& list) strreg(f.normalizedType); strreg(f.tag); - for (int j = 0; j < f.arguments.count(); ++j) { + int argsCount = f.arguments.count() - (f.isPrivateSignal ? 1 : 0); + for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (!isBuiltinType(a.normalizedType)) strreg(a.normalizedType); @@ -580,7 +581,7 @@ void Generator::generateFunctions(const QList<FunctionDef>& list, const char *fu if (f.revision > 0) flags |= MethodRevisioned; - int argc = f.arguments.count(); + int argc = f.arguments.count() - (f.isPrivateSignal ? 1 : 0); fprintf(out, " %4d, %4d, %4d, %4d, 0x%02x,\n", stridx(f.name), argc, paramsIndex, stridx(f.tag), flags); @@ -608,7 +609,8 @@ void Generator::generateFunctionParameters(const QList<FunctionDef>& list, const fprintf(out, " "); // Types - for (int j = -1; j < f.arguments.count(); ++j) { + int argsCount = f.arguments.count() - (f.isPrivateSignal ? 1 : 0); + for (int j = -1; j < argsCount; ++j) { if (j > -1) fputc(' ', out); const QByteArray &typeName = (j < 0) ? f.normalizedType : f.arguments.at(j).normalizedType; @@ -617,7 +619,7 @@ void Generator::generateFunctionParameters(const QList<FunctionDef>& list, const } // Parameter names - for (int j = 0; j < f.arguments.count(); ++j) { + for (int j = 0; j < argsCount; ++j) { const ArgumentDef &arg = f.arguments.at(j); fprintf(out, " %4d,", stridx(arg.name)); } @@ -1056,12 +1058,19 @@ void Generator::generateStaticMetacall() cdef->classname.constData(), cdef->classname.constData()); const FunctionDef &f = cdef->constructorList.at(ctorindex); int offset = 1; - for (int j = 0; j < f.arguments.count(); ++j) { + + int argsCount = f.arguments.count() - (f.isPrivateSignal ? 1 : 0); + for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (j) fprintf(out, ","); fprintf(out, "(*reinterpret_cast< %s>(_a[%d]))", a.typeNameForCast.constData(), offset++); } + if (f.isPrivateSignal) { + if (argsCount > 0) + fprintf(out, ", "); + fprintf(out, "%s", QByteArray(f.arguments.last().normalizedType + "()").constData()); + } fprintf(out, ");\n"); fprintf(out, " if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break;\n"); } @@ -1098,13 +1107,20 @@ void Generator::generateStaticMetacall() fprintf(out, "%s->", f.inPrivateClass.constData()); fprintf(out, "%s(", f.name.constData()); int offset = 1; - for (int j = 0; j < f.arguments.count(); ++j) { + + int argsCount = f.arguments.count() - (f.isPrivateSignal ? 1 : 0); + for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (j) fprintf(out, ","); fprintf(out, "(*reinterpret_cast< %s>(_a[%d]))",a.typeNameForCast.constData(), offset++); isUsed_a = true; } + if (f.isPrivateSignal) { + if (argsCount > 0) + fprintf(out, ", "); + fprintf(out, "%s", QByteArray(f.arguments.last().normalizedType + "()").constData()); + } fprintf(out, ");"); if (f.normalizedType != "void") { fprintf(out, "\n if (_a[0]) *reinterpret_cast< %s*>(_a[0]) = _r; } ", @@ -1131,12 +1147,19 @@ void Generator::generateStaticMetacall() anythingUsed = true; fprintf(out, " {\n"); fprintf(out, " typedef %s (%s::*_t)(",f.type.rawName.constData() , cdef->classname.constData()); - for (int j = 0; j < f.arguments.count(); ++j) { + + int argsCount = f.arguments.count() - (f.isPrivateSignal ? 1 : 0); + for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (j) fprintf(out, ", "); fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData()); } + if (f.isPrivateSignal) { + if (argsCount > 0) + fprintf(out, ", "); + fprintf(out, "%s", f.arguments.last().normalizedType.constData()); + } if (f.isConst) fprintf(out, ") const;\n"); else diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index c35f27deaf..0caa124e79 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -309,6 +309,10 @@ void Moc::parseFunctionArguments(FunctionDef *def) if (!until(COMMA)) break; } + + if (!def->arguments.isEmpty() + && def->arguments.last().normalizedType == "QPrivateSignal") + def->isPrivateSignal = true; } bool Moc::testFunctionAttribute(FunctionDef *def) diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index e20e29acb8..66cc942a9f 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -92,7 +92,7 @@ struct FunctionDef { FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), isStatic(false), inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), - isScriptable(false), isSlot(false), isSignal(false), + isScriptable(false), isSlot(false), isSignal(false), isPrivateSignal(false), isConstructor(false), isDestructor(false), isAbstract(false), revision(0) {} Type type; QByteArray normalizedType; @@ -116,6 +116,7 @@ struct FunctionDef bool isScriptable; bool isSlot; bool isSignal; + bool isPrivateSignal; bool isConstructor; bool isDestructor; bool isAbstract; |