Coding Style Configuration (DATAFLOW Code)

by Marco Wuelser

 

This Reference Article has been written for Version 2.1 of the DATAFLOW Software. For Previous Releases use the version selection in the navigation bar at the top of this page.


This Tab is part of Build Configuration Page in the Project Settings dialog.

 

Tab Description

The Coding Style Page in the Build Configuration is used to configure the generate code so that it fits a variety of different coding styles. These settings are language independent, but not all may be applicable to a certain target language.

 

See the C++ Code Generation article for an overview on code generation.

 

Tab Actions

In addition, a reset button is provided. This will reset all style configuration to the default settings if clicked.

This button sets all coding style configuration settings to the default value.

 

Tab Groups

The page shows the following groups in Advanced mode:

  • Whitespaces
  • Indent Levels (A)
  • Padding (A)

For each group, if an option is only shown in advanced mode, it will be marked with (A).

 

Whitespaces Group

The used white spaces and line breaks can be defined for the generated code:

Brace Style

This field defines the brace style for all generated code. Available options are:

  • K&R
  • Allman
  • IMT (Modified K&R)
Indent with Tabs
When this field is checked, all generated indents will use tabs instead of spaces.
Number of Indents
This field defines the number of spaces (or tabs) used for a single indent.
Line Endings
This field defines the line ending format (UNIX or Windows) used for all generated code files.
Newline after Constructor Initializer
Adds a newline after the constructor initializer and befor the opening brace for C++ source code files with a class constructor.

 

Brace style

Defines when line breaks are inserted into the generated code in relation to braces.

KR Brace Style

In KR Brace style, all opening braces are placed on the same line.
Keywords after braces are placed on the same line.

KR Style Example

 

Allman Brace Style

In Allman Brace style, all opening braces are placed on a new line.
Keywords after braces are placed on a new line.

Allman Style Example

 

IMT Brace Style

In IMT Brace style, all opening braces are placed on the same line.
Keywords after braces are placed on a new line.

IMT Style Example

 

Indents

Defines if indention is performed with tabs or spaces. It is also possible to adjust the number of tabs or spaces used for a single indent.

Indent with tabs

Example with 2 tabs per indent:

Indent with Tabs Configuration

Indent with Tabs Example

Indent with spaces

Example with 4 spaces per indent:

Indent with Spaces Configuration

Indent with Spaces Example

Line Endings

The line endings can be configured to use windows or unit style line endings. Generated code files will always end with a newline to avoid issues with command line based tools.

Windows Line Endings

For Windows line endings, an CR followed by an LF character is used:

Windows Line Ending Configuration

Windows Line Ending Example

Unix Line Endings

For Unix line endings, an LF character is used:

Unix Line Ending Configuration

Unix Line Ending Example

 

Indent Levels Group (A)

The number of indents (see white spaces for the configuration of a singe indent) can be defined for various elements of the generated code:

