UML and SysML to C - Class Code Generator Specification

This section describes the UML and SysML to C code generation for structured classes.

This page discusses:

Glossary

Acronym Definition
SPO Software Production Operation
BL Behavior Layer
ML Middleware Layer
BSM Behavior Specific Middleware
TSM Target Specific Middleware

Referenced Documents

Document Internal Reference
Targeted Application Concepts [1]
C Code Architecture Specification [2]
UML and SysML to C - Software Production Operation Specification [3]
UML and SysML to C - Interface Code Generation Specifications [4]
UML and SysML to C - Statemachine Code Generator Specification [5]

General Concepts

UML class code generation is part of the components generation as presented in [1] is invoked during execution of UML to C operation as presented in [3]

This document focuses on the C code generation for the class model.

In addition of this general introduction, it is important to remind that the C code generator generates C code from UML classes. UML classes are dedicated to object-oriented programming – OOP - which is not the case of the C language.

The concepts of OOP are the following ones:

  • Encapsulation - An object encapsulates properties and operations.
  • Abstraction - Capability to hide internal members and implementation to concentrate.
  • Inheritance - An object can inherit from another object to refine or define its behavior.
  • Polymorphism - Capability to substitute an object by another one as soon as they share the same interface.

Generated C code supports the concepts of the object-oriented programming using a specific implementation such as:

Encapsulation

A structure is created for the class.

Properties are part of the structure.

Operations are declared as follows: All functions have a prefix with the name of the class and take as the first parameter a pointer to the structure representing the class.

Example of encapsulation

Abstraction

Abstraction is possible by hiding some private operations using the keyword static of C.

On the opposite, protected operations cannot be hidden and the visibility of properties cannot be controlled. Nevertheless, documentation is inserted to inform of the visibility of a member.

Inheritance

In case of inheritance, a variable representing the inherited class is inserted in the structure of the class.

In addition, constructors are generated and called to instantiate each element.

Here is an example of a class Rectangle, which inherits from a class Shape.

Declaration of a rectangle

Implementation of rectangle constructor

Polymorphism

Polymorphism is supported using a mechanism of virtual table.

Supported Elements

Here is an exhaustive list of elements used by the code generator to produce the code with a summary of the purpose and impact.

Element Description
Attached File File attached to a UML class. This file is extracted during the code generation.
Class Element for which a .c file is generated.
Association An Association is a relation between two classes. It can be directed or bidirectional. It can be public, protected, or private.
Aggregation An Aggregation is a kind of association with a meaning of containment. It can be directed or bidirectional. It can be public, protected, or private.
Composition A Composition means that the root class is composed and another class. It can be directed or bidirectional. It can be public, protected, or private.
UML Data Type SysML Value Type Type of a Property, ValueProperty, Argument, or Flow Port.
Flow Property A Flow Property is a member of an Interface Block referenced by a Proxy Port and representing a data transmitted through that port.
Generalization A Class can inherit from another class
Interface Realization Relation describing the realization of one or several interfaces by a class. Each realized interface is embedded in the class structure and connected through a dedicated virtual table and thunk functions.
Usage An object uses another one. Generate an include.
Dependency Dependency of a class to another class or interface
Operation There are two ways to use the Operation element: - Member of a class representing a method. - Member of an Interface or an Interface Block
Property There are two different purposes for the property element: - A property can be a member of a class representing an attribute. It can be public, protected, or private. - A property can be a member of an Interface referenced by a port and representing a data transmitted through that port.
Classifier Behavior A behavior can be a State Machine, an Activity, or an Opaque Behavior. The behavior can be in a class itself and attached to an operation.
Port Proxy Port Flow Port Element describing a data exchange point with other classes.
Interface There are two different purposes for the interface element: - Element describing elements transmitted through a Port element - Abstract class that can be realized by another class (use the Interface Realization)
Interface Block Element describing elements transmitted through a Proxy Port element
Signal Signal is a message fired and received between behaviors.
Artifact represents a library that can be either user or system

Code Generator Specification

This section is divided in 2 parts:

  • The generated files specification
  • The behavior specification

Files Specifications

Generated code class elements are composed of two files for each class:

  • <ClassName>.h
  • <ClassName>.c
  • internal_types.h

General requirements related to file content are described in [2].

<ClassName>.h

<ClassName>.h header file describes the content of a class entity. This file declares all the elements associated with a class.

File <ClassName>.h is generated for each UML class element involved in the code generation.

A macro is generated to read the content of the file as a C declaration if it is included directly or indirectly from a C++ file.

Rationale: During compilation, information of this file must be treated as C information.

/* Macro to prevent error if file is included from a Cpp file */
#ifdef __cplusplus
extern "C" {
#endif

Example: Cpp macro

#include to the file <Top_ClassName>_types.h is generated for the selected UML also known as top class. Requirement not supported – ZA7

<Top_ClassName>_types.h file contains the types used at interface with top UML class.

#include to the file internal_types.h is generated.

internal_types.h file contains the types used in the selected UML class and its subelements.

For every other type the current class depends on — through inheritance, composition, aggregation, association or usage — the header generates either an #include or a forward declaration, depending on what the declaration requires:

  • an #include when the definition is required: a base class, a member held by value, an array of values, and any type that cannot be declared ahead of its definition (an enumeration, a type alias, a record type such as a communication event);
  • a forward declaration of the struct when the name is enough: a member declared as a pointer — which is the case of every association, composition and aggregation relation — as well as the parameter and return types of the declared functions.

Every type that is only announced in the header is included in the corresponding implementation file, so the generated code never depends on an indirect inclusion to compile.

A user-specific section is generated to give the opportunity to insert additional includes

/**********************************************************************
 * Includes declaration
 **********************************************************************/

#include "LockManager_internal_types.h"
#include "LockableElement.h"

/* BEG_USER_CODE(header) do not remove */
/* Add your includes here */
/* END_USER_CODE(header) do not remove */

Example: Includes section

See chapter 9.2 for more details.

Note that namespace that is a CPP concept is not supported by the C code generation.

A forward declaration of the struct is generated prior to structures definition. The forward declarations are grouped in a single section, after every #include directive and before the type definitions; the struct of the current class is declared there as well, which allows a structure to refer to itself.

A structure identified as a virtual table is generated to contain the function pointers for each operation of the class.

The virtual table enables the implementation of interfaces and the generalization of classes.

Declaration is done in section VIRTUAL TABLE MEMBERS SECTION. To get more information on the declaration, see the dedicated section in chapter 9.2.

If the Memory Optimization option is set to Prefer ROM, a const structure is generated containing the const variables generated from properties declared as read-only and the const variables generated from relations with a fixed multiplicity.

The const structure enables the declaration of const elements in the ROM section to reduce RAM consumption.

If Memory Optimization option is set to Prefer ROM, the 3 first fields of the const structure are:

  • A const pointer to the virtual table,
  • A const pointer to the structure of the class,
  • A function pointer to the default destructor.

Const properties are generated in the const struct definition in CONST HEADER MEMBERS SECTION. To get more information on the declaration, see the dedicated section in chapter 9.2.

The class is represented by a structure. The structure is declared using the regular c declaration mechanism. To get more information on the declaration, see the dedicated section in chapter 9.2.

If the Memory Optimization option is set to none, the 2 first fields of the structure are:

  • A const pointer to the virtual table,
  • A function pointer to the default destructor.

If the Memory Optimization option is set to Prefer ROM, the first field of the structure are:

  • A const pointer to the const structure.

To get more information on the declaration, see the dedicated section in chapter 9.2.

Properties are generated in the struct definition in HEADER VARIABLE MEMBERS SECTION and HEADER CONST MEMBERS SECTION. To get more information on the declaration, see the dedicated section in chapter 9.2.

The Operations are generated as functions following the struct definition in FUNCTIONS DECLARATION SECTION. To get more information on the declaration, see the dedicated section in chapter 9.2.

In addition of the attributes declared in the class, the struct must contain extra sections depending on the model.

Extra Sections - Constraint Block Parameters Section

In the context of a SysML Constraint Block, a variable is generated for each parameter of each constraint block.

Extra Sections - Communication Interface Section

If the class contains ports or behaviors scheduled by a ExecutionType, an extra variable referencing the interface part of the class is generated.

If the Memory Optimization option is set to Prefer ROM, this section is declared in const structure, in the regular structure otherwise.

Extra Sections - Shared Variables Declaration

In the context of a SysML Block containing an Internal Block Diagram or a UML class containing a Composite Structure Diagram, a shared variable is created for each property that belongs to an Interface referenced by ports. If two ports are connected by a connector, one single shared variable is created for both sides. Variables are generated in structure in CSE – SHARED VARIABLES SECTION. To get more information on the declaration, see the dedicated section in chapter 9.2.

Shared variables is used to store data transmitted via the connectors from a port to another port.

/**********************************************************************
 * Type definition
 **********************************************************************/
/**
 * Forward declaration
 */
struct LockManager_;

typedef struct {

  <VIRTUAL TABLE MEMBERS SECTION – See chapter 9.2>

} LockManager_vtable;

/** @generated_from _19_0_3_16600ad_1654593306068_127462_42636 */    
typedef struct LockManager_ {
  /** Pointer to virtual table */
  const LockManager_vtable *vtable;

  /** Function pointer to destructor function generated automatically */
  void (*dtor)(struct LockManager_*);

  <HEADER CONST MEMBERS SECTION – See chapter 9.2>
  <HEADER VARIABLE MEMBERS SECTION – See chapter 9.2>

  /**********************************************************************
   * Constraint block parameters section
   **********************************************************************/
  <CONSTRAINT BLOCK PARAMETERS SECTION – See chapter 9.2>

  /**
   * Communication Interface structure
   * @generated_from ${class_generated_from_id}
   * @reverse_ignore
   */
  LockManager_cseItf cseItf;

  /**********************************************************************
   * Communication & Scheduling Environment - Shared variables declaration
   **********************************************************************/
  <CSE – SHARED VARIABLES SECTION – See chapter 9.2>

  /* BEG_USER_CODE(user_section) do not remove */
  /* Declare your attributes and methods here */
  /* END_USER_CODE(user_section) do not remove */

} LockManager;

<FUNCTIONS DECLARATION SECTION – See chapter 9.2>

Example: Structure declaration if memory optimization is set to none.

/**********************************************************************
 * Type definition
 **********************************************************************/
/**
 * Forward declaration
 */
struct LockManager_;

typedef struct {

  <VIRTUAL TABLE MEMBERS SECTION – See chapter 9.2>

} LockManager_vtable;

/** @generated_from _19_0_3_16600ad_1654593306068_127462_42636 */    
typedef struct {
  /** Pointer to virtual table */
  const LockManager_vtable *vtable;
  /* Pointer to variable part */
  const struct button_cls_ *varPart;

  /**
   * Function pointer to destructor function generated automatically
   */
  void (*dtor)(struct LockManager_*);

  <HEADER CONST MEMBERS SECTION – See chapter 9.2>

  /**
   * Communication Interface structure
   * @generated_from ${class_generated_from_id}
   * @reverse_ignore
   */
  LockManager_cseItf cseItf;

} LockManager_const;

typedef struct LockManager_ {
  /* Pointer to variable part */
  const LockManager_const *constPart;

  <HEADER VARIABLE MEMBERS SECTION – See chapter 9.2>

  /**********************************************************************
   * Constraint block parameters section
   **********************************************************************/
  <CONSTRAINT BLOCK PARAMETERS SECTION – See chapter 9.2>

  /**********************************************************************
   * Communication & Scheduling Environment - Shared variables declaration
   **********************************************************************/
  <CSE – SHARED VARIABLES SECTION – See chapter 9.2>

  /* BEG_USER_CODE(user_section) do not remove */
  /* Declare your attributes and methods here */
  /* END_USER_CODE(user_section) do not remove */

} LockManager;

<FUNCTIONS DECLARATION SECTION – See chapter 9.2>

Example: Structure declaration if memory optimization is set to Prefer ROM.

<Class name>.c

<ClassName>.c source file implements functions declared in the corresponding header file for a class.

File <ClassName>.c is generated for each UML class element involved in the code generation.

#include to the header file of the corresponding class is inserted.

A user-specific section is generated to give the opportunity to insert additional includes.

/**********************************************************************
 * Includes declaration
 **********************************************************************/

#include "VehicleDoorsManager.h"
#include "LockableElement.h"

/* BEG_USER_CODE(header) do not remove */
/* Add your includes here */
/* END_USER_CODE(header) do not remove */

Example: Include to header of class.

Default destructor is declared as static and a defined in the local members declaration.

Protected and private functions are declared as static and a defined in the local members declaration. The content of this section is described in chapter 9.2.

A const variable named <ClassName>_vt and typed with <ClassName>_vtable is declared and initialized for the virtual table. In addition, for each realized interface, a const variable named <ClassName>_as_<InterfaceName>_vt and typed with <InterfaceName>_vtable is declared and initialized. The content of these sections is described in chapter 9.2.

/**********************************************************************
 * Local Members Declaration 
 **********************************************************************/
/**
 * Destructor declaration
 * Generated automatically
 * @generated_from _2022x_16600ad_1673889073704_233637_17321
 * @reverse_ignore
 */
static void LockableElement_dtor(struct LockableElement_* self);

<PROTECTED AND PRIVATE FUNCTIONS SECTION – See chapter 9.2>

/** vtable variable declaration */
const LockableElement_vtable LockableElement_vt = {
  <VIRTUAL TABLE MEMBERS INITIALIZATION – See chapter 9.2>
};

A section CLASS OPERATION IMPLEMENTATION containing implemented of class operations is inserted. The content of this section is described in chapter 9.2.

/**********************************************************************
 * Functions Implementation 
 **********************************************************************/

<IMPLEMENTATION MEMBERS SECTION – See chapter 9.2>

Example: Class implementation

internal_types.h

The internal_type.h file describes the data types used by the properties and the operations in the model.

File internal_types.h is generated for the input element that is a class.

General requirements related to file content and structure are described in [2].

#include to the file stdbool_itf.h is generated.

The stdbool.h file defines bool.

Each type used by at interface level class is generated. See chapter 9.2 for more details depending on the elements.

#include \<stdbool.h\>

\<DATA TYPES DECLARATION -- See chapter 9.2\>

Example: Data types declaration

Based on the dependency between types, each type referencing another type is defined after this type.

Each type definition is protected by a #ifdef, #define, #endif mechanism.

Each type is defined by the C typedef mechanism.

/**********************************************************************
 * Data Type <type> definition
 * @generated_from <uuid>
 **********************************************************************/
#ifndef <type>_DEFINITION
#define <type>_DEFINITION
typedef <base_type> <type>;
#endif

Example: Type declaration

Semantic Code Specifications

This section describes the behavior of the code generator depending on the UML element.

Package with C++ Namespace Stereotype

The concept of namespace is not supported by C code generator.

The stereotype C++ namespace is not used by the C code generator.

Class

HEADER VARIABLE MEMBERS SECTION and HEADER CONST MEMBERS SECTION

A class is translated into several structures containing fields and operations pointers corresponding to the properties and operations of the class and a list of functions declared outside the structure. Refer to chapter <ClassName>.h for more details.

If a generalization relation is created from a class to another one, this inheritance relation is reproduced by declaring an instance of the inherited class into the structure of the class source of this generalization relation.

Generalization

The visibility is not a concept supported with C code generation. This concept is used for documentation purpose. The visibility level is printed in the comment above the variable declaration. REQ NOT YET SUPPORTED

/** @generated from: <class uuid> */
typedef struct A {
    /**
     * @brief Public Inheritance realization to class B
     * @generated_from _2022x_16600ad_1673889073704_233637_17321
     */
    B extended_class_B;
}A;

Example: Class declaration with generalization

If the class uses the stereotype C++Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)).

/** @generated from: <class uuid> */
struct __attribute__((packed)) A {
};

Example: Class declaration with packed

If a class uses the stereotype C++Aligned, and the alignment attribute is set to a valid value, and the compiler parameter is set to gcc, the generated code must include the keyword __attribute__((aligned({alignment}))).

struct __attribute__((aligned({alignment}))) A {
};

Example: Class declaration using aligned

A valid value for alignment is an integer that is a power of two.

Abstract Class

A class is abstract when all functions are defined as virtual. See virtual operation.

Friend Class

The concept of Friend class is not supported by the C code generator.

The usage of a relation applying the C++ Friend stereotype is not supported.

Global Functions and Variables
Global functions and variables

Global functions and variables are declared using an unnamed class with C++Global stereotype.

Global functions and variables are mapped to operations and attributes into an unnamed class with the stereotype «C++Global».

The generated files are named global.cpp and global.h.

Properties declared in the global class are declared directly in the file without structure.

Operations declared in the global class are declared directly in the file.

Operations declared in the global class are declared without the extra argument self like other operations that belong to a standard class.

If a global variable uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the alignment attribute is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).

int __attribute__((aligned({alignment}))) myGlobalVariable

Example: Global variable declaration using aligned

int* __attribute__((aligned({alignment}))) myGlobalVariable

Example: Global pointer declaration using aligned

A valid value for alignment is an integer that is a power of two.

If a global variable uses the stereotype C++Aligned, and the selected C version is greater than or equal to C23, and the alignment attribute is set to a valid value, the generated code must include the keyword alignas({alignment}).

alignas({alignment}) int myGlobalVariable

Example: Global variable declaration using alignas

A valid value for alignment is an integer that is a power of two.

The keywords alignas({alignment}) and __attribute__((packed)) cannot be applied simultaneously to the same type or variable. When both are defined, the generated code must use alignas({alignment}) and omit __attribute__((packed)).

Composition Relation – Black Diamond

HEADER CONST MEMBERS SECTION

if a composition relation is created from a class to another one with a multiplicity 1, a variable is created in the structure of the source class of relation to point to the target class in the const members section part.

if a composition relation is created from a class to another one as not directional, a pointer variable is created in the structure of the target class of relation to point to the source class in the const members section part.

Compositions that are not directional are not supported because of a compilation error and cyclic dependency.

Not directional composition relation

typedef struct A {
    /**
     * @brief Public attribute for composition relation to B:b
     * @generated from: _2022x_16600ad_1674047956690_871296_20640
     */
    struct B b;
}A;

Example: Variable in source class

typedef struct B {
    /**
     * @brief Public attribute for associationrelation to A:a
     * @generated from: _2022x_16600ad_1677666453655_204390_17509
     */
    struct A *a;
}B;

Example: Variable in target class for not directional relation

if a composition relation is created from a class to another one with a multiplicity fixed and greater than 1, an array of variables is created in the structure of the source class of relation to point to the target class with the size equal to the multiplicity in the const members section part.

typedef struct A {
    /**
     * @brief Public attribute for composition relation to array<B,2>:b
     * @generated from: _2022x_16600ad_1674047956690_871296_20640
     */
    struct B b[2];
}A;

Example: Composition with a multiplicity of 2

Relations with a multiplicity * are not supported.

HEADER VARIABLE MEMBERS SECTION

if a composition relation is created from a class to another one with a variable multiplicity between 2 values and upper multiplicity greater than 1, an array of variables is created in the structure of the source class of relation to point to the target class with the size equal to the multiplicity in the variable section part.

Relations with a multiplicity * are not supported.

Aggregation Relation – White Diamond

HEADER CONST MEMBERS SECTION

if an aggregation relation is created from a class to another one with a multiplicity 1, a pointer variable is created in the structure of the source class of relation to point to the target class in the const members section part.

if an aggregation relation is created from a class to another one as not directional, a pointer variable is created in the structure of the target class of relation to point to the source class.

Aggregation relation

typedef struct A {
    /**
     * @brief Public attribute for aggregation relation to B:b
     * @generated from: _2022x_16600ad_1677666453655_544305_17510
     */
    struc B *b; 
}A;

Example: Variable in source class

typedef struct B {
    /**
     * @brief Public attribute for aggregation relation to A:a
     * @generated from: _2022x_16600ad_1677666453655_204390_17509
     */
    struct A *a;
}B;

Example: Variable in target class for not directional relation

If an aggregation relation is created from a class to another one with a multiplicity fixed and greater than 1, an array of pointers is created in the structure of the source class of relation to point to the target class with the size equal to the multiplicity in the const members section part.

typedef struct A {
    /**
     * @brief Public attribute for aggregation relation to array<B,2>:b
     * @generated from: _2022x_16600ad_1677666453655_544305_17510
     */
    struct B *b[2]; 
}A;

Example: Aggregation with a multiplicity of 2

Relations with a multiplicity * are not supported.

HEADER VARIABLE MEMBERS SECTION

If an aggregation relation is created from a class to another one with a variable multiplicity between 2 values and upper multiplicity greater than 1, an array of pointers is created in the structure of the source class of relation to point to the target class with the size equal to the multiplicity in the const members section part.

Relations with a multiplicity * are not supported.

Association Relation

HEADER CONST MEMBERS SECTION

If an association relation exists between two classes with a multiplicity 1, a pointer variable is created in each class to point to the other class.

Association relation

typedef struct A {
    /**
     * @brief Public attribute for associationrelation to B:b
     * @generated from: _2022x_16600ad_1677666453655_204390_17509
     */
    struct B *b;
}A;

typedef struct B {
    /**
     * @brief Public attribute for associationrelation to A:a
     * @generated from: _2022x_16600ad_1677666453655_204390_17509
     */
    struct A *a;
}B;

Example: Association between 2 classes

if an association relation exists between 2 classes with a multiplicity fixed and greater than 1, an array of pointer is created in each class to point to the other class with the size equal to the multiplicity.

