Coding Style Configuration (DATAFLOW Code)

by Marco Wuelser

 

The DATAFLOW Code Generator can be configured to generate code that fits a variety of different coding styles. These settings are language independent, but not all may be applicable to a certain target language.

White spaces

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

White Space Configuration

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

 

 

 

Indentations

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

Indentation Configuration

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

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

Padding Configuration

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

File Headers

The file headers can be configured for the following types of files independent of each other:

  • Header files
  • Source Files
  • Test Files

File Header Configuration

The header templates support placeholders that will be expanded on code generation:

File Header Placeholders

The placeholders that can be used in the file header are shown in the table below:

Placeholder Replaced with Example Remark
INPUT_FILE Intermediate filename (*.dff)
dataflow_mySystem_StartupController.dff
Will be the same for all files of an artifact, e.g. AP.h, AP.cpp, Handler.h, Handler.cpp and Test.cpp
BUILDER_TIMESTAMP Date/Time of code generation in ISO format
2021-10-04 10:53:38
Will be the same for all files generated together.
BUILDER_VERSION Code generator version
2.1.5.0
This may differ from the DATAFLOW Studio/Designer version.
BUILDER_USER User account that performed the code generation
wuelser@imt.ch
 
GENERATOR_LANGUAGE Selected language including variants
CPP14
 
GENERATOR_PLATFORM Target platform
STM32_F103_MD
 
GENERATOR_RUNTIME Runtime type / architecture
ARM_CORTEX_M3
 
GENERATOR_RUNTIME_VERSION Runtime version the code was generated for.
2.7.1.0
 

Documentation Comments

The generated documentation comments can be configured with the following options:

Documentation Configuration

Documentation Style

The documentation style configuration defines the format for documentation comments. Such comments are generated for classes, members and methods based on the element description defined in the DATAFLOW Model.

Javadoc Documentation Style

Genertes documentation commens in the Javadoc format that can be parsed by doxygen.

Javadoc Documentation Style Configuration

/**
* Copy constructor.
* @param other The copied instance.
*/
MyProtocolProtocol ( const MyProtocolProtocol& other );

Qt Documentation Style

Generates documentation comments in the Qt format that can be parsed by doxygen.

Qt Documentation Style Configuration

/*!
* Copy constructor.
* \param other The copied instance.
*/
MyProtocolProtocol(const MyProtocolProtocol& other);

XML Documentation Style

Generates documentation comments in XML format that is better suited to be parsed by custom tools.

XML Documentation Style Configuration

/// <summary>
/// Copy constructor.
/// </summary>
/// <param name="other">The copied instance.</param>
MyProtocolProtocol(const MyProtocolProtocol& other);

 

Static Code Analyzer Excludes

The static code checker suppression configuration options of the code generator are described in the article C++ Static Code Checker Support.

 

 

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

Required Module: DATAFLOW Code, DATAFLOW Frames

Go back