Namespace Contents (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Class Contents (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Other Block Contents (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Braces (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Access Specifiers (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Case Labels (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Case Contents (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.
Initializer Lists (A)
The indent level indicates how many indent levels are added for a certain code section. Each indent level is equal to the number of white spaces configured above.

 

Namespace Content Indent

Indents namespace contents by the given number of levels in relation to the parent block.

Example for C++ with indent of 2 spaces:

// level 0
namespace dataflow{
int a;
}

// level 1
namespace dataflow{
int a;
}

// level 2
namespace dataflow{
int a;
}

 

Class Content Indent

Indents class contents by the given number of levels in relation to the parent block.

Example for C++ with indent of 2 spaces:

// level 0
class A{
public:
A();
};

// level 1
class A{
public:
A();
};

// level 2
class A{
public:
A();
};

 

Other Block Indent

Indents blocks contents that are neither a class or namspace (e.g. function, if, else, ...) by the given number of levels in relation to the parent block.

Example for C++ with indent of 2 spaces:

// level 0
void a(int b){
if (b == 0) {
c();
}
else {
d();
}
}

// level 1
void a(int b){
if (b == 0) {
c();
}
else {
d();
}
}

// level 2
void a(int b){
if (b == 0) {
c();
}
else {
d();
}
}

 

Brace Indent

Indents braces by the given number of levels in relation to the parent block.

Example with indent of 2 spaces and allman style:

// level 0
void a(int b)
{
if (b == 0)
{
c();
}
}

// level 1
void a(int b)
{
if (b == 0)
{
c();
}
}

// level 2
void a(int b)
{
if (b == 0)
{
c();
}
}

 

Access Specifier Indent

Indents c++ access specifiers in classes by the given number of levels in relation to the class contents.

Example with indent of 2 spaces:

// level 0
class A{
public:
A();
};

// level 1
class A{
public:
A();
};

// level 2
class A{
public:
A();
};

 

Case Label Indent

Indents case labels in switch case blocks by the given number of levels in relation to the switch contents.

Example with indent of 2 spaces:

// level 0
switch(a){
case 1:
break;
default:
break;
}

// level 1
switch(a){
case 1:
break;
default:
break;
}

// level 2
switch(a){
case 1:
break;
default:
break;
}

 

Case Content Indent

Indents case contents in switch case blocks by the given number of levels in relation to the switch contents.

Example with indent of 2 spaces:

// level 0
switch(a){
case 1:
break;
default:
break;
}

// level 1
switch(a){
case 1:
break;
default:
break;
}

// level 2
switch(a){
case 1:
break;
default:
break;
}

 

 

Padding Group (A)

The placement of white spaces before and after certain symbols in the generated code can be configured as well.

Braces (A)

Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol. For lists, adding a space before, in between and after arguments can also be enabled.

The code generator will merge multiple spaces into one, e.g. when there is a space after an open parentheses and one before the first argument.

Brackets (A)
Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol. For lists, adding a space before, in between and after arguments can also be enabled.
Parentheses (A)
Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol. For lists, adding a space before, in between and after arguments can also be enabled.
Angle Brackets (A)
Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol. For lists, adding a space before, in between and after arguments can also be enabled.
Initializers (A)
Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol. For lists, adding a space before, in between and after arguments can also be enabled.
Operators (A)
Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol.
Keywords (A)
Defines the padding for the given code symbol. Padding adds spaces before and/or after the symbol.
Align Enumerators (A)
Adds additional spaces to align all enumeration values on the same column.
Align Identifiers (A)
Adds additional spaces to align all identifier values on the same column.

 

The code generator will not generate multiple spaces in a row (except for indentations, see above). If two required padding spaces intersect, they are merged to a single space. The generator will also avoid trailing white-spaces (white-spaces at the end of a line followed by a newline) and white-spaces before a semicolon.

Brace Padding

Adds spaces before and after braces:

if(a){c();};      // no brace padding
if(a) {c();}; // brace padding before open
if(a){ c();}; // brace padding after open
if(a){c(); }; // brace padding before close
if(a) { c(); }; // all brace padding together

Before argument and after argument have no effect. C++ Initializers use the specific style below and ignore this style.

 

Bracket Padding

Add spaces before and after brackets:

int a[2];     // no bracket padding
int a [2]; // bracket padding before open
int a[ 2]; // bracket padding after open
int a[2 ]; // bracket padding before close
int a [ 2 ]; // all bracket padding together

When a bracket contains coma seperated arguments, spaces are added before and after the coma:

int a[2,3,4];         // no bracket padding
int a[2 ,3 ,4]; // bracket padding before coma
int a[2, 3, 4]; // bracket padding after coma
int a[2 , 3 , 4]; // bracket padding before and after coma
int a [ 2 , 3 , 4 ]; // all bracket padding together

 

Parenthese Padding

Add spaces before and after parentheses:

void a(int a){        // no parenthese padding
void a (int a){ // parenthese padding before open
void a( int a){ // parenthese padding after open
void a(int a ){ // parenthese padding before close
void a(int a) { // parenthese padding after close
void a ( int a ) { // all parenthese padding together

When a parenthese contains coma seperated arguments, spaces are added before and after the coma:

void a(int a,bool b,float c){          // no parenthese padding
void a(int a ,bool b ,float c){ // parenthese padding before coma
void a(int a, bool b, float c){ // parenthese padding after coma
void a(int a , bool b , float c){ // parenthese padding before and after coma
void a ( int a , bool b , float c ) { // all parenthese padding together

 

Initializer Padding

Add spaces before and after braces in C++ initializer:

int a={1};     // no initializer padding
int a= {1}; // initializer padding before open
int a={ 1}; // initializer padding after open
int a={1 }; // initializer padding before close
int a={1}; // initializer padding after close (ignored because of semicolon)
int a= { 1 }; // all initializer padding together

When a parentheses contains coma separated argument, spaces are added before and after the coma:

int a[]={1,2,3};         // no initializer padding
int a[]={1 ,2 ,3}; // initializer padding before coma
int a[]={1, 2, 3}; // initializer padding after coma
int a[]={1 , 2 , 3}; // initializer padding before and after coma
int a[]= { 1 , 2 , 3 }; // all initializer padding together

 

Operator Padding

Add spaces before and after operators:

 int a=b+c;      // no operator padding
int a =b +c; // operator padding before
int a= b+ c; // all operator padding after
int a = b + c; // all operator padding

 

Keyword Padding

Add spaces before and after keywords:

 }else if(a){    // no keyword padding
} else if(a){ // keyword padding before
}else if (a){ // keyword padding after
} else if (a){ // all keyword padding

 

Required Module: DATAFLOW Code

This Article has been written based on V1.6.1 of the DATAFLOW Designer software. 
Latest update 2021-10-15 by WAA.

Go back