Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are the best prettyprint options for C++ code?
    primarykey
    data
    text
    <p>My partner and I are working on a prettyprinter for C++ code. The tool parses input C++ code 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.</p> <p>Thanks, Joe</p> <p>Below are some of the current options (sorry for the length):</p> <hr> <h1>1. Control Blocks</h1> <hr> <h2>1.1 IndentString </h2> <hr> <p>Define the white space string that’s used for each indent.</p> <p>Example:</p> <p>• IndentString “ ”</p> <pre><code>void f () { int a; } </code></pre> <p>• IndentString “\t”</p> <pre><code>void f () { int m; } </code></pre> <hr> <h2>1.2 OpenBraceLocation </h2> <hr> <p>Three options are: “EndOfLine”, “NextLine”, or “NextLineAsWellAsCloseParen”</p> <p>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.</p> <p>Applies to if, while, for, switch and do-while statements.</p> <p>If not present the “EndOfLine” option is used.</p> <p>Example:</p> <p>• OpenBraceLocation EndOfLine</p> <pre><code>if(val){ val++; } </code></pre> <p>• OpenBraceLocation NextLine</p> <pre><code>if(val) { val++; } </code></pre> <p>• OpenBraceLocation NextLineAsWellAsCloseParen</p> <pre><code>if(val ){ val++; } </code></pre> <hr> <h2>1.3 NoBracesAroundSingleStatementBlock</h2> <hr> <p>Braces are removed from statement blocks that have only one statement. This option applies to do-while, for, if, and while blocks. </p> <p>Example:</p> <p>• NoBracesAroundSingleStatementBlock is present</p> <pre><code>if(a) func(); </code></pre> <p>• NoBracesAroundSingleStatementBlock is not present</p> <pre><code>if(a) { func(); } </code></pre> <hr> <h1>2. Classes</h1> <hr> <h2>2.1 virtualQualifier </h2> <hr> <p>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.</p> <p>Example :</p> <p>• virtualQualifier Everwhere</p> <pre><code>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); </code></pre> <p>• virtualQualifier Minimalist</p> <pre><code>class Base { virtual void f(int a); } class Derived : public Base { void f( int a); class MostDerived : public Derived { void f( int a); </code></pre> <hr> <h2>2.2 SortClassMembers </h2> <hr> <p>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.</p> <p>Example:</p> <p>• SortClassMembers Data/Functions Access Alpha</p> <pre><code>class Compiler { private: string inputFileName; public: Compiler( string const &amp; inputFileName_); genOutput( string const &amp; outputFileName_); private: analyze(); emitCode( string const &amp; ); parse(); tokenize( string const &amp; inputFileName_); } </code></pre> <p>• SortClassMembers Access Functions/Data Alpha</p> <pre><code>class C { public: Compiler( string const &amp; inputFileName_); genOutput( string const &amp; outputFileName_); private: analyze(); emitCode( string const &amp; ); parse(); tokenize( string const &amp; inputFileName_); private: string inputFileName; } </code></pre> <p>• SortClassMembers Access Alpha</p> <pre><code>class C { public: Compiler( string const &amp; inputFileName_); genOutput( string const &amp; outputFileName_); private: analyze(); emitCode( string const &amp; ); string inputFileName; parse(); tokenize( string const &amp; inputFileName_); } </code></pre> <hr> <h1>3. Files</h1> <hr> <h2>3.1 MaxLineWidth </h2> <hr> <p>Define the maximum line width. PrettyC++ will intelligently wrap longer lines if possible.</p> <p>Example:</p> <p>• MaxLineWidth 80</p> <pre><code>int x = 123456789; </code></pre> <p>• MaxLineWidth 10</p> <pre><code>int x = 123456789; </code></pre> <hr> <h2>3.2 constLocation </h2> <hr> <p>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.</p> <p>Example :</p> <p>• constLocation Before</p> <pre><code>const int x; </code></pre> <p>• constLocation After</p> <pre><code>int const x; </code></pre> <hr> <h1>4. Names</h1> <hr> <h2>4.1 AllNamesStartCase </h2> <hr> <p>Options are “LowerCase” or “UpperCase”.</p> <p>Example:</p> <p>• AllNamesStartCase LowerCase </p> <pre><code>int variable = 123456789; </code></pre> <p>• AllNamesStartCase UpperCase</p> <pre><code>int Variable = 123456789; </code></pre> <hr> <h2>4.2 AllNamesDelimitWords </h2> <hr> <p>Options are “CaseDelimited” or “UnderscoreDelimited”. Words are identified by as either starting with a capital letter or following an underscore.</p> <p>Example:</p> <p>• AllNamesDelimitWords CaseDelimited</p> <pre><code>int myVariable = 123456789; </code></pre> <p>• AllNamesDelimitWords UnderscoreDelimited</p> <pre><code>int my_variable = 123456789; </code></pre> <hr> <h2>4.3 FunctionNamesStartCase </h2> <hr> <p>Options are “LowerCase” or “UpperCase”.</p> <p>Example:</p> <p>• FunctionNamesStartCase LowerCase </p> <pre><code>void function() { return; } </code></pre> <p>• FunctionNamesStartCase UpperCase</p> <pre><code>void Function() { return; } </code></pre> <hr> <h2>4.4 FunctionNamesDelimitWords </h2> <hr> <p>Options are “CaseDelimited” or “UnderscoreDelimited”. Words are identified by as either starting with a capital letter or following an underscore.</p> <p>Example:</p> <p>• FunctionNamesDelimitWords CaseDelimited</p> <pre><code>void myFunction() { return; } </code></pre> <p>• FunctionNamesDelimitWords UnderscoreDelimited</p> <pre><code>void my_function() { return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload