Using compiler plugins

2012-08-03 Thread Lubos Lunak

 Hello,

 as a followup to building LO with the Clang compiler, I tried to have a look 
at writing plugins for it during the last SUSE Hackweek. It turned out to be 
quite straightforward, after one gets into it, and it seems to open 
possibilities to do quite powerful things.

 As a demo, attached is a plugin that can do two actions:

- Convert postfix operator++ to prefix operator++ (I think we have an EasyHack 
for this). This can be run as a separate step from compilation, it analyzes 
the given source file, checks where the return value fo the expression is 
unused, in which case it modifies the source and prints it out.

- Check arguments to 
com::sun::star::lang::XMultiServiceFactory::createInstance() calls. This is 
to be run during normal compilation and it could be checked that the argument 
is correct (i.e. prevent typos). Unlike manual checking, this can more easily 
identify the right places in the code (and, once written, it's not 
manual :) ).

 If you have clang including devel files installed, it should be enough to 
just run make in the demo, which will also run the two actions on two testing 
files (but I've also run them manually on some real LO code).

 It's just a proof of concept, but I think it shows the possibilities. 

 Rewriting actions could be used to handle presumably quite a number of 
EasyHack-like changes. Whether that would be done in less time and could be 
more complicated depends on what the changes exactly would be. Something like 
renaming a class is probably much better done with plain sed, and way too ... 
sophisticated changes would be probably easier to do manually rather than 
trying to find the AST manipulations, but I think there are still enough 
changes that would be better done this way. And this could also allow more 
LO4 changes than we'd be able to do manually.

 The checking actions could be normally incorporated into our build when one 
builds with Clang, and Clang-based tinderbox(es) could check it for the rest 
of developers.

 Upstream ccache and icecream both have a working support for this in their 
repositories (and my SUSE packages in home:llunak:clang have it too).

 In case somebody asks, I haven't really looked into GCC plugins, but I doubt 
the support there matches Clang's. I think GCC does not have any support for 
rewriting of the source code, and GCC plugins use C API as opposed to Clang's 
C++ API (which is reasonably easy, 'clang++ a.cpp -Xclang -ast-dump' gives an 
overview of the AST and browsing clang/include/clang/AST/ gives the API for 
handling it).

 So, the remaining things to do would be:

- See if we actually want to use this in practice (I guess yes :) )
- Integrate with our build system. Should be fairly easy, Makefile to build 
the plugin, gbuild changes to use it, gbuild changes to make it easy to 
figure out exact compilation commands for each .cxx and a script to use a 
rewriting plugin.
- Find out what we can actually use it for. Some EasyHacks are a good start, 
but the list might get quite long.

-- 
 Lubos Lunak
 l.lu...@suse.cz


loplugin.tar.gz
Description: application/tgz
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Using compiler plugins

2012-08-03 Thread Caolán McNamara
On Fri, 2012-08-03 at 15:05 +0200, Lubos Lunak wrote:
 - Find out what we can actually use it for. Some EasyHacks are a good start, 
 but the list might get quite long.

I'd be interested to know it'd be possible, in theory anyway, to detect
e.g. pointless OUString instances where only its ctor and dtor are
called and nothing else ?

C.

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Using compiler plugins

2012-08-03 Thread Lubos Lunak
On Friday 03 of August 2012, Caolán McNamara wrote:
 On Fri, 2012-08-03 at 15:05 +0200, Lubos Lunak wrote:
  - Find out what we can actually use it for. Some EasyHacks are a good
  start, but the list might get quite long.

 I'd be interested to know it'd be possible, in theory anyway, to detect
 e.g. pointless OUString instances where only its ctor and dtor are
 called and nothing else ?

 You mean things like this?

void foo()
{
OUString a;
}

 Yes, even in practice, see attachment.

 But I think this one is generic enough that it should be actually preferably 
done upstream. There are already GCC/Clang attributes pure and const for 
marking functions, so there could be a similar attribute to mark ctors/dtors 
of classes where the ctor/dtor themselves do not have any side-effects (for a 
suitable definition of side-effect).

-- 
 Lubos Lunak
 l.lu...@suse.cz


loplugin.tar.gz
Description: application/tgz
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Using compiler plugins

2012-08-03 Thread Enrico Weigelt
Hi,

  as a followup to building LO with the Clang compiler, I tried to
  have a look
 at writing plugins for it during the last SUSE Hackweek. It turned
 out to be
 quite straightforward, after one gets into it, and it seems to open
 possibilities to do quite powerful things.

snip

Sounds interesting. But let me get that straigt:
you're using the compiler plugins just as refactoring/analysis tools,
not for the actual production build, right ?

Because otherwise that's likely to introduce problems for build/package
engineering, especially when it comes to isolated builds and cross-
compiling.

By the way: crosscompiling, optimally, should be a standard test run
in tinderbox builds.


cu
-- 
Mit freundlichen Grüßen / Kind regards 

Enrico Weigelt 
VNC - Virtual Network Consult GmbH 
Head Of Development 

Pariser Platz 4a, D-10117 Berlin
Tel.: +49 (30) 3464615-20
Fax: +49 (30) 3464615-59

enrico.weig...@vnc.biz; www.vnc.de 
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice