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

Thomas Gahr ml at dadommas.de
Wed Feb 1 22:27:02 CET 2012


On Thursday 02 February 2012 00:34:16 Flex Ferrum wrote:
> >> 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

...and this is just the type of macro-trickery I was hoping for and could not 
come up with myself - thanks a lot!

> 
> 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.

This is great! I'm sure something can be worked out using this. I just checked 
out wip/clang and I will look into it.

> 
> > ...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.
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator



More information about the Qt-creator mailing list