[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] Problems with code formatter and legacy code - what is possible at all?
|
Nobody with some internal formatter knowledge? Please, just give me a
hint like "yes, go for it" or "don't even bother, won't work". Thanks.
Achim wrote on 2009-04-06 13:19:
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