Identifier Format Control - MATLAB & Simulink (original) (raw)

You can customize generated identifiers by using identifier naming rules. An identifier naming rule consists of a macro that contains a combination of literal text, tokens, and token decorators. The code generator replaces the tokens in the macro with certain text values depending on the type of token. For example, use the $R token to insert the root model name into an identifier. For information about how to modify the expanded values, see Modify Identifier Format Tokens by Using Token Decorators.

Use identifier naming rules to generate identifiers that are unique, space-efficient, and compliant with your coding standards. You can set model-wide default identifier naming rules by using model configuration parameters. To set default naming rules for certain types of data elements, use the Embedded Coder® Dictionary. To override default naming rules for individual modeling elements, use the Code Mappings editor. Different identifier naming rules support different sets of tokens.

Literal text that you include in an identifier naming rule must contain only characters that are valid in C and C++ identifiers (a-z, A-Z,_, and 0-9). If you place multiple tokens consecutively in an identifier naming rule, the code generator inserts the underscore (_) character between each pair of expanded tokens, even if a token expands to an empty value. You cannot use the same token multiple times in one identifier naming rule.

The code generator prioritizes tokens in the order shown in the Identifier Format Tokens table. Tokens that are listed earlier in the table are higher priority than those that are listed later. If the generated identifier exceeds the value of the Maximum identifier length model configuration parameter, the code generator truncates tokens from lowest priority to highest priority until the length does not exceed the configuration parameter value.

Identifier Format Tokens

Token Description
C∣Expandstoachecksumtoavoidnamingcollisionsforsharedutilities.Forsharedutilitiesthatyoudonotgeneratefroma[MATLABFunction](../../simulink/slref/matlabfunction.html)block,C Expands to a checksum to avoid naming collisions for shared utilities. For shared utilities that you do not generate from a MATLAB Function block,CExpandstoachecksumtoavoidnamingcollisionsforsharedutilities.Forsharedutilitiesthatyoudonotgeneratefroma[MATLABFunction](../../simulink/slref/matlabfunction.html)block,C expands to a checksum only if the identifier naming rule does not contain Norifthegeneratedidentifierlengthexceedsthevalueofthe∗∗[Maximumidentifierlength](../../rtw/ref/maximumidentifierlength.html)∗∗modelconfigurationparameter.ForsharedutilitiesthatyougeneratefromaMATLABFunctionblock,N or if the generated identifier length exceeds the value of the Maximum identifier length model configuration parameter. For shared utilities that you generate from a MATLAB Function block, Norifthegeneratedidentifierlengthexceedsthevalueofthe[Maximumidentifierlength](../../rtw/ref/maximumidentifierlength.html)modelconfigurationparameter.ForsharedutilitiesthatyougeneratefromaMATLABFunctionblock,C expands to a checksum regardless of the identifier length and whether the identifier naming rule contains$N.This token is available only for the**Shared utilities identifier format** model configuration parameter. Use the Shared checksum length model configuration parameter to set the length of the checksum.
$M Expands to name-mangling text. The code generator generates name-mangling text to avoid naming collisions in generated identifiers. By default, the code generator generates name-mangling text that is as short as possible without introducing naming collisions and omits the name-mangling text if there are no collisions. You can specify a minimum length for the name-mangling text by using the**Minimum mangle length** model configuration parameter.For more information, see Avoid Identifier Naming Collisions.
$U Expands to custom text that you specify in the Custom token text model configuration parameter.
F∣Expandstothenameofasubsystemmethod.Forexample,whenthecodegeneratorgeneratesanupdatemethodidentifier,F Expands to the name of a subsystem method. For example, when the code generator generates an update method identifier, FExpandstothenameofasubsystemmethod.Forexample,whenthecodegeneratorgeneratesanupdatemethodidentifier,F expands toUpdate. For Stateflow® functions, $F expands to an empty value.This token is available only for the Subsystem methods model configuration parameter.
N∣ExpandstotextderivedfromthenameoftheSimulink®objectforwhichthecodegeneratorisgeneratinganidentifier.IdentifiernamingrulesinthemodelconfigurationparameterscanproducetextfortheN Expands to text derived from the name of the Simulink® object for which the code generator is generating an identifier. Identifier naming rules in the model configuration parameters can produce text for the NExpandstotextderivedfromthenameoftheSimulinkRobjectforwhichthecodegeneratorisgeneratinganidentifier.IdentifiernamingrulesinthemodelconfigurationparameterscanproducetextfortheN token that does not correspond directly to visible text in Simulink.You can configure the length of the expansion of the$N token by using the System-generated identifiers model configuration parameter.
$R Expands to the name of the root model. To avoid naming collisions, this token is required if you use referenced models. If the root model name contains characters that are not valid in C or C++ identifiers, the code generator replaces those characters with underscores (_).For more information, see Avoid Identifier Naming Collisions Between Referenced Models.
$H For root-level blocks, this token expands to root. For subsystem-level blocks, this token expands tos_N_, where_N_ is a unique system number. For Stateflow functions, this token expands to an empty value.Available for only the Subsystem methods and Field name of global types model configuration parameters.
A∣Expandstoanabbreviationthatcorrespondstothedatatypeofthegeneratedvariable.Forexample,foraninteger,A Expands to an abbreviation that corresponds to the data type of the generated variable. For example, for an integer, AExpandstoanabbreviationthatcorrespondstothedatatypeofthegeneratedvariable.Forexample,foraninteger,A expands toi32.This token is available only for the**Local block output variables,Local temporary variables, andField name of global types** model configuration parameters.
I∣Expandstoastringthatrepresentstheinput/outputtypeofasubsystemmethodargument.Iftheargumentisaninput,I Expands to a string that represents the input/output type of a subsystem method argument.If the argument is an input, IExpandstoastringthatrepresentstheinput/outputtypeofasubsystemmethodargument.Iftheargumentisaninput,I expands tou.If the argument is an output, Iexpandstoy.Iftheargumentisaninputandoutput,I expands toy.If the argument is an input and output, Iexpandstoy.Iftheargumentisaninputandoutput,I expands touy.This token is available only for the Subsystem method arguments model configuration parameter.
$G This token expands differently in different identifier naming rules.For data items, this token expands to the name of the name of the storage class of the data item.For the Header File naming rule of a storage class in the Embedded Coder Dictionary, this token expands to the name of the storage class.For service interface naming rules in the Embedded Coder Dictionary, this token expands to the name of the service.
$E Expands to one of these tags that describes the type of a generated file:capicapi_hostdttestinterfaceprivatetypesThis token is available for only the Header files and Source files model configuration parameters.
$X Expands to the name of the entry-point callable function that encloses a service function call.This token is available only for sender, receiver, data transfer, and timer service function naming rules in the Embedded Coder Dictionary.

