diff options
-rw-r--r-- | doc/typesystemvariables.rst | 55 | ||||
-rw-r--r-- | shibokengenerator.cpp | 18 |
2 files changed, 71 insertions, 2 deletions
diff --git a/doc/typesystemvariables.rst b/doc/typesystemvariables.rst index 26f05477d..15fe8732c 100644 --- a/doc/typesystemvariables.rst +++ b/doc/typesystemvariables.rst @@ -9,14 +9,21 @@ by the correct values. This also shields the developer from some |project| implementation specifics. +.. _variables: + Variables ========= + +.. _return_argument: + **%0** Replaced by the name of the return variable of the Python method/function wrapper. +.. _arg_number: + **%#** Replaced by the name of a C++ argument in the position indicated by ``#``. @@ -42,6 +49,8 @@ Variables value ``123``. +.. _argument_names: + **%ARGUMENT_NAMES** Replaced by a comma separated list with the names of all C++ arguments that @@ -78,52 +87,98 @@ Variables %1, Point(6, 9), %3, Point(3, 4), %5 +.. _arg_type: + +**%ARG#_TYPE** + + Replaced by the type of a C++ argument in the position indicated by ``#``. + The argument counting starts with ``%1``, since ``%0`` represents the return + variable in other contexts, but ``%ARG0_TYPE`` will not translate to the + return type, as this is already done by the + :ref:`%RETURN_TYPE <return_type>` variable. + 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``. + + +.. _converttopython: + **%CONVERTTOPYTHON[CPPTYPE]** Replaced by a |project| conversion call that converts a C++ variable of the type indicated by ``CPPTYPE`` to the proper Python object. +.. _cppself: + **%CPPSELF** Replaced by the wrapped C++ object instance that owns the method in which the code with this variable was inserted. +.. _function_name: + **%FUNCTION_NAME** Replaced by the name of a function or method. +.. _pyarg: + **%PYARG_#** Similar to ``%#``, but is replaced by the Python arguments (PyObjects) received by the Python wrapper method. +.. _pyself: + **%PYSELF** Replaced by the Python wrapper variable (a PyObject) representing the instance bounded to the Python wrapper method which receives the custom code. +.. _pythontypeobject: + **%PYTHONTYPEOBJECT** Replaced by the Python type object for the context in which it is inserted: method or class modification. +.. _return_type: + **%RETURN_TYPE** Replaced by the type returned by a function or method. +.. _type: + **%TYPE** Replaced by the name of the class to which a function belongs. Should be used in code injected to methods. +.. _example: + Example ======= diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index 7024f84b1..d2172fedf 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -862,8 +862,7 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, // replace "toPython "converters code.replace(toPythonRegex, "Shiboken::Converter<\\1>::toPython"); - - // replace %PYARG variables + // replace %PYARG_# variables if (numArgs > 1) { code.replace(pyArgsRegex, "pyargs[\\1-1]"); } else { @@ -873,6 +872,21 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, else code.replace("%PYARG_1", usePyArgs ? "pyargs[0]" : "arg"); } + + // replace %ARG#_TYPE variables + foreach (const AbstractMetaArgument* arg, func->arguments()) { + QString argTypeVar = QString("%ARG%1_TYPE").arg(arg->argumentIndex() + 1); + QString argTypeVal = arg->type()->cppSignature(); + code.replace(argTypeVar, argTypeVal); + } + + static QRegExp cppArgTypeRegexCheck("%ARG(\\d+)_TYPE"); + int pos = 0; + while ((pos = cppArgTypeRegexCheck.indexIn(code, pos)) != -1) { + ReportHandler::warning("Wrong index for %ARG#_TYPE variable ("+cppArgTypeRegexCheck.cap(1)+") on "+func->signature()); + pos += cppArgTypeRegexCheck.matchedLength(); + } + // replace template variable for return variable name code.replace("%0", retvalVariableName()); |