You can customize generated identifiers by specifying the Identifier format
control parameters on the Code Generation > Identifiers
pane in the Configuration Parameters dialog box. For each parameter, you can enter a macro
that specifies whether, and in what order, certain text is included within generated
identifiers. For example, you can specify that the root model name be inserted into each
identifier using the $R
token.
The macro can include:
Valid tokens, which are listed in Identifier Format Tokens. You can use or omit tokens depending on what you want
to include in the identifier name. The Shared utilities identifier
format parameter requires you to specify the checksum token,
$C
. The other parameters require the mangling token,
$M
. For more information, see Control Name Mangling in Generated Identifiers. The mangling token is subject to the use and ordering
restrictions noted in Identifier Format Control Parameter Values.
Token decorators, which are listed in Control Case with Token Decorators. You can use token decorators to control the case of generated identifiers for each token.
Valid C or C++ language identifier characters (a-z, A-Z, _ ,
0-9
).
The build process generates each identifier by expanding tokens and inserting the
resultant text into the identifier. The tokens are expanded in the order listed in Identifier Format Tokens. Groups of characters are inserted in the positions that
you specify around tokens directly into the identifier. Contiguous token expansions are
separated by the underscore (_
) character.
Identifier Format Tokens
Token | Description |
---|---|
$C | This token is required for Shared utilities identifier
format. If the identifier exceeds the Maximum identifier
length, the code generator inserts an 8-character checksum to avoid
naming collisions. The position of the |
$M | This token is required. If necessary, the
code generator inserts name-mangling text to avoid naming collisions. Modify
checksum character length by using Shared checksum length
parameter. The position of the |
$U | Insert text that you specify for the |
$F | Insert method name (for example, |
$N | Insert name of object (block, signal or signal object, state, parameter, shared utility function or parameter object) for which identifier is being generated. |
$R | Insert root model name into identifier, replacing unsupported characters
with the underscore ( Note: This token replaces the Prefix model name to global identifiers option in previous releases. |
$H | Insert tag indicating system hierarchy level. For root-level blocks, the
tag is the text Note: This token replaces the Include System Hierarchy Number in Identifiers option in previous releases. |
$A | Insert data type acronym (for example, Note: This token replaces the Include data type acronym in identifier option in previous releases. |
$I |
For example, |
$G | Insert the name of a storage class that is associated with the data item. This token is also available in the naming rule that you specify for the Header File for a storage class in the Embedded Coder® Dictionary. |
$E | Insert the file type.
This token is required for Header files and Source files. |
Identifier Format Control Parameter Values lists the default macro value, the supported tokens, and the applicable restrictions for each Identifier format control parameter.
Identifier Format Control Parameter Values
Parameter | Default Value | Supported Tokens | Restrictions |
---|---|---|---|
Global variables | $R$N$M | $M , $R ,
$G ,$N ,$U | $F , $H , $A ,
$E , and $I are not allowed. |
Global types | $N$R$M_T | $M , $R ,
$G ,$N ,$U | $F , $H , $A ,
$E , and $I are not allowed. |
Field name of global types | $N$M | $M , $N , $H ,
$A , $U | $R , $F , $G ,
$E , and $I are not allowed. |
Subsystem methods | $R$N$M$F | $M , $R , $N ,
$H , $F , $U | $F and $H are empty for Stateflow® functions; $A , $G ,
$E , and $I are not allowed. |
Subsystem method arguments | rt$I$N$M
| $M , $N , $I ,
$U | $R , $F , $H ,
$G , $E , and $A are not
allowed. |
Local temporary variables | $N$M | $M , $R , $N ,
$A , $U | $F , $H , $G ,
$E , and $I are not allowed. |
Local block output variables | rtb_$N$M | $M , $N , $A ,
$U | $R , $F , $H ,
$G , $E , and $I are not
allowed. |
Constant macros | $R$N$M | $M , $R , $N ,
$U | $F , $H , $A ,
$G , $E , and $I are not
allowed. |
Shared utilities identifier format | $N$C | $N , $C , $R ,
$U | $C is required. $M , $F ,
$H , $A , $G ,
$E , and $I are not allowed. |
EMX array utility functions identifier
format | emx$M$N | $M , $N ,$R | $C , $U , $F ,
$H , $A , $G ,
$E , and $I are not allowed. |
EMX array types identifier
format | emxArray_$M$N | $M , $N ,$R |
$C , $U , $F ,
$H , $A , $G ,
$E , and $I are not allowed. |
Header files | $R$E | $R ,$U ,$E |
$C , $M , $N ,
$F , $H , $A ,
$G , and $I are not allowed. |
Source files | $R$E | $R ,$U ,$E |
$C , $M , $N ,
$F , $H , $A ,
$G , and $I are not allowed. |
Data files | $R_data | $R ,$U |
$C , $M , $N ,
$F , $H , $A ,
$G , $E , and $I are not
allowed. |
Non-ERT-based targets (such as the GRT target) implicitly use a default
$R$N$M
specification. This default specification consists of the root
model name, followed by the name of the generating object (signal, parameter, state, and so
on), followed by name-mangling text.
For limitations that apply to Identifier format control parameters, see Exceptions to Identifier Formatting Conventions and Identifier Format Control Parameters Limitations.
On the Code Generation > Identifiers pane, you can use token decorators to control the case of generated
identifiers. Place a decorator immediately after the target token and enclose the decorator
in square brackets [ ]
. For example, you can set Global
variables to $R[uL]$N$M
, which capitalizes the first letter
of the model name and forces the remaining characters in the model name to lowercase.
The table shows how to manipulate the expansion of the $R
token for a
model whose name is modelName
.
Desired Expansion | Description | Token and Decorator |
---|---|---|
ModelName | First letter of model name is uppercase. Remaining characters are not modified. | $R[u] |
Modelname | First letter of model name is uppercase. Remaining characters are lowercase. | $R[uL] |
MODELNAME | All characters are uppercase. | $R[U] |
modelname | All characters are lowercase. | $R[L] |
mODELNAME | First letter of model name is lowercase. Remaining characters are uppercase. | $R[lU] |
modelName | First letter of model name is lowercase. Remaining characters are not modified. | $R[l] |
When you use a decorator, the code generator removes the underscore character
(_
) that appears between tokens by default. However, you can append
each decorator with an underscore: $R[U_]$N
. For example, if you set the
Global variables parameter to $R[u_]$N[uL]$M
for a
model named modelName
and a DWork
structure
represented by DW
, the result is ModelName_Dw
.
This example shows how you can customize generated identifiers by specifying the Identifier format control parameters on the Code Generation > Identifiers pane in the Configuration Parameters dialog box. To maintain model traceability, it is important that incremental revisions to a model have minimal impact on the identifier names that appear in the generated code. This example shows how you can use name mangling by specifying the Identifier format control parameters to minimally impact the identifier names.
model='rtwdemo_symbols';
open_system(model)
% Cleanup
rtwdemoclean;
close_system(model,0)