UML and SysML to C++ - Constraint Code Generator Specification

This section describes the UML and SysML to C++ constraint code generation.

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 Concept [1]
C++ Code Architecture Specification [2]

General Concepts

Constraint code generation if part of the behavior layer in Figure 1 and is produced during the behavior code generation.

Behavior Layer

The behavior layer is composed of components see [1] for more details.

If we zoom in the behavior layer and more specifically on Component1, it is composed as displayed in the Figure 2.

Detailed behavior layer

As displayed the code of the component is composed of multiple layers:

  • The Interface layer purpose is double:
    • Declare for the component the communication APIs, which can be called,
    • Expose to the middleware the scheduling APIs implemented by the component.
  • The class layer is the UML class selected for the code generation. In other words, it is the top element of the component.
  • If any, the classifier behavior is the main behavior associated with the top class, this behavior , and then schedules sub behaviors depending on the design. The behavior can be designed in multiple languages:
    • Statemachine
    • Activity
    • Opaque behavior
    • Constraint
  • If any, the class model is also generated.

This document focuses on the behavior part and more specifically on the C code generation for the constraints.

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.

SysML stereotype Description
UML Class SysML Block Element used as Top Class. Input selection to trigger the code generation.
Constraint Block Element describing a constraint between multiple parameters
Constraint Property Instance of a constraint block belonging to a parent block.
Constraint Parameter Parameter of a Constraint block.

Validation Constraints

-

Code Generator Specification

This section is divided in two parts:

  • The generated files specification
  • The behavior specification

Files Specifications

The constraint blocks generation is composed of:

  • A <Class name>_Constraints.h file
  • A <Class name>_Constraints.cpp file

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

<Class name>_Constraints.h

This file declares the list of functions implementing the constraints offered by the constraint blocks referenced using a constraint property in the class.

Include to <Class name>.h is inserted after header.

Macro definition is inserted to open the C functions declaration section. (This requirement may be removed)

A function is declared for each constraint property. See chapter 9.2 for more details depending on the elements.

Macro definition is inserted to close the C functions declaration section. (This requirement may be removed)

#include "<Class name>.h"

#ifdef __cplusplus
extern "C" {
#endif

<CONSTRAINT_FCT_DECLARATION – see chapter 9.2>

#ifdef __cplusplus
}
#endif

Example: Include and C functions section.

<Class name>_Constraints.cpp

This file implements the list of functions implementing the constraints offered by the constraint blocks referenced via a part property in the class.

Include to <Class name>_Constraints.h is inserted after header.

A function is implemented for each Constraint property. See chapter 9.2 for more details depending on the elements.

#include "<Class name>_Constraints.h"

<CONSTRAINT_FCT_IMPLEMENTATION – see chapter 9.2>

Example: Include and implementation of constraints

Semantic Code Specifications

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

Constraint Property

CONSTRAINT_FCT_DECLARATION

A function is declared for each Constraint property.

A documentation is generated for each function.

Function name is composed of the constraint property name if any and the constraint block name. (Validation rule required: constraint block name)

Function takes a pointer to the top class structure as a unique argument.

Function returns a pointer to the top class structure.

/**
 * Constraint block declaration : <Constraint property>_<Constraint block>
 * @generated from: <constraint block uuid>
 */
<Class name> * <Constraint property>_<Constraint_block>(<Class name> * inst);

Example: Function declaration

CONSTRAINT_FCT_IMPLEMENTATION

A function is declared for each Constraint property.

A documentation is generated for each function.

Function name is composed of the constraint property name if any and the constraint block name. (Validation rule required: constraint block name)

Function takes a pointer to the top class structure as a unique argument.

Function returns a pointer to the top class structure.

Function starts by initiating parameters with the data connected to parameters.

Constraint specification is printed after parameters initialization.

Each parameter value is replicated to data connected to the parameter.

/**
 * Constraint block declaration : <Constraint property>_<Constraint block>
 * @generated from: <constraint block uuid>
 */
<Class name> * <Constraint property>_<Constraint_block>(<Class name> * inst){
/* Init constraint parameters */    
<INIT_PARAMETERS>

/* Constraint specification */
    out=in1+in2;

/* Update binded data */
<REPLICATE_PARAMETERS>

    return inst;
}

Example: Constraint function implementation

Constraint Parameter

INIT_PARAMETERS

A variable is created for each constraint parameter with the name of the parameter and its type.

The constraint parameter variable is initiated with the value of the connected property or flow ports. These values are stored in the top class entity.

<Type> <param name> = inst-><property name>;

Example: Parameter creation

REPLICATE_PARAMETERS

The constraint parameter variable value is copied to the connected property or flow ports.

inst-><property name> = <param name>;

Example: Parameter value replication