Bug 354854 - Signals and slots functions are not colorized inside of connect/disconnect macro
Summary: Signals and slots functions are not colorized inside of connect/disconnect macro
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: git master
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-04 19:35 UTC by Piotr Mierzwinski
Modified: 2021-01-26 18:43 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Mierzwinski 2015-11-04 19:35:22 UTC
As in topic. Nor signal neither slot function is colorized when is using inside connect/disconnect macro.
Additionally sometimes arguments in these functions are not colorized. As I observed when arguments are Qt classes or standard C/C++ types then are colorized, otherwise don't.

Below you can find examples coming from my own Qt4 project (located at git://git.qtcmd.org/qtcmd2.git), file: subsystemmanager.cpp

  connect(m_subsystem, SIGNAL(signalNameOfProcessedFile( const QString &, const QString & )),
		pProgressDlg, SLOT(slotSetFilesName( const QString &, const QString & )));
  connect(m_subsystem, SIGNAL(signalCounterProgress( long long, Vfs::ProgressCounter, bool )),
		pProgressDlg, SLOT(slotSetCounter( long long, Vfs::ProgressCounter, bool )));
Here "QString" and "long long" are colorized, but "Vfs::ProgressCounter" doesn't. 

Similar happen in below example. Where const and int are colorized and FileInfo.
  disconnect(m_subsystem, SIGNAL(signalShowFileOverwriteDlg(const FileInfo &, FileInfo &, int &)),  
		     this, SLOT(slotShowFileOverwriteDlg(const FileInfo &, FileInfo &, int &)) );

ProgressCounter is enum type.
FileInfo is local class located in project.
Skiping connect/disconnect macros the names FileInfo and ProgressCounter are colorized in other places. For example in signal declarations.

In project configuration I've added couple of Includes/Imports related to Qt4 headers: QtGui, QtCore, QtMultimedia, QtNetwork.

Reproducible: Always


Actual Results:  
Function use inside connect/disconnect macro is not colorized
Additionally if arguments in these functions are coming from local classes are also not colorized.

Expected Results:  
Functions inside connect/disconnect macro should be colorized
Arguments coming from local classes placed in these functions should be also colorized. The same like Qt based.

KDevelop and KDevplatform cloned (branch 5.0) at 04.11.2015
Comment 1 Kevin Funk 2015-11-04 20:34:44 UTC
Yep, it's not standard C++ what you see in old-style signal/slot connects, thus Clang chokes on that.

Note:
- Highlighting works fine for new-style connects
- Does not work for old-style connects

This needs custom-handling in KDevelop, which we didn't implement yet.

Arguably, people move to new-style connects, so this is less of an issue by now...
Comment 2 Piotr Mierzwinski 2015-11-04 21:39:01 UTC
I suppose you mean C++11 - only one standard supported currently in KDevelop.
In project configuration C/C++parser -> Predefined profile inside combo there is 7 standards. Do you plan to handle all of them?
In this moment I can't select different one than "C++11".

My example came from Qt4 project, so this is standard from Qt4. The same is saying Qt4 documentation in cases of use. Example from documentation:
 QLabel *label = new QLabel;
 QScrollBar *scrollBar = new QScrollBar;
 QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
                  label,  SLOT(setNum(int)));

People who are coding in Qt5 can/must move to new style of connect/disconnect macros.
I have Qt4 project and the most likely in the future I want to move with it to Qt5, but not now and for sure not in this year. Still, I think, there are many developing projects using Qt4.
If you saying "this is less of an issue by now", so I have to wait (with hope) till will be fixed someday in the future :/. Now I have KDevelop 4.7.x
Yes. I know the reason. You (KDevelop team) have not much manpower.
Comment 3 Milian Wolff 2015-11-05 14:04:18 UTC
Yep, we are aware of this situation and I completely agree with you - we _have_ to keep support for Qt 4 and the "old" signal/slot connect syntax.

It should actually be possible, I think, with a bit of macro hackery.
Comment 4 Milian Wolff 2016-01-24 18:28:43 UTC
Git commit 0474b1a0063c32abc9d89143bc2343db4d21b7f7 by Milian Wolff.
Committed on 24/01/2016 at 18:28.
Pushed by mwolff into branch '5.0'.

