Writing new Clang plugins (Re: replacing OUString::valueOf(static_cast<sal_Int32>) ??)

Lubos Lunak l.lunak at suse.cz
Fri Jan 11 05:57:12 PST 2013


On Friday 11 of January 2013, Jean-Noël Rouvignac wrote:
> 2013/1/10 Lubos Lunak <l.lunak at suse.cz>
>
> >  > > Unless all you want to convert is only places which do the explicit
> > > >
> > > > cast, this will need a (fairly simple) Clang plugin.
> > >
> > > Sure, if you feel like writing one.
> >
> >  Actually, I'd prefer to write a howto about that first, whenever I get
> > to doing that, so that I don't have to write every single plugin. Such a
> > plugin
> > will be still much simpler than a regexp or any other way.
>
> Please do, I would be interested in that.
> Maybe you already have some URLs to share on this subject?

 I'm not aware of anything very useful at this point. The existing tutorials 
that can be found mostly say how to create a plugin itself, but not much 
more. Since I've already created a plugin for LO, now "writing a plugin" in 
LO actually means adding another class with new functionality to the one LO 
plugin, so what is needed now is documentation on the internal Clang API that 
is used for writing the functionality.

 That API is documented at http://clang.llvm.org/doxygen/ , but I understand 
that throwing that at somebody unfamiliar with it must be scaring (hint: the 
most commonly needed is the class hiearchy starting from clang::Stmt, as 
those are classes representing the program in the AST). I myself actually 
find it easier to read directly doxygen docs in the includes, mostly Decl*.h 
Expr*.h Stmt*.h in include/clang/AST/ . The API is however rather intuitive 
and straightforward, once one gets into it. And finding out how a particular 
piece of code is represented in the AST is a matter of compiling it 
with 'clang++ -Xclang -ast-dump' and matching the output to Clang classes.

 If you want to give it a try now, look under compilerplugins/ in the LO 
sources.

-- 
 Lubos Lunak
 l.lunak at suse.cz


More information about the LibreOffice mailing list