Model Compiler Validation Rules

When the model compiler transforms a model to C++ it checks the model against several validation rules. If a rule fails, the model compiler will report a problem as a build message. Each validation rule has a default severity which is either Warning or Error:

There is also a third severity, Information. There are no validation rules with this severity by default, but you can configure validation rules so they report problems as information messages rather than warnings or errors. It should also be noted that the model compiler prints several information messages throughout the process of building. These are, however, not the result of any validation rules but just serve as information about what the model compiler is currently doing. For example:

08:55:50 : INFO : Generating source files...

Configuring Validation Rules

Model RealTime checks for semantic problems in your application by running certain validation rules. This ensures that errors and warnings are detected as early as possible. Hence, you can configure which validation rule to use for checking a model. Model RealTime also lets you configure the severity of a rule.

A validation rule can be configured by a simple 5-character string where the first letter specifies the severity (X, I, W, or E), and the remaining digits specify the rule ID.

Image showing an enlarged view of the different letters of the configuration rules.

Each letter has a unique meaning.

At this stage, let's see how to configure a validation rule in Model RealTime. To configure validation rules, follow the steps below:

  1. Navigate to Window - Preferences - RealTime Development - Build/Transformations - C++ in Eclipse.
  2. In the Rule Configuration textbox, enter the validation rule ID prefixed with one of the letters X, I, W, or E. Note that you can add either a single 5-character string or a comma-separated list of 5 character strings (this is useful for setting multiple configuration rule scenarios).

Let's say that you enter a rule configuration as given below:

X0003,I0004,W0002,E0001,I0005

Then, the configuration would mean the following:

Model RealTime has named each of the above-mentioned validation IDs. The description for each ID with the rule names is given in the following table:

ID Rule Name Description Default Severity
0001 AttributeInitialization Signifies that the class does not contain a constructor where an attribute with a default value can be initialized. Hence the default value of the attribute will be ignored. Warning
0002 TransitionUnreachable Occurs when the model contains duplicate trigger events on more than one transition from the same origination point. Warning
0003 EffectDuplicated Indicates that a duplicate method has been generated as a result of the transition effect, and that the triggers are not compatible with the inherited method. Warning
0004 GuardDuplicated Indicates that a duplicate method has been generated for the guard of the transition as the triggers are not compatible with the inherited method. Warning
0005 MultiplicityBadFormat Indicates that the application is unable to parse multiplicity when an incorrect value of multiplicity is entered. Warning

The ID of a validation rule is printed just after its severity while building the application. For example, assume that you get the below warning when building a model.

14:43:05 : WARNING[0001] : HelloWorld::Class1::attribute1 : This attribute has a default value and the 'Initializer Kind' property is set to 'Constructor', but no constructor will be generated where it can be initialized. The attribute default value will be ignored. Theattribute default value will be ignored.

In the message above, the validation rule ID that caused this warning is 0001. You can change the severity of this message to Error by providing the rule configuration as E0001. Moreover, you can also disable the rule, so that neither a warning nor an error is reported, by providing the rule configuration as X0001.

The model compiler only lets you configure validation rules that have an ID. So if you get an error or a warning without any ID, you cannot change the severity, nor disable that rule.

Note that if you enter a value other than the validation rules in the Rule Configuration textbox, then while building the application you may get an error message, for example, "Incorrect syntax for rule configuration".

When doing a batch build, validation rules can be configured by using the --ruleConfiguration parameter. For example, to configure a warning for message 0001, specify --ruleConfiguration=W0001.

Running from the Command Line

You can also run the model compiler from the command line. You can use the following command line syntax for running the model compiler.

--ruleConfiguration=rules

Here, the 'rules' is a comma-separated list of rule IDs prefixed with X, W, I or E.

For example, the following is a command line script to disable the validation rule ID 0001.

--ruleConfiguration=X0001

Note that you should only configure a rule once, but if you do it multiple times, the last configuration will take precedence. The ID of a rule can be seen from the message that gets printed when the rule is enabled and fails. The ID will be printed right after the severity in the build message.