<html><body><div><div>Hello,</div><div><br></div><div>I would like to add support for recognising Qt's signal/slot mechanism to clang by using attributes. For that, I have a proposal for a few small changes to the clang parser. These changes use the attributes to mark AST nodes as signal/slot/invokable, and expose those attributes through libclang.</div><div><br></div><div>A bit of background: if you are more familiar with Objective-C, then the signal/slot mechanism works nearly exactly the same as Cocoa's IBAction/IBOutlet: it uses a meta-type system to invoke the methods, or let slots connected to a signal know that the signal was emitted. Qt's meta-type system also allows for "invokable methods", which can be called/invoked without being tagged as slot.</div><div><br></div><div>Example:</div><div><br></div><div>class Test {</div><div>public:</div><div>    Q_INVOKABLE void invokableA();</div><div><br></div><div>public slots:</div><div>    void slotA();</div><div>    void inlineSlotB() {}</div><div><br></div><div>signals:</div><div>    void signalC();</div><div><br></div><div>private:</div><div>    Q_SIGNAL void signalD(), signalE();</div><div>    Q_SLOT void slotF(), slotG();</div><div>    void not_a_slot_or_slot();</div><div>    Q_SLOT void inlineSlotH() {}</div><div>};</div><div><br></div><div>(To be used properly with Qt, the class would also have to inherit from QObject, and have the Q_OBJECT macro right after the opening brace.)</div><div><br></div><div>Taking a leaf from Cocoa's book, we can use the pre-processor to inject:</div><div><br></div><div>#define signals protected __attribute__((q_signal))</div><div>#define slots __attribute__((q_slot))</div><div>#define Q_SIGNAL __attribute__((q_signal))</div><div>#define Q_SLOT __attribute__((q_slot))</div><div>#define Q_INVOKABLE __attribute__((q_invokable))</div><div><br></div><div>Then the proposed change to clang is to handle it as follows:</div><div>- for method declarations or inline method definitions, accept the q_signal/q_slot/q_invokable attributes, and add the attribute to the AST node</div><div>- for C++ access specifiers, accept an additional (trailing) q_* attribute, and add the attribute to all AST nodes for methods until the next specifier</div><div><br></div><div>This is equivalent to how moc (Qt's Meta-Object Compiler) generates the meta-object for a QObject.</div><div><br></div><div>Attached is a proof-of-concept implementation/patch (with the above example as test-case). It also adds the attributes as cursor kinds to libclang, so a client application (like Qt Creator) can use it to find out which of the methods are "tagged" as a signal/slot/invokable</div><div><br></div><div>-- Erik.</div><div><br></div></div></body></html>