[petsc-dev] Style Guide: How to format single-line if/for/while-blocks?

Barry Smith bsmith at mcs.anl.gov
Mon Jan 21 22:17:25 CST 2013


  Karl,

     Can it handle code with all the CPP crap we have (how does the CPP stuff fit in the AST)? Can you make a make clangify rule in the makefile similar to make uncrustify so we can verify how fantastic it is?

     In my reading a few months ago the LLVM/clang pretty printers sucked and there was no serious effort to make them better. (I could have misunderstood).

     If the clang AST to source code pretty printer doesn't produce code that we can easily edit and manipulate then it isn't any good to us. It has to generate code pretty dang close to the code we have currently used to. 

   Barry


On Jan 21, 2013, at 10:10 PM, Karl Rupp <rupp at mcs.anl.gov> wrote:

> Hi guys,
> 
> >>>> Yes, though
>>>>> 
>>>>> if (y < 12) {
>>>>>   ierr = Something();CHKERRQ(ierr);
>>>>> }
>>>>> 
>>>>> takes three times as many lines. I don't care much either way, but it's
>>>>> nice to not waste vertical space.
>>>> 
>>>> I agree here.
>>> 
>>> I've prefered the 1 liners as well.
>> 
>> So, am I the only one that like the uniformity of the three-liner?
> 
> I think I'm currently on the best way towards a rabbit hole, with uncrustify lacking the full understanding of the code an thus bound to failure. Rather than tuning regular expressions and the like, I'll spend some time on investigate further what Clang can do for us.
> 
> First and foremost, it gives us access to the abstract syntax tree (AST), see e.g.
>  http://clang.llvm.org/docs/IntroductionToTheClangAST.html
> and already contains a formatter for Chromium-Style, Google-Style, LLVM-Style. The formatter for multiple Languages is currently less than 2000 lines of code and eventually far more powerful than what we need.
> 
> Via the C-interface LibClang
> http://clang.llvm.org/doxygen/group__CINDEX.html
> or LibTooling
> http://clang.llvm.org/docs/LibTooling.html
> it's much more natural to generate *the* PETSc-representation of code irrespective of the input, and from the same AST generate e.g. the Knepley-representation of code. At the same time, Clang remains an optional dependency: One can work directly with the PETSc-representation without Clang installed.
> 
> Also, I found that they (Clang) are indeed aiming at a full code documentation generator:
>  http://clang.llvm.org/OpenProjects.html
> There is already a lot of parsing of Doxygen-style comments done in Clang and accessible via the AST, so it's mostly missing output generators only. It will take more time to reach maturity, though. It may, however, be just what it needs to replace sowing in terms of Fortran stubs generation and user manual generation.
> 
> Best regards,
> Karli
> 
> 
> 




More information about the petsc-dev mailing list