typedef struct A {
    /**
     * @brief Public attribute for associationrelation to array<B,2>:b
     * @generated from: _2022x_16600ad_1677666453655_204390_17509
     */
    struct B *b[2];
}A;

typedef struct B {
    /**
     * @brief Public attribute for association relation to array<A,2>:a
     * @generated from: _2022x_16600ad_1677666453655_204390_17509
     */
    struct A *a[2];
}B;

Example: Association between two classes with a multiplicity of 2 in both directions

Relations with a multiplicity * are not supported.

HEADER VARIABLE MEMBERS SECTION

if an association relation exists between 2 classes with a variable multiplicity and upper multiplicity greater than 1, an array of pointer is created in each class to point to the other class with the size equal to the multiplicity.

Relations with a multiplicity * are not supported.

Usage relation

A usage relation is used to declare that a class usage another element. It is translated into an include of the element in the generated code.

A usage relation can be used from a class to an interface or another class.

If a class declares a usage relation to another entity, the corresponding #include is generated.

For class object, the generated #include in the context of a usage relation is generated by adding automatically the suffix .h if the name of the element does not contain a suffix.

For interface object, the generated #include in the context of a usage relation is generated using the name of the interface.

If the C++ Include stereotype applied on the usage relation carries the value Class Forward, a forward declaration of the used struct is generated in the header instead of an #include, and the #include is generated in the implementation file. The value None generates neither.

If no C++ Include stereotype is applied on the usage relation, the generated #include is generated as a system include using <>.

If a C++ Include stereotype is applied on the usage relation, it is possible to generate a user include using “” or a system include using <>. REQ NOT SUPPORTED

Usage relation

For optimization reasons, two new stereotypes are proposed as replacement of C++Include:

“C++ Location“ stereotype applies on usage relation. It supersedes use of “C++ Include“ stereotype. It helps to specify whether used element is targeted for source header or implementation.

“C++ Kind“ stereotype applies on UML artifact. It supersedes information eventually set in “C++ Include“ stereotype.

Example: artifact with “C++IncludeKind“ set to System in Class.h

#include <Artifact.h>

Example: artifact with “C++IncludeKind“ set to User in Class.h

#include "Artifact.h"

Example: usage relation with “C++Location“ set to Header in Class.h

#include "UsedClass.h"

Example: usage relation with “C++Location“ set to Implementation in Class.c

#include "UsedClass.h"

Interface Realization

Interface realization enables a class to realize one or several interfaces. An interface is an abstract class whose operations are realized by the implementing class. Polymorphism is supported through a mechanism of virtual table: each interface and each class owns its own virtual table. A class realizing an interface is connected to the interface virtual table through dedicated thunk functions, so an object can be substituted by another one as soon as they share the same interface.

A class can realize multiple interfaces. The same mechanism is used to realize an interface and to specialize a class through a generalization relation.

HEADER VARIABLE MEMBERS SECTION

A file named <interface name>.h is generated for each realized interface and the corresponding #include is generated in the implementing class header file.

For each realized interface, a variable typed with the interface structure and named extended_class_<interface name> is generated in the structure of the implementing class.

/** @generated_from _2024x_3_1ca00d3_1747908200222_116813_4036 */
typedef struct ParentClass_ {
    /** Pointer to virtual table */
    const ParentClass_vtable *vtable;

    /** Function pointer to destructor function generated automatically */
    void (*dtor)(struct ParentClass_*);

    /** @generated_from _2024x_3_1ca00d3_1747908200223_308090_4038 */
    AnIfc extended_class_AnIfc;

    /** @generated_from _2024x_3_1ca00d3_1747908200224_329975_4039 */
    AnotherIfc extended_class_AnotherIfc;

} ParentClass;

Example: Class realizing two interfaces AnIfc and AnotherIfc

VIRTUAL TABLE MEMBERS INITIALIZATION SECTION

For each realized interface, a dedicated virtual table named <ClassName>_as_<InterfaceName>_vt and typed with <InterfaceName>_vtable is generated and initialized for the implementing class.

For each operation of a realized interface that is realized by the implementing class (i.e. an operation with the same signature), the dedicated virtual table is initialized with the corresponding thunk function (see below).

/** vtable variable declaration */
const ParentClass_vtable ParentClass_vt = {
    ParentClass_myOp2,
    ParentClass_myOp,
};

/** vtable declaration for extended class AnIfc */
const AnIfc_vtable ParentClass_as_AnIfc_vt = {
    .myOp2 = ParentClass_as_AnIfc_myOp2_thunk,
};

/** vtable declaration for extended class AnotherIfc */
const AnotherIfc_vtable ParentClass_as_AnotherIfc_vt = {
    .myOp = ParentClass_as_AnotherIfc_myOp_thunk,
};

Example: Class virtual table and one dedicated virtual table per realized interface

IMPLEMENTATION MEMBERS SECTION

For each operation of a realized interface that is realized by the implementing class, a thunk function named <ClassName>_as_<InterfaceName>_<operationName>_thunk is generated. The thunk function is registered in the dedicated virtual table <ClassName>_as_<InterfaceName>_vt.

A thunk function receives a pointer to the realized interface structure, recovers the pointer to the implementing class structure using the offsetof macro on the extended_class_<InterfaceName> member, and delegates the call to the corresponding operation of the implementing class.

/**
 * Thunk function connecting extended_class_AnIfc::myOp2 -> ParentClass::myOp2
 * @generated_from _2024x_3_1ca00d3_1747908200231_870497_4049
 */
void ParentClass_as_AnIfc_myOp2_thunk(struct AnIfc_* self){
    ParentClass *clsPtr = (ParentClass*)((char*)self - offsetof(ParentClass, extended_class_AnIfc));
    ParentClass_myOp2(clsPtr);
}

/**
 * Thunk function connecting extended_class_AnotherIfc::myOp -> ParentClass::myOp
 * @generated_from _2024x_3_1ca00d3_1747908200231_326294_4050
 */
void ParentClass_as_AnotherIfc_myOp_thunk(struct AnotherIfc_* self, const Integer /*in*/ param){
    ParentClass *clsPtr = (ParentClass*)((char*)self - offsetof(ParentClass, extended_class_AnotherIfc));
    ParentClass_myOp(clsPtr, param);
}

Example: Thunk functions delegating realized interface operations to the implementing class

Constructor

For each realized interface, the constructor of the implementing class calls the constructor of the embedded interface variable extended_class_<InterfaceName>.

void InterfaceRealizationTestClass_ctor(InterfaceRealizationTestClass* self) {

    /* Init pointer to destructor */
    self->dtor = &InterfaceRealizationTestClass_dtor;

    /* Init pointer to virtual table */
    self->vtable = &InterfaceRealizationTestClass_vt;

    /* Call extended class ParentClass constructor */
    ParentClass_ctor(&self->extended_class_ParentClass);

}

Example: Constructor initializing the embedded realized interface

Property

HEADER VARIABLE MEMBERS SECTION

Each property declared in a UML class is replicated in the generated code in the structure of the class except for const variables.

Property declaration in a class

A brief description is generated for any property describing the type and name of the variable.

Additional documentation is generated if the documentation section is a field in the model.

Type of the property is used as declared in the model.

The visibility is not a concept supported with C code generation. This concept is used for documentation purpose. The visibility level is printed in the comment above the variable declaration.

Visibility of the property is used as declared in the model.

/**
 * @brief Public attribute for composition relation to LockEnum:lockStatus
 * This is my documentation for LockControl
 * @generated_from _19_0_3_16600ad_1654594678283_920922_43338
 */
LockEnum lockStatus;

Example: Property declaration

Pointer Declaration

If a type modifier * is defined for a property, it is used to declare a pointer to a variable.

/** @generated_from _2022x_16600ad_1673889212530_542477_17485 */
Boolean *LockStatus;

Example: Pointer

List Declaration

The concept of List is not supported by the C code generator.

Array Declaration
Array configuration

if the property applies the stereotype C++ Attributes and array value is configured, variable is generated as an array<Variable Type, length>.

/**
 * @brief Public attribute array<Boolean,3>:LockStatus
 * @generated_from _2022x_16600ad_1673889212530_542477_17485
 */
Boolean LockStatus[3];

Example: Array declaration

Mutable

The concept of Mutable is not supported by C code generator.

Bit Field

The concept of bit field is not supported by the C code generator.

Extern

-

Volatile

The concept of volatile is not supported by the C code generator.

CLASS OPERATION IMPLEMENTATION

Default value is defined in the constructor of the structure as it is impossible to define default value to struct members in C.

HEADER CONST MEMBERS SECTION
Const

If the isReadOnly attribute of the property is set to true, the variable is declared as const in the CONST MEMBERS section.

/**
 * @brief Attribute Boolean:debugMode
 * @generated_from _2022x_2_1ca00d3_1686732945801_136413_17517
 */
const Boolean debugMode;

Example: Const declaration

Packed

If the property uses the stereotype C++Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)), except for bitfield, pointer and reference properties.

typedef struct ClassWithAttrPacked_ {
     * @brief <brief description>
     * @generated_from <class uuid>
     */
    int __attribute__((packed)) attributePacked;

} ClassPacked;

Example: Property declaration with packed

Aligned

If the property uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the selected C version is not greater than or equal to C23, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).

typedef struct ClassWithAttrAligned_ {
int __attribute__((aligned({alignment}))) attributeAligned;
struct MyType* __attribute__((aligned({alignment}))) x;
} ClassAligned;

Example: Property declaration using alignment

A valid value for alignment is an integer that is a power of two.

If the property uses the stereotype C++Aligned, and the selected C version is greater than or equal to C23, and the attribute alignment is set to a valid value, the generated code must include the keyword alignas({alignment}) except for bitfield and reference properties.

typedef struct ClassWithAttrAligned_ {
    alignas({alignment}) int myProperty1;
alignas({alignment}) int *myProperty2;
} ClassAligned;

Example: Property declaration using alignas

A valid value for alignment is an integer that is a power of two.

The keywords alignas({alignment}) and __attribute__((packed)) cannot be applied simultaneously to the same type or variable. When both are defined, the generated code must use alignas({alignment}) and omit __attribute__((packed)).

Operation

FUNCTIONS DECLARATION SECTION
Operation declaration in class

Each operation declared as public in a UML Class is declared in the header file after the structure representing the class object.

Each operation is declared with a prefix having the name of the class object followed by an underscore.

Each operation with the parameter isStatic set to false or not set is declared with a first parameter, which is a pointer to the structure as the first argument.

A brief description is generated for any property describing the type and name of the variable.

Additional documentation is generated if the documentation section is filled in the model.

Visibility is displayed in the comment associated with the operation as declared in the model.

/** 
 * @brief Public operation LockableElement_lockDoors
 * @generated_from _2022x_16600ad_1673944282153_805594_18447 */
Boolean LockableElement_lockDoors(struct LockableElement* self);

Example: Operation declaration

Constructor

If an operation uses the stereotype C++ Constructor, the function is declared as a constructor in the header file.

Default constructor is automatically generated for class object even if not declared in the class. This constructor is generated with the suffix _ctor. Constructor parameters are automatically calculated to enable the initialization of members if required.

A constructor defined in a class is declared with a specific suffix _user_ctor to distinguish this constructor from the ones that are automatically generated.

/**
 * @brief Public constructor
 * @generated_from _2022x_16600ad_1677492413311_524708_17320
 */
void LockableElement_user_ctor(LockableElement* self);

Example: Constructor declaration

If a class contains association relations, a default constructor is generated for each relation with an argument for the corresponding association relation as pointer to the destination of the association. The name of the constructor contains the name of the association to distinguish it.

If a class contains aggregation relations, the default constructor is generated with an argument for each aggregation relation as a pointer to the destination of the aggregation.

Default constructor is generated with the arguments for associations followed by arguments for aggregations.

/**
 * @brief Public constructor
 * @generated_from _2022x_16600ad_1677492413311_524708_17320
 */
void Root_associated_ctor(Root* self, struct Asso * asso, struct Aggreg_* aggreg;

Example: Default constructor with an association and an aggregation

Explicit Constructor

The concept of explicit constructor is not supported by the C code generator.

Destructor

A default destructor is automatically generated for a class object even if not declared in the class. This destructor is represented as a function pointer in the structure. The constructor is positioned as the first attribute of the structure.

/** @generated from: <class uuid> */
typedef struct A {
    /**
     * Function pointer to destructor function generated automatically
     */
    void (*dtor)(struct LockableElement*);
}A;

If an operation uses the stereotype C++ Destructor, the function is declared as a destructor in the header file. – Not supported – add a rule.

Getter / setter

Getter/setter can be configured by the context menu:

Getter and setter menu

Class with getter and setter of a property

Getter and setter are declared in the header file for each function declared accordingly in the model.

/**
 * @brief Setter method for attribute WindowPosition
 * this is an example of documentation from model
 * @generated from: _2022x_16600ad_1677147742721_382790_17804
 */
void Door_setWindowPosition(Door* self, ControlEnum /*in*/ windowPosition);

/**
 * @brief Getter method for attribute WindowPosition
 * @generated from: _2022x_16600ad_1677147745041_9971_17808
 */
ControlEnum Door_getWindowPosition(Door* self);

Example: Getter and setter

Inline

If an operation uses the stereotype C++ operation and the attribute Inline is set to true, the function is generated as an inline function.

/**
 * @brief Public operation isLocked
 * @generated_from _2022x_16600ad_1677575910398_769750_17568
 */
inline bool LockableElement_isLocked(LockableElement* self);

Example: Inline

Virtual

If an operation uses the stereotype C++ operation and the attribute Virtual is set to true, the function is generated as a pure virtual function.

Virtual function is not yet supported.

The concept of Volatile is not supported by the C code generator.

Static

If the attribute isStatic is set to true for an operation, the first argument of the operation is not generated. (On opposite of REQ_UML_CLS_C_9293).

Const

The concept of Const function is not supported by C code generator.

Friend

The concept of Friend operation is not supported by the C code generator.

The usage of a relation applying the C++ Friend stereotype is not supported.

Function Pointer

Function pointer not yet supported. Add a validation rule.

Operator

The concept of Operator is not supported by the C code generator.

Exception

The concept of exception is not supported by the C code generator.

Global

The concept of exception is not supported by the C code generator.

Operation Behavior

A behavior can be attached to an operation to represent its implementation. This can be done using the Method attribute of an operation.

If an activity is assigned to an operation, a variable typed with the struct representing the activity is declared in the private section of the class containing the operation.

typedef struct block1{
    /**
     * Instance of Activity associated to operation op1
     */
    Model_Act1_struct Model_Act1_Activity;
}

Example: Operation with activity

IMPLEMENTATION MEMBERS SECTION

Each operation declared in a UML class is generated in the source file.

Operation declaration in class

A brief description is generated for any property describing the type and name of the variable.

Additional documentation is generated if the documentation section is a field in the model.

User code section is inserted in operation to let the user fills a behavior.

If any, a default return code is inserted in the user code section.

/**
 * @brief Public operation isClosed
 * @generated_from _2022x_16600ad_1673944282153_805594_18447
 */
Boolean VehicleDoorsManager_lockDoors(VehicleDoorsManager* self){

    /* BEG_USER_CODE(_2022x_16600ad_1673944282153_805594_18447) do not remove */
    /* Add your code here */
    return 0;
    /* END_USER_CODE(_2022x_16600ad_1673944282153_805594_18447) do not remove */
}

Example: Operation implementation

Constructor

Default constructor is automatically generated for class object even if not declared in the class. Constructor parameters and implementation are automatically implemented to enable proper initialization of elements.

Default constructor initializes the destructor as the first step.

/**
 * Constructor generated automatically to initialize data structure
 * @generated_from _2022x_16600ad_1673888904467_347445_17229
 */
void VehicleDoorsManager_ctor(VehicleDoorsManager* self, struct LockManager* lockManager){
  /* Init pointer to destructor */
  self->dtor = VehicleDoorsManager_dtor;

  /* Init pointer to virtual table */
  Self->vtable = &vtable;

  /* Init aggregation destination */
  self->lockManager = lockManager;

  /* Default values */

  /* Call hierarchical constructors */
  Door_ctor(&self->frontRightDoor);
  Door_ctor(&self->rearLeftDoor);
  Door_ctor(&self->rearRightDoor);
  Door_ctor(&self->frontLeftDoor);
}

Example: Default Constructor

If an operation uses the stereotype C++ Constructor, the function is generated as a constructor in the source code.

/**
 * @brief Public constructor
 * @generated_from _2022x_16600ad_1677662449242_503106_17437
 */
void VehicleDoorsManager_user_ctor(VehicleDoorsManager* self){
    /* BEG_USER_CODE(_2022x_16600ad_1677662449242_503106_17437) do not remove */
    /* Add your code here */
    /* END_USER_CODE(_2022x_16600ad_1677662449242_503106_17437) do not remove */
}

Example: Constructor

Explicit Constructor

The concept of Explicit constructor is not supported by C code generator.

Destructor

A default destructor is automatically generated for a class object even if not declared in the class. This destructor is implemented as a static function.

Default destructor called automatically destructor of contained elements when required.

/* Function pointer to destructor function generated automatically */
static void VehicleDoorsManager_dtor(struct VehicleDoorsManager* self){
    /* Call hierarchical destructors */
    self->frontRightDoor.dtor(&self->frontRightDoor);
    self->rearLeftDoor.dtor(&self->rearLeftDoor);
    self->rearRightDoor.dtor(&self->rearRightDoor);
    self->frontLeftDoor.dtor(&self->frontLeftDoor);

    /* Clean pointer to destructor */
    self->dtor = NULL;
}

Example: Destructor implementation

Default destructor is configured in the default constructor.

/**
 * Constructor generated automatically to initialize data structure
 * @generated_from _2022x_16600ad_1673888904467_347445_17229
 */
void VehicleDoorsManager_ctor(VehicleDoorsManager* self, struct LockManager* lockManager){
    /* Init pointer to destructor */
    self->dtor = VehicleDoorsManager_dtor;

}

Example: Constructor initialization

Getter/Setter

Getter and setter are generated for each function declared accordingly in the model and content is automatically generated to access or modify the associated attribute.

/**
 * @brief Setter method for attribute WindowPosition
 * @generated_from _2022x_16600ad_1677147742721_382790_17804
 */
void Door_setWindowPosition(Door* self, ControlEnum /*in*/ windowPosition){
    self->WindowPosition = windowPosition;
}

/**
 * @brief Getter method for attribute WindowPosition
 * @generated_from _2022x_16600ad_1677147745041_9971_17808
 */
ControlEnum Door_getWindowPosition(Door* self){
    return self->WindowPosition;
}

Example: Getter and setter

Inline

If an operation uses the stereotype C++ operation and the attribute Inline is set to true, the function is generated as an inline function.

/**
 * @brief Public operation isLocked
 * @generated_from _2022x_16600ad_1677575910398_769750_17568
 */
inline bool LockableElement_isLocked(LockableElement* self){

    /* BEG_USER_CODE(_2022x_16600ad_1677575910398_769750_17568) do not remove */
    /* Add your code here */
    return 0;
    /* END_USER_CODE(_2022x_16600ad_1677575910398_769750_17568) do not remove */
}

Example: Inline

Operation Behavior

If an opaque behavior is assigned to an operation, this opaque behavior is replicated in the operation body.

void ClassA_OperationWithBeh(ClassA* self){

    /* BEG_USER_CODE(_2024x_1ca00d3_1700818869010_751926_3013) do not remove */    FriendClass c;
    c.privateOp();
    /* END_USER_CODE(_2024x_1ca00d3_1700818869010_751926_3013) do not remove */
}

Example: Operation with behavior

If an activity is assigned to an operation, this activity must be invoked in the operation body.

The invoke phase consist in a first initialization performed once flowed by the call of the activity code.

/**
 * @brief Public operation op1
 * @generated_from _2024x_1_1ca00d3_1715702379719_574529_3630
 */
Integer block1_op1(block1* self, Integer /*in*/ param1, Integer /*in*/ param2){
    static Boolean first = true;
    if(first){
        _basic_Model_Act1_init(&self->Model_Act1_Activity);
        first = false;
    }
    self->Model_Act1_Activity.param1=param1;
    self->Model_Act1_Activity.param2=param2;
    self->Model_Act1_Activity.WALL_CLOCK = tal_GetTime();
    (void)_basic_Model_Act1(&self->Model_Act1_Activity);
    return self->Model_Act1_Activity.param3;
}

Example: Operation with activity

VIRTUAL TABLE MEMBERS SECTION

A function pointer is declared for each public operation in the virtual table to access the function with an object-oriented style. The name of the function pointer is the name of the operation.

/** 
 * @brief Public operation LockableElement_lockDoors
 * @generated_from _2022x_16600ad_1673944282153_805594_18447 */
Boolean (*lockDoors)(struct LockableElement* self);

Example: Pointer to operation in a virtual table

VIRTUAL TABLE MEMBERS INITIALIZATION SECTION

the function pointer for each operation is initialized in the virtual table with the function declared in section FUNCTIONS DECLARATION SECTION and PROTECTED AND PRIVATE FUNCTIONS SECTION.

All operations must be declared exactly in the same order than fct pointers are defined.

Operations are defined before variables.

/** vtable variable declaration */
const LockableElement_vtable LockableElement_vt = {
    LockableElement_user_ctor,
    LockableElement_virtualOperation,
    LockableElement_isLocked,
    LockableElement_isUnlocked,
    LockableElement_lock,
    LockableElement_unlock,
};

Example: Operation initialized in the virtual table

Operation Parameter

FUNCTIONS DECLARATION SECTION and IMPLEMENTATION MEMBERS SECTION

Type of parameter of operation with direction set as return is used as the return type of the operation.

Parameter of operation with direction set as in or out or inout is used as parameter of the operation.

Type of parameter of operation with direction set as in or out or inout is used in parameter declaration of the operation.

Direction in or out or inout of parameter is used for documentation purpose.

/**
 * @generated_from _2022x_16600ad_1677147742721_382790_17804
 */
void Door_setWindowPosition(Door* self, ControlEnum /*in*/ windowPosition);

Example: Parameters

Pointer Declaration

If a type modifier * is set for a parameter, it is used to declare a pointer to a variable.

/**
 * @generated_from _2022x_16600ad_1677147742721_382790_17804
 */
void Door_setWindowPosition(Door* self, ControlEnum* /*out*/ windowPosition);

Example: Pointer

List Declaration

The concept of List is not supported by the C code generator.

Array Declaration

If the parameter applies the C++ Attributes stereotypes and array value is configured, parameter is generated as an array<Parameter Type, length>.

Array configuration

/** @generated from: _2022x_2_1ca00d3_1685001263779_527188_17508 */
void Configuration_setConfiguration(Configuration* self, Integer /*in*/ configuration[2]);

Example: Parameter as array

Variable Length Parameter List

Variable length parameter lists are not yet supported. Add a validation rule.

Dependency Relation

In case of a dependency relation between 2 objects (UML class or UML Interfaces) target elements of the relation are automatically generated if the source of the relation is part of the generation.

Flow Port

HEADER VARIABLE MEMBERS SECTION

A variable is expected to be created in the class to store the values exchanged by the flow ports of the class.

For each flow port, a variable typed with the type referenced by the flow port is generated.

For each flow port, a variable named with the name of the Port and a suffix _data is generated.

/**
 * Public data for Flow Port flowPort
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43081
 */
Integer flowPort_data;

Example: Flow port variable

Proxy Port and Interface Block and Flow Property

HEADER VARIABLE MEMBERS SECTION

A variable is expected to be created in the class to store the values exchanged by the flow properties transmitted through proxy ports of the class.

For each flow property contained in an interface block, which is referenced by a proxy port, a variable typed with the type referenced by the flow property is generated.

For each flow property contained in an interface block, which is referenced by a proxy port, a variable named with the name of the proxy port, an _ and the flow property name is generated.

/**
 * Public data for Flow Property myFlowProperty of Interface Block myItf in Proxy Port myPort
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43081
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43082
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43083
 */
Integer myPort_myItf;

Example: Flow property variable

Port, Interface and Property

HEADER VARIABLE MEMBERS SECTION

A variable is expected to be created in the class to store the values exchanged by the properties transmitted through ports of the class.

For each property contained in an interface, which is referenced by a port, a variable typed with the type referenced by the property is generated.

For each property contained in an interface, which is referenced by a port, a variable named with the name of the port, an _ and the property name is generated.

/**
 * Public data for Property myFlowProperty of Interface myItf in Port myPort
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43081
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43082
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43083
 */
Integer myPort_myItf;

Example: Flow property variable

Interface

HEADER VARIABLE MEMBERS SECTION and HEADER CONST MEMBERS SECTION

An interface is translated into several structures containing fields and operations corresponding to the properties and operations of the class. Refer to chapter <ClassName>.h for more details.

The list of functions declared outside the structure like generated for a class are not generated in case of a structure.

A file named <interface name>.h must be created, except for C standard Library headers.

IMPLEMENTATION MEMBERS SECTION

As a rationale, only a header file is generated.

Classifier Behavior

HEADER VARIABLE MEMBERS SECTION

A variable typed with the structure of the behavior is generated for the classifier behavior with public visibility.

See [4] for more information on the structure naming. All structures are named with the same pattern.

A variable having the name of the behavior is generated for the classifier behavior with public visibility.

/**
 * Data for Behavior Statemachine
 * @generated from: _19_0_3_16600ad_1654593633874_525666_43081
 */
Statemachine_struct Statemachine;

Example: Classifier behavior variable

Data Type and Value Type and Enumeration

Data Types generation in class is not yet supported.

A type can be a redefinition of an existing type using a generalization relation.

Redefinitions of Real, Boolean, Integer value_types

Data Types and Value Types are used to type the data contained in classes.

DATA TYPES DECLARATION

Each Data Type or Value Type that are referenced by a property, parameter, operation argument, are expected to be defined in internal_types.h.

Primitive Type

Data types defined in C++ ANSI profile are supported. No typedef must be generated.

Data type defined in C++ ANSI Profile

Data types defined in UML Standard Profile/MagicDraw profile/datatypes are supported. Typedef is generated or not according to the following requirements.

Supported MagicDraw Data types

Datatypes defined in UML Standard Profile/MagicDraw profile/datatypes Color, StructuredExpression, date and XML are not supported.

Data types defined in UML Standard Profile/UML 2 Metamodel/Primitive Types are supported. Typedef is generated according to the following requirements.

Supported UML2 Data types

Datatype defined in UML Standard Profile/UML 2 Metamodel/Primitive Types UnlimitedNatural is not supported.

Not supported UML2 Data types

Data types defined in SysML/Libraries/PrimitiveValueTypes are supported. Typedef is generated according to the following requirements.

Supported UML2 Data types

Datatypes defined in SysML/Libraries/PrimitiveValueTypes” Complex” and Number are not supported.

A Data Type or a Value Type having one of the following names are not defined:

  • char,
  • bool,
  • int,
  • double,
  • float,
  • long,
  • long double,
  • long int,
  • short int,
  • signed char,
  • unsigned char,
  • unsigned int,
  • unsigned long int,
  • unsigned short int,
  • wchar_t.

If an Integer type of the following profiles is referenced directly or indirectly in the design, an Integer type is generated:

Integer is defined as an int.

#ifndef Integer_DEFINITION
#define Integer_DEFINITION
typedef int Integer;
#endif

Example: Integer type declaration

If a Boolean type of the following profiles is referenced directly or indirectly in the design, a Boolean type is generated:

Boolean is defined as a bool.

#ifndef Boolean_DEFINITION
#define Boolean_DEFINITION
typedef bool Boolean;
#endif

Example: Boolean type declaration

If a Real type of the following profiles is referenced directly or indirectly in the design, a Real type is generated:

Real is defined as a double.

#ifndef Real_DEFINITION
#define Real_DEFINITION
typedef double Real;
#endif

Example: Real type declaration

If a String type of the following profiles is referenced directly or indirectly in the design, a String type is generated:

String is defined as a char*.

#ifndef String_DEFINITION
#define String_DEFINITION
typedef char* String;
#endif

Example: String type declaration

If a primitive type uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the attribute alignment is set to a valid value, then the generated code must include the keyword __attribute__((aligned({alignment}))).

typedef int __attribute__((aligned({alignment}))) alignedInteger;

Example: Primitive type declaration using aligned

A valid value for alignment an integer that is a power of two.

Array Type
data1 is defined as an array

An array is generated when a property, a parameter, or a type references another type with a multiplicity greater than 1.

An array is defined with a naming convention as the following: Array_<size>_<referencedType>.

/**********************************************************************
 * Data Type Array_3_Integer definition
 **********************************************************************/
#ifndef Array_3_Integer_DEFINITION
#define Array_3_Integer_DEFINITION
typedef Integer Array_3_Integer[3];
#endif /* Array_3_Integer */

Example: Array definition in model

If an array type uses the stereotype C++Aligned, and thecompiler” parameter is set to gcc, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).