Mark Qt signals and slots as such in the DUChain.

This is a first step towards bringing back the old KDevelop 4 level
of support for Qt. There is a lot of work left to be done though.

This patch so far only marks class function declarations that are
Qt slots or signals as such. The main idea here is taken from the
Qt Creator clang code model, so credit where credit is due: Good
job!

When a TU is parsed that contains a system include path that ends with
/QtCore we prepend the include paths to our "wrappedQtHeaders" folder.
This so far only contains "QtCore/qobjectdefs.h" which includes the
real "qobjectdefs.h" via `#include_next`. Then we redefine the MOC
macros for signals and slots to inject __attribute__((annotate())
tokens with qt_slot/qt_signal contents where appropriate. This can
then be looked up when traversing the AST via CXCursor_AnnotateAttr
cursors.

M  +6    -0    languages/clang/duchain/CMakeLists.txt
M  +24   -0    languages/clang/duchain/builder.cpp
M  +24   -2    languages/clang/duchain/parsesession.cpp
A  +57   -0    languages/clang/duchain/wrappedQtHeaders/QtCore/qobjectdefs.h     [License: GPL (v3)]
M  +62   -0    languages/clang/tests/test_duchain.cpp
M  +1    -0    languages/clang/tests/test_duchain.h

http://commits.kde.org/kdevelop/0474b1a0063c32abc9d89143bc2343db4d21b7f7
Comment 5 Milian Wolff 2016-01-24 18:44:55 UTC
Git commit 065d303e87723f6fea9e4cd230a0e5c94042450e by Milian Wolff.
Committed on 24/01/2016 at 18:44.
Pushed by mwolff into branch '5.0'.

Do not offer to implement Qt signals.

M  +1    -1    languages/clang/codecompletion/completionhelper.cpp
M  +3    -23   languages/clang/duchain/builder.cpp
M  +22   -0    languages/clang/util/clangutils.cpp
M  +10   -0    languages/clang/util/clangutils.h

http://commits.kde.org/kdevelop/065d303e87723f6fea9e4cd230a0e5c94042450e
Comment 6 Milian Wolff 2016-01-24 21:33:48 UTC
To report uses inside SIGNAL()/SLOT() macros, we have multiple options:

- rewrite uses of qFlagLocation based on the string literal argument it gets passed:
    CallExpr (103) | type: "const char *" (101) | display: "qFlagLocation" | loc: test.cpp@[(17,5),(17,23)] | isUse
      UnexposedExpr (100) | type: "const char *(*)(const char *)" (101) | display: "qFlagLocation" | loc: test.cpp@[(17,5),(17,23)] 
        DeclRefExpr (101) | type: "const char *(const char *)" (111) | display: "qFlagLocation" | loc: test.cpp@[(17,5),(17,23)] | isUse
      UnexposedExpr (100) | type: "const char *" (101) | loc: test.cpp@[(17,5),(17,23)] 
        StringLiteral (109) | type: "const char [24]" (112) | canonical type: "char const[24]" (112) | display: ""2mySignal()\000test.cpp:17"" | loc: test.cpp@[(17,5),(17,23)] 

- rewrite uses of the macros themselves, assuming we get access to its argument

- we could also overwrite the macros as needed using our new qobjectdefs.h shim.

The oldcpp plugin has some logic for finding the corresponding signal/slot from a normalized signature afaik, which we can revive for that purpose.

Once that is done we can look at the nice-to-have things:

For Q_PROPERTY we can leverage the static assert trick that Olivier found and documented here: https://woboq.com/blog/moc-with-clang.html
This would then be followed by a parsing of the string literal and extracting the getter, setter and notify signal and reporting uses for them.

For Q_PRIVATE_SLOT we could use a custom macro with a special marker attribute.
Comment 7 Piotr Mierzwinski 2021-01-26 18:43:17 UTC
Seems this currently work. I tested this with syntax of singal / connect provided in Qt5.