QM  7.0.0
Model-Based Design Tool
Loading...
Searching...
No Matches
Code Engineering

Working with Transitions to HistoryWorking with Directories

This Code Engineering section covers the following subjects:

Code engineering** is the process of designing, implementing, and maintaining source code. This section describes how QM™ can assist you in this process by providing a unique approach to modeling the structure and content of the generated source code, also known as the "physical design" as defined below:

Note
Physical design is the decomposition of the source code into directories and files, such as header files (.h files) and implementation files (.c or .cpp files), as well as "makefiles", build scripts, etc. The critical aspect of physical design is managing the inter-dependencies among the source code modules, as well as an information hiding policy to expose only the desired interfaces in the header files. Additionally, physical design of automatically generated source code must also afford a sufficiently flexible way of interfacing with hand-crafted code or any existing 3rd-party code.

Physical Design

In QM™, directories and files are first-class model elements, so the physical design is an integral part of the model, just as the logical design is. This approach makes QM™ a unique tool on the market that allows you to explicitly perform physical design of the generated code as an integral part of the modeling process (as opposed to tweaking the code generator or adjusting hundreds of parameters of a "model compiler").

Remarks
If you have used other modeling tools, the QM™ approach might feel like turning automatic code generation upside down↑ because QM™ does not impose any code structure by itself, but rather gives you the complete control of what is being generated. In contrast, most other modeling tools on the market use an implicit and inflexible physical design, in which, for example, each class generates a <class-name>.h header file and <class-name>.c/.cpp implementation file.

The main enabler of the explicit physical design is representing directories and files as model items that can be added to the model and edited as any other parts of the model. But, it is critical to understand that the directories and files in the model are not the actual directories and files on disk. Rather, you should think of these model items as "templates" that the QM™ code generator uses to create the actual directories and files on your disk. (The word "template" here should not be confused with the "C++ templates"!)

Note
QM™ supports also External Files, which combine the user-provided code with sections of generated-code. This merging of a file-template with generated-code is achieved by clearly delimiting the generated-sections with special comments. Such External Files can be edited inside any editor/IDE of choice and are not editable inside QM.

The following picture shows an example of a directory-"template" and some file-"templates" in QM™. The file-"template" is shown both in the Model Explorer and in the MDI window:

Directory and file templates in a QM model

The following picture shows how the directory-"template" and file-"templates" in the model generate the physical directory and files on disk. The code generation process is depicted as arrows from the model items to the files on disk.

Code generation uses the directory and file templates to create directories and files on disk
Note
The model items for modeling directories and files were called in this section directory-"template" and file-"template", respectively, so that you can get used to distinguishing the model items from the physical directories and files on your disk. In the following sections, however, the model items will be simply referred to directories and files, with the understanding that a model can hold only the "templates" for directories and files.

Compliance with MISRA-C/C++

The parts of code generated by QM™ are compliant with the industry safe coding standards for C and C++. Specifically, the QM code generator for the C language emits code compliant with the MISRA-C:2023↑ and the QM code generator for the C++ language emits code compliant with the MISRA-C++:2023↑.

Note
Of course, the compliance with any coding standard, such as MISRA, can be guaranteed only for parts of code actually created by the tool. The other parts of the code, such as code copied from the file-templates or action code attached to state machines, is provided externally to the tool. Such code might not be compliant with the MISRA rules.

Working with Transitions to HistoryWorking with Directories