typedef int __attribute__((aligned({alignment}))) Array_3_Integer[3];

Example: Array type declaration using aligned

A valid value for alignment an integer that is a power of two.

Structure Type
Structure definition in model

A struct is defined for a value type or a data type containing one or multiple properties.

/**********************************************************************
 * Data Type Struct definition
 **********************************************************************/
#ifndef Struct_DEFINITION
#define Struct_DEFINITION
typedef struct {
    unsigned int data1;
    double data2;
    bool data3;
} Struct;
#endif /* Struct */

Example: structure definition

If the structure type uses the stereotype C+Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)).

typedef struct __attribute__((packed)) {
    int attribute1;
    int attribute2;
} StructType;

Example: Structure declaration with packed

If the property of the structure type uses the stereotype C++Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)), except for bitfield, pointer and reference properties.

typedef struct {
    int attribute1;
    struct OtherStrucType __attribute__((packed)) attribute2;
} StructType;

Example: Property structure declaration with packed

If the structure type uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).

typedef struct __attribute__((aligned({alignment}))) {
    int attribute1;
    int attribute2;
} StructType;

Example: Structure declaration using aligned

A valid value for alignment is an integer that is a power of two.

If the property of the structure type uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the selected C version is not greater than or equal to C23, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))) except for bitfield and reference properties.

