From e1abacfdf77b539e50578b35bee48e67184e1ea7 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Fri, 24 Jun 2022 11:31:08 +0200 Subject: moc: Cleanup handling of default arguments in functions Change-Id: I0a381525b92ce5f0b51296a02d9ab98c7a204efc Reviewed-by: Thiago Macieira --- src/tools/moc/moc.cpp | 53 +++++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'src/tools/moc') diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index c6e8f0bda8..a14f0c1ccd 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -578,6 +578,17 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) return true; } +inline void handleDefaultArguments(QList *functionList, FunctionDef &function) +{ + // support a function with a default argument by pretending there is an + // overload without the argument (the original function is the overload with + // all arguments present) + while (function.arguments.size() > 0 && function.arguments.constLast().isDefault) { + function.wasCloned = true; + function.arguments.removeLast(); + *functionList += function; + } +} void Moc::parse() { @@ -895,11 +906,7 @@ void Moc::parse() if (funcDef.isConstructor) { if ((access == FunctionDef::Public) && funcDef.isInvokable) { def.constructorList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def.constructorList += funcDef; - } + handleDefaultArguments(&def.constructorList, funcDef); } } else if (funcDef.isDestructor) { // don't care about destructors @@ -908,29 +915,17 @@ void Moc::parse() def.publicList += funcDef; if (funcDef.isSlot) { def.slotList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def.slotList += funcDef; - } + handleDefaultArguments(&def.slotList, funcDef); if (funcDef.revision > 0) ++def.revisionedMethods; } else if (funcDef.isSignal) { def.signalList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def.signalList += funcDef; - } + handleDefaultArguments(&def.signalList, funcDef); if (funcDef.revision > 0) ++def.revisionedMethods; } else if (funcDef.isInvokable) { def.methodList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def.methodList += funcDef; - } + handleDefaultArguments(&def.methodList, funcDef); if (funcDef.revision > 0) ++def.revisionedMethods; } @@ -1180,11 +1175,7 @@ void Moc::parseSlots(ClassDef *def, FunctionDef::Access access) ++def->revisionedMethods; } def->slotList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def->slotList += funcDef; - } + handleDefaultArguments(&def->slotList, funcDef); } } @@ -1228,11 +1219,7 @@ void Moc::parseSignals(ClassDef *def) ++def->revisionedMethods; } def->signalList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def->signalList += funcDef; - } + handleDefaultArguments(&def->signalList, funcDef); } } @@ -1667,11 +1654,7 @@ void Moc::parseSlotInPrivate(ClassDef *def, FunctionDef::Access access) funcDef.access = access; parseFunction(&funcDef, true); def->slotList += funcDef; - while (funcDef.arguments.size() > 0 && funcDef.arguments.constLast().isDefault) { - funcDef.wasCloned = true; - funcDef.arguments.removeLast(); - def->slotList += funcDef; - } + handleDefaultArguments(&def->slotList, funcDef); if (funcDef.revision > 0) ++def->revisionedMethods; -- cgit v1.2.3