aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator/generator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Cleanup pointer whitespace everywhereChristian Tismer2019-06-241-36/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Among other files to fix, basewrapper.(cpp|h) was full of uncommon pointer whitespace. After fixing that, I could not resist and fixed also libshiboken, generators, and after acceptance also PySide. Most of the time, this regex worked fine (\w\w+)([*&]+)[ ]*(?![&*]*[/=]) replaced with \1 \2 but everything was checked by hand. I did not touch the shiboken tests which are quite hairy. It turned out that inserting a space between a variable and asterisk causes a crash of shiboken, if the same line contains "CONVERTTOCPP". This was temporarily fixed by adding another space after it. Example.. sources/pyside2/PySide2/glue/qtcore.cpp line 977 QByteArray * cppSelf = %CONVERTTOCPP[QByteArray *](obj); //XXX /|\ omitting this space crashes shiboken! cppgenerator.cpp was special, since it was modified to _generate_ correct pointer whitespace. This caused a few testcases to fail, which had to be adjusted, again. This was difficult since some internal names must end on "*" and generated code normally not. Removing the last errors involved binary search on path sets... Apply C++ 11 fixits to the changed code, where applicable. Done-with: Friedemann.Kleint@qt.io Task-number: PYSIDE-1037 Change-Id: I4ac070f52c5efb296c05d581c9d46e6f397a6c81 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* shiboken: Generate code for smart pointers only within declaring packageFriedemann Kleint2019-06-131-2/+5
| | | | | | | | | | | | | | | | Check on the type entry whether code needs to be generated in the current package. Fixes: PYSIDE-1024 Change-Id: I82132b077ac6192b96d979cb5596d0e6fecbc76b Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken: Fix handling shared pointers passed by const-ref, take 2Friedemann Kleint2019-06-131-1/+7
| | | | | | | | | | | | | | | | With fd126b28e1d9b02ea16c813bc392461bdb05bd1d, broken wrapper code would still be generated for "const_QSharedPointer_QSize___&" depending on whether the const-ref or plain value type was encountered first when parsing. Fix the problem by stripping the qualifiers from the metatype added to GeneratorPrivate::m_instantiatedSmartPointers partially reverting fd126b28e1d9b02ea16c813bc392461bdb05bd1d. Change-Id: Ie6691e045b7d65baa3a0bc72dd8637f09eeaf111 Fixes: PYSIDE-1016 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken: Fix generation of init functions and types for const-refs of smart ↵Friedemann Kleint2019-06-061-0/+2
| | | | | | | | | | | | | | pointers Add a convenience to strip all qualifiers and use that. This at least fixes the naming (for example, getInitFunctionName returning "const_QSharedPointer_QSize___&"), the init function for the type itself is missing, though. Task-number: PYSIDE-1016 Change-Id: Id61b3c879199fc061e2846007951e3e9c82b85c4 Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Remove some special handling for QObject'sFriedemann Kleint2019-04-101-1/+1
| | | | | | | | | | | | For types, QObjects are equivalent to objects, there is no need to differentiate. Remove the code trying to find whether a type is a QObject. Only AbstractMetaClass needs to know whether it inherits QObject. Add a simple check recursing down the base classes. Change-Id: I2365b451c8873f044b06c09b58aff29e2db3c5b7 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken: Search for classes by type entry instead of nameFriedemann Kleint2019-04-031-1/+1
| | | | | | | | | Searching by name is more efficient and has problems when extending namespaces. Search by type entry instead where possible. Change-Id: I131329a6648bb7f0a02cba08a5fbbc0531e0c51f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken: Further refactorings related to the package nameFriedemann Kleint2019-04-021-10/+12
| | | | | | | | | | | | Let Generator::packageName() return the default package name of the type data base instead of storing it in a member variable. Instead, use a member variable for the module name which is derived from it, since it is queried many times. Use the default type system entry instead of searching for it via package name. Change-Id: I171330b3d73d2e3ceac239e4c1c6f130e9f5ee7b Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken/Typedatabase: Store type system entries separatelyFriedemann Kleint2019-03-261-12/+6
| | | | | | | | | This makes it easier to access the default type system entry, which will always be the first one in the list. Change-Id: Ie0844cef5fa4f0cd8bc50c28898e54a42845c830 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken: Generate static_cast for constructor parameters with spaceFriedemann Kleint2018-11-141-2/+7
| | | | | | | | unsigned long(0) does not work, use static_cast<unsigned long>(0). Fixes: PYSIDE-846 Change-Id: If41baebdf0b1228b658408e4c300872d17143e6f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Stop updating timestamps of generated files that haven't changedAlexandru Croitor2018-10-231-14/+1
| | | | | | | | | | | | | | This is a change in preparation for improved incremental builds, where modifying one typesystem XML file will not force rebuilding all generated cpp files. The previous logic was incorrect, file timestamps should not be updated if the generated files are unchanged, instead the build rules need to be adapted to prevent unnecessary rebuilds. Change-Id: Ia47f8ff1970e974d0e617b6891ab58666da3b1ff Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Use class FileOut for the module source file as wellFriedemann Kleint2018-10-191-18/+3
| | | | | | | | | | | Ensure the diff/dry-run options work for this file as well. Move the touchFile() utility around and adapt the verifyDirectoryFor() helper to take a string. Task-number: PYSIDE-834 Change-Id: Ic34b5f8eff304d9de85f60082f582f0537805cd4 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken: Check whether enum should be converted to int for the protected hackFriedemann Kleint2018-10-011-1/+21
| | | | | | | | | | | Find the AbstractMetaEnum belonging to the type entry and perform some checks. Generally do not use int for public enums. Warn when a protected scoped enum is encountered as this cannot be converted. Task-number: PYSIDE-817 Change-Id: I02b566093b331ea2ea627bf72964aad0a1a51c83 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Refactor finding of enumsFriedemann Kleint2018-09-281-11/+1
| | | | | | | | | | In the AbstractMetaBuilder, change the list of enums into a QHash with the type entry as key since that is mostly used for searching. Streamline and simplify the search functionality accordingly. Task-number: PYSIDE-817 Change-Id: I205cad1f90bc26511ea6b6e9b76ddb1bae544cf1 Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Add default constructible with default valuesFriedemann Kleint2018-09-131-1/+10
| | | | | | | | | | | | | | Extend the check for default constructible by also checking whether the first argument has an unmodified default value, for example: explicit QSqlIndex(const QString &cursorName = QString(), const QString &name = QString()); This can be treated like default constructible, except that {} may not be used for return values. Task-number: PYSIDE-62 Change-Id: I70af2a624de54201158a4b56e51b67ef115c2fc6 Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Refactor Generator::minimalConstructor(AbstractMetaClass)Friedemann Kleint2018-09-131-81/+32
| | | | | | | | | | | | | | | | | | | | Add some convenience functions returning the status of default expressions to AbstractMetaArgument. Rewrite the function to only insert suitable candidates into an ordered multimap instead of looping twice over all candidates. This unearthed a bug in the old algorithm trying to find the maximum number of arguments: When no candidates were found, maxArgs was left at 0, which caused it to assume default constructible. This triggered for the QMatrixNxN classes inheriting QGenericMatrix<int, int, Type> with (unsupported) non-type template parameters. For these, the default constructor needs to be specified now. Task-number: PYSIDE-62 Change-Id: I5ce2bed43001780553048d8af0addaba2b22410b Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* shiboken: Introduce DefaultValueFriedemann Kleint2018-09-121-38/+153
| | | | | | | | | | | | | | | | | | | | Introduce a small class storing the return value of Generator::minimalConstructor() consisting of a type enumeration and a value, offering formatting for the use cases variable initializations, return values and constructor arguments lists. Having distinct formatting for the different use cases has some advantages: - Can use nullptr without casts (except in constructor arguments lists, where the type is needed for disambiguation). - In the previous implementation using a string, "" indicated an error; so, it was not possible to use it for default-constructors. It is now possible to handle default-constructors for initialization ("Foo f" instead of "Foo f = Foo()". - Can use {} for return values. Task-number: PYSIDE-62 Change-Id: I73229cb957d4b92b43de4cdbc3c66703f48faa61 Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Store null enum valuesFriedemann Kleint2018-09-121-1/+5
| | | | | | | | | | | | | If an enum has a null value, store that on the EnumTypeEntry for use in Generator::minimalConstructor() as a default value. Fully qualify scoped enum value type entries for this purpose. The value can then be used for default values instead of an ugly static_cast<EnumType>(0). Task-number: PYSIDE-62 Change-Id: I42cb2ca63fb1da6c795df630ab30bded66aac901 Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Fix non-deterministic order of some SBK type indexesFriedemann Kleint2018-07-261-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change underlying type of the type database from a QHash<qualified_name, list of entries> to a QMultiMap<qualified_name, entry>. Previously, there was an allEntries() accessor and a function named entries() building a QHash<qualified_name, entry>. Simplify this so that there is only an entries() accessor returning the QMultiMap. Refactor the various Typedatabase::find() functions to operate on an iterator range of the QMultiMap. This unearthed some bugs: 1) In the generators, the call to findType(packageName()) would return the namespace entry for "sample" instead of the intended module type entry named "sample" due to the ordering. Add a new function to search for module type entries and assert that it finds it. 2) There was a duplicate, empty primitive type entry for QModelIndexList. Task-number: PYSIDE-757 Change-Id: I1814e4ca67d306e1488398507707cfd07b3f2c78 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Fix some clang-tidy warnings in shibokenFriedemann Kleint2018-07-231-6/+7
| | | | | | | | | | | | | | | | | - 'else if' after return/break/continue - Use const ref for complex arguments passed by value where possible - Fix 'if (foo) delete foo' to 'delete foo' - Use container.isEmpty() instead of container.size() in checks - Use ' = default' for trivial constructors/destructors - Use range based for where possible - Complete constructor initializer lists - Fix invocations of static methods - Replace some reinterpret_cast by static_cast - Remove unused variables/fields - Use initializer lists for return types Change-Id: Id5b44a2f9d429f66ef069d532a1cd31df796d38e Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: Refactor command line arguments handlingFriedemann Kleint2018-07-161-2/+7
| | | | | | | | | | | In main, replace the class ArgsHandler by plain QMap handling. Remove the args parameter of Generator::doSetup() and add a new virtual handleOption(key, value) to the generators instead. Add missing initialization. Change-Id: I9bc844172a81244f729d87a3d4262545e6433904 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* shiboken: Remove unused code from the generatorsFriedemann Kleint2018-06-281-13/+0
| | | | | Change-Id: I88c4148000acba2ba1e2013fe587e7f5fbe6c2ca Reviewed-by: Christian Tismer <tismer@stackless.com>
* Change license from all the filesCristian Maureira-Fredes2018-05-031-1/+1
| | | | | | | | | | | | | | | | | Removing the word 'project' from all the headers, and changing the PySide reference from the examples to Qt for Python: The following line was used inside the source/ and build_scripts/ directory: for i in $(grep -r "the Qt for Python project" * |grep -v "pyside2-tools" | awk '{print $1}' | sed 's/:.*//g');do sed -i 's/the\ Qt\ for\ Python\ project/Qt\ for\ Python/g' $i;done and the following line was used inside the examples/ directory: for i in $(grep -r "of the PySide" * |grep -v "pyside2-tools" | awk '{print $1}' | sed 's/:.*//g');do sed -i 's/of\ the\ PySide/of\ the\ Qt\ for\ Python/g' $i;done Change-Id: Ic480714686ad62ac4d81c670f87f1c2033d4ffa1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Rename PySide references to Qt for PythonCristian Maureira-Fredes2018-04-271-1/+1
| | | | | | | | | When referring to the project one should use "Qt for Python" and for the module "PySide2" Change-Id: I36497df245c9f6dd60d6e160e2fc805e48cefcae Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* shiboken: Fix some clazy warningsFriedemann Kleint2018-01-171-2/+2
| | | | | | | | | | | | - Mixing const/non-const iterators - Do not use operator[] on temporaries of type QVector - Remove unused nontrivial variables - Add Q_FALLTHROUGH() - Potential detach in range-based for Change-Id: I89391fdda616f119eadd7de529eb6cee69343f85 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Shiboken: Improve Handling of array typesFriedemann Kleint2017-08-031-3/+6
| | | | | | | | | | | Change the AbstractMetaType::signature() functions to work with the nested AbstractMetaType types instead of TypeEntry so that the correct array signatures appear in the signature of AbstractMetaFunction. Task-number: PYSIDE-354 Task-number: PYSIDE-516 Change-Id: I90aa11891c95ccdcbae81fb70db4bec0e62f5923 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* shiboken: Further refactor command line arguments and helpFriedemann Kleint2017-06-091-2/+2
| | | | | | | | | | | | | | Replace the QMap of options returned by the generators by a vector of pairs to allow for specifying the order. This allows for better formatting -I/-F/-T in multiple lines. Add -h for help. Move the missing typelib file handling into main and print a help hint there. Change-Id: I5a95bd8d193be012aaa7ce3934945b25e21d3f79 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* move everying into sources/shiboken2 (5.9 edition)Oswald Buddenhagen2017-05-221-0/+864
in preparation for a subtree merge. this should not be necessary to do in a separate commit, but git is a tad stupid about following history correctly without it.