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

Thomas Gahr ml at dadommas.de
Wed Feb 1 20:07:05 CET 2012


On Wednesday 01 February 2012 22:31:15 Flex Ferrum wrote:
> >> Just imagine what during clang processing "SLOT(foo(int))" is
> >> expanding into something like this:
> >> 
> >> __qtcreator_this_class_method_ref_as_slot(foo(int))
> > 
> > It doesn't get expanded as that.
> > 
> > After clang (or any "real" preprocessor for that matter) had its go, it's
> > essentially 'some_function("some_string_literal")'.
> 
> 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.

But I think your suggestion:
__qtcreator_this_class_method_ref_as_slot(foo(int))
is not legal C++ syntax and would nonetheless need to be:
__qtcreator_this_class_method_ref_as_slot("foo(int)")
...which leads to what André Pönitz said:

>>You'd now "just need  to parse the string lteral and add the resulting data 
>>to clang's code model". 

Given the possibilities of slots like:

"foo(MyTypeA,SomeLibraryType&,int,double)"

one would need to construct a lookup for a member function with a valid 
signature - getting types MyTypeA and SomeLibraryType from the ASTContext, 
construct a FunctionCallExpr etc... All types of the arguments must be known 
to generate the correct FunctionCallExpr that references the correct overload 
of foo.

Maybe one could re-purpose clang's parser to provide this kind of information 
- having a regexp turn:
"foo(MyTypeA,SomeLibraryType&,int,double*)"
into:
"foo(*(MyTypeA*)0,*(SomeLibraryType*)0,*(int*)0,*(double**)0)"
makes it a legal C++ call expression that can be parsed by clang in a 
potential second run or by another CompilerInstance having an 
ExternalSemaSource providing all Decls found in the main translation unit.

But that would mean parsing dozens or even hundreds of such small snippets per 
translation unit and this is very hackish at best.

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


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