Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
AW: [cdt-dev] Problems with code formatter and legacy code - what is possible at all?

Dear Achim,

at the moment I evaluate the mechanisms for refactoring in JDT for
use in a different project and for a pretty different purpose.
By doing this I learnt a lot about the AST and AST visitor mechanisms (of JDT).
Assuming that the AST implementation in CDT is comparable to
that one in JDT, I can give some answers or at least my opinion
to your questions.

If CDT provides the possibility to implement a customized
CodeFormatterVisitor in the same way that JDT does, I am pretty
sure that you can implement your wishes 1), 2), 3), 4), 6), and 7).
The only point I am unsure about is the comments.


Mit freundlichen Grüßen / Best regards

Dr. Nils Hagge
Projektleiter Vorfeld

Siemens AG
Industry Sector, I IA&DT ATS 13
Telefon +49 911 895-3484
Telefax +49 911 895-153484
mailto:nils.hagge@xxxxxxxxxxx
http://www.siemens.com/automation

Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Gerhard Cromme
Managing Board: Peter Loescher, Chairman, President and Chief Executive Officer; 
Wolfgang Dehen, Heinrich Hiesinger, Joe Kaeser, Jim Reid-Anderson, Hermann Requardt,
Siegfried Russwurm, Peter Y. Solmssen
Registered offices: Berlin and Munich; 
Commercial registries: Berlin Charlottenburg, HRB 12300, Munich, HRB 6684
WEEE-Reg.-No. DE 23691322

-----Ursprüngliche Nachricht-----
Von: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] Im Auftrag von Achim Bursian
Gesendet: Montag, 6. April 2009 13:19
An: CDT Dev Mailinglist
Betreff: [cdt-dev] Problems with code formatter and legacy code - what is possible at all?

Hello,
we want to move a large C++ code base from XEmacs to Eclipse/CDT as main 
editor. These are hundreds of thounds LOC, all under source code control 
of course. I tried to find some settings to mimic our old XEmacs 
formatting style in CDT, but with no luck. There are some areas where 
I'm absolutely lost.

I'm very willing to add some code to CDT to enhance the formatter, but 
before I dive into the depth of the formatter, I wanted to hear your 
opinions whether it is actually possible what I want to do.

The main reason for this issue is that we want as few merge conflicts as 
possible after formatting with CDT. Our code is maintained in several 
branches to support patches for old releases, and only the main branch 
will be moved to Eclipse. So the formatting between XEmacs and 
Eclipse/CDT has to be consistent. I see several areas of problems at the 
moment.

1) Preformatted member lists
============================
Existing code:
class T
{
    ICIpoState*         ipoStateP;
    BSChannelId         chanId;
    BSAlarmhandler*     alarmP;
    ICAxConfig          axConfig ;
};

All members are aligned to the same column.
After formatting with CDT:
class T
{
    ICIpoState* ipoStateP;
    BSChannelId chanId;
    BSAlarmhandler* alarmP;
    ICAxConfig axConfig;
};


2) public/private alignment
============================
Existing code:
class T
{
  private:
    ICIpoState*         ipoStateP;
  public:
    ICAxConfig          axConfig ;
};

The private/public/protected keywords are indented 2 chars, while all 
other indentation is 4 chars.

After formatting with CDT:
class T
{
    private:
        ICIpoState* ipoStateP;
    public:
        ICAxConfig axConfig;
};

Also possible with CDT:
class T
{
private:
    ICIpoState* ipoStateP;
public:
    ICAxConfig axConfig;
};

Changing the indentation size to 2 chars wouldn't help, as if's etc. 
shall be indented with 4 chars.

3) return type on extra line
============================
Existing code:

void
CPTestCl::reset()
{
    return;
}

After formatting with CDT:

void CPTestCl::reset()
{
    return;
}

If the return type is on a line by itself, I don't want it to be 
combined with the method name. But if it already is like
 void CPTestCl::reset()
it shouldn't be split onto two lines either. Basically, just leave it as 
it is.

4) Preformatted parameter lists
===============================
Existing code:
void
CPTestCl::load(int v1,
               int v2,
               int mode
    )
{
  ...

All params are aligned to the same column.

After formatting with CDT:

void CPTestCl::load( int v1, int v2, int mode )
{
  ...   

5) Column aligned comments
==========================
Existing code:

    if (oldAddedVel)                    // comment 1
    {
        if (aGisMCS->isResetPos())      // comment 2
          return;

After formatting with CDT:

    if (oldAddedVel) // comment 1
    {
        if (aGisMCS->isResetPos()) // comment 2
            return;

6) Simple if clauses
==========================
See code in 5). After the if without braces, the next line ("return") 
should be indented 2 chars only, not 4 chars.

7) Inconsistent blanks
======================
Existing code:

class T
{
    ICIpoState*         ipoStateP;
    ICAxConfig          axConfig ;
};

After formatting with CDT:

class T
{
    ICIpoState*         ipoStateP;
    ICAxConfig          axConfig;
};

Mind the space after axConfig. I would like to keep that as it is, even 
if it is inconsistent :-(



Maybe there is more, but these are the most prominent problems.
If you could comment on any or all of these issues whether it might be 
possible to change the formatter to do what I want?
If the formatter only sees the AST, then maybe it isn't possible at all 
to retain the whitespace as it is?

BTW: Please, don't give me advice about good style, this is a bunch of 
legacy code, it is as it is. And we want to keep it that way, to reduce 
maintenance in our code repository to a minimum.
But not being ale to use the formatter of CDT would render Eclipse/CDT 
less powerful than XEmacs, which would be a shame.

Thanks in advance,
     Achim

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top