[cfe-dev] Qt signal/slots checker impelmentation question

Evgeniy Dushistov via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 11 15:39:18 PST 2015


Hi,

recently I submit patch to review that implement
Qt signal/slot checker:

http://reviews.llvm.org/D14592

It basically checks that if you call QObject connect
method, like this:
connect(&send, SIGNAL(f2(int, double*)), &recv, SLOT(onf2(int,
double*)));

then `decltype(send)` have method `f2` with such signature
and `decltype(recv)` have method `onf2` with matched signature,
plus signatures of `f2` and `onf2` matches each other (actually
param pack of `onf2` should be prefix of param pack of `f2`).

SIGNAL and SLOT macroses convert their arguments to string,
so in the checker I have two string and have to normalize them,
for example convert types of function argument like this:
`int const` -> `int`
`const int` -> `int`

Currently for normalization I use algorithm, similar to Qt:
handed written parser around ~ 200 lines of code (
of course it  has some unhandled cases, like handling of `volatile`).

The expected input and output of such normalize algorithm
can be found via patch review URL in file:
unittests/StaticAnalyzer/QtSignalSlotCheckerTest.cpp

And I wonder how many efforts and lines of code will be take
"parse + print in desired way" 
inside Checker with libclang help?

By `libclang help` I mean I receive control via
`void checkPostCall(const CallEvent &Call, CheckerContext &C) const`

and I found `connect` call with string like this:
"f(const QString&, QVarint)"

after that I ask libclang parse such forward function declaration:
"extern void f(const QString&, QVariant);"
and use types like `QString` and `QVariant` from current context.

-- 
/Evgeniy



More information about the cfe-dev mailing list