Hi All,
My partner and I are working on a prettyprinter for C++. The tool parses C++ and prints the resulting AST, so we have quite a bit of flexibility. We've implemented a few options for the user to control the output and now we're looking for opinions about the most important options. If you could take a look at our current (below) and then tell us what you like/dislike, what else should be there, etc. that would be great.
Thanks, Joe
Below are some of the current options (sorry for the length):
1. Control Blocks
1.1 IndentString
Define the white space string that’s used for each indent.
Example:
• IndentString “ ”
void f ()
{
int a;
}
• IndentString “\t”
void f ()
{
int m;
}
1.2 OpenBraceLocation
Three options are: “EndOfLine”, “NextLine”, or “NextLineAsWellAsCloseParen”
Start the open braces on the same or next line as the keyword that it’s associated with. Last option moves the close paren prior to the open brace if it exists to the next line as well.
Applies to if, while, for, switch and do-while statements.
If not present the “EndOfLine” option is used.
Example:
• OpenBraceLocation EndOfLine
if(val){
val++;
}
• OpenBraceLocation NextLine
if(val)
{
val++;
}
• OpenBraceLocation NextLineAsWellAsCloseParen
if(val
){
val++;
}
1.3 NoBracesAroundSingleStatementBlock
Braces are removed from statement blocks that have only one statement. This option applies to do-while, for, if, and while blocks.
Example:
• NoBracesAroundSingleStatementBlock is present
if(a)
func();
• NoBracesAroundSingleStatementBlock is not present
if(a)
{
func();
}
2. Classes
2.1 virtualQualifier
The options are: “Everywhere” or “Minimalist”. When “Everywhere” is used the keyword “virtual” appears in all derived classes in front of the function declared to be virtual in the base class. With “Minimalist” it only appears in the base class.
Example :
• virtualQualifier Everwhere
class Base
{
virtual void f(int a);
}
class Derived : public Base
{
virtual void f( int a);
class MostDerived : public Derived
{
virtual void f( int a);
• virtualQualifier Minimalist
class Base
{
virtual void f(int a);
}
class Derived : public Base
{
void f( int a);
class MostDerived : public Derived
{
void f( int a);
2.2 SortClassMembers
The level options are “Access”, “Data/Functions” or “Functions/Data”, and “Alpha”. If no level-option is provided or the SortClassMember is not present the order of the members is unchanged.
Example:
• SortClassMembers Data/Functions Access Alpha
class Compiler
{
private:
string inputFileName;
public:
Compiler( string const & inputFileName_);
genOutput( string const & outputFileName_);
private:
analyze();
emitCode( string const & );
parse();
tokenize( string const & inputFileName_);
}
• SortClassMembers Access Functions/Data Alpha
class C
{
public:
Compiler( string const & inputFileName_);
genOutput( string const & outputFileName_);
private:
analyze();
emitCode( string const & );
parse();
tokenize( string const & inputFileName_);
private:
string inputFileName;
}
• SortClassMembers Access Alpha
class C
{
public:
Compiler( string const & inputFileName_);
genOutput( string const & outputFileName_);
private:
analyze();
emitCode( string const & );
string inputFileName;
parse();
tokenize( string const & inputFileName_);
}
3. Files
3.1 MaxLineWidth
Define the maximum line width. PrettyC++ will intelligently wrap longer lines if possible.
Example:
• MaxLineWidth 80
int x = 123456789;
• MaxLineWidth 10
int x =
123456789;
3.2 constLocation
The options are “Before” or “After”. The Before option places the const keyword before the type specifier. The After option places the const keyword after the type specifier.
Example :
• constLocation Before
const int x;
• constLocation After
int const x;
4. Names
4.1 AllNamesStartCase
Options are “LowerCase” or “UpperCase”.
Example:
• AllNamesStartCase LowerCase
int variable = 123456789;
• AllNamesStartCase UpperCase
int Variable = 123456789;
4.2 AllNamesDelimitWords
Options are “CaseDelimited” or “UnderscoreDelimited”. Words are identified by as either starting with a capital letter or following an underscore.
Example:
• AllNamesDelimitWords CaseDelimited
int myVariable = 123456789;
• AllNamesDelimitWords UnderscoreDelimited
int my_variable = 123456789;
4.3 FunctionNamesStartCase
Options are “LowerCase” or “UpperCase”.
Example:
• FunctionNamesStartCase LowerCase
void function() { return; }
• FunctionNamesStartCase UpperCase
void Function() { return; }
4.4 FunctionNamesDelimitWords
Options are “CaseDelimited” or “UnderscoreDelimited”. Words are identified by as either starting with a capital letter or following an underscore.
Example:
• FunctionNamesDelimitWords CaseDelimited
void myFunction() { return; }
• FunctionNamesDelimitWords UnderscoreDelimited
void my_function() { return; }