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:
Brace style
Defines when line breaks are inserted into the generated code in relation to braces.
KR Brace StyleIn KR Brace style, all opening braces are placed on the same line.
|
Allman Brace StyleIn Allman Brace style, all opening braces are placed on a new line.
|
IMT Brace StyleIn IMT Brace style, all opening braces are placed on the same line.
|
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 tabsExample with 2 tabs per indent:
|
Indent with spacesExample with 4 spaces per indent:
|
Line EndingsThe 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 EndingsFor Windows line endings, an CR followed by an LF character is used:
|
Unix Line EndingsFor Unix line endings, an LF character is used:
|
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:
Namespace Content IndentIndents namespace contents by the given number of levels in relation to the parent block. Example for C++ with indent of 2 spaces: // level 0
|
Class Content IndentIndents class contents by the given number of levels in relation to the parent block. Example for C++ with indent of 2 spaces: // level 0
|
Other Block IndentIndents 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
|
Brace IndentIndents braces by the given number of levels in relation to the parent block. Example with indent of 2 spaces and allman style: // level 0
|
Access Specifier IndentIndents 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
|
Case Label IndentIndents 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
|
Case Content IndentIndents 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
|
Padding
The placement of white spaces before and after certain symbols in the generated code can be configured as well.
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 PaddingAdds spaces before and after braces: if(a){c();}; // no brace padding Before argument and after argument have no effect. C++ Initializers use the specific style below and ignore this style.
|
Bracket PaddingAdd spaces before and after brackets: int a[2]; // no bracket padding When a bracket contains coma seperated arguments, spaces are added before and after the coma: int a[2,3,4]; // no bracket padding
|
Parenthese PaddingAdd spaces before and after parentheses: void a(int a){ // no parenthese padding 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
|
Initializer PaddingAdd spaces before and after braces in C++ initializer: int a={1}; // no initializer padding When a parentheses contains coma separated argument, spaces are added before and after the coma: int a[]={1,2,3}; // no initializer padding
|
Operator PaddingAdd spaces before and after operators: int a=b+c; // no operator padding
|
Keyword PaddingAdd spaces before and after keywords: }else if(a){ // no 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
The header templates support placeholders that will be expanded on code generation:
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 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 StyleGenertes documentation commens in the Javadoc format that can be parsed by doxygen. /** |
Qt Documentation StyleGenerates documentation comments in the Qt format that can be parsed by doxygen. /*! |
XML Documentation StyleGenerates documentation comments in XML format that is better suited to be parsed by custom tools. /// <summary> |
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