The $N and $R tokens are available in the Pre Statement and Post Statement Embedded Coder Dictionary properties, but those properties do not otherwise apply identifier format control rules.

Identifier Naming Rules by Identifier Type

This table lists types of identifiers that you can configure by using identifier naming rules. Some types of identifiers are configurable from multiple identifier naming rules in different places. The Naming Rule column lists each location that contains a naming rule that modifies the identifier type. To set model-wide default naming rules, use identifier naming rules in the model configuration parameters. To set default naming rules for certain types of data elements, use naming rules in the Embedded Coder Dictionary.

To override naming rules for individual modeling elements, use the Code Mappings editor. For function mappings, the Code Mappings editor interprets**Function Name, GetFunction, andSetFunction** properties as identifier naming rules and supports token expansion. These properties are listed in the table. For data mappings, the Code Mappings editor interprets each Identifier property as plain text. These properties are not listed in the table.

For identifier naming rules that support the $R token, that token is required for models that use model referencing. For identifier naming rules that support the$N token, the table lists the value that the code generator uses when expanding that token.

The model configuration parameter identifier naming rules are available for only ERT-based targets. Non-ERT-based targets such as GRT implicitly use a default value of$R$N$M for those parameters. The model configuration parameter identifier naming rules do not affect objects that have a storage class other thanAuto.

