diff options
-rw-r--r-- | doc/typesystemvariables.rst | 54 | ||||
-rw-r--r-- | shibokengenerator.cpp | 24 |
2 files changed, 69 insertions, 9 deletions
diff --git a/doc/typesystemvariables.rst b/doc/typesystemvariables.rst index 0a3da0bcb..26f05477d 100644 --- a/doc/typesystemvariables.rst +++ b/doc/typesystemvariables.rst @@ -21,13 +21,61 @@ Variables Replaced by the name of a C++ argument in the position indicated by ``#``. The argument counting starts with ``%1``, since ``%0`` represents the return - variable name. + variable name. If the number indicates a variable that was removed in the + type system description, but there is a default value for it, this value will + be used. Consider this example: + + .. code-block:: c++ + + void argRemoval(int a0, int a1 = 123); + + + .. code-block:: xml + + <modify-function signature="argRemoval(int, int)"> + <modify-argument index="2"> + <remove-argument/> + </modify-argument> + </modify-function> + + The ``%1`` will be replaced by the C++ argument name, and ``%2`` will get the + value ``123``. **%ARGUMENT_NAMES** - Replaced by a comma separated list with the names of all arguments that were - not removed on the type system description for the method/function. + Replaced by a comma separated list with the names of all C++ arguments that + were not removed on the type system description for the method/function. If + the removed argument has a default value (original or provided in the type + system), this value will be inserted in the argument list. + + Take the following method and related type system description as an example: + + .. code-block:: c++ + + void argRemoval(int a0, Point a1 = Point(1, 2), bool a2 = true, Point a3 = Point(3, 4), int a4 = 56); + + + .. code-block:: xml + + <modify-function signature="argRemoval(int, Point, bool, Point, int)"> + <modify-argument index="2"> + <remove-argument/> + <replace-default-expression with="Point(6, 9)"/> + </modify-argument> + <modify-argument index="4"> + <remove-argument/> + </modify-argument> + </modify-function> + + As seen on the XML description, the function's ``a1`` and ``a3`` arguments + were removed. If any ``inject-code`` for this function uses ``%ARGUMENT_NAMES`` + the resulting list will be the equivalent of using individual argument type + system variables this way: + + .. code-block:: c++ + + %1, Point(6, 9), %3, Point(3, 4), %5 **%CONVERTTOPYTHON[CPPTYPE]** diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index 52eaff163..7024f84b1 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -897,19 +897,31 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, // replace template variables for individual arguments int removed = 0; for (int i = 0; i < func->arguments().size(); i++) { - if (func->argumentRemoved(i+1)) + QString argReplacement; + if (func->argumentRemoved(i+1)) { + const AbstractMetaArgument* arg = func->arguments().at(i); + if (!arg->defaultValueExpression().isEmpty()) + argReplacement = arg->defaultValueExpression(); removed++; - code.replace("%" + QString::number(i+1), QString("cpp_arg%1").arg(i - removed)); + } + + if (argReplacement.isEmpty()) + argReplacement = QString("cpp_arg%1").arg(i - removed); + code.replace("%" + QString::number(i+1), argReplacement); } - // replace template variables for unremoved arguments - int i = 0; + // replace template variables for a list of arguments + removed = 0; QStringList argumentNames; foreach (const AbstractMetaArgument* arg, func->arguments()) { - if (func->argumentRemoved(arg->argumentIndex() + 1)) + if (func->argumentRemoved(arg->argumentIndex() + 1)) { + if (!arg->defaultValueExpression().isEmpty()) + argumentNames << arg->defaultValueExpression(); + removed++; continue; + } - QString argName = QString("cpp_arg%1").arg(i++); + QString argName = QString("cpp_arg%1").arg(arg->argumentIndex() - removed); if (shouldDereferenceArgumentPointer(arg)) argName.prepend('*'); argumentNames << argName; |