QM  4.0.0
Code Engineering

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 aspects of physical design is managing the inter-dependencies among the source code modules as well as 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 a "model compiler").

Note
If you have used other modeling tools, the QM™ approach might feel like turning 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 <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"!)

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:

ce_phys.png
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.

ce_disk.png
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.

MISRA Compliance

The parts of code generated by QM™ are compliant with the Motor Industry Software Reliability Association (MISRA) Guidelines. Specifically, the QM code generator for the C language emits code compliant with the MISRA C:2004 and the QM code generator for the C++ language emits code compliant with the MISRA C++:2008.

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.

The other code engineering tasks described in this section include:


Next: Working with Directories