Identifier Type Naming Rule Default Value Required Tokens Other Supported Tokens Resolution of $N Notes
Global variable Global variables model configuration parameter RRRN$M M∣M MN, R,R, R,U Text derived from the data item that the global variable is associated with, such as a signal name
Global type Global types model configuration parameter NNNR$M_T M∣M MN, R,R, R,U Text derived from the name of the Simulink data type
Field name of global type Field name of global types model configuration parameter NNNM M∣M MA, H,H, H,N,$U Text derived from the name of the data item that the field is associated with
Subsystem method Subsystem methods model configuration parameter RRRN$M$F M∣M MF, H,H, H,N,$R, $U Text derived from the name of the subsystem
Subsystem method argument Subsystem method arguments model configuration parameter rt$I$N$M M∣M MI, N,N, N,U Text derived from the names of the subsystem and subsystem port
Local temporary variable Local temporary variables model configuration parameter NNNM M∣M MA, N,N, N,R,$U Text derived from the data item that the variable is associated with, such as a signal name
Local block output variable Local block output variables model configuration parameter rtb_$N$M M∣M MA, N,N, N,U Text derived from the name of block
Constant macro Constant macros model configuration parameter RRRN$M M∣M MN, R,R, R,U Text derived from the data item that the constant macro is associated with, such as a block name You can also configure constant macros by using the Generate scalar inlined parameters as model configuration parameter.
Header file Header files model configuration parameter RRRE E∣E ER, U∣None∣CannotconsistofexactlyU None Cannot consist of exactly UNoneCannotconsistofexactlyE. Must contain literal text, another token, or a token decorator.Must not include.h or .hpp.
Header File property in Embedded Coder Dictionary, under Memory > Storage Class N.h∣N.h N.hN or R∣R RG, $U Model or subsystem that the data is associated with Must end with .h or.hpp.If Data Scope is set to Exported, must not resolve to the name of a file that is generated for the model, such as_model_.h or_model__types.h.
Header File property in data interface Embedded Coder Dictionary, under Functions > Function Customization Template None None N,N, N,R, $U Name of the function
Header File Name property in Embedded Coder Dictionary, under General None None R,R, R,U None
Source file Source files model configuration parameter RRRE E∣E ER, U∣None∣CannotconsistofexactlyU None Cannot consist of exactly UNoneCannotconsistofexactlyE. Must contain literal text, another token, or a token decorator. Must not include.c or .cpp.
Definition File property in Embedded Coder Dictionary, under Memory > Storage Class N.c∣None∣N.c None N.cNoneG, N,N, N,R,$U Model or subsystem that the data is associated with Must end with .c or .cpp.
Definition File property in data interface Embedded Coder Dictionary, under Functions > Function Customization Template None None N,N, N,R, $U Name of the function
Data file Data files model configuration parameter R_data∣None∣R_data None R_dataNoneR, $U None
Initialize/Terminate function Function Naming Rule property in service interface Embedded Coder Dictionary, under Execution > Initialize and Terminate Functions RRRN None M,M, M,N, R,R,R,U initialize for the initialization function of the component modelterminate for the termination function of the component model
Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Subcomponent Initialize and Terminate Functions (since R2024a) RRRN None M,M, M,N, R,R,R,U
Function Name property in Code Mappings editor Functions tab None None M,M, M,N, R,R,R,U This property does not support regular expression token decorators.
Periodic/aperiodic function Function Naming Rule property in service interface Embedded Coder Dictionary, under Execution > Periodic and Aperiodic Functions RRRN None M,M, M,N, R,R,R,U For periodic functions of the component model, step if there is only one periodic function, or step0,step1, step2, … if there are multiple. The code generator produces these functions if you select the Single output/update function model configuration parameter.For update functions of the component model, update if there is only one update function, or update0,update1, update2, … if there are multiple. The code generator produces these functions if you clear theSingle output/update function model configuration parameter.For output functions of the component model, output if there is only one output function, or output0,output1, output2, … if there are multiple. The code generator produces these functions if you clear theSingle output/update function model configuration parameter.For aperiodic functions of the component model, text derived from the control signal name or function-call Inport block name.For the reset function of the component model, the value of theEvent name parameter of the Event Listener block inside theReset Function block.
Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Subcomponent Periodic and Aperiodic Functions (since R2024a) RRRN None M,M, M,N, R,R,R,U
Function Name property in Code Mappings editor Functions tab None None M,M, M,N, R,R,R,U This property does not support regular expression token decorators.
Receiver service interface function Function Naming Rule property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Receiver get_$X$N N∣N NG, M,M, M,R,$U, $X Inport block name
Sender service interface function Function Naming Rule for Value property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Sender set_$X$N N∣N NG, M,M, M,R,$U, $X Outport block name
Function Naming Rule for Value by Reference property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Sender getref_$X$N N∣N NG, M,M, M,R,$U, $X Outport block name
Data transfer service interface function Receiver Function Naming Rule property in service interface Embedded Coder Dictionary, under Service Interfaces > Data Transfer get_$X$N N∣N NM, R,R, R,X Data transfer signal name, such asDataTransferAt__
Sender Function Naming Rule parameter in service interface Embedded Coder Dictionary, under Service Interfaces > Data Transfer set_$X$N N∣N NM, R,R, R,X Data transfer signal name, such asDataTransferAt__
Shared utility function Function Naming Rule property in service interface Embedded Coder Dictionary, under Internal > Shared Utility Functions NNNC C∣C CN, R,R, R,U Name of the function
Type name Type Name property in Embedded Coder Dictionary, under Memory > Storage Class RRRN$G$M None G,G, G,M, N,N,N,R,$U Model or subsystem that the data is associated with This property is visible only if you set the Storage Type property to Structured.
Instance name Instance Name property in Embedded Coder Dictionary, under Memory > Storage Class GGGN$M None G,G, G,M, N,N,N,R,$U Model or subsystem that the data is associated with This property is visible only if you set the Storage Type property to Structured.
Getter function Name of Getter property in Embedded Coder Dictionary, under Memory > Storage Class get_$N$M N∣N NM, R,R, R,U Associated data element This property is visible only if you set the Data Access property to Function, and the**Allowed Access** property to Read/Write orRead-only.
GetFunction property in the Code Mappings Editor Property Inspector get_$N None $N This property is visible only for a data element that has theGetSet storage class. This property does not support regular expression token decorators.For more information, seeAccess Data Through Functions with Storage Class GetSet.
Setter function Name of Setter property in Embedded Coder, under Memory > Storage Class set_$N$M N∣N NM, R,R, R,U Associated data element This property is visible only if you set the Data Access property to Function, the Access Mode property to Value, and the Allowed Access property to Read/Write orWrite-only.
SetFunction property in the Code Mappings Editor Property Inspector set_$N None $N This property is visible only for a data element that has theGetSet storage class. This property does not support regular expression token decorators.For more information, seeAccess Data Through Functions with Storage Class GetSet.

Limitations

These generated identifiers do not fully comply with the setting of theMaximum identifier length parameter:

See Also

Topics