typedef struct {
    int attribute1;
    struct OtherStrucType __attribute__((aligned({alignment}))) attribute2;
} StructType;

Example: Property structure declaration using aligned

A valid value for alignment is an integer that is a power of two.

If the property of the structure type uses the stereotype C++Aligned, and the selected C version is greater than or equal to C23, and the attribute alignment is set to a valid value, the generated code must include the keyword alignas({alignment}) except for bitfield and reference properties.

typedef struct {
    int attribute1;
    alignas({alignment}) struct OtherStrucType attribute2;
alignas(16) int *attribute3;
} StructType;

Example: Property structure declaration using alignas

A valid value for alignment is an integer that is a power of two.

Enumeration Type

An enum is identified as an Enumeration in the design.

Enumeration definition in model

An enum is defined for an enumeration.

/**********************************************************************
 * Data Type ControlEnum definition
 * @generated_from _2022x_16600ad_1673975868491_889391_20271
 **********************************************************************/
#ifndef ControlEnum_DEFINITION
#define ControlEnum_DEFINITION
typedef enum {
    Idle,
    Open,
    Close
} ControlEnum;
#endif /* ControlEnum */

If the enumeration uses the stereotype C++Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)).

enum __attribute__((packed)) EnumPacked{
    literal1,
    literal2
};

Example: Enumeration declaration with packed

If an enumeration literal has the attribute value of C++ANSI profile defined, then the value of that attribute is used in the generated code. The value attribute must be a signed integer.

enum EnumPacked{
    literal1 = 1,
    literal2
};

Example: Enumeration declaration with attribute value defined

If an enumeration literal has a specification of the kind Literal Integer defined, the value of that specification is used in the generated code.

If an enumeration literal has both a specification and the attribute value of C++ANSI Profile defined, the value is used in the generated code instead of the specification.

If neither the specification nor the value attribute of the C++ ANSI Profile is defined for an enumeration literal, the name of the enumeration literal is used in the generated code.

If the enumeration uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).

enum __attribute__((aligned({alignment}))) MyEnumeration {
    literal1,
    literal2
};

Example: Enumeration declaration using aligned

A valid value for alignment is an integer that is a power of two.

Union Type

If a union uses the stereotype C++Packed, and the attribute packed is set to true, and the compiler parameter is set to gcc, the generated code must have the keyword __attribute__((packed)).

typedef union __attribute__((packed)) MyUnion {
    int i;
    double d;
} MyUnionType;

Example: Union declaration using alignment

If a union uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).


                

typedef union __attribute__((aligned({alignment}))) MyUnion {

int i;

double d;

};

Example: Union declaration using aligned

A valid value for alignment is an integer that is a power of two.

Signal

DATA TYPES DECLARATION

Each signal, which is received or produced by any behavior, is expected to be defined in internal_types.h.

If a component contains one or multiple signals, a trigger_type is generated.

/**********************************************************************
 * Data Type trigger_type definition
 **********************************************************************/
#ifndef trigger_type_DEFINITION
#define trigger_type_DEFINITION
typedef bool trigger_type;
#endif /* trigger_type */

Example: Trigger_type declaration

If a signal references one or multiple properties, a dedicated structure is generated for the data transmitted with the signal.

/**********************************************************************
 * Data Type Signal definition
 **********************************************************************/
#ifndef Signal_DEFINITION
#define Signal_DEFINITION
typedef struct {
    Integer s1;
    Integer s2;
} Signal;
#endif /* Signal */

Example: Signal content declaration

A signal type is declared by a structure named SignalEvent_<signal_name>l_type. This structure contains at least one trigger field with type trigger_type to store the event activation.

If a signal references one or multiple properties, an addition field named <signal_name> is added to the structure.

/**********************************************************************
 * Data Type SignalEvent_Signal_type definition
 **********************************************************************/
#ifndef SignalEvent_Signal_type_DEFINITION
#define SignalEvent_Signal_type_DEFINITION
typedef struct {
    trigger_type trigger;
    Signal data;
} SignalEvent_Signal_type;
#endif /* SignalEvent_Signal_type */

If the signal uses the stereotype C++Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)).

typedef struct __attribute__((packed)) {
    trigger_type trigger;
    Signal data;
} SignalEvent_Signal_type;

Example: Signal declaration with packed

If the property of the signal uses the stereotype C++Packed and the attribute packed is set to true and the compiler parameter is set on gcc, the generated code must have the keyword __attribute__((packed)), except for bitfield, pointer and reference properties.

typedef struct {
    trigger_type trigger;
    Signal __attribute__((packed)) data;
} SignalEvent_Signal_type;

Example: Property signal declaration with packed

If the signal uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))).

typedef struct __attribute__((aligned({alignment}))) {
    trigger_type trigger;
    Signal data;
} SignalEvent_Signal_type;

Example: Signal declaration using alignment

A valid value for alignment is an integer that is a power of two.

If the property of the signal uses the stereotype C++Aligned, and the compiler parameter is set to gcc, and the selected C version is not greater than or equal to C23, and the attribute alignment is set to a valid value, the generated code must include the keyword __attribute__((aligned({alignment}))) except for bitfield, pointer, and reference properties.

typedef struct {
    trigger_type trigger;
    Signal __attribute__((aligned({alignment}))) data;
} SignalEvent_Signal_type;

Example: Property signal declaration using alignment

A valid value for alignment is an integer that is a power of two.

If the property of the signal uses the stereotype C++Aligned, and the selected C version is greater than or equal to C23, and the attribute alignment is set to a valid value, the generated code must include the keyword alignas({alignment}) except for bitfield and reference properties.

typedef struct {
    trigger_type trigger;
    alignas({alignment}) Signal data;
} SignalEvent_Signal_type;

Example: Property signal declaration using alignas

A valid value for alignment is an integer that is a power of two.