[Qt-creator] QtCreator C++ code parser and clang integration status

Flex Ferrum flexferrum at gmail.com
Wed Feb 1 21:34:16 CET 2012


>> But if we manage to predefine macros SLOT as
>> #define SLOT(smth) __qtcreator_this_class_method_ref_as_slot(smth)
>> _before_ clang preprocessing then clang _does_ it. Also it reports
>> warning about SLOT redefinition in the qt headers but we can ignore
>> it. Right?
> That's exactly what I was thinking, too.
>>
>> I have to notice what this is one of the possible ways. I'm not sure
>> what clang allows such trick. But if it can...
> ...what I was thinking, again :)
> clang::PreProcessor::setPredefines? clang::ExternalPreprocessorSource?
> Maybe even better: subclass clang::PPCallbacks and install it on the
> preprocessor using PreProcessor::addPPCallbacks
> This way one will get notified when SLOT and SIGNAL are defined, maybe even
> changing their definition. Or be notified when they are expanded via
> PPCallbacks::MacroExpands.

If clang allows something like this then following trick is possible:

#define SLOT_INNER_EXPANDER_foo(...) qtcreator_slot_handler<__VA_ARGS__>().foo()
#define SLOT(param) SLOT_INNER_EXPANDER_##param

class A
{
public:
	void foo(int);
	void foo(const char*, double);
	void bar()
	{
		SLOT(foo(int));
		SLOT(foo(const char*, double));
	}
};

This code is preprocessed into:

class A
{
public:
 void foo(int);
 void foo(const char*, double);
 void bar()
 {
  qtcreator_slot_handler<int>().foo();
  qtcreator_slot_handler<const char*, double>().foo();
 }
};

So we have both slot argument types and slot name in the result AST.
Macro SLOT_INNER_EXPANDER_XXX (where XXX is any valid identifier) and
SLOT require special handling within preprocessor callbacks.


> ...these are just spontaneous random ideas but I would like to test if it can
> be done or how stuff is handled in QtCreator atm - is there a branch that uses
> clang? Where can I find it?

https://qt.gitorious.org/qt-creator/qt-creator/commits/wip/clang

Best Regards,
Flex Ferrum.



More information about the Qt-creator mailing list